Search code examples
javainstrumentation

Instrument Java Thread


I am trying to instrument java.lang.Thread class with ASM. But it's not being loaded into ASM.

I start my program with:

java -javaagent:agent.jar -jar program.jar

Other classes from program.jar are loaded and instrumented. Is it possible to instrument Thread as well?


Solution

  • Probably not. Even if you retransform the java.lang.Thread class, retransformations cannot be applied if a class has frames on a threadstack, and by definition, I would expect some of Thread's frames to be at the top of every threadstack (including the one running your java agent!).