Package org.apache.bcel.classfile
Class Code
java.lang.Object
org.apache.bcel.classfile.Attribute
org.apache.bcel.classfile.Code
This class represents a chunk of Java byte code contained in a
method. It is instantiated by the
Attribute.readAttribute() method. A Code
attribute contains informations about operand stack, local
variables, byte code and the exceptions handled within this
method.
This attribute has attributes itself, namely LineNumberTable which
is used for debugging purposes and LocalVariableTable which
contains information about the local variables.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Attribute[]
private byte[]
private CodeException[]
private int
private int
Fields inherited from class org.apache.bcel.classfile.Attribute
constant_pool, length, name_index, tag
-
Constructor Summary
ConstructorsConstructorDescriptionCode
(int name_index, int length, int max_stack, int max_locals, byte[] code, CodeException[] exception_table, Attribute[] attributes, ConstantPool constant_pool) Code
(int name_index, int length, DataInput file, ConstantPool constant_pool) Initialize from another object. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Called by objects that are traversing the nodes of the tree implicitely defined by the contents of a Java class.private int
copy
(ConstantPool _constant_pool) void
dump
(DataOutputStream file) Dump code attribute to file stream in binary format.byte[]
getCode()
private int
int
int
void
setAttributes
(Attribute[] attributes) void
setCode
(byte[] code) void
setExceptionTable
(CodeException[] exception_table) void
setMaxLocals
(int max_locals) void
setMaxStack
(int max_stack) toString()
toString
(boolean verbose) Methods inherited from class org.apache.bcel.classfile.Attribute
addAttributeReader, addAttributeReader, clone, getConstantPool, getLength, getName, getNameIndex, getTag, println, readAttribute, readAttribute, removeAttributeReader, setConstantPool, setLength, setNameIndex
-
Field Details
-
max_stack
private int max_stack -
max_locals
private int max_locals -
code
private byte[] code -
exception_table
-
attributes
-
-
Constructor Details
-
Code
Initialize from another object. Note that both objects use the same references (shallow copy). Use copy() for a physical copy. -
Code
Code(int name_index, int length, DataInput file, ConstantPool constant_pool) throws IOException - Parameters:
name_index
- Index pointing to the name Codelength
- Content length in bytesfile
- Input streamconstant_pool
- Array of constants- Throws:
IOException
-
Code
public Code(int name_index, int length, int max_stack, int max_locals, byte[] code, CodeException[] exception_table, Attribute[] attributes, ConstantPool constant_pool) - Parameters:
name_index
- Index pointing to the name Codelength
- Content length in bytesmax_stack
- Maximum size of stackmax_locals
- Number of local variablescode
- Actual byte codeexception_table
- Table of handled exceptionsattributes
- Attributes of code: LineNumber or LocalVariableconstant_pool
- Array of constants
-
-
Method Details
-
accept
Called by objects that are traversing the nodes of the tree implicitely defined by the contents of a Java class. I.e., the hierarchy of methods, fields, attributes, etc. spawns a tree of objects. -
dump
Dump code attribute to file stream in binary format.- Overrides:
dump
in classAttribute
- Parameters:
file
- Output file stream- Throws:
IOException
-
getAttributes
- Returns:
- Collection of code attributes.
- See Also:
-
getLineNumberTable
- Returns:
- LineNumberTable of Code, if it has one
-
getLocalVariableTable
- Returns:
- LocalVariableTable of Code, if it has one
-
getCode
public byte[] getCode()- Returns:
- Actual byte code of the method.
-
getExceptionTable
- Returns:
- Table of handled exceptions.
- See Also:
-
getMaxLocals
public int getMaxLocals()- Returns:
- Number of local variables.
-
getMaxStack
public int getMaxStack()- Returns:
- Maximum size of stack used by this method.
-
getInternalLength
private int getInternalLength()- Returns:
- the internal length of this code attribute (minus the first 6 bytes) and excluding all its attributes
-
calculateLength
private int calculateLength()- Returns:
- the full size of this code attribute, minus its first 6 bytes, including the size of all its contained attributes
-
setAttributes
- Parameters:
attributes
- the attributes to set for this Code
-
setCode
public void setCode(byte[] code) - Parameters:
code
- byte code
-
setExceptionTable
- Parameters:
exception_table
- exception table
-
setMaxLocals
public void setMaxLocals(int max_locals) - Parameters:
max_locals
- maximum number of local variables
-
setMaxStack
public void setMaxStack(int max_stack) - Parameters:
max_stack
- maximum stack size
-
toString
- Returns:
- String representation of code chunk.
-
toString
-
copy
-