-
Couldn't load subscription status.
- Fork 1k
make rmi instrumentation indy-compatible + add module opener #12585
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
Merged
Merged
Changes from 9 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
a7fdf1a
make rmi instrumentation indy-compatible
SylvainJuge dd05ff3
Merge branch 'main' of github.com:open-telemetry/opentelemetry-java-i…
SylvainJuge 1a9a687
add module opener
SylvainJuge 31fb5c2
enhance javadoc
SylvainJuge 6e46140
add TODO for current module open impl.
SylvainJuge 101710d
fix logging
SylvainJuge 9c251f0
use module opener only when supported
SylvainJuge f381c67
Merge branch 'main' of github.com:open-telemetry/opentelemetry-java-i…
SylvainJuge 9c9f775
Merge branch 'main' of github.com:open-telemetry/opentelemetry-java-i…
SylvainJuge de48095
share module opening between indy and inline
laurit d64d5fd
Update javaagent-tooling/javaagent-tooling-java9/src/main/java/io/ope…
laurit 377a301
Update javaagent-tooling/javaagent-tooling-java9/src/main/java/io/ope…
laurit 0f20c60
Merge pull request #3 from laurit/rmi-open
SylvainJuge bd70195
add TODO + spotless reformat
SylvainJuge b14f5e0
compile before push I should
SylvainJuge ab4662c
spotless again
SylvainJuge 3235f3a
do not use module opener for java < 9
SylvainJuge aa23db0
remove obsolete comment
SylvainJuge 66cc354
remove obsolete comment
SylvainJuge e7bc7bd
Merge branch 'main' of github.com:open-telemetry/opentelemetry-java-i…
SylvainJuge 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
81 changes: 81 additions & 0 deletions
81
...avaagent-tooling-java9/src/main/java/io/opentelemetry/javaagent/tooling/ModuleOpener.java
This file contains hidden or 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,81 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.javaagent.tooling; | ||
|
|
||
| import static java.util.logging.Level.FINE; | ||
| import static java.util.logging.Level.WARNING; | ||
|
|
||
| import java.lang.instrument.Instrumentation; | ||
| import java.util.Collection; | ||
| import java.util.Collections; | ||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Set; | ||
| import java.util.logging.Logger; | ||
|
|
||
| /** | ||
| * Module opener provides ability to open JPMS modules and allows instrumentation classloader to | ||
| * access module contents without requiring JVM arguments modification. <br> | ||
| * Usage of this class must be guarded with an {@code net.bytebuddy.utility.JavaModule#isSupported} | ||
| * check as it's compiled for Java 9+, otherwise an {@link UnsupportedClassVersionError} will be | ||
| * thrown for java 8. | ||
| */ | ||
| public class ModuleOpener { | ||
SylvainJuge marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| private static final Logger logger = Logger.getLogger(ModuleOpener.class.getName()); | ||
|
|
||
| private ModuleOpener() {} | ||
|
|
||
| /** | ||
| * Opens JPMS module to a class loader unnamed module | ||
| * | ||
| * @param classFromTargetModule class from target module | ||
| * @param openTo class loader to open module for | ||
| * @param packagesToOpen packages to open | ||
| */ | ||
| public static void open( | ||
| Instrumentation instrumentation, | ||
| Class<?> classFromTargetModule, | ||
| ClassLoader openTo, | ||
| Collection<String> packagesToOpen) { | ||
|
|
||
| Module targetModule = classFromTargetModule.getModule(); | ||
| Module openToModule = openTo.getUnnamedModule(); | ||
| Set<Module> openToModuleSet = Collections.singleton(openToModule); | ||
| Map<String, Set<Module>> missingOpens = new HashMap<>(); | ||
| for (String packageName : packagesToOpen) { | ||
| if (!targetModule.isOpen(packageName, openToModule)) { | ||
| missingOpens.put(packageName, openToModuleSet); | ||
| logger.log( | ||
| FINE, | ||
| "Exposing package '{0}' in module '{1}' to module '{2}'", | ||
| new Object[] {packageName, targetModule, openToModule}); | ||
| } | ||
| } | ||
| if (missingOpens.isEmpty()) { | ||
| return; | ||
| } | ||
|
|
||
| if (!instrumentation.isModifiableModule(targetModule)) { | ||
| logger.log(WARNING, "Module '{0}' can't be modified", targetModule); | ||
| return; | ||
| } | ||
|
|
||
| try { | ||
| instrumentation.redefineModule( | ||
| targetModule, | ||
| Collections.<Module>emptySet(), // reads | ||
| Collections.<String, Set<Module>>emptyMap(), // exports | ||
| missingOpens, // opens | ||
| Collections.<Class<?>>emptySet(), // uses | ||
| Collections.<Class<?>, List<Class<?>>>emptyMap() // provides | ||
| ); | ||
| } catch (Exception e) { | ||
| logger.log(WARNING, "unable to redefine module", e); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or 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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.