JVM_字节码:字节码常量池分析

2019-06-27  本文已影响0人  CalmHeart

分析的条件: 基于上一篇的16进制字节码及反编译结果(javap -verbose the desire class)

分析的时候可以使用(jclasslib)进行查看,也提供了IDEA的plugin,显示的信息比较完善,比较优雅的分门别类字节码的相关信息。

IDEA插件界面
分析的结果

反编译结果:

Classfile /C:/spring_lecture/target/classes/com/compass/spring_lecture/binarycode/MyTest1.class
  Last modified 2019年6月26日; size 521 bytes
  MD5 checksum e84ac7b4ed245fd5824849fb69bacc27
  Compiled from "MyTest1.java"
public class com.compass.spring_lecture.binarycode.MyTest1
  minor version: 0 //小版本
  major version: 52 //大版本
  flags: (0x0021) ACC_PUBLIC, ACC_SUPER
  this_class: #3                          // com/compass/spring_lecture/binarycode/MyTest1
  super_class: #4                         // java/lang/Object
  interfaces: 0, fields: 1, methods: 3, attributes: 1
Constant pool://常量池
   #1 = Methodref          #4.#20         // java/lang/Object."<init>":()V
   #2 = Fieldref           #3.#21         // com/compass/spring_lecture/binarycode/MyTest1.a:I
   #3 = Class              #22            // com/compass/spring_lecture/binarycode/MyTest1
   #4 = Class              #23            // java/lang/Object
   #5 = Utf8               a
   #6 = Utf8               I
   #7 = Utf8               <init>
   #8 = Utf8               ()V
   #9 = Utf8               Code
  #10 = Utf8               LineNumberTable
  #11 = Utf8               LocalVariableTable
  #12 = Utf8               this
  #13 = Utf8               Lcom/compass/spring_lecture/binarycode/MyTest1;
  #14 = Utf8               getA
  #15 = Utf8               ()I
  #16 = Utf8               setA
  #17 = Utf8               (I)V
  #18 = Utf8               SourceFile
  #19 = Utf8               MyTest1.java
  #20 = NameAndType        #7:#8          // "<init>":()V
  #21 = NameAndType        #5:#6          // a:I
  #22 = Utf8               com/compass/spring_lecture/binarycode/MyTest1
  #23 = Utf8               java/lang/Object
{
  public com.compass.spring_lecture.binarycode.MyTest1();
    descriptor: ()V
    flags: (0x0001) ACC_PUBLIC
    Code:
      stack=2, locals=1, args_size=1
         0: aload_0
         1: invokespecial #1                  // Method java/lang/Object."<init>":()V
         4: aload_0
         5: iconst_1
         6: putfield      #2                  // Field a:I
         9: return
      LineNumberTable:
        line 4: 0
        line 6: 4
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
            0      10     0  this   Lcom/compass/spring_lecture/binarycode/MyTest1;

  public int getA();
    descriptor: ()I
    flags: (0x0001) ACC_PUBLIC
    Code:
      stack=1, locals=1, args_size=1
         0: aload_0
         1: getfield      #2                  // Field a:I
         4: ireturn
      LineNumberTable:
        line 10: 0
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
            0       5     0  this   Lcom/compass/spring_lecture/binarycode/MyTest1;

  public void setA(int);
    descriptor: (I)V
    flags: (0x0001) ACC_PUBLIC
    Code:
      stack=2, locals=2, args_size=2
         0: aload_0
         1: iload_1
         2: putfield      #2                  // Field a:I
         5: return
      LineNumberTable: //行号表
        line 14: 0
        line 15: 5
      LocalVariableTable: //局部变量表
        Start  Length  Slot  Name   Signature
            0       6     0  this   Lcom/compass/spring_lecture/binarycode/MyTest1;
            0       6     1     a   I
}
SourceFile: "MyTest1.java"

通过16进制编辑器查看字节码结果:


16进制表示


字节码的数据类型:共有11种数据类型

Class的数据类型
上一篇 下一篇

猜你喜欢

热点阅读