Java代码是怎么运行的 [jvm]

2016-08-30
$ javap -v com.fenqile.outbiz.live800.Main
Classfile */classes/com/fenqile/outbiz/live800/Main.class
  Last modified Aug 11, 2016; size 465 bytes
  MD5 checksum 5571749f566b0de9228a8b1154d52824
  Compiled from "Main.java"
public class com.fenqile.outbiz.live800.Main
  SourceFile: "Main.java"
  minor version: 0
  major version: 51
  flags: ACC_PUBLIC, ACC_SUPER
Constant pool:
   #1 = Methodref          #4.#18         //  java/lang/Object."<init>":()V
   #2 = Methodref          #19.#20        //  com/alibaba/dubbo/container/Main.main:([Ljava/lang/String;)V
   #3 = Class              #21            //  com/fenqile/outbiz/live800/Main
   #4 = Class              #22            //  java/lang/Object
   #5 = Utf8               <init>
   #6 = Utf8               ()V
   #7 = Utf8               Code
   #8 = Utf8               LineNumberTable
   #9 = Utf8               LocalVariableTable
  #10 = Utf8               this
  #11 = Utf8               Lcom/fenqile/outbiz/live800/Main;
  #12 = Utf8               main
  #13 = Utf8               ([Ljava/lang/String;)V
  #14 = Utf8               args
  #15 = Utf8               [Ljava/lang/String;
  #16 = Utf8               SourceFile
  #17 = Utf8               Main.java
  #18 = NameAndType        #5:#6          //  "<init>":()V
  #19 = Class              #23            //  com/alibaba/dubbo/container/Main
  #20 = NameAndType        #12:#13        //  main:([Ljava/lang/String;)V
  #21 = Utf8               com/fenqile/outbiz/live800/Main
  #22 = Utf8               java/lang/Object
  #23 = Utf8               com/alibaba/dubbo/container/Main
{
  public com.fenqile.outbiz.live800.Main();
    flags: ACC_PUBLIC
    Code:
      stack=1, locals=1, args_size=1
         0: aload_0
         1: invokespecial #1                  // Method java/lang/Object."<init>":()V
         4: return
      LineNumberTable:
        line 11: 0
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
               0       5     0  this   Lcom/fenqile/outbiz/live800/Main;

  public static void main(java.lang.String[]);
    flags: ACC_PUBLIC, ACC_STATIC
    Code:
      stack=1, locals=1, args_size=1
         0: aload_0
         1: invokestatic  #2                  // Method com/alibaba/dubbo/container/Main.main:([Ljava/lang/String;)V
         4: return
      LineNumberTable:
        line 14: 0
        line 15: 4
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
               0       5     0  args   [Ljava/lang/String;
}

编译版本

You're looking for this on the command line (for a class called MyClass):

On Unix/Linux:

javap -verbose MyClass | grep "major"

On Windows:

javap -verbose MyClass | findstr "major"

You want the major version from the results. Here are some example values:

  • Java 5 uses major version 49
  • Java 6 uses major version 50
  • Java 7 uses major version 51
  • Java 8 uses major version 52

常量池

Comments
Write a Comment