final class CodeAttribute extends Attribute
Code
attribute structure for a method. This includes information about the
maximum stack depth and maximum local variables, exception table data,
and the bytecode array itself.Modifier and Type | Field and Description |
---|---|
private int |
attrLength
Number of associated attributes.
|
private java.util.List |
attrs
List of all attributes associated with this Code attribute.
|
private java.util.List |
code
List of all bytecode containers which compose the code array.
|
private java.util.List |
excTables
List of all exception tables associated with the code array.
|
private int |
maxLocals
Maximum number of local variables used at one time in the method.
|
private int |
maxStack
Maximum depth, in 32-bit slots, of the operand stack.
|
CODE, CONSTANTVALUE, DEPRECATED, EXCEPTIONS, INNERCLASS, LINENUMBERTABLE, LOCALVARIABLETABLE, SOURCEFILE, SYNTHETIC
Constructor and Description |
---|
CodeAttribute(ConstantPool pool)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
(package private) void |
addCodeUnit(CodeUnit unit)
This method adds a unit of code to the end of the code array.
|
(package private) void |
addInstruction(Instruction instruc)
This method adds a single instruction to the end of the code array.
|
(package private) void |
fixupStack()
This method calls
fixupStack on each bytecode container
in this attribute. |
private int |
getCodeLength()
Return the length of the bytecode array in this code attribute,
measured in bytes.
|
protected int |
getLength()
Return the total length in bytes of this code attribute, including
the bytecode array and all other data.
|
private void |
layoutCode()
This method assigns the final address offsets to each unit of code
in the code array of this attribute, then fixes up all of the
instructions which cause a branch to another instruction.
|
(package private) void |
setMaxLocals(int maxLocals)
Set the maximum number of local variable used at one time in this
method.
|
(package private) void |
setMaxStack(Compiler compiler)
This method iterates over all of the bytecode containers in the code
array to determine the maximum depth which the JVM's operand stack
may reach in the execution of this bytecode.
|
java.lang.String |
toString()
Get a string representation of this object.
|
protected void |
writeContent(java.io.DataOutput out)
This method writes the data content of this code attribute to the
specified output stream.
|
private int maxStack
private int maxLocals
private java.util.List code
private java.util.List excTables
private java.util.List attrs
private int attrLength
CodeAttribute(ConstantPool pool)
Code
attribute object associated
with the specified constant pool.pool
- Constant pool with which this code attribute is associated.public java.lang.String toString()
toString
in class java.lang.Object
protected int getLength()
protected void writeContent(java.io.DataOutput out) throws java.io.IOException
writeContent
in class Attribute
out
- Output stream to which to write data.java.io.IOException
- if any error occurs during writing.void addInstruction(Instruction instruc)
instruc
- Instruction to add.void addCodeUnit(CodeUnit unit)
unit
- Code unit to add to the end of the array.void setMaxStack(Compiler compiler)
compiler
- Object which manages the maximum stack depth.void setMaxLocals(int maxLocals)
maxLocals
- Maximum number of local variables.void fixupStack()
fixupStack
on each bytecode container
in this attribute. The purpose is to remove any superfluous stack
entries before branching control when checking for null variable
references at runtime.private int getCodeLength()
private void layoutCode()