public final class CodeAttribute_info extends Attribute_info
Method_info
structures. A Code attribute
contains the JVM instructions and auxiliary information for a single Java method,
instance initialization method, or class or interface initialization method.
Every Java Virtual Machine implementation must recognize Code attributes. There
must be exactly one Code attribute in each method_info structure.The Code attribute has the format
Code_attribute { u2 attribute_name_index; u4 attribute_length; u2 max_stack; u2 max_locals; u4 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[attributes_count]; }The value of the max_stack item gives the maximum number of words on the operand stack at any point during execution of this method.
The value of the max_locals item gives the number of local variables used by this method, including the parameters passed to the method on invocation. The index of the first local variable is 0 . The greatest local variable index for a one-word value is max_locals-1 . The greatest local variable index for a two-word value is max_locals-2.
The value of the code_length item gives the number of bytes in the code array for this method. The value of code_length must be greater than zero; the code array must not be empty.The code array gives the actual bytes of Java Virtual Machine code that implement the method.
The value of the exception_table_length item gives the number of entries in the
exception_table table. Each entry in the exception_table array describes one
exception handler in the code array: see Exception_info
.
The value of the attributes_count item indicates the number of attributes of the Code attribute. Each value of the attributes table must be a variable-length attribute structure. A Code attribute can have any number of optional attributes associated with it.
Modifier and Type | Field and Description |
---|---|
private static boolean |
DEBUG |
static byte[] |
EMPTY_BYTE_ARRAY |
private IAttributeCollection |
m_attributes |
private byte[] |
m_code |
private int |
m_codeSize |
private IExceptionHandlerTable |
m_exceptionHandlerTable |
int |
m_max_locals |
int |
m_max_stack |
ATTRIBUTE_BRIDGE, ATTRIBUTE_CODE, ATTRIBUTE_CONSTANT_VALUE, ATTRIBUTE_EXCEPTIONS, ATTRIBUTE_INNERCLASSES, ATTRIBUTE_LINE_NUMBER_TABLE, ATTRIBUTE_SOURCEFILE, ATTRIBUTE_SYNTHETIC, m_attribute_length, m_name_index
Constructor and Description |
---|
CodeAttribute_info(IConstantCollection constants,
int attribute_name_index,
long attribute_length,
UDataInputStream bytes) |
CodeAttribute_info(int attribute_name_index,
int max_stack,
int max_locals,
byte[] code,
IExceptionHandlerTable exceptionHandlerTable,
IAttributeCollection attributes) |
Modifier and Type | Method and Description |
---|---|
void |
accept(IAttributeVisitor visitor,
java.lang.Object ctx) |
java.lang.Object |
clone()
Performs a deep copy.
|
IAttributeCollection |
getAttributes() |
byte[] |
getCode()
NOTE: must also use getCodeSize()
|
int |
getCodeSize() |
IExceptionHandlerTable |
getExceptionTable() |
long |
length()
Returns the total length of this attribute when converted to
.class format [including the 6-byte header]
|
void |
setCode(byte[] code,
int codeSize) |
java.lang.String |
toString() |
void |
writeInClassFormat(UDataOutputStream out) |
getName, new_Attribute_info
public static final byte[] EMPTY_BYTE_ARRAY
public int m_max_stack
public int m_max_locals
private byte[] m_code
private int m_codeSize
private IExceptionHandlerTable m_exceptionHandlerTable
private IAttributeCollection m_attributes
private static final boolean DEBUG
public CodeAttribute_info(int attribute_name_index, int max_stack, int max_locals, byte[] code, IExceptionHandlerTable exceptionHandlerTable, IAttributeCollection attributes)
CodeAttribute_info(IConstantCollection constants, int attribute_name_index, long attribute_length, UDataInputStream bytes) throws java.io.IOException
java.io.IOException
public final byte[] getCode()
public final int getCodeSize()
public IAttributeCollection getAttributes()
public IExceptionHandlerTable getExceptionTable()
public long length()
Attribute_info
length
in class Attribute_info
public void accept(IAttributeVisitor visitor, java.lang.Object ctx)
accept
in class Attribute_info
public java.lang.String toString()
toString
in class Attribute_info
public java.lang.Object clone()
clone
in class Attribute_info
public void writeInClassFormat(UDataOutputStream out) throws java.io.IOException
writeInClassFormat
in interface IClassFormatOutput
writeInClassFormat
in class Attribute_info
java.io.IOException
public void setCode(byte[] code, int codeSize)