-
Notifications
You must be signed in to change notification settings - Fork 1
Constant Pool
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 |
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;
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;
The CONSTANT_String_info
structure is used to represent constant objects of the type String
:
typedef struct
{
u1 tag;
struct
{
u2 string_index;
} * data;
} CONSTANT_String_info;
The CONSTANT_Integer_info
and CONSTANT_Float_info
structures represent 4-byte numeric (int
and float
) constants:
typedef struct
{
u1 tag;
struct
{
u4 bytes;
} * data;
} CONSTANT_Integer_info,
CONSTANT_Float_info;
The CONSTANT_Long_info
and CONSTANT_Double_info
represent 8-byte numeric (long
and double
) constants:
typedef struct
{
u1 tag;
struct
{
u4 high_bytes;
u4 low_bytes;
} * data;
} CONSTANT_Long_info,
CONSTANT_Double_info;
The CONSTANT_NameAndType_info
structure is used to represent a field or method, without indicating which class or interface type it belongs to:
typedef struct
{
u1 tag;
struct
{
u2 name_index;
u2 descriptor_index;
} * data;
} CONSTANT_NameAndType_info;
The CONSTANT_Utf8_info
structure is used to represent constant string values:
typedef struct
{
u1 tag;
struct
{
u2 length;
u1 *bytes;
} * data;
} CONSTANT_Utf8_info;
The CONSTANT_MethodHandle_info
structure is used to represent a method handle:
typedef struct
{
u1 tag;
struct
{
u1 reference_kind;
u2 reference_index;
} * data;
} CONSTANT_MethodHandle_info;
The CONSTANT_MethodType_info
structure is used to represent a method type:
typedef struct
{
u1 tag;
struct
{
u2 descriptor_index;
} * data;
} CONSTANT_MethodType_info;
The CONSTANT_InvokeDynamic_info
structure is used by an invokedynamic
instruction to specify a bootstrap method, the dynamic invocation name, the argument and return types of the call, and optionally, a sequence of additional constants called static arguments to the bootstrap method.
typedef struct
{
u1 tag;
struct
{
u2 bootstrap_method_attr_index;
u2 name_and_type_index;
} * data;
} CONSTANT_InvokeDynamic_info;