attr
Class codeAttr
java.lang.Object
|
+--util.dataRead
|
+--attr.attrInfo
|
+--attr.codeAttr
- public class codeAttr
- extends attrInfo
Attribute for the byte code for a Java method. The attribute name
for the codeAttr is "Code". Note that if the method is native or
abstract, then it can't have a "Code" attribute.
The structure of a Code attribute is:
Code_attribute {
u2 name_index;
u4 total_length;
u2 max_stack;
u2 max_locals;
u4 code_length;
u1 code[ code_length ];
u2 exceptions_table_length;
exceptInfo except[ exceptions_table_length ];
u2 attributes_count;
attribute_info attributes[ attributes_count ];
}
Where
exceptInfo {
u2 start_pc;
U2 end_pc;
u2 handler_pc;
u2 catch_type;
}
The attribute_name_index and attribute length are read by the
attrFactory.allocAttr method. These values are passed into the class
constructor.
In the exceptInfo the catch_type is an index into the constant
pool. The object at this index must be a CONSTANT_Class_info
object (e.g., constClass_or_String) for an exception class that
this exception is designated to catch. This class must be the
class Throwable or one of its subclasses.
Although code_length is 32-bits wide, its value must be less than
0x10000 (65536) (see JVM Spec 4.8.1).
The max_stack value is the size of the operand stack. This in
in word units, where an int is one word and a long or double
is two:
At any point in time an operand stack has an associated depth,
where a value of type long or double contributes two units to
the depth and a value of any other type contributes one unit.
(JVM Spec 3.6.2)
The max_locals value is the size of the local frame allocated on
entry to the method. This frame will hold local variables and
method arguments. As with max_stack, the units are words. Like
the stack, the frame is word aligned so a boolean or a byte
occupies a word and a long or a double occupies two words (JVM
Spec 3.6.1).
If max_locals is zero, then there are no local variables.
If debug is turned and the method has local variables then
the codeAttributes table will contain a LocalVariableTable
attribute. This attribute in turn contains a table of
local variable information.
- Author:
- Ian Kaplan
Constructor Summary |
codeAttr(java.lang.String name,
int length,
java.io.DataInputStream dStream,
constPool constPoolSec)
codeAttr constructor
|
Method Summary |
java.util.Vector |
getLocalVarVec()
If there are local variables in the method, return a vector
containing the local variable name declarations. |
int |
getMax_locals()
|
int |
getMax_stack()
|
Methods inherited from class java.lang.Object |
,
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
registerNatives,
toString,
wait,
wait,
wait |
max_stack
private int max_stack
max_locals
private int max_locals
codeBuf
private byte[] codeBuf
exceptTab
private codeAttr.exceptInfo[] exceptTab
codeAttributes
private attrInfo[] codeAttributes
codeAttr
public codeAttr(java.lang.String name,
int length,
java.io.DataInputStream dStream,
constPool constPoolSec)
- codeAttr constructor
Here the length argument is the attribute length (e.g., the
total length of the attribute).
getLocalVarVec
public java.util.Vector getLocalVarVec()
- If there are local variables in the method, return a vector
containing the local variable name declarations. There should
be only one localVarTabAttr in the codeAttributes table.
getMax_locals
public int getMax_locals()
getMax_stack
public int getMax_stack()