Skip to content

Constant Pool

Donizyo edited this page Apr 8, 2016 · 4 revisions

Java Virtual Machine instructions do not rely on the run-time layout of classes, interfaces, class instances, or arrays. Instead, instructions refer to symbolic information in the constant_pool table.

All constant_pool table entries have the following general format:

typedef struct
{
    u1 tag;
    void * data;
} cp_info;

Each item in the constant_pool table must begin with a 1-byte tag indicating the kind of cp_info entry. The contents of the info array vary with the value of tag. The valid tags and their values are listed as below:

Constant Type Value
CONSTANT_Utf8 1
CONSTANT_Integer 3
CONSTANT_Float 4
CONSTANT_Long 5
CONSTANT_Double 6
CONSTANT_Class 7
CONSTANT_String 8
CONSTANT_Fieldref 9
CONSTANT_Methodref 10
CONSTANT_InterfaceMethodref 11
CONSTANT_NameAndType 12
CONSTANT_MethodHandle 15
CONSTANT_MethodType 16
CONSTANT_InvokeDynamic 18

CONSTANT_Class_info

The CONSTANT_Class_info structure is used to represent a class or an interface:

typedef struct
{
    u1 tag;
    struct
    {
        u2 name_index;
    } * data;
} CONSTANT_Class_info;

CONSTANT_Fieldref_info, CONSTANT_Methodref_info, and CONSTANT_InterfaceMethodref_info

Fields, methods, and interface methods are represented by similar structures:

typedef struct
{
    u1 tag;
    struct
    {
        u2 class_index;
        u2 name_and_type_index;
    } * data;
} CONSTANT_Fieldref_info,
        CONSTANT_Fieldref_info,
        CONSTANT_InterfaceMethodref_info;
Clone this wiki locally