3.3 Methods Data Structure
The methods data structure is an array of method structure items. Each
item consists of:
- access flags (private/public/protected, static, final, synchronized, native, abstract, strictfp)
- method name reference (an index in the constant pool)
- descriptor reference (an index in the constant pool to the type of the method)
- attributes - an array of attributes
The last item is an array of additional attributes that provide
additional information about the method. Each Java Virtual Machine
should recognize the attributes Code, Exceptions, and Synthetic.
Every method which is not abstract or native must have exactly one
Code attribute (otherwise zero).
BML-related method attributes are described in Method Attributes.
3.3.1 Code Attribute
The structure of a method's Code attribute is as follows:
- attribute name (Code) and length
- max_stacks - maximum depth of the operand stack
- max_locals - number of local variables in the local variable
array allocated upon invocation of this method, including the local
variables used to pass parameters to the method when it is invoked
- the code - an array of opcodes (i.e., the instruction list)
- exception table - an array of exception handlers, each of which
is represented by a quadruple: start_pc, end_pc, handler_pc and
catch_type. The first two items describe the boundaries of the try catch
block. The first three item are indexes in the code array, the fourth
item is an index in the constant pool containing the exception class.
- attributes - an array of attributes
There is no requirement on a Java Virtual Machine to recognize any
attributes in the attributes item above. A virtual machine may
recognize for debugging and specification purposes the following code
attributes: LineNumberTable, LocalVariableTable.
BML-related code attributes are described in Code Attributes.
3.3.2 LocalVariableTable Attribute
The LocalVariableTable is an optional attribute of a method's Code attribute.
It may be used by debuggers to determine the value of a given local
variable during the execution of a method. There may be more than one
LocalVariableTable attribute in the Code attribute, but each local
variable can be mentioned at most once. The order of
LocalVariableTable attributes is unspecified.
The structure of each entry in the local variable table is as follows:
- start_pc, length - the begining and length of the code fragment, where the given local variable has a meaningful value
- name reference - index in the constant pool, where the variable name is stored
- descriptor - index in the constant pool, where the variable type is stored (as a field description)
- index - index of the local variable array
3.3.3 LineNumberTable Attribute
The LineNumberTable is an optional attribute of a method's Code attribute.
It may be used by debuggers to determine which part of the Java Virtual
Machine code array corresponds to a given line number in the original
source file. There may be more than one LineNumberTable attributes in
the Code attribute, and their order is unspecified. Moreover, the
mapping from code addresses to source lines does not have to be in a
one-to-one correspondence.
The structure of each entry in the line number table is as follows:
- start_pc - index in the Code array
- line_number - number of the source code line, corresponding to the given bytecode instruction