Search code examples
javajvmbytecodememory-address

JVM bytecode line number


We are trying to analyze Java code with only bytecode.

Is there a way to either let JVM spit out the addresses of bytecode it is executing or intercept the addresses of the bytecode issued to JVM at runtime ?

According to the crash stack, it seems that JVM should have all that information.


Solution

  • There are open source code coverage tools available and what these do is used instrumentation of the code to track which lines have been executed.

    The JVM executes native machine code, rather than byte code at runtime. You need to use code injection to add instructions to what ever you need between byte code instructions but this will slow down the execution. If you just need to see if a line is executed ever you can set a flag for each line once which should be quicker.