-
Notifications
You must be signed in to change notification settings - Fork 329
Add Java 26 support to CI Visibility #10839
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
Open
daniel-mohedano
wants to merge
10
commits into
master
Choose a base branch
from
daniel.mohedano/java26-support-module-redefinition
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
2d8960b
fix: module redefinition to support dd-javac-plugin on jdk26
daniel-mohedano fd887e0
chore: remove ignore to run MavenSmokeTest on JDK26
daniel-mohedano ce0dcf3
fix: update resource project pom to support JDK26
daniel-mohedano d3ad1b1
Merge branch 'master' into daniel.mohedano/java26-support-module-rede…
daniel-mohedano 34053f5
chore: spotless
daniel-mohedano 25dca90
fix: renaming
daniel-mohedano 1869284
fix: fully qualify classes
daniel-mohedano c30dfe5
chore: spotless
daniel-mohedano 082abbf
Merge branch 'master' into daniel.mohedano/java26-support-module-rede…
daniel-mohedano adb3df5
fix: pr suggestions
daniel-mohedano 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
65 changes: 65 additions & 0 deletions
65
...-visibility/src/main/java/datadog/trace/civisibility/compiler/CompilerModuleExporter.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,65 @@ | ||
| package datadog.trace.civisibility.compiler; | ||
|
|
||
| import datadog.trace.util.JDK9ModuleAccess; | ||
| import java.lang.instrument.ClassFileTransformer; | ||
| import java.lang.instrument.Instrumentation; | ||
| import java.security.ProtectionDomain; | ||
| import java.util.concurrent.ConcurrentHashMap; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| /** | ||
| * Exports jdk.compiler internal packages to the classloader that loads dd-javac-plugin. | ||
| * | ||
| * <p>On JDK 16+ (strong encapsulation), dd-javac-plugin's CompilerModuleOpener uses burningwave to | ||
| * export these packages. On JDK 26+, burningwave fails due to Unsafe restrictions (JEP 471/498). | ||
| * This transformer intercepts dd-javac-plugin class loading and does the export using | ||
| * Instrumentation.redefineModule() instead. | ||
| * | ||
| * <p>Each Maven compilation step (compile, testCompile) may use a different classloader, so we | ||
| * track which classloaders have already been exported to and re-export for new ones. | ||
| */ | ||
| public class CompilerModuleExporter implements ClassFileTransformer { | ||
|
|
||
| private static final Logger LOGGER = LoggerFactory.getLogger(CompilerModuleExporter.class); | ||
|
|
||
| private static final String COMPILER_PLUGIN_CLASS_PREFIX = "datadog/compiler/"; | ||
| private static final String[] COMPILER_PACKAGES = { | ||
| "com.sun.tools.javac.api", | ||
| "com.sun.tools.javac.code", | ||
| "com.sun.tools.javac.comp", | ||
| "com.sun.tools.javac.tree", | ||
| "com.sun.tools.javac.util" | ||
| }; | ||
|
|
||
| private final Instrumentation inst; | ||
| private final ConcurrentHashMap<ClassLoader, Boolean> exportedClassLoaders = | ||
| new ConcurrentHashMap<>(); | ||
|
|
||
| public CompilerModuleExporter(Instrumentation inst) { | ||
| this.inst = inst; | ||
| } | ||
|
|
||
| @Override | ||
| public byte[] transform( | ||
| ClassLoader loader, | ||
| String className, | ||
| Class<?> classBeingRedefined, | ||
| ProtectionDomain protectionDomain, | ||
| byte[] classfileBuffer) { | ||
| if (loader != null && className != null && className.startsWith(COMPILER_PLUGIN_CLASS_PREFIX)) { | ||
| exportedClassLoaders.computeIfAbsent(loader, this::exportJdkCompilerModule); | ||
| } | ||
| return null; // no bytecode modification | ||
| } | ||
|
|
||
| private Boolean exportJdkCompilerModule(ClassLoader loader) { | ||
| try { | ||
| JDK9ModuleAccess.exportModuleToUnnamedModule(inst, "jdk.compiler", COMPILER_PACKAGES, loader); | ||
| LOGGER.debug("Exported jdk.compiler to classloader {}", loader); | ||
| } catch (Throwable e) { | ||
| LOGGER.debug("Could not export jdk.compiler packages for compiler plugin", e); | ||
| } | ||
| return Boolean.TRUE; | ||
| } | ||
| } |
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
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.
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.
Can
java.lang.Modulebe imported so that we don't have to specify its full name every time?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.
I followed the approach that was already in use in the file out of caution, although adding the imports doesn't seem to cause any failures/side effects. @mcculls might have better context here as he did the original implementation for the class