The JVMclass format uses constant_pool_countto indicate the size of the pool of class constants:
ClassFile {
u4 magic;
u2 minor_version;
u2 major_version;
u2 constant_pool_count;
cp_info constant_pool[constant_pool_count-1];
u2 access_flags;
u2 this_class;
u2 super_class;
u2 interfaces_count;
u2 interfaces[interfaces_count];
u2 fields_count;
field_info fields[fields_count];
u2 methods_count;
method_info methods[methods_count];
u2 attributes_count;
attribute_info attributes[attributes_count];
}
Where is constant_pool_countdefined as
The value of an element constant_pool_countis equal to the number of entries in the table constant_poolplus one.
Why is the number indicated in this method “plus one” instead of just being equal to the number of constants? Meanwhile interfaces_count, fields_count, methods_countand attributes_countit does not seem to follow this pattern.
Some assumptions:
- This may have something to do with achieving optimal byte alignment.
- Perhaps this is an artifact of a particular design decision elsewhere in the JVM
: :
- , , , . -, 1 ( 0), . [3] , ( ) , phantom, .
, , long double, , " " - 1, .