-
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 18 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
82 changes: 0 additions & 82 deletions
82
...ntelemetry/javaagent/instrumentation/rmi/context/jpms/ExposeRmiModuleInstrumentation.java
This file was deleted.
Oops, something went wrong.
32 changes: 0 additions & 32 deletions
32
...pentelemetry/javaagent/instrumentation/rmi/context/jpms/RmiJpmsInstrumentationModule.java
This file was deleted.
Oops, something went wrong.
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
84 changes: 84 additions & 0 deletions
84
...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,84 @@ | ||
| /* | ||
| * 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 io.opentelemetry.javaagent.bootstrap.AgentClassLoader; | ||
| import java.lang.instrument.Instrumentation; | ||
| import java.util.Collection; | ||
| import java.util.Collections; | ||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
| import java.util.Set; | ||
| import java.util.logging.Logger; | ||
| import javax.annotation.Nullable; | ||
| import net.bytebuddy.description.type.PackageDescription; | ||
| import net.bytebuddy.dynamic.loading.ClassInjector; | ||
| import net.bytebuddy.utility.JavaModule; | ||
|
|
||
| /** | ||
| * 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()); | ||
|
|
||
| // AgentClassLoader is in unnamed module of the bootstrap loader | ||
| private static final JavaModule UNNAMED_BOOT_MODULE = JavaModule.ofType(AgentClassLoader.class); | ||
|
|
||
| private ModuleOpener() {} | ||
|
|
||
| /** | ||
| * Opens JPMS module to a class loader unnamed module | ||
| * | ||
| * @param targetModule target module | ||
| * @param openTo class loader to open module for, {@literal null} to use the unnamed module of | ||
| * bootstrap classloader. | ||
| * @param packagesToOpen packages to open | ||
| */ | ||
| public static void open( | ||
| Instrumentation instrumentation, | ||
| JavaModule targetModule, | ||
| @Nullable ClassLoader openTo, | ||
| Collection<String> packagesToOpen) { | ||
|
|
||
| JavaModule openToModule = | ||
| openTo != null ? JavaModule.of(openTo.getUnnamedModule()) : UNNAMED_BOOT_MODULE; | ||
| Set<JavaModule> openToModuleSet = Collections.singleton(openToModule); | ||
| Map<String, Set<JavaModule>> missingOpens = new HashMap<>(); | ||
| for (String packageName : packagesToOpen) { | ||
| if (!targetModule.isOpened(new PackageDescription.Simple(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; | ||
| } | ||
|
|
||
| try { | ||
| ClassInjector.UsingInstrumentation.redefineModule( | ||
| instrumentation, | ||
| targetModule, | ||
| Collections.emptySet(), | ||
| Collections.emptyMap(), | ||
| missingOpens, | ||
| Collections.emptySet(), | ||
| Collections.emptyMap()); | ||
| } catch (Exception e) { | ||
| logger.log(WARNING, "Failed to redefine module '" + targetModule.getActualName() + "'", 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.
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.