0

We have written a custom tracer using JVMTI which gets the runtime call flow from a Java Application hosted at any server(Tomcat/JBoss). Now, we would like to get the list of executed statements of those methods which are part of runtime call flow. Basically we are looking for which control statements have participated during the runtime. Is there a way we could achieve this using JVMTI? If not JVMTI, can anyone help me if there are any other options to achieve this.

Regards, NAK

NAK
  • 71
  • 1
  • 4
  • There is no such thing like a “statement” in compiled code. The closest you can get, are line numbers when debugging information has been compiled into the class files. But I doubt that gathering information at such granularity is really useful. – Holger Oct 05 '18 at 10:11
  • @Holger, thank you for your response. I will try to see what I can do with line numbers. But how do I get those line numbers? – NAK Oct 05 '18 at 12:00
  • [`jvmti / GetLineNumberTable`](https://docs.oracle.com/javase/7/docs/platform/jvmti/jvmti.html#GetLineNumberTable) – Holger Oct 05 '18 at 12:02
  • Thanks Holger. But on what event can I call thIs GetLineNumber? We use MethodEntry and MethodExit to get the call flow. On what event can I call this? Pardon me, I am little new to this. – NAK Oct 07 '18 at 17:22
  • `single_step` or `breakpoint`. You don’t get them without affecting the execution. As said, I doubt that gathering information at such granularity is really useful. – Holger Oct 08 '18 at 09:59
  • Thanks Holger. I tried GetLineNumberTable at MethodEntry and MethodExit, that gives all the lines of the method irrespective of what has got executed. I also tried single_step, this gives location of every instruction and not the line. Please correct me, if my understanding is wrong – NAK Oct 09 '18 at 17:26
  • You have to combine these information. The line number table tells you how to map instructions to line numbers and the single step execution allows you to step until reaching an instruction associated with a different line number. Alternatively, you may set a breakpoint at those locations. Or you instrument the code to report the line numbers itself at these locations. Either way is complicated. And so is the relation between source code lines and bytecode instructions. Think of loops, `finally` blocks, lambda expressions and combinations of them… – Holger Oct 10 '18 at 06:06
  • Thanks Holger, As suggested by you, let me try to combine the LineNumber Table information and Single Step instruction location and see if I am able to achieve. Yes, I will also check for scenarios where there are loops, finally, etc – NAK Oct 12 '18 at 04:46
  • Thanks Holger, I could get the executed Line numbers by combining LineNumberTable and SingleStep. Thanks for your input. – NAK Oct 26 '18 at 06:38

0 Answers0