next up previous contents
Next: Java API native methods Up: No Title Previous: Opcode blocks

The class file

  The main contents of the class file is a symbolical table called the constant_pool, the field declarations and the methods with their bytecode. The outline of the class file is shown in figure 14.

   figure1011
Figure 14: The class file.

There are four elements in the class file that are of variable length. These are cp_info, field_info, method_info and attribute_info. These are described in subsequent sections.

magic
is the identifier for the class file format. It is always set to 0xCAFEBABE.

minor_version and major_version
are set by the compiler. They are used by the JVM to check if it can interpret the class file.

constant_pool_count
indicates the number of cp_info entries in the constant_pool array.

constant_pool
is an array of variable length. The contents are cp_info elements. These describe symbolical references to other classes, string constants, class names, field names etc. The different cp_info entries are described in section B.1.

access_flags
describe the type of the class file. The different flags are described in table 1.

   table1036
Table 1: Access flags for the class file.

this_class
is an index into the constant_pool array. The entry contains a reference to the name of this class file.

super_class
is an index to the constant_pool array. The entry contains a reference to the name of the superclass, if there is one. The only class without a superclass is Object.

interface_count
shows how many interfaces this class file uses.

interfaces
is an array containing indexes to the constant_pool array which describe the interfaces used by this class.

fields_count
shows how many field_info entries there are in the fields array.

fields
is an array containing variable length field_info entries. These represent all the fields in the class file (i.e. instance- and class variables). The different entries are described in section B.2.

methods_count
shows the number of method_info entries in the methods array.

methods
contains variable length method_info entries which describe all the methods in this class. The method_info is described in greater detail in section B.2.

attributes_count
gives the number of attribute_info entries in the attributes array.

attributes
contains variable length attribute_info entries which describes attributes and information about the class file. The various attribute_info entries are described in section B.3 to section B.7 .

Constant pool

  The constant_pool is a collection of different symbolical references and constants. To separate the different entries (called cp_info), tags are used. The first byte in every cp_info holds the tag. The Parser knows what kind of entry to read when the tag is identified. The different tags are shown in table 2. A description of the various entries follows directly after the table.

   table1078
Table 2: Constant pool tags.

CONSTANT_Class_info
The name_index refers to another entry in the constant_pool which describes the name of the class.

   figure1092
Figure 15: The CONSTANT_Class_info.

CONSTANT_Fieldref_info,
CONSTANT_Methodref_info,
CONSTANT_InterfaceMethodref_info
The name_and_type_index refers to another entry in the constant_pool which is a CONSTANT_NameAndType_info. The class_name refers to a CONSTANT_Class_info which describes the class where the item is defined.

   figure1106
Figure 16: The CONSTANT_Fieldref_info, CONSTANT_Methodref_info and CONSTANT_InterfaceMethodref_info.

CONSTANT_String_info
The string_index refers to a CONSTANT_Utf8_info entry containing the bytes of the String.

   figure1118
Figure 17: The CONSTANT_String_info.

CONSTANT_Integer_info,
CONSTANT_Float_info
The bytes contains the constant number value.

   figure1128
Figure 18: The CONSTANT_Integer_info and CONSTANT_Float_info.

CONSTANT_Long_info,
CONSTANT_Double_info
The high_bytes and the low_bytes are put together to form the constant number value. These two entries confiscate two subsequent constant_pool entries each. The entry directly after the first is invalid.

   figure1140
Figure 19: The CONSTANT_Long_info and CONSTANT_Double_info.

CONSTANT_NameAndType_info
The indexes refers to two
CONSTANT_Utf8_info entries.

   figure1150
Figure 20: The CONSTANT_NameAndType_info.

CONSTANT_Utf8_info
The number in length gives the length of the bytes array in bytes. This entry contains the bytes of various names and descriptors.

   figure1161
Figure 21: The CONSTANT_Utf8_info.

Fields & Methods

    This is used to describe fields and methods defined in the class.

   figure1174
Figure 22: The field_info and method_info.

access_flags
describe the type of the field_info and method_info. The different flags for fields are described in table 3 and for methods in table 4.

   table1189
Table 3: Access flags for the field_info.

   table1200
Table 4: Access flags for the method_info.

name_index
is an index into the constant_pool array. The entry contains a reference to the name of this field or method.
descriptor_index
is an index into the constant_pool array. The entry contains a reference to the descriptor of this field or method.
attributes_count
indicates the number of attributes in the following
attributes array.
attributes
is an array containing extra information about this field or method. Only the ConstantValue attribute is defined for fields. Methods have two defined attributes. They are the Code- and the Exceptions attribute. All other attributes are discarded.

SourceFile attribute

    This attribute is used to get an reference to the name of this class. The attribute is only used as an attribute in the class file.

   figure1222
Figure 23: The SourceFile attribute.

attribute_name_index
refers to an entry in the constant_pool array. The entry contains the string ``SourceFile''.
attribute_length
gives the length of this attribute in bytes. The first six bytes are excluded.
sourcefile_index
refers to an entry in the constant_pool array. The entry contains the the name of this class.

ConstantValue attribute

  This attribute is used to get a reference to a constant value entry in the constant_pool. The attribute is only used as an attribute to the field_info structure.

   figure1240
Figure 24: The ConstantValue attribute.

attribute_name_index
refers to an entry in the constant_pool array. The entry contains the string ``ConstantValue''.
attribute_length
gives the length of this attribute in bytes. The first six bytes are excluded.
constantvalue_index
refers to an entry in the constant_pool array. The entry contains a numeric constant.

Code attribute

  This attribute is used to hold the opcodes for a method. The attribute is only used as an attribute to the code attribute.

   figure1257
Figure 25: The Code attribute.

attribute_name_index
refers to an entry in the constant_pool array. The entry contains the string ``Code''.
attribute_length
gives the length of this attribute in bytes. The first six bytes are excluded.
max_stack
gives the maximum stack size used by this method.
max_locals
gives the number of local variables used by this method.
code_length
gives the number of bytes in the following code array.
code
is an array of opcodes and operands. This bytecode implement the method.
exception_table_length
gives the number of exception_table items in the following array.
exception_table
contains exception handler items. The structure of these are:
start_pc
gives the start of the range in which the exception handler is active.
end_pc
gives the end of the range in which the exception handler is active.
handler_pc
refers to the starting point of this exception. It refers in the code array.
catch_type
refers to an entry in the constant_pool array. The entry contains a description of the exception which can be caught.

attributes_count
gives the length of this attribute in bytes. The first six bytes are excluded.
attributes
is an array containing extra information about the code. There are only two defined attributes. They are the LineNumberTable- and the LocalVariableTable attribute. All other attributes are discarded.

Exceptions attribute

  This attribute shows the various exceptions a method may throw. The attribute is only used as an attribute to the method_info structure.

   figure1281
Figure 26: The Exceptions attribute.

attribute_name_index
refers to an entry in the constant_pool array. The entry contains the string ``Exceptions''.
attribute_length
gives the length of this attribute in bytes. The first six bytes are excluded.
number_of_exceptions
gives the number of items in the following array.
exception_index_table
refers to an entry in the constant_pool array. The entry contains a description of the exception which can be thrown.

LineNumberTable attribute

  This attribute is used as debugging information. It shows the connection between an opcode and a line in the Java program that produced the opcode. The attribute is only used as an attribute to the code attribute.

   figure1298
Figure 27: The LineNumberTable attribute.

attribute_name_index
refers to an entry in the constant_pool array. The entry contains the string ``LineNumberTable''.
attribute_length
gives the length of this attribute in bytes. The first six bytes are excluded.
line_number_table_length
gives the number of items in the
line_number_table array.
line_number_table
contains the following entries:
start_pc
gives the start opcode at which the line_number starts.
line_number
gives the corresponding Java program line number.

LocalVariableTable attribute

  This attribute is used as debugging information. It shows when a local variable is defined in the method and the type of it. The attribute is only used as an attribute to the code attribute.

   figure1318
Figure 28: The LocalVariableTable attribute.

attribute_name_index
refers to an entry in the constant_pool array. The entry contains the string ``LocalVariableTable''.
attribute_length
gives the length of this attribute in bytes. The first six bytes are excluded.
local_variable_table_length
gives the number of items in the
local_variable_table array.
local_variable_table
contains the following entries:
start_pc
gives the start opcode at which the local variable is set.
length
gives the length, in bytes, at which the local variable is set.
name_index
refers to an entry in the constant_pool array. The entry contains the name of the local variable.
descriptor_index
refers to an entry in the constant_pool array. The entry contains the descriptor of the local variable.
index
gives the index into the method's local variables at which this local variable is used.


next up previous contents
Next: Java API native methods Up: No Title Previous: Opcode blocks

Magnus Hjersing
Wed Dec 18 18:44:00 MET 1996