All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class gnu.bytecode.CodeAttr

java.lang.Object
   |
   +----gnu.bytecode.Attribute
           |
           +----gnu.bytecode.CodeAttr

public class CodeAttr
extends Attribute
implements AttrContainer
Represents the contents of a standard "Code" attribute.

Most of the actual methods that generate bytecode operation are in this class (typically with names starting with emit), though there are also some in Method.

Note that a CodeAttr is an Attribute of a Method, and can in turn contain other Attributes, such as a LineNumbersAttr.

Author:
Per Bothner

Constructor Index

 o CodeAttr(Method)

Method Index

 o addHandler(int, int, int, ClassType, ConstantPool)
Add an exception handler.
 o addHandler(int, int, int, int)
Add an exception handler.
 o addLocal(Type)
Add a new local variable (in the current scope).
 o assignConstants(ClassType)
Add any needed constant pool entries for this Attribute.
 o disAssemble(ClassTypeWriter, int, int)
 o emitAdd()
 o emitArrayLength()
 o emitArrayLoad(Type)
Load an element from an array.
 o emitArrayStore(Type)
Store into an element of an array.
 o emitCatchEnd()
 o emitCatchStart(Variable)
 o emitCheckcast(Type)
 o emitConvert(Type)
Convert the element on top of the stack to requested type
 o emitConvert(Type, Type)
 o emitDiv()
 o emitDup(int)
Compile code to duplicate the top 1 or 2 words.
 o emitDup(int, int)
Compile code to duplicate with offset.
 o emitDup(Type)
 o emitElse()
Compile start of else clause.
 o emitFi()
Compile end of conditional.
 o emitFinallyEnd()
 o emitFinallyStart()
 o emitGetField(Field)
Compile code to get a non-static field value.
 o emitGetStatic(Field)
Compile code to get a static field value.
 o emitGoto(Label)
Compile an unconditional branch (goto).
 o emitGoto(Label, int)
Compile an unconditional branch (goto) or a jsr.
 o emitGotoIf(int)
Compile start of a conditional: if (!(x OPCODE 0)) ...
 o emitGotoIfEq(Label)
Compile a conditional transfer if 2 top stack elements are equal.
 o emitGotoIfEq(Label, boolean)
 o emitGotoIfNE(Label)
Compile conditional transfer if 2 top stack elements are not equal.
 o emitIfIntCompare(int)
Compile start of a conditional: if (!(x OPCODE y)) ...
 o emitIfIntLt()
 o emitIfIntNotZero()
Compile start of conditional: if (x != 0)
 o emitIfNEq()
Compile start of a conditional: if (x != y) ...
 o emitInstanceof(Type)
 o emitInvokeMethod(Method, int)
 o emitInvokeSpecial(Method)
 o emitInvokeStatic(Method)
Compile a static method call.
 o emitInvokeVirtual(Method)
Compile a virtual method call.
 o emitLoad(Variable)
Comple code to push the contents of a local variable onto the statck.
 o emitMul()
 o emitNew(ClassType)
Invoke new on a class type.
 o emitNewArray(Type)
Compile code to allocate a new array.
 o emitPop(int)
Compile code to pop values off the stack (and ignore them).
 o emitPrimop(int, int, Type)
 o emitPushDouble(double)
 o emitPushInt(int)
 o emitPushLong(long)
 o emitPushNull()
 o emitPushString(String)
 o emitPushThis()
 o emitPutField(Field)
Compile code to put a non-static field value.
 o emitPutStatic(Field)
Compile code to put a static field value.
 o emitRem()
 o emitRet(Variable)
Emit a 'ret' instruction.
 o emitReturn()
Compile a method return.
 o emitStore(Variable)
 o emitSub()
 o emitSwap()
 o emitThrow()
 o emitTryCatchEnd()
 o emitTryEnd()
 o emitTryStart(boolean)
 o enterScope(Scope)
 o finalize_labels()
 o getArg(int)
Get the index'th parameter.
 o getAttributes()
 o getCode()
Get the code (instruction bytes) of this method.
 o getCodeLength()
Set the current lengthof the code (instruction bytes) of this method.
 o getConstants()
 o getLength()
Return the length of the attribute in bytes.
 o getMaxLocals()
Get the maximum number of local variable words in this method.
 o getMaxStack()
Get the maximum number of words on the operand stack in this method.
 o getMethod()
 o popScope()
 o popType()
 o print(ClassTypeWriter)
 o pushScope()
 o pushType(Type)
 o put1(int)
Write an 8-bit byte to the current code-stream.
 o put2(int)
Write a 16-bit short to the current code-stream
 o put4(int)
Write a 32-bit int to the current code-stream
 o putIndex2(CpoolEntry)
 o putLineNumber(int)
 o reachableHere()
True if control could reach here.
 o reserve(int)
 o setAttributes(Attribute)
 o setCode(byte[])
Set the code (instruction bytes) of this method.
 o setCodeLength(int)
Set the length the the code (instruction bytes) of this method.
 o setMaxLocals(int)
Set the maximum number of local variable words in this method.
 o setMaxStack(int)
Set the maximum number of words on the operand stack in this method.
 o topType()
 o write(DataOutputStream)
Write out the contents of the Attribute.

Constructors

 o CodeAttr
 public CodeAttr(Method meth)

Methods

 o getAttributes
 public final Attribute getAttributes()
 o setAttributes
 public final void setAttributes(Attribute attributes)
 o getMethod
 public final Method getMethod()
 o getConstants
 public final ConstantPool getConstants()
 o reachableHere
 public boolean reachableHere()
True if control could reach here.

 o getMaxStack
 public int getMaxStack()
Get the maximum number of words on the operand stack in this method.

 o getMaxLocals
 public int getMaxLocals()
Get the maximum number of local variable words in this method.

 o setMaxStack
 public void setMaxStack(int n)
Set the maximum number of words on the operand stack in this method.

 o setMaxLocals
 public void setMaxLocals(int n)
Set the maximum number of local variable words in this method.

 o getCode
 public byte[] getCode()
Get the code (instruction bytes) of this method. Does not make a copy.

 o setCode
 public void setCode(byte code[])
Set the code (instruction bytes) of this method.

Parameters:
code - the code bytes (which are not copied). Implicitly calls setCodeLength(code.length).
 o setCodeLength
 public void setCodeLength(int len)
Set the length the the code (instruction bytes) of this method. That is the number of current used bytes in getCode(). (Any remaing bytes provide for future growth.)

 o getCodeLength
 public int getCodeLength()
Set the current lengthof the code (instruction bytes) of this method.

 o reserve
 public final void reserve(int bytes)
 o put1
 public final void put1(int i)
Write an 8-bit byte to the current code-stream.

Parameters:
i - the byte to write
 o put2
 public final void put2(int i)
Write a 16-bit short to the current code-stream

Parameters:
i - the value to write
 o put4
 public final void put4(int i)
Write a 32-bit int to the current code-stream

Parameters:
i - the value to write
 o putIndex2
 public final void putIndex2(CpoolEntry cnst)
 o putLineNumber
 public final void putLineNumber(int linenumber)
 o pushType
 public final void pushType(Type type)
 o popType
 public final Type popType()
 o topType
 public final Type topType()
 o emitPop
 public void emitPop(int nvalues)
Compile code to pop values off the stack (and ignore them).

Parameters:
nvalues - the number of values (not words) to pop
 o emitSwap
 public void emitSwap()
 o emitDup
 public void emitDup(int size,
                     int offset)
Compile code to duplicate with offset.

Parameters:
size - the size of the stack item to duplicate (1 or 2)
offset - where to insert the result (must be 0, 1, or 2) The new words get inserted at stack[SP-size-offset]
 o emitDup
 public void emitDup(int size)
Compile code to duplicate the top 1 or 2 words.

Parameters:
size - number of words to duplicate
 o emitDup
 public void emitDup(Type type)
 o enterScope
 public void enterScope(Scope scope)
 o pushScope
 public Scope pushScope()
 o popScope
 public Scope popScope()
 o getArg
 public Variable getArg(int index)
Get the index'th parameter.

 o addLocal
 public Variable addLocal(Type type)
Add a new local variable (in the current scope).

Parameters:
type - type of the new Variable.
Returns:
the new Variable.
 o emitPushInt
 public final void emitPushInt(int i)
 o emitPushLong
 public void emitPushLong(long i)
 o emitPushDouble
 public void emitPushDouble(double x)
 o emitPushString
 public final void emitPushString(String str)
 o emitPushNull
 public void emitPushNull()
 o emitPushThis
 public final void emitPushThis()
 o emitArrayLength
 public final void emitArrayLength()
 o emitArrayStore
 public void emitArrayStore(Type element_type)
Store into an element of an array. Must already have pushed the array reference, the index, and the new value (in that order). Stack: ..., array, index, value => ...

 o emitArrayLoad
 public void emitArrayLoad(Type element_type)
Load an element from an array. Must already have pushed the array and the index (in that order): Stack: ..., array, index => ..., value

 o emitNew
 public void emitNew(ClassType type)
Invoke new on a class type. Does not call the constructor!

Parameters:
type - the desired new object type
 o emitNewArray
 public void emitNewArray(Type element_type)
Compile code to allocate a new array. The size shold have been already pushed on the stack.

Parameters:
type - type of the array elements
 o emitAdd
 public final void emitAdd()
 o emitSub
 public final void emitSub()
 o emitMul
 public final void emitMul()
 o emitDiv
 public final void emitDiv()
 o emitRem
 public final void emitRem()
 o emitPrimop
 public void emitPrimop(int opcode,
                        int arg_count,
                        Type retType)
 o emitLoad
 public final void emitLoad(Variable var)
Comple code to push the contents of a local variable onto the statck.

Parameters:
var - The variable whose contents we want to push.
 o emitStore
 public void emitStore(Variable var)
 o emitGetStatic
 public final void emitGetStatic(Field field)
Compile code to get a static field value. Stack: ... => ..., value

 o emitGetField
 public final void emitGetField(Field field)
Compile code to get a non-static field value. Stack: ..., objectref => ..., value

 o emitPutStatic
 public final void emitPutStatic(Field field)
Compile code to put a static field value. Stack: ..., value => ...

 o emitPutField
 public final void emitPutField(Field field)
Compile code to put a non-static field value. Stack: ..., objectref, value => ...

 o emitInvokeMethod
 public void emitInvokeMethod(Method method,
                              int opcode)
 o emitInvokeVirtual
 public void emitInvokeVirtual(Method method)
Compile a virtual method call. The stack contains the 'this' object, followed by the arguments in order.

Parameters:
method - the method to invoke virtually
 o emitInvokeSpecial
 public void emitInvokeSpecial(Method method)
 o emitInvokeStatic
 public void emitInvokeStatic(Method method)
Compile a static method call. The stack contains the the arguments in order.

Parameters:
method - the static method to invoke
 o emitGoto
 public final void emitGoto(Label label,
                            int opcode)
Compile an unconditional branch (goto) or a jsr.

Parameters:
label - target of the branch (must be in this method).
 o emitGoto
 public final void emitGoto(Label label)
Compile an unconditional branch (goto).

Parameters:
label - target of the branch (must be in this method).
 o emitGotoIfEq
 public final void emitGotoIfEq(Label label,
                                boolean invert)
 o emitGotoIfEq
 public final void emitGotoIfEq(Label label)
Compile a conditional transfer if 2 top stack elements are equal.

 o emitGotoIfNE
 public final void emitGotoIfNE(Label label)
Compile conditional transfer if 2 top stack elements are not equal.

 o emitGotoIf
 public final void emitGotoIf(int opcode)
Compile start of a conditional: if (!(x OPCODE 0)) ... The value of x must already have been pushed.

 o emitIfIntNotZero
 public final void emitIfIntNotZero()
Compile start of conditional: if (x != 0)

 o emitIfIntCompare
 public final void emitIfIntCompare(int opcode)
Compile start of a conditional: if (!(x OPCODE y)) ... The value of x and y must already have been pushed.

 o emitIfIntLt
 public final void emitIfIntLt()
 o emitIfNEq
 public final void emitIfNEq()
Compile start of a conditional: if (x != y) ... The values of x and y must already have been pushed.

 o emitRet
 public void emitRet(Variable var)
Emit a 'ret' instruction.

Parameters:
var - the variable containing the return address
 o emitElse
 public final void emitElse()
Compile start of else clause.

 o emitFi
 public final void emitFi()
Compile end of conditional.

 o emitConvert
 public final void emitConvert(Type type)
Convert the element on top of the stack to requested type

 o emitConvert
 public final void emitConvert(Type from,
                               Type to)
 o emitCheckcast
 public void emitCheckcast(Type type)
 o emitInstanceof
 public void emitInstanceof(Type type)
 o emitThrow
 public final void emitThrow()
 o emitReturn
 public final void emitReturn()
Compile a method return.

 o addHandler
 public void addHandler(int start_pc,
                        int end_pc,
                        int handler_pc,
                        int catch_type)
Add an exception handler.

 o addHandler
 public void addHandler(int start_pc,
                        int end_pc,
                        int handler_pc,
                        ClassType catch_type,
                        ConstantPool constants)
Add an exception handler.

 o emitTryStart
 public void emitTryStart(boolean has_finally)
 o emitTryEnd
 public void emitTryEnd()
 o emitCatchStart
 public void emitCatchStart(Variable var)
 o emitCatchEnd
 public void emitCatchEnd()
 o emitFinallyStart
 public void emitFinallyStart()
 o emitFinallyEnd
 public void emitFinallyEnd()
 o emitTryCatchEnd
 public void emitTryCatchEnd()
 o finalize_labels
 public void finalize_labels()
 o assignConstants
 public void assignConstants(ClassType cl)
Add any needed constant pool entries for this Attribute.

Overrides:
assignConstants in class Attribute
 o getLength
 public final int getLength()
Return the length of the attribute in bytes.

Overrides:
getLength in class Attribute
 o write
 public void write(DataOutputStream dstr) throws IOException
Write out the contents of the Attribute.

Overrides:
write in class Attribute
 o print
 public void print(ClassTypeWriter dst)
Overrides:
print in class Attribute
 o disAssemble
 public void disAssemble(ClassTypeWriter dst,
                         int offset,
                         int length)

All Packages  Class Hierarchy  This Package  Previous  Next  Index