-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix redefinition failure on openj9 (open-telemetry#5009)
* Fix redefinition failure on openj9 * isntead of remembering the list of interfaces the class has remember whether it has any of the virutal field marker interfaces * address review comment * ensure virtual field detection works when internal-reflection instrumentation is disabled
- Loading branch information
Showing
4 changed files
with
55 additions
and
8 deletions.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
instrumentation/internal/internal-reflection/bootstrap/build.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
plugins { | ||
id("otel.javaagent-bootstrap") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
...nt-bootstrap/src/main/java/io/opentelemetry/javaagent/bootstrap/VirtualFieldDetector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.bootstrap; | ||
|
||
import io.opentelemetry.instrumentation.api.cache.Cache; | ||
import java.util.Arrays; | ||
|
||
/** Helper class for detecting whether given class has virtual fields. */ | ||
public final class VirtualFieldDetector { | ||
|
||
private static final Cache<Class<?>, Boolean> classesWithVirtualFields = Cache.weak(); | ||
|
||
private VirtualFieldDetector() {} | ||
|
||
/** | ||
* Detect whether given class has virtual fields. This method looks for virtual fields only from | ||
* the specified class not its super classes. | ||
* | ||
* @param clazz a class | ||
* @return true if given class has virtual fields | ||
*/ | ||
public static boolean hasVirtualFields(Class<?> clazz) { | ||
// clazz.getInterfaces() needs to be called before reading from classesWithVirtualFields | ||
// as the call to clazz.getInterfaces() triggers adding clazz to that map via instrumentation | ||
// calling VirtualFieldDetector#markVirtualFieldsPresent() from Class#getInterfaces() | ||
Class<?>[] interfaces = clazz.getInterfaces(); | ||
// to avoid breaking in case internal-reflection instrumentation is disabled check whether | ||
// interfaces array contains virtual field marker interface | ||
if (Arrays.asList(interfaces).contains(VirtualFieldInstalledMarker.class)) { | ||
return true; | ||
} | ||
return classesWithVirtualFields.get(clazz) != null; | ||
} | ||
|
||
public static void markVirtualFieldsPresent(Class<?> clazz) { | ||
classesWithVirtualFields.put(clazz, Boolean.TRUE); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters