JVM常量池Constant pool結構速查

sayWhat_sayHello發表於2018-12-17

上面的數字是常量池的標誌。

1:
CONSTANT_Utf8_info {
    u1 tag;
    u2 length;
    u1 bytes[length];
}

3:
CONSTANT_Integer_info {
    u1 tag;
    u4 bytes;
}

4:
CONSTANT_Float_info {
    u1 tag;
    u4 bytes;
}

5:
CONSTANT_Long_info {
    u1 tag;
    u4 high_bytes;
    u4 low_bytes;
}

6:
CONSTANT_Double_info {
    u1 tag;
    u4 high_bytes;
    u4 low_bytes;
}

7:
CONSTANT_Class_info {
    u1 tag;
    u2 name_index;
}

8:
CONSTANT_String_info {
    u1 tag;
    u2 string_index;
}

9:
CONSTANT_Fieldref_info {
    u1 tag;
    u2 class_index;
    u2 name_and_type_index;
}

10:
CONSTANT_Methodref_info {
    u1 tag;
    u2 class_index;
    u2 name_and_type_index;
}

11:
CONSTANT_InterfaceMethodref_info {
    u1 tag;
    u2 class_index;
    u2 name_and_type_index;
}

12:
CONSTANT_NameAndType_info {
    u1 tag;
    u2 name_index;
    u2 descriptor_index;
}

15:
CONSTANT_MethodHandle_info {
    u1 tag;
    u1 reference_kind;
    u2 reference_index;
}

16:
CONSTANT_MethodType_info {
    u1 tag;
    u2 descriptor_index;
}

17:
CONSTANT_InvokeDynamic_info {
    u1 tag;
    u2 bootstrap_method_attr_index;
    u2 name_and_type_index;
}

相關文章