Skip to content

Commit

Permalink
Support spring-boot-devtoools reloadable classlaoder
Browse files Browse the repository at this point in the history
  • Loading branch information
amarziali committed Aug 6, 2024
1 parent 60ddc9e commit cce2b0d
Show file tree
Hide file tree
Showing 10 changed files with 237 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package datadog.trace.bootstrap.instrumentation.classloading;

@FunctionalInterface
public interface MemoizerResetter {
void reset();

abstract class Supplier {
private static volatile MemoizerResetter SUPPLIER;

public static void reset() {
if (SUPPLIER != null) {
SUPPLIER.reset();
}
}

public static synchronized void registerIfAbsent(MemoizerResetter supplier) {
if (SUPPLIER == null) {
SUPPLIER = supplier;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import datadog.trace.agent.tooling.bytebuddy.iast.TaintableRedefinitionStrategyListener;
import datadog.trace.agent.tooling.bytebuddy.matcher.DDElementMatchers;
import datadog.trace.agent.tooling.bytebuddy.memoize.MemoizedMatchers;
import datadog.trace.agent.tooling.bytebuddy.memoize.Memoizer;
import datadog.trace.agent.tooling.bytebuddy.outline.TypePoolFacade;
import datadog.trace.agent.tooling.usm.UsmExtractorImpl;
import datadog.trace.agent.tooling.usm.UsmMessageFactoryImpl;
Expand Down Expand Up @@ -109,6 +110,7 @@ public static ClassFileTransformer installBytebuddyAgent(

if (InstrumenterConfig.get().isResolverMemoizingEnabled()) {
MemoizedMatchers.registerAsSupplier();
Memoizer.registerAsSupplier();
} else {
DDElementMatchers.registerAsSupplier();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import datadog.trace.api.InstrumenterConfig;
import datadog.trace.api.cache.DDCache;
import datadog.trace.api.cache.DDCaches;
import datadog.trace.bootstrap.instrumentation.classloading.MemoizerResetter;
import de.thetaphi.forbiddenapis.SuppressForbidden;
import java.util.ArrayList;
import java.util.BitSet;
Expand Down Expand Up @@ -91,6 +92,10 @@ public static void resetState() {
}
}

public static void registerAsSupplier() {
MemoizerResetter.Supplier.registerIfAbsent(Memoizer::resetState);
}

public static void clear() {
memos.clear();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@
0 org.springframework.boot.context.embedded.EmbeddedWebApplicationContext
0 org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer$*
0 org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedWebappClassLoader
0 org.springframework.boot.devtools.restart.classloader.RestartClassLoader
0 org.springframework.boot.web.embedded.netty.NettyWebServer$*
0 org.springframework.boot.web.embedded.tomcat.TomcatEmbeddedWebappClassLoader
0 org.springframework.boot.web.embedded.tomcat.TomcatWebServer$1
Expand Down
23 changes: 21 additions & 2 deletions dd-java-agent/instrumentation/spring-boot/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,23 @@ muzzle {
module = 'spring-boot'
versions = "[1.3.0.RELEASE,3)"
}
pass {
group = 'org.springframework.boot'
module = 'spring-boot-devtools'
versions = "[1.3.0.RELEASE,3)"
}
pass {
group = 'org.springframework.boot'
module = 'spring-boot'
versions = "[3,)"
javaVersion = "17"
}
pass {
group = 'org.springframework.boot'
module = 'spring-boot-devtools'
versions = "[3,)"
javaVersion = "17"
}
}

apply from: "$rootDir/gradle/java.gradle"
Expand All @@ -39,16 +50,24 @@ dependencies {
implementation project(':dd-java-agent:instrumentation:span-origin')

compileOnly group: 'org.springframework.boot', name: 'spring-boot', version: '1.3.0.RELEASE'
compileOnly group: 'org.springframework.boot', name: 'spring-boot-devtools', version: '1.3.0.RELEASE'
testImplementation group: 'org.springframework.boot', name: 'spring-boot', version: '1.3.0.RELEASE'
testImplementation group: 'org.springframework.boot', name: 'spring-boot-devtools', version: '1.3.0.RELEASE'
testImplementation project(':dd-java-agent:instrumentation:trace-annotation')
boot1LatestDepTestImplementation group: 'org.springframework.boot', name: 'spring-boot', version: '1.+'
boot1LatestDepTestImplementation group: 'org.springframework.boot', name: 'spring-boot-devtools', version: '1.+'
boot1LatestDepForkedTestImplementation group: 'org.springframework.boot', name: 'spring-boot', version: '1.+'
boot2TestImplementation group: 'org.springframework.boot', name: 'spring-boot', version: '2.0.0.RELEASE'
boot2TestImplementation group: 'org.springframework.boot', name: 'spring-boot-devtools', version: '2.0.0.RELEASE'
boot2ForkedTestImplementation group: 'org.springframework.boot', name: 'spring-boot', version: '2.0.0.RELEASE'
boot2LatestDepTestImplementation group: 'org.springframework.boot', name: 'spring-boot', version: '1.+'
boot2LatestDepForkedTestImplementation group: 'org.springframework.boot', name: 'spring-boot', version: '1.+'
boot2LatestDepTestImplementation group: 'org.springframework.boot', name: 'spring-boot', version: '2.+'
boot2LatestDepTestImplementation group: 'org.springframework.boot', name: 'spring-boot-devtools', version: '2.+'
boot2LatestDepForkedTestImplementation group: 'org.springframework.boot', name: 'spring-boot', version: '2.+'
boot3TestImplementation group: 'org.springframework.boot', name: 'spring-boot', version: '3.0.0'
boot3TestImplementation group: 'org.springframework.boot', name: 'spring-boot-devtools', version: '3.0.0'
boot3ForkedTestImplementation group: 'org.springframework.boot', name: 'spring-boot', version: '3.0.0'
latestDepTestImplementation group: 'org.springframework.boot', name: 'spring-boot', version: '+'
latestDepTestImplementation group: 'org.springframework.boot', name: 'spring-boot-devtools', version: '+'
latestDepForkedTestImplementation group: 'org.springframework.boot', name: 'spring-boot', version: '+'
latestDepTestImplementation group: 'org.springframework.boot', name: 'spring-boot-starter-logging', version: '+'
latestDepForkedTestImplementation group: 'org.springframework.boot', name: 'spring-boot-starter-logging', version: '+'
Expand Down
Loading

0 comments on commit cce2b0d

Please sign in to comment.