public class CodeAttribute extends AttributeInfo implements Opcode
Code_attribute
.
To browse the code
field of
a Code_attribute
structure,
use CodeIterator
.
CodeIterator
,
iterator()
Modifier and Type | Class and Description |
---|---|
(package private) static class |
CodeAttribute.LdcEntry |
static class |
CodeAttribute.RuntimeCopyException
An exception that may be thrown by
copy()
in CodeAttribute . |
Modifier and Type | Field and Description |
---|---|
private java.util.ArrayList |
attributes |
private ExceptionTable |
exceptions |
private int |
maxLocals |
private int |
maxStack |
static java.lang.String |
tag
The name of this attribute
"Code" . |
constPool, info, name
AALOAD, AASTORE, ACONST_NULL, ALOAD, ALOAD_0, ALOAD_1, ALOAD_2, ALOAD_3, ANEWARRAY, ARETURN, ARRAYLENGTH, ASTORE, ASTORE_0, ASTORE_1, ASTORE_2, ASTORE_3, ATHROW, BALOAD, BASTORE, BIPUSH, CALOAD, CASTORE, CHECKCAST, D2F, D2I, D2L, DADD, DALOAD, DASTORE, DCMPG, DCMPL, DCONST_0, DCONST_1, DDIV, DLOAD, DLOAD_0, DLOAD_1, DLOAD_2, DLOAD_3, DMUL, DNEG, DREM, DRETURN, DSTORE, DSTORE_0, DSTORE_1, DSTORE_2, DSTORE_3, DSUB, DUP, DUP_X1, DUP_X2, DUP2, DUP2_X1, DUP2_X2, F2D, F2I, F2L, FADD, FALOAD, FASTORE, FCMPG, FCMPL, FCONST_0, FCONST_1, FCONST_2, FDIV, FLOAD, FLOAD_0, FLOAD_1, FLOAD_2, FLOAD_3, FMUL, FNEG, FREM, FRETURN, FSTORE, FSTORE_0, FSTORE_1, FSTORE_2, FSTORE_3, FSUB, GETFIELD, GETSTATIC, GOTO, GOTO_W, I2B, I2C, I2D, I2F, I2L, I2S, IADD, IALOAD, IAND, IASTORE, ICONST_0, ICONST_1, ICONST_2, ICONST_3, ICONST_4, ICONST_5, ICONST_M1, IDIV, IF_ACMPEQ, IF_ACMPNE, IF_ICMPEQ, IF_ICMPGE, IF_ICMPGT, IF_ICMPLE, IF_ICMPLT, IF_ICMPNE, IFEQ, IFGE, IFGT, IFLE, IFLT, IFNE, IFNONNULL, IFNULL, IINC, ILOAD, ILOAD_0, ILOAD_1, ILOAD_2, ILOAD_3, IMUL, INEG, INSTANCEOF, INVOKEDYNAMIC, INVOKEINTERFACE, INVOKESPECIAL, INVOKESTATIC, INVOKEVIRTUAL, IOR, IREM, IRETURN, ISHL, ISHR, ISTORE, ISTORE_0, ISTORE_1, ISTORE_2, ISTORE_3, ISUB, IUSHR, IXOR, JSR, JSR_W, L2D, L2F, L2I, LADD, LALOAD, LAND, LASTORE, LCMP, LCONST_0, LCONST_1, LDC, LDC_W, LDC2_W, LDIV, LLOAD, LLOAD_0, LLOAD_1, LLOAD_2, LLOAD_3, LMUL, LNEG, LOOKUPSWITCH, LOR, LREM, LRETURN, LSHL, LSHR, LSTORE, LSTORE_0, LSTORE_1, LSTORE_2, LSTORE_3, LSUB, LUSHR, LXOR, MONITORENTER, MONITOREXIT, MULTIANEWARRAY, NEW, NEWARRAY, NOP, POP, POP2, PUTFIELD, PUTSTATIC, RET, RETURN, SALOAD, SASTORE, SIPUSH, STACK_GROW, SWAP, T_BOOLEAN, T_BYTE, T_CHAR, T_DOUBLE, T_FLOAT, T_INT, T_LONG, T_SHORT, TABLESWITCH, WIDE
Modifier | Constructor and Description |
---|---|
private |
CodeAttribute(ConstPool cp,
CodeAttribute src,
java.util.Map classnames)
Constructs a copy of
Code_attribute . |
(package private) |
CodeAttribute(ConstPool cp,
int name_id,
java.io.DataInputStream in) |
|
CodeAttribute(ConstPool cp,
int stack,
int locals,
byte[] code,
ExceptionTable etable)
Constructs a
Code_attribute . |
Modifier and Type | Method and Description |
---|---|
int |
computeMaxStack()
Computes the maximum stack size and sets
max_stack
to the computed size. |
AttributeInfo |
copy(ConstPool newCp,
java.util.Map classnames)
Makes a copy.
|
private static CodeAttribute.LdcEntry |
copyCode(byte[] code,
int beginPos,
int endPos,
ConstPool srcCp,
byte[] newcode,
ConstPool destCp,
java.util.Map classnameMap) |
private byte[] |
copyCode(ConstPool destCp,
java.util.Map classnames,
ExceptionTable etable,
CodeAttribute destCa)
Copies code.
|
private static void |
copyConstPoolInfo(int i,
byte[] code,
ConstPool srcCp,
byte[] newcode,
ConstPool destCp,
java.util.Map classnameMap) |
byte[] |
get()
This method is not available.
|
AttributeInfo |
getAttribute(java.lang.String name)
Returns the attribute with the specified name.
|
java.util.List |
getAttributes()
Returns
attributes[] . |
byte[] |
getCode()
Returns
code[] . |
int |
getCodeLength()
Returns
code_length . |
java.lang.String |
getDeclaringClass()
Returns the name of the class declaring the method including
this code attribute.
|
ExceptionTable |
getExceptionTable()
Returns
exception_table[] . |
int |
getMaxLocals()
Returns
max_locals . |
int |
getMaxStack()
Returns
max_stack . |
(package private) void |
getRefClasses(java.util.Map classnames) |
void |
insertLocalVar(int where,
int size)
Changes the index numbers of the local variables
to append a new parameter.
|
CodeIterator |
iterator()
Makes a new iterator for reading this code attribute.
|
int |
length()
Returns the length of this
attribute_info
structure. |
(package private) void |
renameClass(java.util.Map classnames) |
(package private) void |
renameClass(java.lang.String oldname,
java.lang.String newname) |
void |
set(byte[] newinfo)
This method is not available.
|
void |
setAttribute(StackMap sm)
Adds a stack map table for J2ME (CLDC).
|
void |
setAttribute(StackMapTable smt)
Adds a stack map table.
|
(package private) void |
setCode(byte[] newinfo)
Sets
code[] . |
void |
setMaxLocals(int value)
Sets
max_locals . |
void |
setMaxStack(int value)
Sets
max_stack . |
private static void |
shiftIndex(CodeIterator ci,
int lessThan,
int delta) |
private static void |
shiftIndex0(CodeIterator ci,
int index,
int opcode,
int lessThan,
int delta,
int opcode_i_0,
int opcode_i) |
private static void |
shiftIndex8(CodeIterator ci,
int index,
int opcode,
int lessThan,
int delta) |
(package private) void |
write(java.io.DataOutputStream out) |
copyAll, getConstPool, getLength, getName, getRefClasses, lookup, read, remove, renameClass, renameClass, writeAll
public static final java.lang.String tag
"Code"
.private int maxStack
private int maxLocals
private ExceptionTable exceptions
private java.util.ArrayList attributes
public CodeAttribute(ConstPool cp, int stack, int locals, byte[] code, ExceptionTable etable)
Code_attribute
.cp
- constant pool tablestack
- max_stack
locals
- max_locals
code
- code[]
etable
- exception_table[]
private CodeAttribute(ConstPool cp, CodeAttribute src, java.util.Map classnames) throws BadBytecode
Code_attribute
.
Specified class names are replaced during the copy.cp
- constant pool table.src
- source Code attribute.classnames
- pairs of replaced and substituted
class names.BadBytecode
CodeAttribute(ConstPool cp, int name_id, java.io.DataInputStream in) throws java.io.IOException
java.io.IOException
public AttributeInfo copy(ConstPool newCp, java.util.Map classnames) throws CodeAttribute.RuntimeCopyException
Map
object.copy
in class AttributeInfo
newCp
- the constant pool table used by the new copy.classnames
- pairs of replaced and substituted
class names.CodeAttribute
object.CodeAttribute.RuntimeCopyException
- if a BadBytecode
exception is thrown, it is
converted into
RuntimeCopyException
.public int length()
attribute_info
structure.
The returned value is attribute_length + 6
.length
in class AttributeInfo
void write(java.io.DataOutputStream out) throws java.io.IOException
write
in class AttributeInfo
java.io.IOException
public byte[] get()
get
in class AttributeInfo
java.lang.UnsupportedOperationException
- always thrown.public void set(byte[] newinfo)
set
in class AttributeInfo
java.lang.UnsupportedOperationException
- always thrown.void renameClass(java.lang.String oldname, java.lang.String newname)
renameClass
in class AttributeInfo
void renameClass(java.util.Map classnames)
renameClass
in class AttributeInfo
void getRefClasses(java.util.Map classnames)
getRefClasses
in class AttributeInfo
public java.lang.String getDeclaringClass()
public int getMaxStack()
max_stack
.public void setMaxStack(int value)
max_stack
.public int computeMaxStack() throws BadBytecode
max_stack
to the computed size.max_stack
BadBytecode
- if this method fails in computing.public int getMaxLocals()
max_locals
.public void setMaxLocals(int value)
max_locals
.public int getCodeLength()
code_length
.public byte[] getCode()
code[]
.void setCode(byte[] newinfo)
code[]
.public CodeIterator iterator()
public ExceptionTable getExceptionTable()
exception_table[]
.public java.util.List getAttributes()
attributes[]
.
It returns a list of AttributeInfo
.
A new element can be added to the returned list
and an existing element can be removed from the list.AttributeInfo
public AttributeInfo getAttribute(java.lang.String name)
name
- attribute nameAttributeInfo
object or null.public void setAttribute(StackMapTable smt)
smt
- the stack map table added to this code attribute.
If it is null, a new stack map is not added.
Only the old stack map is removed.public void setAttribute(StackMap sm)
sm
- the stack map table added to this code attribute.
If it is null, a new stack map is not added.
Only the old stack map is removed.private byte[] copyCode(ConstPool destCp, java.util.Map classnames, ExceptionTable etable, CodeAttribute destCa) throws BadBytecode
BadBytecode
private static CodeAttribute.LdcEntry copyCode(byte[] code, int beginPos, int endPos, ConstPool srcCp, byte[] newcode, ConstPool destCp, java.util.Map classnameMap) throws BadBytecode
BadBytecode
private static void copyConstPoolInfo(int i, byte[] code, ConstPool srcCp, byte[] newcode, ConstPool destCp, java.util.Map classnameMap)
public void insertLocalVar(int where, int size) throws BadBytecode
LocalVariableAttribute
,
LocalVariableTypeAttribute
,
StackMapTable
, or StackMap
.
These attributes must be explicitly updated.where
- the index of the new parameter.size
- the type size of the new parameter (1 or 2).BadBytecode
LocalVariableAttribute.shiftIndex(int, int)
,
LocalVariableAttribute.shiftIndex(int, int)
,
StackMapTable.insertLocal(int, int, int)
,
StackMap.insertLocal(int, int, int)
private static void shiftIndex(CodeIterator ci, int lessThan, int delta) throws BadBytecode
lessThan
- If the index of the local variable is
less than this value, it does not change.
Otherwise, the index is increased.delta
- the indexes of the local variables are
increased by this value.BadBytecode
private static void shiftIndex8(CodeIterator ci, int index, int opcode, int lessThan, int delta) throws BadBytecode
BadBytecode
private static void shiftIndex0(CodeIterator ci, int index, int opcode, int lessThan, int delta, int opcode_i_0, int opcode_i) throws BadBytecode
BadBytecode