-
Notifications
You must be signed in to change notification settings - Fork 909
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix redefinition failure on openj9 #5009
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
a83ef40
Fix redefinition failure on openj9
laurit 98e0016
isntead of remembering the list of interfaces the class has remember …
laurit 7bec956
address review comment
laurit b7c7b8f
ensure virtual field detection works when internal-reflection instrum…
laurit File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
35 changes: 35 additions & 0 deletions
35
...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,35 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.bootstrap; | ||
|
||
import io.opentelemetry.instrumentation.api.cache.Cache; | ||
|
||
/** 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() | ||
clazz.getInterfaces(); | ||
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ClassValue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As ClassValue is not mutable, it works best if you can compute the value on first use. Here we can't really compute the value, so the best we could do would be to use a mutable object as value of ClassValue, initialize it to false, and update it when the actual value is known. With current solution we can ignore the classes that don't have virtual fields, with ClassValue we would probably end up initializing a ClassValue for these too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
makes sense, thx!