Class MethodCompiler
- All Implemented Interfaces:
OpCode
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate CodeAttributeprivate booleanprivate ExecutableElementprivate booleanprivate final List<ExceptionTable> protected ExecutableElementprotected ExecutableTypeprivate final List<VariableElement> private MethodInfoprivate booleanprotected SubClassprivate Stringstatic final StringFields inherited from class Assembler
asm, asmStack, labelMap, labels, out, T_BOOLEAN, T_BYTE, T_CHAR, T_DOUBLE, T_FLOAT, T_INT, T_LONG, T_SHORT, types, WIDEFIXOFFSET, wideIndexFields inherited from interface OpCode
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, BREAKPOINT, 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, 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, IMPDEP1, IMPDEP2, IMUL, INEG, INSTANCEOF, 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, NOT_IF_ACMPEQ, NOT_IF_ACMPNE, NOT_IF_ICMPEQ, NOT_IF_ICMPGE, NOT_IF_ICMPGT, NOT_IF_ICMPLE, NOT_IF_ICMPLT, NOT_IF_ICMPNE, NOT_IFEQ, NOT_IFGE, NOT_IFGT, NOT_IFLE, NOT_IFLT, NOT_IFNE, NOT_IFNONNULL, NOT_IFNULL, POP, POP2, PUTFIELD, PUTSTATIC, RET, RETURN, SALOAD, SASTORE, SIPUSH, SWAP, TABLESWITCH, WIDE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddExceptionHandler(Block block, String handler, Class<? extends Throwable>... catchTypes) Adds an exception handler.voidaddExceptionHandler(Block block, String handler, List<? extends TypeMirror> thrownTypes) Adds an exception handler.voidaddNewArray(String name, Class<?> aClass, int size) Create new arrayvoidaddNewArray(String name, TypeMirror type, int size) Create new arrayvoidaddVariable(String name, Class<?> type) Add new local variablevoidaddVariable(String name, TypeMirror type) Add new local variablevoidCreate new objectvoidanew(TypeElement clazz) Create new objectprivate intargumentCount(List<? extends VariableElement> parameters) voidassignDefault(String name) assign default type for local variable depending on type.voidCheck whether object is of given typevoidcheckcast(TypeElement objectref) Check whether object is of given typevoidcheckcast(TypeMirror type) Check whether object is of given typevoidconvert(String fromVariable, TypeMirror to) Convert a local variable to given type.voiddconst(double value) Push double constant.voidend()Deprecated.Current implementation does nothingvoidvoidfconst(float value) Push float constant.voidfixAddress(String name) Labels a current positionvoidGet field from classvoidGet field from this classvoidgetField(VariableElement field) Fetch field from objectgetLocalDescription(int index) return a descriptive text about local variable named name.getLocalName(int index) Returns the name of local variable at indexgetLocalType(int index) Returns the type of local variable at indexgetLocalType(String name) returns the type of local variable named name.getLocalVariable(int index) Returns local variable at index.getLocalVariable(String name) intgetLocalVariableIndex(String name) List<? extends TypeMirror> voidgetStaticField(Class<?> cls, String name) Get field from classvoidgetStaticField(String name) Get field from this classvoidgetStaticField(VariableElement field) Fetch field from objectbooleanhasLocalVariable(String name) Return true if named variable is added.voidiconst(boolean value) Push int constantvoidiconst(int value) Push int constant.protected abstract voidvoidIncrement local variable or field by constantvoidinvoke(ExecutableElement method) voidinvokeConstructor(Class<?> cls, Class<?>... parameters) voidinvokeMethod(Class<?> cls, String name, Class<?>... parameters) voidinvokespecial(Class<?> cls, String name, Class<?>... parameters) Invoke instance method; special handling for superclass, private, and instance initialization method invocationsvoidinvokespecial(ExecutableElement method) Invoke instance method; special handling for superclass, private, and instance initialization method invocationsvoidinvokestatic(Class<?> cls, String name, Class<?>... parameters) Invoke a class (static) methodvoidinvokestatic(ExecutableElement method) Invoke a class (static) methodvoidinvokevirtual(Class<?> cls, String name, Class<?>... parameters) Invoke instance method; dispatch based on classIf method is interface calls invokeinterface otherwise calls invokevirtual.voidinvokevirtual(ExecutableElement method) Invoke instance method; dispatch based on classIf method is interface calls invokeinterface otherwise calls invokevirtual.voidlconst(long value) Push long constant.voidldc(double constant) Push item from runtime constant pool.voidldc(float constant) Push item from runtime constant pool.voidldc(int constant) Push item from runtime constant pool.voidldc(long constant) Push item from runtime constant pool.voidvoidPush item from runtime constant pool.voidLoad from local variable or non-static fieldvoidloadDefault(Class<?> type) Load default value to stack depending on typevoidloadDefault(TypeMirror type) Load default value to stack depending on typeintprivate intlocalSize(int offset, int length) voidlookupswitch(LookupList list) Compiles lookupswitchfinal voidnameArgument(String name, int index) Names an argumentvoidnameArguments(String[] args) voidCreate new arrayvoidnewarray(TypeMirror type, int count) Create new arrayvoidoptimizedSwitch(String def, LookupList list) Compiles a tableswitch, lookupswitch or if/goto depending on contents of LookupList.voidoptimizedSwitch(LookupList list) Compiles a tableswitch, lookupswitch or if/goto depending on contents of LookupList.voidSet field in classvoidSet field in this classvoidputField(VariableElement field) Set field in objectvoidputStaticField(Class<?> cls, String name) Set field in classvoidputStaticField(String name) Set field in this classvoidputStaticField(VariableElement field) Set static field in objectvoidReset a started subroutinevoidsetDebug(ExecutableElement debug) voidsetOptimize(boolean optimize) Set the compiler optimize flag.(package private) voidstartImplement(SubClass subClass, MethodInfo methodInfo) voidstartSubroutine(String target) Compiles the subroutine start.voidStore into local variable or non-static fieldvoidtableswitch(int low, int high, String... symbols) Compiles tableswitchvoidtableswitch(int low, int high, List<String> symbols) Compiles tableswitchvoidtconst(boolean value) voidtconst(byte value) voidtconst(char value) voidtconst(double value) voidtconst(float value) voidtconst(int value) voidtconst(long value) voidvoidvoidIncrement local variable by constantvoidLoad from local variabletoString()voidtreturn()Return.voidStore into local variabletypeForCount(int count) Return a integral class able to support count valuesMethods inherited from class Assembler
aaload, aastore, aconst_null, aload, anew, anewarray, arraylength, astore, athrow, baload, bastore, bipush, caload, castore, checkcast, convert, createBranch, createBranch, d2f, d2i, d2l, d2t, dadd, daload, dastore, dconst, ddiv, dload, dmul, dneg, dstore, dsub, dup, dup_x1, dup_x2, dup2, dup2_x1, dup2_x2, endBlock, f2d, f2i, f2l, f2t, fadd, faload, fastore, fconst, fdiv, fixLabels, fload, fmul, fneg, frem, fstore, fsub, getCode, getfield, getLabel, getstatic, goto_n, goto_w, i2b, i2c, i2d, i2f, i2l, i2s, i2t, iadd, iaload, iand, iastore, idiv, if_icmpeq, if_icmpge, if_icmpgt, if_icmple, if_icmplt, if_icmpne, if_tcmpeq, if_tcmpge, if_tcmpgt, if_tcmple, if_tcmplt, if_tcmpne, ifeq, ifge, ifgt, ifle, iflt, ifne, ifnonnull, ifnull, iinc, iload, imul, instanceo, invokeinterface, invokespecial, invokestatic, invokevirtual, ior, irem, ireturn, ishl, ishr, isReferenced, istore, isub, iushr, ixor, jsr, jsr_w, l2d, l2f, l2i, l2t, labelForAddress, ladd, laload, land, lastore, lconst, ldc_w, ldc2_w, ldiv, lload, lmul, lneg, lookupswitch, lor, lrem, lshl, lshr, lstore, lsub, lushr, lxor, monitorenter, monitorexit, multianewarray, newarray, nop, pop, pop2, position, putfield, putstatic, ret, saload, sastore, setWideIndex, sipush, startBlock, swap, tableswitch, tadd, taload, tand, tastore, tcmp, tcmpg, tcmpl, tcmpl, tconst, tdiv, tinc, tipush, tload, tmul, tneg, tor, trem, treturn, tshl, tshr, tstore, tsub, tushr, txor
-
Field Details
-
SUBROUTINERETURNADDRESSNAME
- See Also:
-
subClass
-
code
-
localVariables
-
debugMethod
-
compiled
private boolean compiled -
subroutine
-
optimize
private boolean optimize -
dump
private boolean dump -
exceptionTableList
-
methodInfo
-
executableElement
-
executableType
-
-
Constructor Details
-
MethodCompiler
protected MethodCompiler()
-
-
Method Details
-
startImplement
- Throws:
IOException
-
getExecutableElement
-
getSubClass
-
getModifiers
-
setOptimize
public void setOptimize(boolean optimize) Set the compiler optimize flag. Affects switches- Parameters:
optimize-
-
getMethodDescription
-
getParameters
-
getReturnType
-
localSize
public int localSize() -
localSize
private int localSize(int offset, int length) -
nameArgument
Names an argument- Parameters:
name- Argument nameindex- First argument is 1, this = 0
-
getLocalVariable
Returns local variable at index. Note! long and double take two positions.- Parameters:
index-- Returns:
-
getLocalVariable
-
getLocalVariableIndex
-
nameArguments
-
getLocalName
Returns the name of local variable at index- Parameters:
index-- Returns:
-
getLocalType
Returns the type of local variable at index- Parameters:
index-- Returns:
-
getLocalType
returns the type of local variable named name.- Parameters:
name-- Returns:
-
hasLocalVariable
Return true if named variable is added.- Parameters:
name-- Returns:
-
getLocalDescription
return a descriptive text about local variable named name.- Parameters:
index-- Returns:
-
addVariable
-
addVariable
Add new local variable- Parameters:
name-type-
-
assignDefault
assign default type for local variable depending on type. (false, 0, null)- Parameters:
name-- Throws:
IOException
-
loadDefault
Load default value to stack depending on type- Parameters:
type-- Throws:
IOException
-
loadDefault
Load default value to stack depending on type- Parameters:
type-- Throws:
IOException
-
startSubroutine
Compiles the subroutine start. Use endSubroutine to end that subroutine.- Parameters:
target-- Throws:
IOException
-
endSubroutine
- Throws:
IOException
-
resetSubroutine
public void resetSubroutine()Reset a started subroutine -
newarray
Create new arrayStack: ..., count => ..., arrayref
- Parameters:
type- array class eg. String[].classcount- array count- Throws:
IOException
-
newarray
Create new arrayStack: ..., => ..., arrayref
- Parameters:
type- array class eg. String[].classcount- array count- Throws:
IOException
-
typeForCount
Return a integral class able to support count values- Parameters:
count-- Returns:
-
tload
Load from local variableStack: ... => ..., value
- Parameters:
name- local variable name- Throws:
IOException- See Also:
-
load
Load from local variable or non-static fieldStack: ... => ..., value
- Parameters:
name- local variable name- Throws:
IOException- See Also:
-
tstore
Store into local variableStack: ..., value => ...
- Parameters:
name- local variable name- Throws:
IOException- See Also:
-
store
Store into local variable or non-static fieldStack: ..., value => ...
- Parameters:
name- local variable name- Throws:
IOException- See Also:
-
inc
Increment local variable or field by constantStack: No change
- Parameters:
name- local variable namecon- signed byte- Throws:
IOException- See Also:
-
tinc
Increment local variable by constantStack: No change
- Parameters:
name- local variable namecon- signed byte- Throws:
IOException- See Also:
-
treturn
Return. If return type is other than void the value at stack is returnedStack: ..., result => ...
- Throws:
IOException- See Also:
-
setDebug
-
fixAddress
Labels a current position- Overrides:
fixAddressin classAssembler- Parameters:
name-- Throws:
IOException
-
anew
Create new objectStack: ... => ..., objectref
- Parameters:
clazz-- Throws:
IOException
-
anew
Create new objectStack: ... => ..., objectref
- Parameters:
clazz-- Throws:
IOException
-
tconst
- Throws:
IOException
-
tconst
- Throws:
IOException
-
tconst
- Throws:
IOException
-
tconst
- Throws:
IOException
-
tconst
- Throws:
IOException
-
tconst
- Throws:
IOException
-
tconst
- Throws:
IOException
-
tconst
- Throws:
IOException
-
tconst
- Throws:
IOException
-
ldc
Push item from runtime constant pool. Creates new constant if neededStack: ... => ..., value
- Overrides:
ldcin classAssembler- Parameters:
constant- int constant- Throws:
IOException- See Also:
-
ldc
Push item from runtime constant pool. Creates new constant if neededStack: ... => ..., value
- Parameters:
constant- float constant- Throws:
IOException- See Also:
-
ldc
Push item from runtime constant pool. Creates new constant if neededStack: ... => ..., value
- Parameters:
constant- long constant- Throws:
IOException- See Also:
-
ldc
Push item from runtime constant pool. Creates new constant if neededStack: ... => ..., value
- Parameters:
constant- double constant- Throws:
IOException- See Also:
-
ldc
Push item from runtime constant pool. Creates new constant if neededStack: ... => ..., value
- Parameters:
constant- String constant- Throws:
IOException- See Also:
-
ldc
- Throws:
IOException
-
getField
Fetch field from objectStack: ..., objectref => ..., value
- Parameters:
field-- Throws:
IOException
-
getStaticField
Fetch field from objectStack: ..., objectref => ..., value
- Parameters:
field-- Throws:
IOException
-
getField
Get field from classStack: ..., => ..., value
- Parameters:
cls-name-- Throws:
IOException
-
getField
Get field from this classStack: ..., => ..., value
- Parameters:
name-- Throws:
IOException
-
getStaticField
Get field from classStack: ..., => ..., value
- Parameters:
cls-name-- Throws:
IOException
-
getStaticField
Get field from this classStack: ..., => ..., value
- Parameters:
name-- Throws:
IOException
-
putField
Set field in objectStack: ..., objectref, value => ...
- Parameters:
field-- Throws:
IOException
-
putStaticField
Set static field in objectStack: ..., objectref, value => ...
- Parameters:
field-- Throws:
IOException
-
putField
Set field in classStack: ..., value => ...
- Parameters:
cls-name-- Throws:
IOException
-
putField
Set field in this classStack: ..., value => ...
- Parameters:
name-- Throws:
IOException
-
putStaticField
Set field in classStack: ..., value => ...
- Parameters:
cls-name-- Throws:
IOException
-
putStaticField
Set field in this classStack: ..., value => ...
- Parameters:
name-- Throws:
IOException
-
invokeConstructor
- Parameters:
cls-parameters-- Throws:
IOException
-
invokeMethod
- Parameters:
cls-name-parameters-- Throws:
IOException
-
invoke
- Parameters:
method-- Throws:
IOException
-
invokespecial
Invoke instance method; special handling for superclass, private, and instance initialization method invocationsStack: ..., objectref, [arg1, [arg2 ...]] => ...
- Parameters:
cls-name-parameters-- Throws:
IOException
-
invokespecial
Invoke instance method; special handling for superclass, private, and instance initialization method invocationsStack: ..., objectref, [arg1, [arg2 ...]] => ...
- Parameters:
method-- Throws:
IOException
-
invokevirtual
Invoke instance method; dispatch based on classIf method is interface calls invokeinterface otherwise calls invokevirtual.Stack: ..., objectref, [arg1, [arg2 ...]] => ...
- Parameters:
cls-name-parameters-- Throws:
IOException
-
invokevirtual
Invoke instance method; dispatch based on classIf method is interface calls invokeinterface otherwise calls invokevirtual.Stack: ..., objectref, [arg1, [arg2 ...]] => ...
- Parameters:
method-- Throws:
IOException
-
invokestatic
Invoke a class (static) methodStack: ..., [arg1, [arg2 ...]] => ...
- Parameters:
cls-name-parameters-- Throws:
IOException
-
invokestatic
Invoke a class (static) methodStack: ..., [arg1, [arg2 ...]] => ...
- Parameters:
method-- Throws:
IOException
-
argumentCount
-
end
Deprecated.Current implementation does nothing- Throws:
IOException
-
toString
-
iconst
Push int constantStack: ..., => ..., i
- Parameters:
value-- Throws:
IOException
-
iconst
Push int constant. Uses either iconst or ldc.Stack: ..., => ..., i
- Overrides:
iconstin classAssembler- Parameters:
value-- Throws:
IOException
-
fconst
Push float constant. Uses either fconst or ldc.Stack: ..., => ..., f
- Parameters:
value-- Throws:
IOException
-
lconst
Push long constant. Uses either lconst or ldc.Stack: ..., => ..., l
- Parameters:
value-- Throws:
IOException
-
dconst
Push double constant. Use either dconst or ldc.Stack: ..., => ..., d
- Parameters:
value-- Throws:
IOException
-
optimizedSwitch
Compiles a tableswitch, lookupswitch or if/goto depending on contents of LookupList.Stack: ..., index => ...,
throws SwitchException if target illegal.
- Parameters:
list-- Throws:
IOException
-
optimizedSwitch
Compiles a tableswitch, lookupswitch or if/goto depending on contents of LookupList.Stack: ..., index => ...,
- Parameters:
def-list-- Throws:
IOException
-
lookupswitch
Compiles lookupswitchStack: ..., index => ...,
- Parameters:
list-- Throws:
IOException
-
tableswitch
Compiles tableswitchStack: ..., index => ...,
- Parameters:
low-high-symbols-- Throws:
IOException
-
tableswitch
Compiles tableswitchStack: ..., index => ...,
- Parameters:
low-high-symbols-- Throws:
IOException
-
addNewArray
Create new arrayStack: ..., count => ..., arrayref
- Parameters:
name-aClass-size-- Throws:
IOException
-
addNewArray
Create new arrayStack: ..., count => ..., arrayref
- Parameters:
name-type-size-- Throws:
IOException
-
checkcast
Check whether object is of given typeStack: ..., objectref => ..., objectref
- Parameters:
objectref-- Throws:
IOException
-
checkcast
Check whether object is of given typeStack: ..., objectref => ..., objectref
- Parameters:
objectref-- Throws:
IOException
-
checkcast
Check whether object is of given typeStack: ..., objectref => ..., objectref
- Parameters:
type-- Throws:
IOException
-
convert
public void convert(String fromVariable, TypeMirror to) throws IOException, IllegalConversionException Convert a local variable to given type. (if it is possible)Stack: ..., => ..., objectref
- Parameters:
fromVariable-to-- Throws:
IOExceptionIllegalConversionException
-
addExceptionHandler
public void addExceptionHandler(Block block, String handler, Class<? extends Throwable>... catchTypes) Adds an exception handler. If one of catchTypes is thrown inside block the execution continues at handler address. Thrown object is pushed in stack.- Parameters:
block-handler-catchTypes- Throwable objects which are caught. If none is present then all throwables are caught. Note! This is not the same as finally!
-
addExceptionHandler
public void addExceptionHandler(Block block, String handler, List<? extends TypeMirror> thrownTypes) Adds an exception handler. If one of catchTypes is thrown inside block the execution continues at handler address. Thrown object is pushed in stack.- Parameters:
block-handler-thrownTypes- Throwable objects which are caught. If none is present then all throwables are caught. Note! This is not the same as finally!
-
implement
- Throws:
IOException
-