Contents Prev Next Up

## Class File Format

# Methods

access_flags
name_index
signature_index
attributes_count
attributes
Code Attribute
attribute_name_index
attribute_length
max_stack
max_locals
code_length
code
exception_table_length
exception_table
start_pc, end_pc
handler_pc
catch_type
attributes_count
attributes
Line Number Table Attribute
attribute_name_index
attribute_length
line_number_table_length
line_number_table
start_pc
line_number
Local Variable Table Attribute
attribute_name_index
attribute_length
local_variable_table_length
line_number_table
start_pc, length
name_index, signature_index
slot

The information for each method immediately follows the method_count field in the class file. Each method is described by a variable length method_info structure. The structure has the following format:

    method_info {
    	u2	access_flags;
    	u2	name_index;
    	u2	signature_index;
    	u2	attributes_count;
    	attribute_info 	attributes[attribute_count];
    }

### access_flags

This is a set of sixteen flags used by classes, methods, and fields to describe various properties and how they many be accessed by methods in other classes. See the table "Access Flags" on page 53 which gives the various bits in this field.

The possible fields that can be set for a method are ACC_PUBLIC, ACC_PRIVATE, ACC_PROTECTED, ACC_STATIC, ACC_FINAL, ACC_SYNCHRONIZED, ACC_NATIVE, and ACC_ABSTRACT.

At most one of ACC_PUBLIC and ACC_PRIVATE can be set for any method.

### name_index

constant_pool[name_index] is a string giving the name of the method.

### signature_index

constant_pool[signature_index]is a string giving the signature of the field. See the section "Signatures" for more information on signatures.

### attributes_count

This value gives the number of additional attributes about this field.

### attributes

A field can have any number of optional attributes associated with it. Each attribute has a name, and other additional information. Currently, the only field attribute recognized is the "Code" attribute, which describes the virtual bytecode that can be executed to perform this method.

Any other attributes are skipped.

### Code Attribute

The "Code" attribute has the following format:

    Code_attribute {
    	u2	attribute_name_index;
    	u2	attribute_length;
    	u1	max_stack;
    	u1	max_locals;
    	u2	code_length;
    	u1	code[code_length];
    	u2	exception_table_length;
    	{  u2 	   start_pc;
    	   u2	   end_pc;
    	   u2	   handler_pc;
    	   u2	   catch_type;
    	} 	exception_table[exception_table_length];
    	u2	attributes_count;
    	attribute_info	attributes[attribute_count];

    }

### attribute_name_index

constant_pool[attribute_name_index] is the string "Code."

### attribute_length

This field gives the total length of the "Code" attribute, excluding the initial four bytes.

### max_stack

Maximum number of entries on the operand stack that will be used during execution of this method. See the other chapters in this spec for more information on the operand stack.

### max_locals

Number of local variable slots used by this method. See the other chapters in this spec for more information on the local variables.

### code_length

The number of bytes in the virtual machine code for this method.

### code

These are the actual bytes of the virtual machine code that implement the method. When read into memory, the first byte of code must be aligned onto a multiple-of-four boundary. See the definitions of the the opcodes "tableswitch" and "tablelookup" for more information on alignment requirements.

### exception_table_length

The number of entries in the following exception table.

### exception_table

Each entry in the exception table describes one exception handler in the code.

### start_pc, end_pc

The two fields start_pc and end_pc give the ranges in the code at which the exception handler is active. The values of both fields are offsets from the start of the code. start_pc is inclusive. end_pc is exclusive.

### handler_pc

This field gives the starting address of the exception handler. The value of the field is an offset from the start of the code.

### catch_type

If catch_type is non-zero, then constant_pool[catch_type] will be the class of exceptions that this exception handler is designated to catch. This exception handler should only be called if the thrown exception is an instance of the given class.

If catch_type is zero, this exception handler should be called for all exceptions.

### attributes_count

This value gives the number of additional attributes about code. The "Code" attribute can itself have attributes.

### attributes

A "Code" attribute can have any number of optional attributes associated with it. Each attribute has a name, and other additional information. Currently, the only code attributes recognized are the "LineNumberTable" and "LocalVariableTable," both of which contain debugging information.

Any other attributes are skipped.

### Line Number Table Attribute

The Line Number Table is used by debuggers and the exception handler to determine which part of the virtual machine code corresponds to a given location in the source. The LineNumberTable_attribute has the following format:

    LineNumberTable_attribute {
    	u2		attribute_name_index;
    	u2		attribute_length;
    	u2		line_number_table_length;
    	{  u2 	   		start_pc;
    		u2	   line_number;
    	}		line_number_table[line_number_table_length];
    }

### attribute_name_index

constant_pool[attribute_name_index] will be the string "LineNumberTable."

### attribute_length

This field gives the total length of the LineNumberTable_attribute, excluding the initial four bytes.

### line_number_table_length

This field gives the number of entries in the following line number table.

### line_number_table

Each entry in the line number table indicates that the line number in the source file changes at a given point in the code.

### start_pc

This field indicates the place in the code at which the code for a new line in the source begins. source_pc is an offset from the beginning of the code.

### line_number

The line number that begins at the given location in the file.

### Local Variable Table Attribute

The Local Variable Table is used by debuggers to determine the value of a given local variable during the dynamic execution of a method. The format of the LocalVariableTable_attribute is as follows:

    LocalVariableTable_attribute {
    	u2	attribute_name_index;
    	u2	attribute_length;
    	u2	local_variable_table_length;
    	{  u2 	   start_pc;
    	   u2	   length;
    	   u2	   name_index;
    	   u2	   signature_index;
    	   u2	   slot;
    	} 	local_variable_table[local_variable_table_length];
    }

### attribute_name_index

constant_pool[attribute_name_index] will be the string "LocalVariableTable."

### attribute_length

This field gives the total length of the LineNumberTable_attribute, excluding the initial four bytes.

### local_variable_table_length

This field gives the number of entries in the following local variable table.

### line_number_table

Each entry in the line number table indicates a code range during which a local variable has a value. It also indicates where on the stack the value of that variable can be found.

### start_pc, length

The given local variable will have a value at the code between start_pc and start_pc + length. The two values are both offsets from the beginning of the code.

### name_index, signature_index

constant_pool[name_index]and constant_pool[signature_index] are strings giving the name and signature of the local variable.

### slot

The given variable will be the slotth local variable in the method's frame.

Contents Prev Next Up

Generated with CERN WebMaker