Next: Textual Representation of Specifications, Previous: Notations for Grammar, Up: Notations and Conventions Used
For descriptions of the class file attributes we follow the rules described in Chapter 4 of The Java Virtual Machine Specification [Lindholm-Yellin]. We summarise here its most important features.
The format of attributes is a binary format with big-endian
representation of multibyte quantities. It is stored in the class file
sequentially without padding or alignment. Java's standard library
contains routines to properly store data in this binary layout. The
descriptions of the format use a C-like structure notation. The
subsequent entries in these structures are by convention called
items. In order to describe the multibyte quantities, special
identifiers are used: u1
, u2
, and u4
, which
unambiguously describe the binary size of the values.
All the attributes adhere to the following general format:
attribute_info { u2 attribute_name_index; u4 attribute_length; u1 info[attribute_length]; }
The field attribute_name_index is an unsigned 16-bit index into the constant pool of the class. The entry pointed to by the attribute_name_index is a CONSTANT_Utf8_info (see Section 4.4.7 of The Java Virtual Machine Specification [Lindholm-Yellin]) structure that represents the name of the attribute. The following item attribute_length is the length of the essential attribute information stored in the info array. The value of the length does not cover the items attribute_name_index and attribute_length.
Here is an example of an attribute description:
ConstantValue_attribute { u2 attribute_name_index; u4 attribute_length; u2 constantvalue_index; }This is a description of a standard Java attribute, used to describe constant values assigned to object fields. In this example the item attribute_length contains the value 2, while the third item constantvalue_index is a particular restriction of the info field above.
For the exact format of BML bytecode attributes see Encoding of BML in Class File Format. The next chapter recapitulates the standard classfile format.