Skip to content

Move jpms clearance advice to bootstrap #8204

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
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dd-java-agent/agent-bootstrap/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ compileMain_java11Java.configure {
dependencies {
main_java11CompileOnly project(':internal-api')
main_java11CompileOnly sourceSets.main.output
main_java11CompileOnly libs.bytebuddy
Copy link
Contributor

@mcculls mcculls Jan 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a small bit of risk here that by adding this dependency someone in the future could depend on a byte-buddy class elsewhere in this module and expect it to be loadable from the bootstrap class-path. Only advice and helpers are going to work here because they are not directly loaded (their bytecode is read and then they're injected into the target class-loader.)

If we wanted to remove that small risk then the other option would be to create a JPMS instrumentation project, which other instrumentations can then depend on.

In the future we should look at separating advice+helpers out more cleanly from instrumentation declarations, because that helps avoid accidental coupling at build-time and makes it easier to re-use them.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO a separate module might be the best solution, as it might be somewhat difficult for a dev to realize that he should not use byte-buddy classes in agent-bootstrap (but it can be done as a future improvement).

}

jar {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package datadog.trace.instrumentation.mule4;
package datadog.trace.bootstrap.instrumentation.jpms;

import datadog.trace.api.GenericClassValue;
import java.util.concurrent.atomic.AtomicBoolean;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package datadog.trace.instrumentation.mule4;
package datadog.trace.bootstrap.instrumentation.jpms;

import static datadog.trace.instrumentation.mule4.JpmsAdvisingHelper.ALREADY_PROCESSED_CACHE;
import static datadog.trace.bootstrap.instrumentation.jpms.JpmsAdvisingHelper.ALREADY_PROCESSED_CACHE;

import net.bytebuddy.asm.Advice;
import net.bytebuddy.implementation.bytecode.assign.Assigner;

/**
* This advice can be used by any instrumentation needing that the instrumented class export its
* package to the unnamed module (where our things resides). This ensures that an instrumentation
* will grant visibility to that class.
*/
public class JpmsClearanceAdvice {
@Advice.OnMethodExit(suppress = Throwable.class)
public static void openOnReturn(@Advice.This(typing = Assigner.Typing.DYNAMIC) Object self) {
Expand Down
23 changes: 0 additions & 23 deletions dd-java-agent/instrumentation/mule-4/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,6 @@ configurations.all {
}

sourceSets {
main_java11 {
java.srcDirs "${project.projectDir}/src/main/java11"
}
test {
output.dir("$buildDir/generated-resources/test", builtBy: 'generateAppResources')
}
Expand All @@ -104,20 +101,6 @@ sourceSets {
}
}

compileMain_java11Java.configure {
setJavaVersion(it, 11)
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

jar {
from sourceSets.main_java11.output
}

forbiddenApisMain_java11 {
failOnMissingClasses = false
}

tasks.named("compileTestGroovy").configure {
dependsOn 'mvnPackage', 'extractMuleServices'
}
Expand All @@ -138,13 +121,7 @@ tasks.named("compileLatestDepForkedTestJava").configure {
dependencies {
compileOnly group: 'org.mule.runtime', name: 'mule-core', version: muleVersion
compileOnly group: 'org.mule.runtime', name: 'mule-tracer-customization-impl', version: muleVersion
compileOnly sourceSets.main_java11.output

main_java11CompileOnly project(':internal-api')
main_java11CompileOnly project(':dd-java-agent:agent-tooling')
main_java11CompileOnly project(':dd-java-agent:agent-bootstrap')

testImplementation sourceSets.main_java11.output
testImplementation project(':dd-java-agent:instrumentation:aws-common')
testImplementation project(':dd-java-agent:instrumentation:reactor-core-3.1')
testImplementation project(':dd-java-agent:instrumentation:reactive-streams')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,6 @@ public String[] knownMatchingTypes() {
};
}

@Override
public String[] helperClassNames() {
return new String[] {
packageName + ".JpmsAdvisingHelper",
};
}

@Override
public Reference[] additionalMuzzleReferences() {
return new Reference[] {
Expand All @@ -54,6 +47,7 @@ public Reference[] additionalMuzzleReferences() {
@Override
public void methodAdvice(MethodTransformer transformer) {
// it does not work with typeInitializer()
transformer.applyAdvice(isConstructor(), packageName + ".JpmsClearanceAdvice");
transformer.applyAdvice(
isConstructor(), "datadog.trace.bootstrap.instrumentation.jpms.JpmsClearanceAdvice");
}
}
Loading