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:
cp_info {
u1 tag;
u1 info[];
}
Each entry in the constant_pool table must begin with a 1-byte tag indicating the kind of constant denoted by the entry. There are 17 kinds of constant, listed in Table 4.4-A with their corresponding tags, and ordered by their section number in this chapter. Each tag byte must be followed by two or more bytes giving information about the specific constant. The format of the additional information depends on the tag byte, that is, the content of the info array varies with the value of tag.
Table 4.4-A. Constant pool tags (by section)
| Constant Kind | Tag | Section |
|---|---|---|
CONSTANT_Class |
7 | §4.4.1 |
CONSTANT_Fieldref |
9 | §4.4.2 |
CONSTANT_Methodref |
10 | §4.4.2 |
CONSTANT_InterfaceMethodref |
11 | §4.4.2 |
CONSTANT_String |
8 | §4.4.3 |
CONSTANT_Integer |
3 | §4.4.4 |
CONSTANT_Float |
4 | §4.4.4 |
CONSTANT_Long |
5 | §4.4.5 |
CONSTANT_Double |
6 | §4.4.5 |
CONSTANT_NameAndType |
12 | §4.4.6 |
CONSTANT_Utf8 |
1 | §4.4.7 |
CONSTANT_MethodHandle |
15 | §4.4.8 |
CONSTANT_MethodType |
16 | §4.4.9 |
CONSTANT_Dynamic |
17 | §4.4.10 |
CONSTANT_InvokeDynamic |
18 | §4.4.10 |
CONSTANT_Module |
19 | §4.4.11 |
CONSTANT_Package |
20 | §4.4.12 |
In a class file whose version number is v, each entry in the constant_pool table must have a tag that was first defined in version v or earlier of the class file format (§4.1). That is, each entry must denote a kind of constant that is approved for use in the class file. Table 4.4-B lists each tag with the first version of the class file format in which it was defined. Also shown is the version of the Java SE Platform which introduced that version of the class file format.
Table 4.4-B. Constant pool tags (by tag)
| Constant Kind | Tag | class file format |
Java SE |
|---|---|---|---|
CONSTANT_Utf8 |
1 | 45.3 | 1.0.2 |
CONSTANT_Integer |
3 | 45.3 | 1.0.2 |
CONSTANT_Float |
4 | 45.3 | 1.0.2 |
CONSTANT_Long |
5 | 45.3 | 1.0.2 |
CONSTANT_Double |
6 | 45.3 | 1.0.2 |
CONSTANT_Class |
7 | 45.3 | 1.0.2 |
CONSTANT_String |
8 | 45.3 | 1.0.2 |
CONSTANT_Fieldref |
9 | 45.3 | 1.0.2 |
CONSTANT_Methodref |
10 | 45.3 | 1.0.2 |
CONSTANT_InterfaceMethodref |
11 | 45.3 | 1.0.2 |
CONSTANT_NameAndType |
12 | 45.3 | 1.0.2 |
CONSTANT_MethodHandle |
15 | 51.0 | 7 |
CONSTANT_MethodType |
16 | 51.0 | 7 |
CONSTANT_Dynamic |
17 | 55.0 | 11 |
CONSTANT_InvokeDynamic |
18 | 51.0 | 7 |
CONSTANT_Module |
19 | 53.0 | 9 |
CONSTANT_Package |
20 | 53.0 | 9 |
Some entries in the constant_pool table are loadable because they represent entities that can be pushed onto the stack at run time to enable further computation. In a class file whose version number is v, an entry in the constant_pool table is loadable if it has a tag that was first deemed to be loadable in version v or earlier of the class file format. Table 4.4-C lists each tag with the first version of the class file format in which it was deemed to be loadable. Also shown is the version of the Java SE Platform which introduced that version of the class file format.
In every case except CONSTANT_Class, a tag was first deemed to be loadable in the same version of the class file format that first defined the tag.
Table 4.4-C. Loadable constant pool tags
| Constant Kind | Tag | class file format |
Java SE |
|---|---|---|---|
CONSTANT_Integer |
3 | 45.3 | 1.0.2 |
CONSTANT_Float |
4 | 45.3 | 1.0.2 |
CONSTANT_Long |
5 | 45.3 | 1.0.2 |
CONSTANT_Double |
6 | 45.3 | 1.0.2 |
CONSTANT_Class |
7 | 49.0 | 5.0 |
CONSTANT_String |
8 | 45.3 | 1.0.2 |
CONSTANT_MethodHandle |
15 | 51.0 | 7 |
CONSTANT_MethodType |
16 | 51.0 | 7 |
CONSTANT_Dynamic |
17 | 55.0 | 11 |
Sections:
- 4.4.1. The CONSTANT_Class_info Structure
- 4.4.2. The CONSTANT_Fieldref_info, CONSTANT_Methodref_info, and CONSTANT_InterfaceMethodref_info Structures
- 4.4.3. The CONSTANT_String_info Structure
- 4.4.4. The CONSTANT_Integer_info and CONSTANT_Float_info Structures
- 4.4.5. The CONSTANT_Long_info and CONSTANT_Double_info Structures
- 4.4.6. The CONSTANT_NameAndType_info Structure
- 4.4.7. The CONSTANT_Utf8_info Structure
- 4.4.8. The CONSTANT_MethodHandle_info Structure
- 4.4.9. The CONSTANT_MethodType_info Structure
- 4.4.10. The CONSTANT_Dynamic_info and CONSTANT_InvokeDynamic_info Structures
- 4.4.11. The CONSTANT_Module_info Structure
- 4.4.12. The CONSTANT_Package_info Structure