• 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

  • 相关阅读:
    罗振宇 知识就是力量之怎样做一个不冲动的人
    C++中stl的map
    stl中顺序性容器,关联容器两者粗略解释
    stl之容器、迭代器、算法几者之间的关系
    mysql技术内幕之常规使用
    essential c++ 第一章 array及vector相关使用
    由函数clock想到的
    编程获得CPU的主频
    Markdown 基本语法
    Future FutrueTask Callable类源码说明以及原理使用
  • 原文地址:https://www.cnblogs.com/DeskZero/p/11438728.html
Copyright © 2020-2023  润新知