开发者

Understanding the Java code life-cycle in JVM from Top to Bottom

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

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 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;
    ALO开发者_如何学运维AD 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 I get about the java code. But I am interested in tracking the life cycle of this java code. i.e. say when I define: int i = 42, which c++ method of the JVM (open jdk) implementation is invoked.

Is there any tool available to analyze the Java code from top to bottom (till assembly language generation)?

Specifically my question is:

  1. How is bytecode interpreted by the JVM
  2. Which c++ code is invoked?

I am finding stuff here: Google code of openjdk


For preliminary analysis you can use -verbose option while executing application

-verbose[:class|gc|jni]

example :

java -verbose:jni Hello

Hope this helps


Is there any tool available to analyze the Java code from top to bottom (till assembly language generation)?

Not to the extent that you want, AFAIK. There is simply not sufficient need for such a tool to justify the effort of building one.

  • In theory, you could build and run a JVM using a C / C++ source level debugger. However I suspect it will take you a long time getting to the point where you can see what is going on when a Java statement gets executed.

  • The other alternative is to dig out the JVM options which tell the JIT compiler to dump the native code that it emits, and then disassemble the native code. But that only tells you a small part of the answer.

Either way, I don't see how you are going to learn much that is particularly relevant ... unless you are planning to implement your own Java code generation tools. And anything that you do learn is likely to be ephemeral; i.e. out of date when Java 7 comes along.

FOLLOWUP

For what you are trying to do (researching the "evolution of HLL VM from pascal VM to JVM.") you are probably wasting your time delving into the innards of the JVM. You will get a better picture, and quicker by locating and reading research papers, articles and developer blogs on the subject. (Check with your supervisor.) If you discover specific points that are not covered adequately by the literature ... it MIGHT be worth diving into the implementation. But at that point you will have a better idea what you should be looking for.

Trust me ... I've done this kind of thing myself.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜