Class文件结构-常量池

2019-08-31 07:23:09来源:博客园 阅读 ()

新老客户大回馈,云服务器低至5折

Class文件结构-常量池

常量池里存放:
1.字面量(Literal)
• 文本字符串
• 声明为final的常量值(final的8种基本类型)
• 非final的基本类型也可能进(doublefloatlong)
2.符号引用(Symbolic References)
• 类和接口的全限定名(Fully Qualified Name)
• 字段的名称和描述符(Descriptor)
• 方法的名称和描述符
备注:
1. constant_pool_count=1表示常量池中有0个常量项
2. 表的第一个字节表示常量类型(tag)

常量项结构总表

 示例:

package zero.desk.constantpool;

public class ConstantPool extends C implements A,B{
private String str = "test string";
private final int a = 10;
private final long b = 10;
private final long bb = 100;
private int c = 11;
private float d = 12f;
private float e = 12f;
private double ee = 12f;

private int m;

public int inc() {
return m + 1;
}
}

Constant pool:
#1 = Methodref #20.#50 // zero/desk/constantpool/C."<init>":()V
#2 = String #51 // test string
#3 = Fieldref #19.#52 // zero/desk/constantpool/ConstantPool.str:Ljava/lang/String;
#4 = Fieldref #19.#53 // zero/desk/constantpool/ConstantPool.a:I
#5 = Long 10l
#7 = Fieldref #19.#54 // zero/desk/constantpool/ConstantPool.b:J
#8 = Long 100l
#10 = Fieldref #19.#55 // zero/desk/constantpool/ConstantPool.bb:J
#11 = Fieldref #19.#56 // zero/desk/constantpool/ConstantPool.c:I
#12 = Float 12.0f
#13 = Fieldref #19.#57 // zero/desk/constantpool/ConstantPool.d:F
#14 = Fieldref #19.#58 // zero/desk/constantpool/ConstantPool.e:F
#15 = Double 12.0d
#17 = Fieldref #19.#59 // zero/desk/constantpool/ConstantPool.ee:D
#18 = Fieldref #19.#60 // zero/desk/constantpool/ConstantPool.m:I
#19 = Class #61 // zero/desk/constantpool/ConstantPool
#20 = Class #62 // zero/desk/constantpool/C
#21 = Class #63 // zero/desk/constantpool/A
#22 = Class #64 // zero/desk/constantpool/B
#23 = Utf8 str
#24 = Utf8 Ljava/lang/String;
#25 = Utf8 a
#26 = Utf8 I
#27 = Utf8 ConstantValue
#28 = Integer 10
#29 = Utf8 b
#30 = Utf8 J
#31 = Utf8 bb
#32 = Utf8 c
#33 = Utf8 d
#34 = Utf8 F
#35 = Utf8 e
#36 = Utf8 ee
#37 = Utf8 D
#38 = Utf8 m
#39 = Utf8 <init>
#40 = Utf8 ()V
#41 = Utf8 Code
#42 = Utf8 LineNumberTable
#43 = Utf8 LocalVariableTable
#44 = Utf8 this
#45 = Utf8 Lzero/desk/constantpool/ConstantPool;
#46 = Utf8 inc
#47 = Utf8 ()I
#48 = Utf8 SourceFile
#49 = Utf8 ConstantPool.java
#50 = NameAndType #39:#40 // "<init>":()V
#51 = Utf8 test string
#52 = NameAndType #23:#24 // str:Ljava/lang/String;
#53 = NameAndType #25:#26 // a:I
#54 = NameAndType #29:#30 // b:J
#55 = NameAndType #31:#30 // bb:J
#56 = NameAndType #32:#26 // c:I
#57 = NameAndType #33:#34 // d:F
#58 = NameAndType #35:#34 // e:F
#59 = NameAndType #36:#37 // ee:D
#60 = NameAndType #38:#26 // m:I
#61 = Utf8 zero/desk/constantpool/ConstantPool
#62 = Utf8 zero/desk/constantpool/C
#63 = Utf8 zero/desk/constantpool/A
#64 = Utf8 zero/desk/constantpool/B

 


原文链接:https://www.cnblogs.com/DeskZero/p/11438728.html
如有疑问请与原作者联系

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:玩转 SpringBoot 2 快速搭建 | RESTful Api 篇

下一篇:Java内存模型以及volatile关键字详解