Open SongTing0711 opened 1 month ago
Did you take a thread dump? Maybe you intercept a method and invoke the proxy again? Or you lock the same object from different threads.
Did you take a thread dump? Maybe you intercept a method and invoke the proxy again? Or you lock the same object from different threads.
Perhaps so, I tried to configure the class that was not enhanced, and the result was successful. However, this is not safe. I tried the following code again, hoping to block the classes that have already been enhanced by cglib, but it still hasn't been blocked why? private static class InnerTransformer implements AgentBuilder.Transformer { @Override public DynamicType.Builder<?> transform(DynamicType.Builder<?> builder, TypeDescription typeDescription, ClassLoader classLoader, JavaModule module, ProtectionDomain protectionDomain) { return builder.visit(Advice.to(MethodServiceAdvice.class) .on(ElementMatchers.not(ElementMatchers.isConstructor()) .and(ElementMatchers .noneOf(ElementMatchers.hasSuperType(ElementMatchers.named("StaticApplicationContext")))) .and(ElementMatchers.not(ElementMatchers.isTypeInitializer())) .and(ElementMatchers.not(ElementMatchers.isSetter())) .and(ElementMatchers.not(ElementMatchers.isGetter())) .and(ElementMatchers.not(ElementMatchers.nameStartsWith("net.bytebuddy.generated"))) .and(ElementMatchers.not(ElementMatchers.nameContains("EnhancerBySpringCGLIB"))) .and(ElementMatchers.not(ElementMatchers.nameContains("$$"))) .and(ElementMatchers.not(ElementMatchers.nameContains("FastClassByCGLIB"))) .and(ElementMatchers.not(ElementMatchers.nameContains("MethodInterceptor"))))); } }
take a thread dump
I tried to take a thread dump, but the PID of tomcat kept changing, so I couldn't get it
You can use jps to find it.
You can use jps to find it. I used JPS, but you can see that the displayed PID keeps changing
![]()
You can use jps to find it. I used JPS, but you can see that the displayed PID keeps changing
![]()
Can you take a look at why the filtering above doesn't work
private static class InnerTransformer implements AgentBuilder.Transformer { @OverRide public DynamicType.Builder transform(DynamicType.Builder builder, TypeDescription typeDescription, ClassLoader classLoader, JavaModule module, ProtectionDomain protectionDomain) { return builder.visit(Advice.to(MethodServiceAdvice.class) .on(ElementMatchers.not(ElementMatchers.isConstructor()) .and(ElementMatchers .noneOf(ElementMatchers.hasSuperType(ElementMatchers.named("StaticApplicationContext")))) .and(ElementMatchers.not(ElementMatchers.isTypeInitializer())) .and(ElementMatchers.not(ElementMatchers.isSetter())) .and(ElementMatchers.not(ElementMatchers.isGetter())) .and(ElementMatchers.not(ElementMatchers.nameStartsWith("net.bytebuddy.generated"))) .and(ElementMatchers.not(ElementMatchers.nameContains("EnhancerBySpringCGLIB"))) .and(ElementMatchers.not(ElementMatchers.nameContains("$$"))) .and(ElementMatchers.not(ElementMatchers.nameContains("FastClassByCGLIB"))) .and(ElementMatchers.not(ElementMatchers.nameContains("MethodInterceptor"))))); } }
I used JPS, but you can see that the displayed PID keeps changing
Are those processes short lived? If so, it's hard to hit a target. Maybe you should change JAVA_TOOL_OPTIONS
to add your agent when any Java process is starting up?
Can you take a look at why the filtering above doesn't work
private static class InnerTransformer implements AgentBuilder.Transformer {
@OverRide
public DynamicType.Builder transform(DynamicType.Builder builder, TypeDescription typeDescription,
ClassLoader classLoader, JavaModule module, ProtectionDomain protectionDomain) {
return builder.visit(Advice.to(MethodServiceAdvice.class)
.on(ElementMatchers.not(ElementMatchers.isConstructor())
.and(ElementMatchers
.noneOf(ElementMatchers.hasSuperType(ElementMatchers.named("StaticApplicationContext"))))
.and(ElementMatchers.not(ElementMatchers.isTypeInitializer()))
.and(ElementMatchers.not(ElementMatchers.isSetter()))
.and(ElementMatchers.not(ElementMatchers.isGetter()))
.and(ElementMatchers.not(ElementMatchers.nameStartsWith("net.bytebuddy.generated")))
.and(ElementMatchers.not(ElementMatchers.nameContains("EnhancerBySpringCGLIB")))
.and(ElementMatchers.not(ElementMatchers.nameContains("$$")))
.and(ElementMatchers.not(ElementMatchers.nameContains("FastClassByCGLIB")))
.and(ElementMatchers.not(ElementMatchers.nameContains("MethodInterceptor")))));
}
}
What filtering do you mean?
What I mean is that based on the previous investigation, it seems that the classes enhanced by cglib have been enhanced again by bytebuddy. Therefore, I want to use the ElementMatchers provided by bytebuddy to filter all the classes enhanced by cglib, which is this code, but it still cannot be successfully filtered private static class InnerTransformer implements AgentBuilder.Transformer { @OverRide public DynamicType.Builder transform(DynamicType.Builder builder, TypeDescription typeDescription, ClassLoader classLoader, JavaModule module, ProtectionDomain protectionDomain) { return builder.visit(Advice.to(MethodServiceAdvice.class) .on(ElementMatchers.not(ElementMatchers.isConstructor()) .and(ElementMatchers .noneOf(ElementMatchers.hasSuperType(ElementMatchers.named("StaticApplicationContext")))) .and(ElementMatchers.not(ElementMatchers.isTypeInitializer())) .and(ElementMatchers.not(ElementMatchers.isSetter())) .and(ElementMatchers.not(ElementMatchers.isGetter())) .and(ElementMatchers.not(ElementMatchers.nameStartsWith("net.bytebuddy.generated"))) .and(ElementMatchers.not(ElementMatchers.nameContains("EnhancerBySpringCGLIB"))) .and(ElementMatchers.not(ElementMatchers.nameContains("$$"))) .and(ElementMatchers.not(ElementMatchers.nameContains("FastClassByCGLIB"))) .and(ElementMatchers.not(ElementMatchers.nameContains("MethodInterceptor"))))); } }
You combine all these matchers. You likely want to use .or
which implies that any condition holds.