1

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.

assylias
  • 321,522
  • 82
  • 660
  • 783
Farn Wang
  • 143
  • 15
  • 1
    Your question is unclear - what do you mean by "spit out the addresses of bytecode"? – assylias Nov 17 '15 at 11:34
  • 1
    Of course, there is. It’s called “debugging API” and you may find it, if you really search for it… – Holger Nov 17 '15 at 12:22
  • Sorry for the confusion. We are trying to do source code coverage analysis. So we want to see whether there is a way to ask JVM to report the line numbers of the Java source code. If JVM cannot, then is there a way to ask JVM to report the line numbers of the executed bytecode. Thanks – Farn Wang Nov 17 '15 at 12:51
  • 1
    @FarnWang It is possible (although I'm not sure how) - you may want to check existing code coverage tools such as cobertura or jacoco... – assylias Nov 17 '15 at 12:59

1 Answers1

1

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.

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130