字节码查看

javac
 -g                         生成所有调试信息
 -g:none                    不生成任何调试信息
 -g:{lines,vars,source}     只生成某些调试信息
 source 源文件调试信息
 lines 行号调试信息
 vars 本地变量调试信息
javac -g:source,lines,vars FooTest.java
javap -verbose FooTest.class
public class FooTest {
    static class Foo {
        int mSplat;
    }

    Foo[] mArray = {new Foo(), new Foo(), new Foo()};

    public void zero() {
        int sum = 0;
        for (int i = 0; i < mArray.length; ++i) {
            sum += mArray[i].mSplat;
        }
    }

    public void one() {
        int sum = 0;
        Foo[] localArray = mArray;
        int len = localArray.length;

        for (int i = 0; i < len; ++i) {
            sum += localArray[i].mSplat;
        }
    }
}
Classfile /E:/svn/bms/bms-server/src/test/java/FooTest.class
  Last modified 2017-10-11; size 801 bytes
  MD5 checksum 8d904b2f3e6e2f56b7047ad2231b7766
  Compiled from "FooTest.java"
public class FooTest
  minor version: 0
  major version: 52
  flags: ACC_PUBLIC, ACC_SUPER
Constant pool:
   #1 = Methodref          #7.#31         // java/lang/Object."<init>":()V
   #2 = Class              #32            // FooTest$Foo
   #3 = Methodref          #2.#31         // FooTest$Foo."<init>":()V
   #4 = Fieldref           #6.#33         // FooTest.mArray:[LFooTest$Foo;
   #5 = Fieldref           #2.#34         // FooTest$Foo.mSplat:I
   #6 = Class              #35            // FooTest
   #7 = Class              #36            // java/lang/Object
   #8 = Utf8               Foo
   #9 = Utf8               InnerClasses
  #10 = Utf8               mArray
  #11 = Utf8               [LFooTest$Foo;
  #12 = Utf8               <init>
  #13 = Utf8               ()V
  #14 = Utf8               Code
  #15 = Utf8               LineNumberTable
  #16 = Utf8               LocalVariableTable
  #17 = Utf8               this
  #18 = Utf8               LFooTest;
  #19 = Utf8               zero
  #20 = Utf8               i
  #21 = Utf8               I
  #22 = Utf8               sum
  #23 = Utf8               StackMapTable
  #24 = Utf8               one
  #25 = Utf8               localArray
  #26 = Utf8               len
  #27 = Class              #35            // FooTest
  #28 = Class              #11            // "[LFooTest$Foo;"
  #29 = Utf8               SourceFile
  #30 = Utf8               FooTest.java
  #31 = NameAndType        #12:#13        // "<init>":()V
  #32 = Utf8               FooTest$Foo
  #33 = NameAndType        #10:#11        // mArray:[LFooTest$Foo;
  #34 = NameAndType        #37:#21        // mSplat:I
  #35 = Utf8               FooTest
  #36 = Utf8               java/lang/Object
  #37 = Utf8               mSplat
{
  FooTest$Foo[] mArray;
    descriptor: [LFooTest$Foo;
    flags:

  public FooTest();
    descriptor: ()V
    flags: ACC_PUBLIC
    Code:
      stack=6, locals=1, args_size=1
         0: aload_0
         1: invokespecial #1                  // Method java/lang/Object."<init>":()V
         4: aload_0
         5: iconst_3
         6: anewarray     #2                  // class FooTest$Foo
         9: dup
        10: iconst_0
        11: new           #2                  // class FooTest$Foo
        14: dup
        15: invokespecial #3                  // Method FooTest$Foo."<init>":()V
        18: aastore
        19: dup
        20: iconst_1
        21: new           #2                  // class FooTest$Foo
        24: dup
        25: invokespecial #3                  // Method FooTest$Foo."<init>":()V
        28: aastore
        29: dup
        30: iconst_2
        31: new           #2                  // class FooTest$Foo
        34: dup
        35: invokespecial #3                  // Method FooTest$Foo."<init>":()V
        38: aastore
        39: putfield      #4                  // Field mArray:[LFooTest$Foo;
        42: return
      LineNumberTable:
        line 5: 0
        line 10: 4
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
            0      43     0  this   LFooTest;

  public void zero();
    descriptor: ()V
    flags: ACC_PUBLIC
    Code:
      stack=3, locals=3, args_size=1
         0: iconst_0
         1: istore_1
         2: iconst_0
         3: istore_2
         4: iload_2
         5: aload_0
         6: getfield      #4                  // Field mArray:[LFooTest$Foo;
         9: arraylength
        10: if_icmpge     31
        13: iload_1
        14: aload_0
        15: getfield      #4                  // Field mArray:[LFooTest$Foo;
        18: iload_2
        19: aaload
        20: getfield      #5                  // Field FooTest$Foo.mSplat:I
        23: iadd
        24: istore_1
        25: iinc          2, 1
        28: goto          4
        31: return
      LineNumberTable:
        line 13: 0
        line 14: 2
        line 15: 13
        line 14: 25
        line 17: 31
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
            4      27     2     i   I
            0      32     0  this   LFooTest;
            2      30     1   sum   I
      StackMapTable: number_of_entries = 2
        frame_type = 253 /* append */
          offset_delta = 4
          locals = [ int, int ]
        frame_type = 250 /* chop */
          offset_delta = 26

  public void one();
    descriptor: ()V
    flags: ACC_PUBLIC
    Code:
      stack=3, locals=5, args_size=1
         0: iconst_0
         1: istore_1
         2: aload_0
         3: getfield      #4                  // Field mArray:[LFooTest$Foo;
         6: astore_2
         7: aload_2
         8: arraylength
         9: istore_3
        10: iconst_0
        11: istore        4
        13: iload         4
        15: iload_3
        16: if_icmpge     35
        19: iload_1
        20: aload_2
        21: iload         4
        23: aaload
        24: getfield      #5                  // Field FooTest$Foo.mSplat:I
        27: iadd
        28: istore_1
        29: iinc          4, 1
        32: goto          13
        35: return
      LineNumberTable:
        line 20: 0
        line 21: 2
        line 22: 7
        line 24: 10
        line 25: 19
        line 24: 29
        line 27: 35
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
           13      22     4     i   I
            0      36     0  this   LFooTest;
            2      34     1   sum   I
            7      29     2 localArray   [LFooTest$Foo;
           10      26     3   len   I
      StackMapTable: number_of_entries = 2
        frame_type = 255 /* full_frame */
          offset_delta = 13
          locals = [ class FooTest, int, class "[LFooTest$Foo;", int, int ]
          stack = []
        frame_type = 250 /* chop */
          offset_delta = 21
}
SourceFile: "FooTest.java"
InnerClasses:
     static #8= #2 of #6; //Foo=class FooTest$Foo of class FooTest
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值