native-methodsbyteman

Byteman on native methods


Can Byteman be used on native methods like Thread.sleep, System.currentTimeMillis() ?

I tried

RULE catch_Thread.sleep
CLASS java.lang.Thread
METHOD java.lang.Thread.sleep(long) void
IF true
DO traceln("[BMAN] Sleep: "+ $1)
ENDRULE

It's not working.


Solution

  • This cannot work. Byteman works by rewriting the bytecode that defines the target method for a rule. A native method is not defined by bytecode. So, it is not possible to rewrite its behaviour.