Closed houxinlin closed 6 months ago
If you are registering the interceptor after the program has started, the class will be loaded already.
To instrument loaded classes, have a look at retransformation. This will however also require you to use Advice
in most cases.
If you are registering the interceptor after the program has started, the class will be loaded already.
To instrument loaded classes, have a look at retransformation. This will however also require you to use
Advice
in most cases.
Do I need to call the following code?
But this doesn't work either, please advise
try {
inst.retransformClasses(allLoadedClass);
} catch (UnmodifiableClassException e) {
throw new RuntimeException(e);
}
I want to intercept the specified method again after the class has been loaded
Register a RetransformationStrategy. This will normally require Advice.
Is it like this? When "org.example.ScheduleTest" is loaded, it still doesn't work
new AgentBuilder.Default()
.type(ElementMatchers.named("org.example.ScheduleTest"))
.transform((builder, typeDescription, classLoader, module,protectionDomain) -> builder
.method(ElementMatchers.any())
.intercept(Advice.to(Interceptor.class)))
.with(AgentBuilder.RedefinitionStrategy.REDEFINITION)
.installOn(inst);
public class Interceptor {
@Advice.OnMethodEnter
static long invokeBeforeEachMethod(
@Advice.Origin String method) {
System.out.println("Entering to invoke : " + method);
return System.currentTimeMillis();
}
@Advice.OnMethodExit
static void invokeWhileExitingEachMethod(@Advice.Origin String method,
@Advice.Enter long startTime) {
System.out.println(
"Method " + method + " took " + (System.currentTimeMillis() - startTime) + "ms");
}
}
This is my code, when I don't use sleep, he can intercept normally