|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.cojen.classfile.DelegatedCodeAssembler
public class DelegatedCodeAssembler
Delegates all method calls to another CodeAssembler. Override any method to track activity or change the way code is generated.
Field Summary | |
---|---|
protected CodeAssembler |
mAssembler
|
Fields inherited from interface org.cojen.classfile.CodeAssembler |
---|
CONVERT_FP_BITS, CONVERT_FP_NORMAL, CONVERT_FP_RAW_BITS |
Constructor Summary | |
---|---|
DelegatedCodeAssembler(CodeAssembler assembler)
|
Method Summary | |
---|---|
void |
arrayLength()
Generates code for an arraylength instruction. |
void |
branch(Location location)
Generates code that performs an unconditional branch to the specified location. |
void |
breakpoint()
Generates a breakpoint instruction for use in a debugging environment. |
void |
checkCast(TypeDesc type)
Generates code that performs an object cast operation. |
void |
convert(TypeDesc fromType,
TypeDesc toType)
Generates code that converts the value of a primitive type already on the stack. |
void |
convert(TypeDesc fromType,
TypeDesc toType,
int fpConvertMode)
Generates code that converts the value of a primitive type already on the stack. |
Label |
createLabel()
Creates a label, whose location must be set. |
LocalVariable |
createLocalVariable(String name,
TypeDesc type)
Creates a LocalVariable reference from a name and type. |
void |
dup()
Generates code for the dup instruction. |
void |
dup2()
Generates code for the dup2 instruction. |
void |
dup2X1()
Generates code for the dup2_x1 instruction. |
void |
dup2X2()
Generates code for the dup2_x2 instruction. |
void |
dupX1()
Generates code for the dup_x1 instruction. |
void |
dupX2()
Generates code for the dup_x2 instruction. |
void |
exceptionHandler(Location startLocation,
Location endLocation,
String catchClassName)
Sets up an exception handler located here, the location of the next code to be generated. |
LocalVariable |
getParameter(int index)
Returns a specific parameter, whose index lies within 0 to getParameterCount() - 1. |
int |
getParameterCount()
Returns the amount of parameters that are accepted by the method being built, not including any "this" reference. |
void |
ifComparisonBranch(Location location,
String choice)
Generates code the performs a conditional branch based on a comparison between two int values on the stack. |
void |
ifComparisonBranch(Location location,
String choice,
TypeDesc type)
Generates code the performs a conditional branch based on a comparison between two values of the given type on the stack. |
void |
ifEqualBranch(Location location,
boolean choice)
Generates code that performs a conditional branch based on the value of two object references on the stack. |
void |
ifNullBranch(Location location,
boolean choice)
Generates code that performs a conditional branch based on the value of an object on the stack. |
void |
ifZeroComparisonBranch(Location location,
String choice)
Generates code the performs a conditional branch based on a comparison between an int value on the stack and zero. |
void |
inline(Object code)
Allows code to disassembled and copied straight in. |
void |
instanceOf(TypeDesc type)
Generates code that performs an instanceof operation. |
void |
integerIncrement(LocalVariable local,
int amount)
Generates code that increments a local integer variable by a signed constant amount. |
void |
invoke(Constructor constructor)
Generates code to invoke a class constructor in any class. |
void |
invoke(Method method)
Generates code to invoke a method. |
void |
invokeConstructor(String className,
TypeDesc[] params)
Generates code to invoke a class constructor in any class. |
void |
invokeConstructor(TypeDesc[] params)
Generates code to invoke a class constructor in this class. |
void |
invokeConstructor(TypeDesc classDesc,
TypeDesc[] params)
Generates code to invoke a class constructor in any class. |
void |
invokeInterface(String className,
String methodName,
TypeDesc ret,
TypeDesc[] params)
Generates code to invoke an interface method in any class. |
void |
invokeInterface(TypeDesc classDesc,
String methodName,
TypeDesc ret,
TypeDesc[] params)
Generates code to invoke an interface method in any class. |
void |
invokePrivate(String methodName,
TypeDesc ret,
TypeDesc[] params)
Generates code to invoke a private method in this class. |
void |
invokeStatic(String className,
String methodName,
TypeDesc ret,
TypeDesc[] params)
Generates code to invoke a static method in any class. |
void |
invokeStatic(String methodName,
TypeDesc ret,
TypeDesc[] params)
Generates code to invoke a static method in this class. |
void |
invokeStatic(TypeDesc classDesc,
String methodName,
TypeDesc ret,
TypeDesc[] params)
Generates code to invoke a static method in any class. |
void |
invokeSuper(Method method)
Generates code to invoke a method in the super class. |
void |
invokeSuper(String superClassName,
String methodName,
TypeDesc ret,
TypeDesc[] params)
Generates code to invoke a method in the super class. |
void |
invokeSuper(TypeDesc superClassDesc,
String methodName,
TypeDesc ret,
TypeDesc[] params)
Generates code to invoke a method in the super class. |
void |
invokeSuperConstructor(TypeDesc[] params)
Generates code to invoke a super class constructor. |
void |
invokeVirtual(String className,
String methodName,
TypeDesc ret,
TypeDesc[] params)
Generates code to invoke a virtual method in any class. |
void |
invokeVirtual(String methodName,
TypeDesc ret,
TypeDesc[] params)
Generates code to invoke a virtual method in this class. |
void |
invokeVirtual(TypeDesc classDesc,
String methodName,
TypeDesc ret,
TypeDesc[] params)
Generates code to invoke a virtual method in any class. |
void |
jsr(Location location)
Generates code that performs a subroutine branch to the specified location. |
void |
loadConstant(boolean value)
Generates code that loads a constant boolean value onto the stack. |
void |
loadConstant(double value)
Generates code that loads a constant double value onto the stack. |
void |
loadConstant(float value)
Generates code that loads a constant float value onto the stack. |
void |
loadConstant(int value)
Generates code that loads a constant int, char, short or byte value onto the stack. |
void |
loadConstant(long value)
Generates code that loads a constant long value onto the stack. |
void |
loadConstant(String value)
Generates code that loads a constant string value onto the stack. |
void |
loadConstant(TypeDesc type)
Generates code that loads a constant class value onto the stack. |
void |
loadField(String className,
String fieldName,
TypeDesc type)
Generates code that loads a value from a field from any class. |
void |
loadField(String fieldName,
TypeDesc type)
Generates code that loads a value from a field from this class. |
void |
loadField(TypeDesc classDesc,
String fieldName,
TypeDesc type)
Generates code that loads a value from a field from any class. |
void |
loadFromArray(TypeDesc type)
Generates code that loads a value from an array. |
void |
loadLocal(LocalVariable local)
Generates code that loads a local variable onto the stack. |
void |
loadNull()
Generates code that loads a null reference onto the stack. |
void |
loadStaticField(String className,
String fieldName,
TypeDesc type)
Generates code that loads a value from a static field from any class. |
void |
loadStaticField(String fieldName,
TypeDesc type)
Generates code that loads a value from a static field from this class. |
void |
loadStaticField(TypeDesc classDesc,
String fieldName,
TypeDesc type)
Generates code that loads a value from a static field from any class. |
void |
loadThis()
Loads a reference to "this" onto the stack. |
void |
mapLineNumber(int lineNumber)
Map the location of the next code to be generated to a line number in source code. |
void |
math(byte opcode)
Generates code for either a unary or binary math operation on one or two values pushed on the stack. |
void |
monitorEnter()
Generates code to enter the monitor on an object loaded on the stack. |
void |
monitorExit()
Generates code to exit the monitor on an object loaded on the stack. |
void |
newObject(TypeDesc type)
Generates code to create a new object. |
void |
newObject(TypeDesc type,
int dimensions)
Generates code to create a new array. |
void |
nop()
Generates an instruction that does nothing. |
void |
pop()
Generates code for the pop instruction. |
void |
pop2()
Generates code for the pop2 instruction. |
void |
ret(LocalVariable local)
Generates code that returns from a subroutine invoked by jsr. |
void |
returnValue(TypeDesc type)
Generates code that returns an object or primitive type. |
void |
returnVoid()
Generates code that returns void. |
void |
storeField(String className,
String fieldName,
TypeDesc type)
Generates code that stores a value into a field from any class. |
void |
storeField(String fieldName,
TypeDesc type)
Generates code that stores a value into a field from this class. |
void |
storeField(TypeDesc classDesc,
String fieldName,
TypeDesc type)
Generates code that stores a value into a field from any class. |
void |
storeLocal(LocalVariable local)
Generates code that pops a value off of the stack into a local variable. |
void |
storeStaticField(String className,
String fieldName,
TypeDesc type)
Generates code that stores a value into a field from any class. |
void |
storeStaticField(String fieldName,
TypeDesc type)
Generates code that stores a value into a field from this class. |
void |
storeStaticField(TypeDesc classDesc,
String fieldName,
TypeDesc type)
Generates code that stores a value into a field from any class. |
void |
storeToArray(TypeDesc type)
Generates code that stores a value to an array. |
void |
swap()
Generates code for the swap instruction. |
void |
swap2()
Generates code for a swap2 instruction. |
void |
switchBranch(int[] cases,
Location[] locations,
Location defaultLocation)
Generates code for a switch statement. |
void |
throwObject()
Generates code that throws an exception. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected final CodeAssembler mAssembler
Constructor Detail |
---|
public DelegatedCodeAssembler(CodeAssembler assembler)
Method Detail |
---|
public int getParameterCount()
CodeAssembler
getParameterCount
in interface CodeAssembler
public LocalVariable getParameter(int index)
CodeAssembler
getParameter
in interface CodeAssembler
public LocalVariable createLocalVariable(String name, TypeDesc type)
CodeAssembler
createLocalVariable
in interface CodeAssembler
name
- Optional name for the LocalVariable.type
- The type of data that the requested LocalVariable can
store.public Label createLabel()
CodeAssembler
CodeBuilder builder; ... Label label = builder.createLabel().setLocation();
createLabel
in interface CodeAssembler
Label.setLocation()
public void exceptionHandler(Location startLocation, Location endLocation, String catchClassName)
CodeAssembler
exceptionHandler
in interface CodeAssembler
startLocation
- Location at the start of the section of
code to be wrapped by an exception handler.endLocation
- Location directly after the end of the
section of code.catchClassName
- The class name of exception to be caught;
if null, then catch every object.public void mapLineNumber(int lineNumber)
CodeAssembler
mapLineNumber
in interface CodeAssembler
public void inline(Object code)
CodeAssembler
inline
in interface CodeAssembler
public void loadNull()
CodeAssembler
loadNull
in interface CodeAssembler
public void loadConstant(String value)
CodeAssembler
loadConstant
in interface CodeAssembler
public void loadConstant(TypeDesc type)
CodeAssembler
loadConstant
in interface CodeAssembler
type
- any object or primitive typepublic void loadConstant(boolean value)
CodeAssembler
loadConstant
in interface CodeAssembler
public void loadConstant(int value)
CodeAssembler
loadConstant
in interface CodeAssembler
public void loadConstant(long value)
CodeAssembler
loadConstant
in interface CodeAssembler
public void loadConstant(float value)
CodeAssembler
loadConstant
in interface CodeAssembler
public void loadConstant(double value)
CodeAssembler
loadConstant
in interface CodeAssembler
public void loadLocal(LocalVariable local)
CodeAssembler
loadLocal
in interface CodeAssembler
local
- The local variable referencepublic void loadThis()
CodeAssembler
loadThis
in interface CodeAssembler
public void storeLocal(LocalVariable local)
CodeAssembler
storeLocal
in interface CodeAssembler
local
- The local variable referenceCodeAssembler.getParameter(int)
,
CodeAssembler.createLocalVariable(java.lang.String, org.cojen.classfile.TypeDesc)
public void loadFromArray(TypeDesc type)
CodeAssembler
The type doesn't need to be an exact match for objects. TypeDesc.OBJECT works fine for all objects. For primitive types, use the appropriate TypeDesc. For an int, the type is TypeDesc.INT.
loadFromArray
in interface CodeAssembler
type
- The type of data stored in the array.public void storeToArray(TypeDesc type)
CodeAssembler
The type doesn't need to be an exact match for objects. TypeDesc.OBJECT works fine for all objects. For primitive types, use the appropriate TypeDesc. For an int, the type is TypeDesc.INT.
storeToArray
in interface CodeAssembler
type
- The type of data stored in the array.public void loadField(String fieldName, TypeDesc type)
CodeAssembler
loadField
in interface CodeAssembler
public void loadField(String className, String fieldName, TypeDesc type)
CodeAssembler
loadField
in interface CodeAssembler
public void loadField(TypeDesc classDesc, String fieldName, TypeDesc type)
CodeAssembler
loadField
in interface CodeAssembler
public void loadStaticField(String fieldName, TypeDesc type)
CodeAssembler
loadStaticField
in interface CodeAssembler
public void loadStaticField(String className, String fieldName, TypeDesc type)
CodeAssembler
loadStaticField
in interface CodeAssembler
public void loadStaticField(TypeDesc classDesc, String fieldName, TypeDesc type)
CodeAssembler
loadStaticField
in interface CodeAssembler
public void storeField(String fieldName, TypeDesc type)
CodeAssembler
storeField
in interface CodeAssembler
public void storeField(String className, String fieldName, TypeDesc type)
CodeAssembler
storeField
in interface CodeAssembler
public void storeField(TypeDesc classDesc, String fieldName, TypeDesc type)
CodeAssembler
storeField
in interface CodeAssembler
public void storeStaticField(String fieldName, TypeDesc type)
CodeAssembler
storeStaticField
in interface CodeAssembler
public void storeStaticField(String className, String fieldName, TypeDesc type)
CodeAssembler
storeStaticField
in interface CodeAssembler
public void storeStaticField(TypeDesc classDesc, String fieldName, TypeDesc type)
CodeAssembler
storeStaticField
in interface CodeAssembler
public void returnVoid()
CodeAssembler
returnVoid
in interface CodeAssembler
public void returnValue(TypeDesc type)
CodeAssembler
The type doesn't need to be an exact match for objects. TypeDesc.OBJECT works fine for all objects. For primitive types, use the appropriate TypeDesc. For an int, the type is TypeDesc.INT.
returnValue
in interface CodeAssembler
public void convert(TypeDesc fromType, TypeDesc toType)
CodeAssembler
int to char byte to double Double to double Float to boolean long to Long Double to ShortIn all, 240 conversions are supported.
convert
in interface CodeAssembler
public void convert(TypeDesc fromType, TypeDesc toType, int fpConvertMode)
CodeAssembler
int to char byte to double Double to double Float to boolean long to Long Double to ShortIn all, 240 conversions are supported.
convert
in interface CodeAssembler
fpConvertMode
- controls floating point conversion if converting
float <--> int or double <--> longpublic void invoke(Method method)
CodeAssembler
invoke
in interface CodeAssembler
public void invokeVirtual(String methodName, TypeDesc ret, TypeDesc[] params)
CodeAssembler
invokeVirtual
in interface CodeAssembler
ret
- May be null if method returns void.params
- May be null if method takes no parameters.public void invokeVirtual(String className, String methodName, TypeDesc ret, TypeDesc[] params)
CodeAssembler
invokeVirtual
in interface CodeAssembler
ret
- May be null if method returns void.params
- May be null if method takes no parameters.public void invokeVirtual(TypeDesc classDesc, String methodName, TypeDesc ret, TypeDesc[] params)
CodeAssembler
invokeVirtual
in interface CodeAssembler
ret
- May be null if method returns void.params
- May be null if method takes no parameters.public void invokeStatic(String methodName, TypeDesc ret, TypeDesc[] params)
CodeAssembler
invokeStatic
in interface CodeAssembler
ret
- May be null if method returns void.params
- May be null if method takes no parameters.public void invokeStatic(String className, String methodName, TypeDesc ret, TypeDesc[] params)
CodeAssembler
invokeStatic
in interface CodeAssembler
ret
- May be null if method returns void.params
- May be null if method takes no parameters.public void invokeStatic(TypeDesc classDesc, String methodName, TypeDesc ret, TypeDesc[] params)
CodeAssembler
invokeStatic
in interface CodeAssembler
ret
- May be null if method returns void.params
- May be null if method takes no parameters.public void invokeInterface(String className, String methodName, TypeDesc ret, TypeDesc[] params)
CodeAssembler
invokeInterface
in interface CodeAssembler
ret
- May be null if method returns void.params
- May be null if method takes no parameters.public void invokeInterface(TypeDesc classDesc, String methodName, TypeDesc ret, TypeDesc[] params)
CodeAssembler
invokeInterface
in interface CodeAssembler
ret
- May be null if method returns void.params
- May be null if method takes no parameters.public void invokePrivate(String methodName, TypeDesc ret, TypeDesc[] params)
CodeAssembler
invokePrivate
in interface CodeAssembler
ret
- May be null if method returns void.params
- May be null if method takes no parameters.public void invokeSuper(Method method)
CodeAssembler
invokeSuper
in interface CodeAssembler
public void invokeSuper(String superClassName, String methodName, TypeDesc ret, TypeDesc[] params)
CodeAssembler
invokeSuper
in interface CodeAssembler
ret
- May be null if method returns void.params
- May be null if method takes no parameters.public void invokeSuper(TypeDesc superClassDesc, String methodName, TypeDesc ret, TypeDesc[] params)
CodeAssembler
invokeSuper
in interface CodeAssembler
ret
- May be null if method returns void.params
- May be null if method takes no parameters.public void invoke(Constructor constructor)
CodeAssembler
invoke
in interface CodeAssembler
public void invokeConstructor(TypeDesc[] params)
CodeAssembler
invokeConstructor
in interface CodeAssembler
params
- May be null if constructor takes no parameters.public void invokeConstructor(String className, TypeDesc[] params)
CodeAssembler
invokeConstructor
in interface CodeAssembler
params
- May be null if constructor takes no parameters.public void invokeConstructor(TypeDesc classDesc, TypeDesc[] params)
CodeAssembler
invokeConstructor
in interface CodeAssembler
params
- May be null if constructor takes no parameters.public void invokeSuperConstructor(TypeDesc[] params)
CodeAssembler
invokeSuperConstructor
in interface CodeAssembler
params
- May be null if constructor takes no parameters.public void newObject(TypeDesc type)
CodeAssembler
If the specified type is an array, this call is equivalent to newObject(type, 1). The size of the dimension must be on the operand stack. To create multi-dimensional arrays, call newObject(type, dimensions).
newObject
in interface CodeAssembler
CodeAssembler.invokeConstructor(org.cojen.classfile.TypeDesc[])
public void newObject(TypeDesc type, int dimensions)
CodeAssembler
For each dimension, its size must be on the operand stack. If the specified dimensions is 0 and the type is not an array, then this call is equivalent to newObject(type).
newObject
in interface CodeAssembler
public void dup()
CodeAssembler
dup
in interface CodeAssembler
public void dupX1()
CodeAssembler
dupX1
in interface CodeAssembler
public void dupX2()
CodeAssembler
dupX2
in interface CodeAssembler
public void dup2()
CodeAssembler
dup2
in interface CodeAssembler
public void dup2X1()
CodeAssembler
dup2X1
in interface CodeAssembler
public void dup2X2()
CodeAssembler
dup2X2
in interface CodeAssembler
public void pop()
CodeAssembler
pop
in interface CodeAssembler
public void pop2()
CodeAssembler
pop2
in interface CodeAssembler
public void swap()
CodeAssembler
swap
in interface CodeAssembler
public void swap2()
CodeAssembler
swap2
in interface CodeAssembler
public void branch(Location location)
CodeAssembler
branch
in interface CodeAssembler
location
- The location to branch topublic void ifNullBranch(Location location, boolean choice)
CodeAssembler
The generated instruction consumes the value on the stack.
ifNullBranch
in interface CodeAssembler
location
- The location to branch tochoice
- If true, do branch when null, else branch when not nullpublic void ifEqualBranch(Location location, boolean choice)
CodeAssembler
The generated instruction consumes the two values on the stack.
ifEqualBranch
in interface CodeAssembler
location
- The location to branch tochoice
- If true, branch when equal, else branch when not equalpublic void ifZeroComparisonBranch(Location location, String choice) throws IllegalArgumentException
CodeAssembler
The generated instruction consumes the value on the stack.
ifZeroComparisonBranch
in interface CodeAssembler
location
- The location to branch tochoice
- One of "==", "!=", "<", ">=", ">" or "<="
IllegalArgumentException
- When the choice is not validpublic void ifComparisonBranch(Location location, String choice) throws IllegalArgumentException
CodeAssembler
The generated instruction consumes the two values on the stack.
ifComparisonBranch
in interface CodeAssembler
location
- The location to branch tochoice
- One of "==", "!=", "<", ">=", ">" or "<="
IllegalArgumentException
- When the choice is not validpublic void ifComparisonBranch(Location location, String choice, TypeDesc type) throws IllegalArgumentException
CodeAssembler
When comparing floating point values, treatment of NaN requires special attention. Ordinarily, it is assumed that the branch location represents the target of a comparison failure, and that the code to handle the "true" condition immediately follows the comparison. If this is not the case, append a 't' suffix to the choice to indicate that the target location is reached for a "true" condition. This suffix is ignored if the type is not a float or double.
The generated instruction(s) consumes the two values on the stack.
ifComparisonBranch
in interface CodeAssembler
location
- The location to branch tochoice
- One of "==", "!=", "<", ">=", ">", "<=", "==t", "!=t",
"type
- Type to expect on the stack
IllegalArgumentException
- When the choice is not validpublic void switchBranch(int[] cases, Location[] locations, Location defaultLocation)
CodeAssembler
The key value to switch on must already be on the stack when this instruction executes. It is consumed by the instruction.
switchBranch
in interface CodeAssembler
cases
- The values to match on. The array length must be the same
as for locations.locations
- The locations to branch to for each case.
The array length must be the same as for cases.defaultLocation
- The location to branch to if the key on
the stack was not matched.public void jsr(Location location)
CodeAssembler
jsr
in interface CodeAssembler
location
- The location to branch topublic void ret(LocalVariable local)
CodeAssembler
ret
in interface CodeAssembler
local
- The local variable reference that contains the return
address. The local variable must be of an object type.public void math(byte opcode)
CodeAssembler
Pass in an opcode from the the Opcode class. The only valid math opcodes are:
IADD, ISUB, IMUL, IDIV, IREM, INEG, IAND, IOR, IXOR, ISHL, ISHR, IUSHR LADD, LSUB, LMUL, LDIV, LREM, LNEG, LAND, LOR, LXOR, LSHL, LSHR, LUSHR FADD, FSUB, FMUL, FDIV, FREM, FNEG DADD, DSUB, DMUL, DDIV, DREM, DNEG LCMP FCMPG, FCMPL DCMPG, DCMPLA not operation (~) is performed by doing a loadConstant with either -1 or -1L followed by math(Opcode.IXOR) or math(Opcode.LXOR).
math
in interface CodeAssembler
opcode
- An opcode from the Opcode class.Opcode
public void arrayLength()
CodeAssembler
arrayLength
in interface CodeAssembler
public void throwObject()
CodeAssembler
throwObject
in interface CodeAssembler
public void checkCast(TypeDesc type)
CodeAssembler
checkCast
in interface CodeAssembler
public void instanceOf(TypeDesc type)
CodeAssembler
instanceOf
in interface CodeAssembler
public void integerIncrement(LocalVariable local, int amount)
CodeAssembler
integerIncrement
in interface CodeAssembler
public void monitorEnter()
CodeAssembler
monitorEnter
in interface CodeAssembler
public void monitorExit()
CodeAssembler
monitorExit
in interface CodeAssembler
public void nop()
CodeAssembler
nop
in interface CodeAssembler
public void breakpoint()
CodeAssembler
breakpoint
in interface CodeAssembler
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |