Contents Prev Next Up

The Java Virtual Machine

Constant Pool

Associated with each class is a constant pool. The constant pool contains the names of all fields, methods, and other such information that is used by any method in the class. At the end of the chapter containing the class file format there is a table of the constant pool types and their associated values.

When the class is first read in from memory, the class structure has two fields related to the constant pool. The nconstants field indicates the number of constants in this classes constant pool. The constant_info.constants_offset field contains an integer offset (in bytes) from the start of the class to the data which describes the constants in the class.

constant_pool[0] may be used by the implementation for whatever purposes it wishes.

constant_pool[1] ... constant_pool[nconstants - 1] are described by the sequence of bytes beginning at the byte indicated by constant_info.constants_offset in the class object. Each sequence of bytes contains a "type" field, followed by one or more type-dependent bytes, describing in more detail the specific field.

Contents Prev Next Up

Generated with CERN WebMaker