Skip to content

Commit 9f28617

Browse files
committed
Optimizing the type pool of byte-buddy (fix #11460)
1 parent c94b409 commit 9f28617

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

apm-sniffer/apm-agent/src/main/java/org/apache/skywalking/apm/agent/SkyWalkingAgent.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import java.util.Collections;
2424
import java.util.List;
2525
import java.util.Map;
26+
import java.util.concurrent.ConcurrentHashMap;
27+
2628
import net.bytebuddy.ByteBuddy;
2729
import net.bytebuddy.agent.builder.AgentBuilder;
2830
import net.bytebuddy.agent.builder.SWAgentBuilderDefault;
@@ -158,7 +160,8 @@ private static AgentBuilder newAgentBuilder() {
158160

159161
SWNativeMethodStrategy nativeMethodStrategy = new SWNativeMethodStrategy(NAME_TRAIT);
160162
return new SWAgentBuilderDefault(byteBuddy, nativeMethodStrategy)
161-
.with(AgentBuilder.DescriptionStrategy.Default.POOL_FIRST);
163+
.with(AgentBuilder.DescriptionStrategy.Default.POOL_FIRST)
164+
.with(new AgentBuilder.PoolStrategy.WithTypePoolCache.Simple(new ConcurrentHashMap<>()));
162165
}
163166

164167
private static class Transformer implements AgentBuilder.Transformer {

apm-sniffer/bytebuddy-patch/src/test/java/org/apache/skywalking/apm/agent/bytebuddy/cases/AbstractInterceptTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
import java.security.ProtectionDomain;
5252
import java.util.Arrays;
5353
import java.util.List;
54+
import java.util.concurrent.ConcurrentHashMap;
5455

5556
public class AbstractInterceptTest {
5657
public static final String BIZ_FOO_CLASS_NAME = "org.apache.skywalking.apm.agent.bytebuddy.biz.BizFoo";
@@ -174,6 +175,7 @@ protected AgentBuilder newAgentBuilder(String nameTrait) {
174175
return new SWAgentBuilderDefault(byteBuddy, new SWNativeMethodStrategy(nameTrait))
175176
.with(AgentBuilder.RedefinitionStrategy.RETRANSFORMATION)
176177
.with(AgentBuilder.DescriptionStrategy.Default.POOL_FIRST)
178+
.with(new AgentBuilder.PoolStrategy.WithTypePoolCache.Simple(new ConcurrentHashMap<>()))
177179
.with(new SWClassFileLocator(ByteBuddyAgent.install(), getClassLoader()));
178180
}
179181

apm-sniffer/bytebuddy-patch/src/test/java/org/apache/skywalking/apm/agent/bytebuddy/cases/ReTransform2Test.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,11 @@ public void testInterceptConstructor() throws Exception {
5454
checkMethodInterceptor(SAY_HELLO_METHOD, 2);
5555

5656
// do retransform
57-
reTransform(instrumentation, BizFoo.class);
57+
int retransformCount = 30;
58+
for (int i = 0; i < retransformCount; i++) {
59+
reTransform(instrumentation, BizFoo.class);
60+
// reTransform(instrumentation, ProjectService.class);
61+
}
5862

5963
// test again
6064
callBizFoo(2);

0 commit comments

Comments
 (0)