Skip to content

Commit 5b5ad0d

Browse files
committed
Merge branch 'mtoff/4-config-sources' of github.com:DataDog/dd-trace-java into mtoff/4-config-sources
2 parents 2626c62 + d9fe333 commit 5b5ad0d

8 files changed

Lines changed: 108 additions & 22 deletions

File tree

dd-java-agent/agent-debugger/src/main/java/com/datadog/debugger/agent/DebuggerTransformer.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,11 @@
5959
import net.bytebuddy.description.type.TypeDescription;
6060
import net.bytebuddy.pool.TypePool;
6161
import org.objectweb.asm.ClassReader;
62+
import org.objectweb.asm.ClassVisitor;
6263
import org.objectweb.asm.ClassWriter;
64+
import org.objectweb.asm.MethodVisitor;
6365
import org.objectweb.asm.Opcodes;
66+
import org.objectweb.asm.commons.JSRInlinerAdapter;
6467
import org.objectweb.asm.tree.ClassNode;
6568
import org.objectweb.asm.tree.MethodNode;
6669
import org.objectweb.asm.tree.analysis.Analyzer;
@@ -487,9 +490,10 @@ private byte[] writeClassFile(
487490
classNode.version = Opcodes.V1_8;
488491
}
489492
ClassWriter writer = new SafeClassWriter(loader);
493+
ClassVisitor visitor = new JsrInliningClassVisitor(writer);
490494
LOGGER.debug("Generating bytecode for class: {}", Strings.getClassName(classFilePath));
491495
try {
492-
classNode.accept(writer);
496+
classNode.accept(visitor);
493497
} catch (Throwable t) {
494498
LOGGER.error("Cannot write classfile for class: {} Exception: ", classFilePath, t);
495499
reportInstrumentationFails(definitions, Strings.getClassName(classFilePath));
@@ -929,6 +933,26 @@ private static Path dumpClassFile(String className, byte[] classfileBuffer) {
929933
}
930934
}
931935

936+
/**
937+
* A {@link org.objectweb.asm.ClassVisitor} that uses {@link
938+
* org.objectweb.asm.commons.JSRInlinerAdapter} to remove JSR instructions and inlines the
939+
* referenced subroutines. This allows pre-Java 6 classes with finally blocks to be successfully
940+
* transformed. Without this an IllegalArgumentException for "JSR/RET are not supported with
941+
* computeFrames option" would be thrown when writing the transformed class.
942+
*/
943+
static class JsrInliningClassVisitor extends ClassVisitor {
944+
protected JsrInliningClassVisitor(ClassVisitor parent) {
945+
super(Opcodes.ASM9, parent);
946+
}
947+
948+
@Override
949+
public MethodVisitor visitMethod(
950+
int access, String name, String descriptor, String signature, String[] exceptions) {
951+
MethodVisitor mv = super.visitMethod(access, name, descriptor, signature, exceptions);
952+
return new JSRInlinerAdapter(mv, access, name, descriptor, signature, exceptions);
953+
}
954+
}
955+
932956
static class SafeClassWriter extends ClassWriter {
933957
private final ClassLoader classLoader;
934958

dd-java-agent/agent-debugger/src/test/java/com/datadog/debugger/agent/CapturedSnapshotTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,24 @@ public void veryOldClassFile() throws Exception {
275275
assertOneSnapshot(listener);
276276
}
277277

278+
/**
279+
* Ensure older pre-Java 6 class files with JSR/RET can be rewritten without "JSR/RET are not
280+
* supported with computeFrames option" exceptions being thrown.
281+
*/
282+
@Test
283+
public void veryOldClassFileWithJsrRet() throws Exception {
284+
final String CLASS_NAME = "antlr.Tool"; // compiled with jdk 1.2
285+
TestSnapshotListener listener = installMethodProbe(CLASS_NAME, "copyFile", null);
286+
Class<?> testClass = Class.forName(CLASS_NAME);
287+
assertNotNull(testClass);
288+
try {
289+
Reflect.onClass(testClass).create().call("copyFile", null, null);
290+
} catch (Throwable t) {
291+
// ignore
292+
}
293+
assertOneSnapshot(listener);
294+
}
295+
278296
@Test
279297
public void oldClass1_1() throws Exception {
280298
final String CLASS_NAME = "org.apache.commons.lang.BooleanUtils"; // compiled with jdk 1.1

dd-java-agent/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ def sharedShadowJar = tasks.register('sharedShadowJar', ShadowJar) {
184184
exclude(project(':dd-trace-api'))
185185
exclude(project(':internal-api'))
186186
exclude(project(':components:context'))
187+
exclude(project(':utils:config-utils'))
187188
exclude(project(':utils:time-utils'))
188189
exclude(dependency('org.slf4j::'))
189190
}

dd-java-agent/instrumentation/junit-5.3/gradle.lockfile

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -132,39 +132,39 @@ org.jspecify:jspecify:1.0.0=latestDepTestCompileClasspath
132132
org.junit.jupiter:junit-jupiter-api:5.12.2=testCompileClasspath,testRuntimeClasspath
133133
org.junit.jupiter:junit-jupiter-api:5.13.4=latest5TestCompileClasspath,latest5TestRuntimeClasspath
134134
org.junit.jupiter:junit-jupiter-api:5.3.0=compileClasspath
135-
org.junit.jupiter:junit-jupiter-api:6.0.0-RC2=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
135+
org.junit.jupiter:junit-jupiter-api:6.0.0-RC3=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
136136
org.junit.jupiter:junit-jupiter-engine:5.12.2=testCompileClasspath,testRuntimeClasspath
137137
org.junit.jupiter:junit-jupiter-engine:5.13.4=latest5TestCompileClasspath,latest5TestRuntimeClasspath
138-
org.junit.jupiter:junit-jupiter-engine:6.0.0-RC2=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
138+
org.junit.jupiter:junit-jupiter-engine:6.0.0-RC3=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
139139
org.junit.jupiter:junit-jupiter-params:5.12.2=testCompileClasspath,testRuntimeClasspath
140140
org.junit.jupiter:junit-jupiter-params:5.13.4=latest5TestCompileClasspath,latest5TestRuntimeClasspath
141-
org.junit.jupiter:junit-jupiter-params:6.0.0-RC2=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
141+
org.junit.jupiter:junit-jupiter-params:6.0.0-RC3=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
142142
org.junit.jupiter:junit-jupiter:5.12.2=testCompileClasspath,testRuntimeClasspath
143143
org.junit.jupiter:junit-jupiter:5.13.4=latest5TestCompileClasspath,latest5TestRuntimeClasspath
144-
org.junit.jupiter:junit-jupiter:6.0.0-RC2=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
144+
org.junit.jupiter:junit-jupiter:6.0.0-RC3=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
145145
org.junit.platform:junit-platform-commons:1.12.2=testCompileClasspath,testRuntimeClasspath
146146
org.junit.platform:junit-platform-commons:1.13.4=latest5TestCompileClasspath,latest5TestRuntimeClasspath
147147
org.junit.platform:junit-platform-commons:1.3.0=compileClasspath
148-
org.junit.platform:junit-platform-commons:6.0.0-RC2=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
148+
org.junit.platform:junit-platform-commons:6.0.0-RC3=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
149149
org.junit.platform:junit-platform-engine:1.12.2=testCompileClasspath,testRuntimeClasspath
150150
org.junit.platform:junit-platform-engine:1.13.4=latest5TestCompileClasspath,latest5TestRuntimeClasspath
151151
org.junit.platform:junit-platform-engine:1.3.0=compileClasspath
152-
org.junit.platform:junit-platform-engine:6.0.0-RC2=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
152+
org.junit.platform:junit-platform-engine:6.0.0-RC3=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
153153
org.junit.platform:junit-platform-launcher:1.12.2=testCompileClasspath,testRuntimeClasspath
154154
org.junit.platform:junit-platform-launcher:1.13.4=latest5TestCompileClasspath,latest5TestRuntimeClasspath
155155
org.junit.platform:junit-platform-launcher:1.3.0=compileClasspath
156-
org.junit.platform:junit-platform-launcher:6.0.0-RC2=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
156+
org.junit.platform:junit-platform-launcher:6.0.0-RC3=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
157157
org.junit.platform:junit-platform-runner:1.12.2=latestDepTestRuntimeClasspath,testRuntimeClasspath
158158
org.junit.platform:junit-platform-runner:1.13.4=latest5TestRuntimeClasspath
159159
org.junit.platform:junit-platform-suite-api:1.12.2=testRuntimeClasspath
160160
org.junit.platform:junit-platform-suite-api:1.13.4=latest5TestRuntimeClasspath
161-
org.junit.platform:junit-platform-suite-api:6.0.0-RC2=latestDepTestRuntimeClasspath
161+
org.junit.platform:junit-platform-suite-api:6.0.0-RC3=latestDepTestRuntimeClasspath
162162
org.junit.platform:junit-platform-suite-commons:1.12.2=latestDepTestRuntimeClasspath,testRuntimeClasspath
163163
org.junit.platform:junit-platform-suite-commons:1.13.4=latest5TestRuntimeClasspath
164164
org.junit:junit-bom:5.12.2=testCompileClasspath,testRuntimeClasspath
165165
org.junit:junit-bom:5.13.4=latest5TestCompileClasspath,latest5TestRuntimeClasspath
166166
org.junit:junit-bom:5.9.1=spotbugs
167-
org.junit:junit-bom:6.0.0-RC2=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
167+
org.junit:junit-bom:6.0.0-RC3=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
168168
org.mockito:mockito-core:4.4.0=latest5TestRuntimeClasspath,latestDepTestRuntimeClasspath,testRuntimeClasspath
169169
org.msgpack:jackson-dataformat-msgpack:0.9.6=latest5TestCompileClasspath,latest5TestRuntimeClasspath,latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
170170
org.msgpack:msgpack-core:0.9.6=latest5TestCompileClasspath,latest5TestRuntimeClasspath,latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath

dd-java-agent/instrumentation/junit-5.3/junit-5.8/gradle.lockfile

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -130,31 +130,31 @@ org.jctools:jctools-core:3.3.0=instrumentPluginClasspath,latestDepTestRuntimeCla
130130
org.jspecify:jspecify:1.0.0=latestDepTestCompileClasspath
131131
org.junit.jupiter:junit-jupiter-api:5.12.2=testCompileClasspath,testRuntimeClasspath
132132
org.junit.jupiter:junit-jupiter-api:5.8.0=compileClasspath
133-
org.junit.jupiter:junit-jupiter-api:6.0.0-RC2=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
133+
org.junit.jupiter:junit-jupiter-api:6.0.0-RC3=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
134134
org.junit.jupiter:junit-jupiter-engine:5.12.2=testCompileClasspath,testRuntimeClasspath
135135
org.junit.jupiter:junit-jupiter-engine:5.8.0=compileClasspath
136-
org.junit.jupiter:junit-jupiter-engine:6.0.0-RC2=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
136+
org.junit.jupiter:junit-jupiter-engine:6.0.0-RC3=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
137137
org.junit.jupiter:junit-jupiter-params:5.12.2=testCompileClasspath,testRuntimeClasspath
138-
org.junit.jupiter:junit-jupiter-params:6.0.0-RC2=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
138+
org.junit.jupiter:junit-jupiter-params:6.0.0-RC3=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
139139
org.junit.jupiter:junit-jupiter:5.12.2=testCompileClasspath,testRuntimeClasspath
140-
org.junit.jupiter:junit-jupiter:6.0.0-RC2=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
140+
org.junit.jupiter:junit-jupiter:6.0.0-RC3=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
141141
org.junit.platform:junit-platform-commons:1.12.2=testCompileClasspath,testRuntimeClasspath
142142
org.junit.platform:junit-platform-commons:1.8.0=compileClasspath
143-
org.junit.platform:junit-platform-commons:6.0.0-RC2=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
143+
org.junit.platform:junit-platform-commons:6.0.0-RC3=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
144144
org.junit.platform:junit-platform-engine:1.12.2=testCompileClasspath,testRuntimeClasspath
145145
org.junit.platform:junit-platform-engine:1.8.0=compileClasspath
146-
org.junit.platform:junit-platform-engine:6.0.0-RC2=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
146+
org.junit.platform:junit-platform-engine:6.0.0-RC3=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
147147
org.junit.platform:junit-platform-launcher:1.12.2=testCompileClasspath,testRuntimeClasspath
148148
org.junit.platform:junit-platform-launcher:1.8.0=compileClasspath
149-
org.junit.platform:junit-platform-launcher:6.0.0-RC2=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
149+
org.junit.platform:junit-platform-launcher:6.0.0-RC3=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
150150
org.junit.platform:junit-platform-runner:1.12.2=latestDepTestRuntimeClasspath,testRuntimeClasspath
151151
org.junit.platform:junit-platform-suite-api:1.12.2=testRuntimeClasspath
152-
org.junit.platform:junit-platform-suite-api:6.0.0-RC2=latestDepTestRuntimeClasspath
152+
org.junit.platform:junit-platform-suite-api:6.0.0-RC3=latestDepTestRuntimeClasspath
153153
org.junit.platform:junit-platform-suite-commons:1.12.2=latestDepTestRuntimeClasspath,testRuntimeClasspath
154154
org.junit:junit-bom:5.12.2=testCompileClasspath,testRuntimeClasspath
155155
org.junit:junit-bom:5.8.0=compileClasspath
156156
org.junit:junit-bom:5.9.1=spotbugs
157-
org.junit:junit-bom:6.0.0-RC2=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
157+
org.junit:junit-bom:6.0.0-RC3=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
158158
org.mockito:mockito-core:4.4.0=latestDepTestRuntimeClasspath,testRuntimeClasspath
159159
org.msgpack:jackson-dataformat-msgpack:0.9.6=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
160160
org.msgpack:msgpack-core:0.9.6=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath

dd-java-agent/instrumentation/junit-5.3/src/main/java/datadog/trace/instrumentation/junit5/ExecutionRequestFactory.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ public class ExecutionRequestFactory {
2929
*/
3030
private static final MethodHandle GET_CANCELLATION_TOKEN =
3131
METHOD_HANDLES.method(ExecutionRequest.class, "getCancellationToken");
32+
/*
33+
* From 6.0.0-RC3 onwards OutputDirectoryProvider is deprecated in favor of OutputDirectoryCreator
34+
*/
35+
private static final MethodHandle GET_OUTPUT_DIRECTORY_CREATOR =
36+
METHOD_HANDLES.method(ExecutionRequest.class, "getOutputDirectoryCreator");
3237

3338
private static final String[] CREATE_PARAMETER_TYPES =
3439
new String[] {
@@ -40,11 +45,48 @@ public class ExecutionRequestFactory {
4045
"org.junit.platform.engine.CancellationToken"
4146
};
4247

48+
private static final String[] CREATE_PARAMETER_TYPES_WITH_CREATOR =
49+
new String[] {
50+
"org.junit.platform.engine.TestDescriptor",
51+
"org.junit.platform.engine.EngineExecutionListener",
52+
"org.junit.platform.engine.ConfigurationParameters",
53+
"org.junit.platform.engine.OutputDirectoryCreator",
54+
"org.junit.platform.engine.support.store.NamespacedHierarchicalStore",
55+
"org.junit.platform.engine.CancellationToken"
56+
};
57+
4358
private static final BiFunction<ExecutionRequest, EngineExecutionListener, ExecutionRequest>
4459
EXECUTION_REQUEST_CREATE = createExecutionRequestHandle();
4560

4661
private static BiFunction<ExecutionRequest, EngineExecutionListener, ExecutionRequest>
4762
createExecutionRequestHandle() {
63+
// 6.0.0-RC3 and later
64+
if (GET_OUTPUT_DIRECTORY_CREATOR != null) {
65+
MethodHandle createMethod =
66+
METHOD_HANDLES.method(
67+
ExecutionRequest.class,
68+
m ->
69+
"create".equals(m.getName())
70+
&& m.getParameterCount() == 6
71+
&& Arrays.equals(
72+
Arrays.stream(m.getParameterTypes()).map(Class::getName).toArray(),
73+
CREATE_PARAMETER_TYPES_WITH_CREATOR));
74+
75+
return (request, listener) -> {
76+
Object creator = METHOD_HANDLES.invoke(GET_OUTPUT_DIRECTORY_CREATOR, request);
77+
Object store = METHOD_HANDLES.invoke(GET_STORE, request);
78+
Object cancellationToken = METHOD_HANDLES.invoke(GET_CANCELLATION_TOKEN, request);
79+
return METHOD_HANDLES.invoke(
80+
createMethod,
81+
request.getRootTestDescriptor(),
82+
listener,
83+
request.getConfigurationParameters(),
84+
creator,
85+
store,
86+
cancellationToken);
87+
};
88+
}
89+
4890
// 6.0.0-M2 and later
4991
if (GET_CANCELLATION_TOKEN != null) {
5092
MethodHandle createMethod =

gradle/dependencies.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ final class CachedData {
2323
exclude(project(':remote-config:remote-config-api'))
2424
exclude(project(':remote-config:remote-config-core'))
2525
exclude(project(':telemetry'))
26+
exclude(project(':utils:config-utils'))
2627
exclude(project(':utils:container-utils'))
2728
exclude(project(':utils:socket-utils'))
2829
exclude(project(':utils:time-utils'))

utils/config-utils/src/main/java/datadog/trace/bootstrap/config/provider/ConfigProvider.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ private static <T> void reportDefault(String key, T defaultValue) {
629629
}
630630

631631
/** Helper class to store resolved configuration values with their metadata */
632-
static class ConfigValueResolver<T> {
632+
static final class ConfigValueResolver<T> {
633633
final T value;
634634
final ConfigOrigin origin;
635635
final int seqId;
@@ -662,8 +662,8 @@ void reReportToCollector(String key, int finalSeqId) {
662662
}
663663
}
664664

665-
/** Helper class for methods that merge maps from multiple sources (e.g., getMergedMap) */
666-
private static class ConfigMergeResolver {
665+
/** Helper class for methods that merge map values from multiple sources (e.g., getMergedMap) */
666+
private static final class ConfigMergeResolver {
667667
private final Map<String, String> mergedValue;
668668
private ConfigOrigin currentOrigin;
669669

0 commit comments

Comments
 (0)