Understanding the Java Code Life Cycle in the JVM from Top to Bottom

I am trying to understand how JVM code is executed by JVM.

let's say I write this Java code:

public class Hello { public static void main(String args[]) { int i = 42; String hello ="World"; System.out.println(hello + i); } } 

This is the bytecode generated (using the eclipse plugin):

 // class version 50.0 (50) // access flags 33 public class cmpe296/Hello { // compiled from: Hello.java // access flags 1 public <init>()V L0 LINENUMBER 3 L0 ALOAD 0 INVOKESPECIAL java/lang/Object.<init>()V RETURN L1 LOCALVARIABLE this Lcmpe296/Hello; L0 L1 0 MAXSTACK = 1 MAXLOCALS = 1 // access flags 9 public static main([Ljava/lang/String;)V L0 LINENUMBER 7 L0 LDC "World" ASTORE 1 L1 LINENUMBER 8 L1 GETSTATIC java/lang/System.out : Ljava/io/PrintStream; ALOAD 1 INVOKEVIRTUAL java/io/PrintStream.println(Ljava/lang/String;)V L2 LINENUMBER 9 L2 RETURN L3 LOCALVARIABLE args [Ljava/lang/String; L0 L3 0 LOCALVARIABLE hello Ljava/lang/String; L1 L3 1 MAXSTACK = 2 MAXLOCALS = 2 } 

This is the only information about java code. But I'm interested in tracking the life cycle of this Java code. that is, when I define: int i = 42 , which is called by C ++ - the JVM implementation method (open jdk).

Is there any tool for analyzing Java code from top to bottom (before generating assembler)?

In particular, my question is:

  • Like bytecode interpreted by JVM
  • What C ++ code is being called?

I find here: google openjdk code

+4
source share
2 answers

Is there any tool for analyzing Java code from top to bottom (before generating assembler)?

Not to the extent you want, AFAIK. There is simply no need for such an instrument to justify the efforts to create it.

  • In theory, you could create and run the JVM using a C / C ++ source level debugger. However, I suspect that it will take you a long time to understand what happens when a Java instruction is executed.

  • Another alternative is to dig out JVM parameters that tell the JIT compiler to dump the native code that it emits, and then parse the native code. But this only speaks of a small part of the answer.

In any case, I don’t understand how you are going to learn a lot, which is especially important ... if you do not plan to implement your own Java code generation tools. And all that you learn is likely to be ephemeral; i.e. obsolete when Java 7 comes in.

Followup

For what you are trying to do (exploring the "evolution of the HLL VM from pascal VM to JVM"), you are probably wasting your time driving the JVM. You will get a better picture and faster by finding and reading scientific articles, articles and development blogs on this subject. (Consult your supervisor.) If you find specific points that are not adequately covered in the literature ... MAY be worth diving into implementation. But at this point you will have a better idea of ​​what you should be looking for.

Believe me ... I did it myself.

+2
source

For preliminary analysis, you can use the -verbose option when running the application

-verbose [: class | ds | JNI]

example:

 java -verbose:jni Hello 

Hope this helps

+3
source

All Articles