Class InstructionGenerator
This class is used by the various model classes to create Java byte codes for each kind of code structure implemented by this library.
Each method that emits an instruction returns the InstructionGenerator so that instructions can be changed, such as:
gen.iload_0()
.iload_1()
.iadd()
.ireturn()
Any strings that refer to types in these instructions are assumed to be in the internal format where "." in the name is replaced with "/" (e.g. "java/lang/String" instead of "java.lang.String".
For more details on each instruction, consult Chapter 6 of the Java Virtual Machine specification.
If you find yourself wondering where particular parameters are, they are likely expected to be on the stack. For example,
iaddtakes no parameters, it expects the two integers to add to be on the stack. It pops them, adds them, and pushes the result onto the stack. Likewise, when using one of the method invocation instructions, the instruction itself has the class that contains the method, and the method name, but the object on which the method is being invoked is on the stack, as are the method parameters.
-
Method Summary
Modifier and TypeMethodDescriptionaaload()Emit an instruction to load an object from an arrayaastore()Emit an instruction to store an object into an arrayEmit an instruction to push a null constant onto the stackaload(int index) Emit an instruction to load a reference from a local variableEmit an instruction to create a new array of objects of a specified typeareturn()Emit an instruction to return an object from the current methodEmit an instruction to retrieve the length of an arrayastore(int index) Emit an instruction to store a reference in a local variableathrow()Emit an instruction to throw an exceptionbaload()Emit an instruction to fetch a value from a byte arraybastore()Emit an instruction to store a value in a byte arraybipush(int value) Emit an instruction to push a byte value onto the stack (like loading a constant, but doesn't require an entry in the constant pool)caload()Emit an instruction to fetch a value from a char arraycastore()Emit an instruction to store a value in a char arrayEmit an instruction to verify that an object can be cast to the specified typed2f()Emit an instruction to convert a double value to a floatd2i()Emit an instruction to convert a double value to an intd2l()Emit an instruction to convert a double value to a longdadd()Emit an instruction to add two doublesdaload()Emit an instruction to fetch a value from an array of doublesdastore()Emit an instruction to store a value in an array of doublesdcmpg()Emit an instruction to compare two doubles where NaN is greater than a valuedcmpl()Emit an instruction to compare two doubles where NaN is less than a valuedconst_0()Emit an instruction to push a double value of 0.0 onto the stackdconst_1()Emit an instruction to push a double value of 1.0 onto the stackddiv()Emit an instruction to divide a double value by a double valuedload(int index) Emit an instruction to load a double value from a local variabledmul()Emit an instruction to multiply two double valuesdneg()Emit an instruction to negate a double valuedrem()Emit an instruction to compute the remainder when dividing one double value by anotherdreturn()Emit an instruction to return a double value from the current methoddstore(int index) Emit an instruction to store a double value in a local variabledsub()Emit an instruction to subtract two double valuesdup()Emit an instruction to duplicate the value on top of the stack.dup_x1()Emit an instruction to duplicate the top value on the stack and insert it two positions back.dup_x2()Emit an instruction to duplicate the top two values on the stack (or the top value if it is a 2-slot value (long or double) and place it two or three positions backdup2()Emit an instruction to duplicate the top two slots on the stack.dup2_x1()Emit an instruction to duplicate the top one or two values on the stack and insert them two or three slots back.dup2_x2()Emit an instruction to duplicate the top one or two values on the stack and insert them two, three, or four slots back.f2d()Emit an instruction to convert a float to a doublef2i()Emit an instruction to convert a float to an intf2l()Emit an instruction to convert a float to a longfadd()Emit an instruction to add two float valuesfaload()Emit an instruction to fetch a float value from an arrayfastore()Emit an instruction to store a float value in an arrayfcmpg()Emit an instruction to compare two floats where NaN is greater than a valuefcmpl()Emit an instruction to compare two floats where NaN is less than a valuefconst_0()Emit an instruction to push a float constant 0.0 onto the stackfconst_1()Emit an instruction to push a float constant 1.0 onto the stackfconst_2()Emit an instruction to push a float constant 2.0 onto the stackfdiv()Emit an instruction to divide two float valuesfload(int index) Emit an instruction to load a float from a local variablefmul()Emit an instruction to multiple two float valuesfneg()Emit an instruction to negate a float valuefrem()Emit an instruction to compute the remainder when dividing two float valuesfreturn()Emit an instruction to return a float value from the current methodfstore(int index) Emit an instruction to store a float value in a local variablefsub()Emit an instruction to two subtract two float valuesgenerateBox(Type type) Generate a box for a typegenerateLambda(MethodDef lambda) Schedules the generation of a lambda methodgenerateLocalVariable(String name, Type type, Label startLoc, Label endLoc, int index) Creates a new local variable with a specific name and type, and a particular range of instructions that it is valid over.Emit an instruction to fetch the value of a fieldEmit an instruction to fetch the value of a static fieldEmit an instruction to jump to a labeli2b()Emit an instruction to convert an int to a bytei2c()Emit an instruction to convert an int to a chari2d()Emit an instruction to convert an int to a doublei2f()Emit an instruction to convert an int to a floati2l()Emit an instruction to convert an int to a longi2s()Emit an instruction to convert an int to a shortiadd()Emit an instruction to add two integersiaload()Emit an instruction to fetch a value from an array of intsiand()Emit an instruction to perform a bitwise and between two integersiastore()Emit an instruction to store a value into an array of intsiconst_0()Emit an instruction to push the int constant 0 onto the stackiconst_1()Emit an instruction to push the int constant 1 onto the stackiconst_2()Emit an instruction to push the int constant 2 onto the stackiconst_3()Emit an instruction to push the int constant 3 onto the stackiconst_4()Emit an instruction to push the int constant 4 onto the stackiconst_5()Emit an instruction to push the int constant 5 onto the stackEmit an instruction to push the int constant -1 onto the stackidiv()Emit an instruction to divide two integersEmit an instruction to compare two objects for equality, and if true, to jump to the specified labelEmit an instruction to compare two objects for non-equality, and if true, to jump to the specified labelEmit an instruction to compare two ints for equality, and if true, to jump to the specified labelEmit an instruction to compare two ints for greater-or-equal, and if true, to jump to the specified labelEmit an instruction to compare two ints for greater-than, and if true, to jump to the specified labelEmit an instruction to compare two ints for less-or-equal, and if true, to jump to the specified labelEmit an instruction to compare two ints for less-than, and if true, to jump to the specified labelEmit an instruction to compare two ints for non-equality, and if true, to jump to the specified labelEmit an instruction to test whether the result of a comparison was equal (0), and if true, jump to the specified labelEmit an instruction to test whether the result of a comparison was greater-or-equal (>= 0), and if true, jump to the specified labelEmit an instruction to test whether the result of a comparison was greater-than (> 0), and if true, jump to the specified labelEmit an instruction to test whether the result of a comparison was less-or-equal (<= 0), and if true, jump to the specified labelEmit an instruction to test whether the result of a comparison was less (< 0), and if true, jump to the specified labelEmit an instruction to test whether the result of a comparison was equal (!= 0), and if true, jump to the specified labelEmit an instruction to test whether an object reference is not null, and if true, jump to the specified labelEmit an instruction to test whether an object reference is null, and if true, jump to the specified labeliinc(int index, int incr) Emit an instruction to increment a local variable by an amount specified by a byteiload(int index) Emit an instruction to load a value from a local variableimul()Emit an instruction to multiple to int valuesineg()Emit an instruction to negate an int valueinstance_of(String type) Emit an instruction to test whether an object reference is an instance of the given class name, pushing 1 onto the stack if true, and 0 if not.invokedynamic(String name, String descriptor, Handle handle, Object... bootstrapArgs) Emit an instruction to create a dynamic method invocation.invokeinterface(String owner, String name, String descriptor) Emit an instruction to invoke an interface methodinvokespecial(String owner, String name, String descriptor) Emit an instruction to invoke a constructor, super, or private methodinvokestatic(String owner, String name, String descriptor) Emit an instruction to invoke a static methodinvokevirtual(String owner, String name, String descriptor) Emit an instruction to invoke a virtual methodior()Emit an instruction to perform a bitwise or of two intsirem()Emit an instruction to compute the remainder from dividing two intsireturn()Emit an instruction to return an int value from the current methodishl()Emit an instruction to shift an int left by a number of bitsishr()Emit an instruction to shift an int right by a number of bits, extending the sign bitistore(int index) Emit an instruction to store an int in a local variableisub()Emit an instruction to subtract two intsiushr()Emit an instruction to shift an int right by a number of bits, not extending the sign bitixor()Emit an instruction to perform a bitwise exclusive-or on two intsEmit an instruction to jump to a subroutinel2d()Emit an instruction to convert a long to a doublel2f()Emit an instruction to convert a long to a floatl2i()Emit an instruction to convert a long to an intEmit an instruction to generate a label at the current instruction positionladd()Emit an instruction to add to longslaload()Emit an instruction to fetch a value from an array of longsland()Emit an instruction to do a bitwise and of two longslastore()Emit an instruction to store a value in an array of longslcmp()Emit an instruction to compare two long valueslconst_0()Emit an instruction to push a long constant 0 onto the stacklconst_1()Emit an instruction to push a long constant 1 onto the stackldc(double d) Emit an instruction to push a constant double onto the stack.ldc(float f) Emit an instruction to push a constant float onto the stack.ldc(int i) Emit an instruction to push a constant int onto the stack.ldc(long l) Emit an instruction to push a constant long onto the stack.Emit an instruction to push a constant object onto the stackEmit an instruction to push a reference to a method onto the stackEmit an instruction to push a reference to a string constant onto the stackldc(ConstantDynamic cd) Emit an instruction to push a dynamic constant onto the stackEmit an instruction to push a method referenced by a handle onto the stackldiv()Emit an instruction to divide two longsvoidlineNumber(int lineNumber) Generate a line number pseudo instruction for debugging and stack traces.lload(int index) Emit an instruction to load a long from a local variablelmul()Emit an instruction to multiple two longslneg()Emit an instruction to negate a long valuelookupswitch(Label default_label, int[] keys, Label[] labels) Emit an instruction to perform a switch using a sorted array of keys, and their corresponding labels.lor()Emit an instruction to perform a bitwise or between two longslrem()Emit an instruction to compute the remainder of dividing two longslreturn()Emit an instruction to return a long value from the current methodlshl()Emit an instruction to perform a bitwise left shift on a long for some number of bitslshr()Emit an instruction to perform a bitwise right shift on a long value, extending the sign bit (i.e.lstore(int index) Emit an instruction to store a long in a local variablelsub()Emit an instruction to subtract two longslushr()Emit an instruction to perform a bitwise right shift on a long value, not extending the sign bit (i.e.lxor()Emit an instruction to perform a bitwise exclusive-or on two longsEmit an instruction to enter a monitor (i.e.Emit an instruction to exit a monitor (i.e.multianewarray(String descriptor, int dims) Create a multi-dimentional arraynew_object(String type) Emit an instruction to allocate a new objectEmit an instruction to create a new array of some native typenop()Emit an instruction to do nothingpop()Emit an instruction to pop a value off the stackpop2()Emit an instruction to pop two values off the stack (or one 2-slot value)Emit an instruction to store a value in a fieldEmit an instruction to store a value in a static fieldrawIntOpcode(int opcode, int index) Inserts a raw opcode that takes an int argument into the instruction streamrawJumpOpcode(int opcode, Label label) Inserts a raw opcode for jumping to a label into the instruction stream.rawOpcode(int opcode) Inserts a raw opcode into the instruction streamret(int index) Returns from a subroutine using the return address stored in a local variablereturn_by_type(Type type) Returns the type of return instruction needed for a value of a specific typeReturns from the current method without returning a valuesaload()Emit an instruction to load a value from an array of shortssastore()Emit an instruction to store a value in an array of shortssipush(int value) Emit an instruction to push an immediate short value onto the stack.swap()Emit an instruction to swap the top 2 1-slot values on the stack.tableswitch(int min, int max, Label default_label, Label[] labels) Emit an instruction to perform a switch using a table lookup.Emit the labels and class name for a try-catch block.
-
Method Details
-
aaload
Emit an instruction to load an object from an array- Returns:
- this instruction generator (for chaining calls)
-
aastore
Emit an instruction to store an object into an array- Returns:
- this instruction generator (for chaining calls)
-
aconst_null
Emit an instruction to push a null constant onto the stack- Returns:
- this instruction generator (for chaining calls)
-
aload
Emit an instruction to load a reference from a local variable- Parameters:
index- The local variable index to load the value from- Returns:
- this instruction generator (for chaining calls)
-
anewarray
Emit an instruction to create a new array of objects of a specified type- Parameters:
type- The type of the array elements- Returns:
- this instruction generator (for chaining calls)
-
areturn
Emit an instruction to return an object from the current method- Returns:
- this instruction generator (for chaining calls)
-
arraylength
Emit an instruction to retrieve the length of an array- Returns:
- this instruction generator (for chaining calls)
-
astore
Emit an instruction to store a reference in a local variable- Parameters:
index- The local variable index this value should be stored in- Returns:
- this instruction generator (for chaining calls)
-
athrow
Emit an instruction to throw an exception- Returns:
- this instruction generator (for chaining calls)
-
baload
Emit an instruction to fetch a value from a byte array- Returns:
- this instruction generator (for chaining calls)
-
bastore
Emit an instruction to store a value in a byte array- Returns:
- this instruction generator (for chaining calls)
-
bipush
Emit an instruction to push a byte value onto the stack (like loading a constant, but doesn't require an entry in the constant pool)- Parameters:
value- The value that should be pushed onto the stack- Returns:
- this instruction generator (for chaining calls)
-
caload
Emit an instruction to fetch a value from a char array- Returns:
- this instruction generator (for chaining calls)
-
castore
Emit an instruction to store a value in a char array- Returns:
- this instruction generator (for chaining calls)
-
checkcast
Emit an instruction to verify that an object can be cast to the specified type- Parameters:
type- The type to check the cast to- Returns:
- this instruction generator (for chaining calls)
-
d2f
Emit an instruction to convert a double value to a float- Returns:
- this instruction generator (for chaining calls)
-
d2i
Emit an instruction to convert a double value to an int- Returns:
- this instruction generator (for chaining calls)
-
d2l
Emit an instruction to convert a double value to a long- Returns:
- this instruction generator (for chaining calls)
-
dadd
Emit an instruction to add two doubles- Returns:
- this instruction generator (for chaining calls)
-
daload
Emit an instruction to fetch a value from an array of doubles- Returns:
- this instruction generator (for chaining calls)
-
dastore
Emit an instruction to store a value in an array of doubles- Returns:
- this instruction generator (for chaining calls)
-
dcmpg
Emit an instruction to compare two doubles where NaN is greater than a value- Returns:
- this instruction generator (for chaining calls)
-
dcmpl
Emit an instruction to compare two doubles where NaN is less than a value- Returns:
- this instruction generator (for chaining calls)
-
dconst_0
Emit an instruction to push a double value of 0.0 onto the stack- Returns:
- this instruction generator (for chaining calls)
-
dconst_1
Emit an instruction to push a double value of 1.0 onto the stack- Returns:
- this instruction generator (for chaining calls)
-
ddiv
Emit an instruction to divide a double value by a double value- Returns:
- this instruction generator (for chaining calls)
-
dload
Emit an instruction to load a double value from a local variable- Parameters:
index- The index of the local variable to load the value from- Returns:
- this instruction generator (for chaining calls)
-
dmul
Emit an instruction to multiply two double values- Returns:
- this instruction generator (for chaining calls)
-
dneg
Emit an instruction to negate a double value- Returns:
- this instruction generator (for chaining calls)
-
drem
Emit an instruction to compute the remainder when dividing one double value by another- Returns:
- this instruction generator (for chaining calls)
-
dreturn
Emit an instruction to return a double value from the current method- Returns:
- this instruction generator (for chaining calls)
-
dstore
Emit an instruction to store a double value in a local variable- Parameters:
index- The index of the local variable to store the value into- Returns:
- this instruction generator (for chaining calls)
-
dsub
Emit an instruction to subtract two double values- Returns:
- this instruction generator (for chaining calls)
-
dup
Emit an instruction to duplicate the value on top of the stack. The value must be a 1-slot value (i.e. not a double or a long)- Returns:
- this instruction generator (for chaining calls)
-
dup_x1
Emit an instruction to duplicate the top value on the stack and insert it two positions back.The top two values on the stack must be 1-slot values (i.e. not double or long)
Stack: x3 x2 (x1) becomes x3 x1 x2 (x1)
- Returns:
- this instruction generator (for chaining calls)
-
dup_x2
Emit an instruction to duplicate the top two values on the stack (or the top value if it is a 2-slot value (long or double) and place it two or three positions backThe top must be a 1-slot value, if x3, x2, and x1 are all 1-slot values, this is:
Stack: x3 x2 x1 becomes x1 x3 x2 x1
If x2 is a two-slot value (x1 must still be a 1-slot), this is:
Stack: x3 x2 x1 becomes x3 x1 x2 x1
- Returns:
- this instruction generator (for chaining calls)
-
dup2
Emit an instruction to duplicate the top two slots on the stack.If x2 and x1 are 1-slot values, this is:
Stack: x2 x1 becomes x2 x1 x2 x1
If x1 is a 2-slot value, this is:
Stack: x2 x1 becomes x2 x1 x1
- Returns:
- this instruction generator (for chaining calls)
-
dup2_x1
Emit an instruction to duplicate the top one or two values on the stack and insert them two or three slots back.If x2 and x1 are 1-slot values, this is:
Stack: x3 x2 x1 becomes x2 x1 x3 x2 x1
If x2 is a 1-slot value and x1 is a two slot value, this is:
Stack: x3 x2 x1 becomes x3 x1 x2 x1
- Returns:
- this instruction generator (for chaining calls)
-
dup2_x2
Emit an instruction to duplicate the top one or two values on the stack and insert them two, three, or four slots back.If x4, x3, x2, and x1 are all 1-slot values, this is:
Stack: x4 x3 x2 x1 becomes x2 x1 x4 x3 x2 x1
If x3 and x2 are 1-slot values and x1 is a two-slot value, this is:
Stack: x3 x2 x1 becomes x1 x3 x2 x1
If x3 is a two-slot value (double or long) and x2 and x1 are 1-slot values, this is:
Stack: x2 x1 x3 x2 x1
If x2 and x1 are both 2-slot values (double or long), this is:
Stack: x2 x1 becomes x1 x2 x1
- Returns:
- this instruction generator (for chaining calls)
-
f2d
Emit an instruction to convert a float to a double- Returns:
- this instruction generator (for chaining calls)
-
f2i
Emit an instruction to convert a float to an int- Returns:
- this instruction generator (for chaining calls)
-
f2l
Emit an instruction to convert a float to a long- Returns:
- this instruction generator (for chaining calls)
-
fadd
Emit an instruction to add two float values- Returns:
- this instruction generator (for chaining calls)
-
faload
Emit an instruction to fetch a float value from an array- Returns:
- this instruction generator (for chaining calls)
-
fastore
Emit an instruction to store a float value in an array- Returns:
- this instruction generator (for chaining calls)
-
fcmpg
Emit an instruction to compare two floats where NaN is greater than a value- Returns:
- this instruction generator (for chaining calls)
-
fcmpl
Emit an instruction to compare two floats where NaN is less than a value- Returns:
- this instruction generator (for chaining calls)
-
fconst_0
Emit an instruction to push a float constant 0.0 onto the stack- Returns:
- this instruction generator (for chaining calls)
-
fconst_1
Emit an instruction to push a float constant 1.0 onto the stack- Returns:
- this instruction generator (for chaining calls)
-
fconst_2
Emit an instruction to push a float constant 2.0 onto the stack- Returns:
- this instruction generator (for chaining calls)
-
fdiv
Emit an instruction to divide two float values- Returns:
- this instruction generator (for chaining calls)
-
fload
Emit an instruction to load a float from a local variable- Parameters:
index- The local variable index the value should be loaded from- Returns:
- this instruction generator (for chaining calls)
-
fmul
Emit an instruction to multiple two float values- Returns:
- this instruction generator (for chaining calls)
-
fneg
Emit an instruction to negate a float value- Returns:
- this instruction generator (for chaining calls)
-
frem
Emit an instruction to compute the remainder when dividing two float values- Returns:
- this instruction generator (for chaining calls)
-
freturn
Emit an instruction to return a float value from the current method- Returns:
- this instruction generator (for chaining calls)
-
fstore
Emit an instruction to store a float value in a local variable- Parameters:
index- The local variable index the value should be stored in- Returns:
- this instruction generator (for chaining calls)
-
fsub
Emit an instruction to two subtract two float values- Returns:
- this instruction generator (for chaining calls)
-
getfield
Emit an instruction to fetch the value of a field- Parameters:
owner- The class to which the field belongsname- The name of the fielddescriptor- The type descriptor of the field- Returns:
- this instruction generator (for chaining calls)
-
getstatic
Emit an instruction to fetch the value of a static field- Parameters:
owner- The class to which the field belongsname- The name of the fielddescriptor- The type descriptor of the field- Returns:
- this instruction generator (for chaining calls)
-
gotolabel
Emit an instruction to jump to a label- Parameters:
label- The label to jump to- Returns:
- this instruction generator (for chaining calls)
-
i2b
Emit an instruction to convert an int to a byte- Returns:
- this instruction generator (for chaining calls)
-
i2c
Emit an instruction to convert an int to a char- Returns:
- this instruction generator (for chaining calls)
-
i2d
Emit an instruction to convert an int to a double- Returns:
- this instruction generator (for chaining calls)
-
i2f
Emit an instruction to convert an int to a float- Returns:
- this instruction generator (for chaining calls)
-
i2l
Emit an instruction to convert an int to a long- Returns:
- this instruction generator (for chaining calls)
-
i2s
Emit an instruction to convert an int to a short- Returns:
- this instruction generator (for chaining calls)
-
iadd
Emit an instruction to add two integers- Returns:
- this instruction generator (for chaining calls)
-
iaload
Emit an instruction to fetch a value from an array of ints- Returns:
- this instruction generator (for chaining calls)
-
iand
Emit an instruction to perform a bitwise and between two integers- Returns:
- this instruction generator (for chaining calls)
-
iastore
Emit an instruction to store a value into an array of ints- Returns:
- this instruction generator (for chaining calls)
-
iconst_m1
Emit an instruction to push the int constant -1 onto the stack- Returns:
- this instruction generator (for chaining calls)
-
iconst_0
Emit an instruction to push the int constant 0 onto the stack- Returns:
- this instruction generator (for chaining calls)
-
iconst_1
Emit an instruction to push the int constant 1 onto the stack- Returns:
- this instruction generator (for chaining calls)
-
iconst_2
Emit an instruction to push the int constant 2 onto the stack- Returns:
- this instruction generator (for chaining calls)
-
iconst_3
Emit an instruction to push the int constant 3 onto the stack- Returns:
- this instruction generator (for chaining calls)
-
iconst_4
Emit an instruction to push the int constant 4 onto the stack- Returns:
- this instruction generator (for chaining calls)
-
iconst_5
Emit an instruction to push the int constant 5 onto the stack- Returns:
- this instruction generator (for chaining calls)
-
idiv
Emit an instruction to divide two integers- Returns:
- this instruction generator (for chaining calls)
-
if_acmpeq
Emit an instruction to compare two objects for equality, and if true, to jump to the specified label- Parameters:
label- The label to jump to if the test is true- Returns:
- this instruction generator (for chaining calls)
-
if_acmpne
Emit an instruction to compare two objects for non-equality, and if true, to jump to the specified label- Parameters:
label- The label to jump to if the test is true- Returns:
- this instruction generator (for chaining calls)
-
if_icmpeq
Emit an instruction to compare two ints for equality, and if true, to jump to the specified label- Parameters:
label- The label to jump to if the test is true- Returns:
- this instruction generator (for chaining calls)
-
if_icmpne
Emit an instruction to compare two ints for non-equality, and if true, to jump to the specified label- Parameters:
label- The label to jump to if the test is true- Returns:
- this instruction generator (for chaining calls)
-
if_icmplt
Emit an instruction to compare two ints for less-than, and if true, to jump to the specified label- Parameters:
label- The label to jump to if the test is true- Returns:
- this instruction generator (for chaining calls)
-
if_icmpge
Emit an instruction to compare two ints for greater-or-equal, and if true, to jump to the specified label- Parameters:
label- The label to jump to if the test is true- Returns:
- this instruction generator (for chaining calls)
-
if_icmpgt
Emit an instruction to compare two ints for greater-than, and if true, to jump to the specified label- Parameters:
label- The label to jump to if the test is true- Returns:
- this instruction generator (for chaining calls)
-
if_icmple
Emit an instruction to compare two ints for less-or-equal, and if true, to jump to the specified label- Parameters:
label- The label to jump to if the test is true- Returns:
- this instruction generator (for chaining calls)
-
ifeq
Emit an instruction to test whether the result of a comparison was equal (0), and if true, jump to the specified label- Parameters:
label- The label to jump to if the test is true- Returns:
- this instruction generator (for chaining calls)
-
ifne
Emit an instruction to test whether the result of a comparison was equal (!= 0), and if true, jump to the specified label- Parameters:
label- The label to jump to if the test is true- Returns:
- this instruction generator (for chaining calls)
-
iflt
Emit an instruction to test whether the result of a comparison was less (< 0), and if true, jump to the specified label- Parameters:
label- The label to jump to if the test is true- Returns:
- this instruction generator (for chaining calls)
-
ifge
Emit an instruction to test whether the result of a comparison was greater-or-equal (>= 0), and if true, jump to the specified label- Parameters:
label- The label to jump to if the test is true- Returns:
- this instruction generator (for chaining calls)
-
ifgt
Emit an instruction to test whether the result of a comparison was greater-than (> 0), and if true, jump to the specified label- Parameters:
label- The label to jump to if the test is true- Returns:
- this instruction generator (for chaining calls)
-
ifle
Emit an instruction to test whether the result of a comparison was less-or-equal (<= 0), and if true, jump to the specified label- Parameters:
label- The label to jump to if the test is true- Returns:
- this instruction generator (for chaining calls)
-
ifnonnull
Emit an instruction to test whether an object reference is not null, and if true, jump to the specified label- Parameters:
label- The label to jump to if the test is true- Returns:
- this instruction generator (for chaining calls)
-
ifnull
Emit an instruction to test whether an object reference is null, and if true, jump to the specified label- Parameters:
label- The label to jump to if the test is true- Returns:
- this instruction generator (for chaining calls)
-
iinc
Emit an instruction to increment a local variable by an amount specified by a byte- Parameters:
index- The index of the local variableincr- The byte value to add to the local variable- Returns:
- this instruction generator (for chaining calls)
-
iload
Emit an instruction to load a value from a local variable- Parameters:
index- The local variable index to load the value from- Returns:
- this instruction generator (for chaining calls)
-
imul
Emit an instruction to multiple to int values- Returns:
- this instruction generator (for chaining calls)
-
ineg
Emit an instruction to negate an int value- Returns:
- this instruction generator (for chaining calls)
-
instance_of
Emit an instruction to test whether an object reference is an instance of the given class name, pushing 1 onto the stack if true, and 0 if not. If the object reference is null, this pushes a 0 onto the stack, which differs from Java's usual notion that a null can be of any object type.- Parameters:
type- The type to check the value against- Returns:
- this instruction generator (for chaining calls)
-
invokedynamic
public InstructionGenerator invokedynamic(String name, String descriptor, Handle handle, Object... bootstrapArgs) Emit an instruction to create a dynamic method invocation. A bootstrap method is invoked the first time this is invoked, and the bootstrap generates a MethodHandle that may invoke a method, or access a field. This is mostly used for lambdas, but can be used for other features as well.- Parameters:
name- The name of the method to invokedescriptor- The type descriptor of the methodhandle- A handle to the bootstrap methodbootstrapArgs- The arguments for the bootstrap method- Returns:
- this instruction generator (for chaining calls)
-
invokeinterface
Emit an instruction to invoke an interface method- Parameters:
owner- The class/interface that owns the methodname- The name of the methoddescriptor- The type descriptor of the method- Returns:
- this instruction generator (for chaining calls)
-
invokespecial
Emit an instruction to invoke a constructor, super, or private method- Parameters:
owner- The class that owns the methodname- The name of the methoddescriptor- The type descriptor of the method- Returns:
- this instruction generator (for chaining calls)
-
invokestatic
Emit an instruction to invoke a static method- Parameters:
owner- The class that owns the methodname- The name of the methoddescriptor- The type descriptor of the method- Returns:
- this instruction generator (for chaining calls)
-
invokevirtual
Emit an instruction to invoke a virtual method- Parameters:
owner- The class that owns the methodname- The name of the methoddescriptor- The type descriptor of the method- Returns:
- this instruction generator (for chaining calls)
-
ior
Emit an instruction to perform a bitwise or of two ints- Returns:
- this instruction generator (for chaining calls)
-
irem
Emit an instruction to compute the remainder from dividing two ints- Returns:
- this instruction generator (for chaining calls)
-
ireturn
Emit an instruction to return an int value from the current method- Returns:
- this instruction generator (for chaining calls)
-
ishl
Emit an instruction to shift an int left by a number of bits- Returns:
- this instruction generator (for chaining calls)
-
ishr
Emit an instruction to shift an int right by a number of bits, extending the sign bit- Returns:
- this instruction generator (for chaining calls)
-
istore
Emit an instruction to store an int in a local variable- Parameters:
index- The local variable index to store the value in- Returns:
- this instruction generator (for chaining calls)
-
isub
Emit an instruction to subtract two ints- Returns:
- this instruction generator (for chaining calls)
-
iushr
Emit an instruction to shift an int right by a number of bits, not extending the sign bit- Returns:
- this instruction generator (for chaining calls)
-
ixor
Emit an instruction to perform a bitwise exclusive-or on two ints- Returns:
- this instruction generator (for chaining calls)
-
jsr
Emit an instruction to jump to a subroutine- Parameters:
label- The label to jump to- Returns:
- this instruction generator (for chaining calls)
-
l2d
Emit an instruction to convert a long to a double- Returns:
- this instruction generator (for chaining calls)
-
l2f
Emit an instruction to convert a long to a float- Returns:
- this instruction generator (for chaining calls)
-
l2i
Emit an instruction to convert a long to an int- Returns:
- this instruction generator (for chaining calls)
-
label
Emit an instruction to generate a label at the current instruction position- Parameters:
label- The label to generate- Returns:
- this instruction generator (for chaining calls)
-
ladd
Emit an instruction to add to longs- Returns:
- this instruction generator (for chaining calls)
-
laload
Emit an instruction to fetch a value from an array of longs- Returns:
- this instruction generator (for chaining calls)
-
land
Emit an instruction to do a bitwise and of two longs- Returns:
- this instruction generator (for chaining calls)
-
lastore
Emit an instruction to store a value in an array of longs- Returns:
- this instruction generator (for chaining calls)
-
lcmp
Emit an instruction to compare two long values- Returns:
- this instruction generator (for chaining calls)
-
lconst_0
Emit an instruction to push a long constant 0 onto the stack- Returns:
- this instruction generator (for chaining calls)
-
lconst_1
Emit an instruction to push a long constant 1 onto the stack- Returns:
- this instruction generator (for chaining calls)
-
ldc
Emit an instruction to push a constant double onto the stack.This method will insert a dconst_0 or dconst_1 instead of ldc if the constant is 0.0 or 1.0
- Parameters:
d- The value to push onto the stack- Returns:
- this instruction generator (for chaining calls)
-
ldc
Emit an instruction to push a constant int onto the stack.This method will insert an iconst_m1, iconst_0, iconst_1, iconst_2, iconst_3, iconst_4, or iconst_5 instead of ldc if the int value is -1, 0, 1, 2, 3, 4, or 5.
- Parameters:
i- The value to push onto the stack- Returns:
- this instruction generator (for chaining calls)
-
ldc
Emit an instruction to push a constant float onto the stack.This method will insert an fconst_0, fconst_1, or fconst_2 instead of ldc if the constant value is 0.0, 1.0, or 2.0
- Parameters:
f- The value to push onto the stack- Returns:
- this instruction generator (for chaining calls)
-
ldc
Emit an instruction to push a constant long onto the stack.This method will insert lconst_0 or lconst_1 instead of ldc if the constant is 0 or 1
- Parameters:
l- The value to push onto the stack- Returns:
- this instruction generator (for chaining calls)
-
ldc
Emit an instruction to push a reference to a string constant onto the stack- Parameters:
s- The string value to push onto the stack- Returns:
- this instruction generator (for chaining calls)
-
ldc
Emit an instruction to push a reference to a method onto the stack- Parameters:
m- The method value to push onto the stack- Returns:
- this instruction generator (for chaining calls)
-
ldc
Emit an instruction to push a method referenced by a handle onto the stack- Parameters:
h- The handle value to push onto the stack- Returns:
- this instruction generator (for chaining calls)
-
ldc
Emit an instruction to push a dynamic constant onto the stackA dynamic constant is computed at runtime once by a bootstrap method
- Parameters:
cd- The ConstantDynamic value to push onto the stack- Returns:
- this instruction generator (for chaining calls)
-
ldc
Emit an instruction to push a constant object onto the stack- Parameters:
o- The object value to push onto the stack- Returns:
- this instruction generator (for chaining calls)
-
ldiv
Emit an instruction to divide two longs- Returns:
- this instruction generator (for chaining calls)
-
lload
Emit an instruction to load a long from a local variable- Parameters:
index- The index of the local variable to load the value from- Returns:
- this instruction generator (for chaining calls)
-
lmul
Emit an instruction to multiple two longs- Returns:
- this instruction generator (for chaining calls)
-
lneg
Emit an instruction to negate a long value- Returns:
- this instruction generator (for chaining calls)
-
lookupswitch
Emit an instruction to perform a switch using a sorted array of keys, and their corresponding labels.The JVM will do a binary search to find the matching key and jump to the label associated with that key, or else jump to the default label.
- Parameters:
default_label- The label to jump to if the key isn't foundkeys- A sorted list of integer keyslabels- The corresponding label for each key- Returns:
- this instruction generator (for chaining calls)
-
lor
Emit an instruction to perform a bitwise or between two longs- Returns:
- this instruction generator (for chaining calls)
-
lrem
Emit an instruction to compute the remainder of dividing two longs- Returns:
- this instruction generator (for chaining calls)
-
lreturn
Emit an instruction to return a long value from the current method- Returns:
- this instruction generator (for chaining calls)
-
lshl
Emit an instruction to perform a bitwise left shift on a long for some number of bits- Returns:
- this instruction generator (for chaining calls)
-
lshr
Emit an instruction to perform a bitwise right shift on a long value, extending the sign bit (i.e. do an arithmetic right shift)- Returns:
- this instruction generator (for chaining calls)
-
lstore
Emit an instruction to store a long in a local variable- Parameters:
index- The index of the local variable to store the value in- Returns:
- this instruction generator (for chaining calls)
-
lsub
Emit an instruction to subtract two longs- Returns:
- this instruction generator (for chaining calls)
-
lushr
Emit an instruction to perform a bitwise right shift on a long value, not extending the sign bit (i.e. do a logical right shift)- Returns:
- this instruction generator (for chaining calls)
-
lxor
Emit an instruction to perform a bitwise exclusive-or on two longs- Returns:
- this instruction generator (for chaining calls)
-
monitorenter
Emit an instruction to enter a monitor (i.e. synchronize on an object)- Returns:
- this instruction generator (for chaining calls)
-
monitorexit
Emit an instruction to exit a monitor (i.e. synchronize on an object)- Returns:
- this instruction generator (for chaining calls)
-
multianewarray
Create a multi-dimentional array- Parameters:
descriptor- The type descriptor of the arraydims- The number of dimensions- Returns:
- this instruction generator (for chaining calls)
-
new_object
Emit an instruction to allocate a new objectNote: This only allocates the object in memory, you have to call the constructor immediately afterwards. The typical sequence is:
new_object(something) dup ; You have to dup the object reference because the constructor consumes it and doesn't return one invokespecial(constructor)- Parameters:
type- The type of object to allocate- Returns:
- this instruction generator (for chaining calls)
-
newarray
Emit an instruction to create a new array of some native type- Parameters:
type- The type of the array elements- Returns:
- this instruction generator (for chaining calls)
-
nop
Emit an instruction to do nothing- Returns:
- this instruction generator (for chaining calls)
-
pop
Emit an instruction to pop a value off the stack- Returns:
- this instruction generator (for chaining calls)
-
pop2
Emit an instruction to pop two values off the stack (or one 2-slot value)- Returns:
- this instruction generator (for chaining calls)
-
putfield
Emit an instruction to store a value in a field- Parameters:
owner- The class that owns the fieldname- The name of the fielddescriptor- The type descriptor of the field- Returns:
- this instruction generator (for chaining calls)
-
putstatic
Emit an instruction to store a value in a static field- Parameters:
owner- The class that owns the fieldname- The name of the fielddescriptor- The type descriptor of the field- Returns:
- this instruction generator (for chaining calls)
-
ret
Returns from a subroutine using the return address stored in a local variable- Parameters:
index- The index of the local variable containing the return address- Returns:
- this instruction generator (for chaining calls)
-
return_void
Returns from the current method without returning a value- Returns:
- this instruction generator (for chaining calls)
-
saload
Emit an instruction to load a value from an array of shorts- Returns:
- this instruction generator (for chaining calls)
-
sastore
Emit an instruction to store a value in an array of shorts- Returns:
- this instruction generator (for chaining calls)
-
sipush
Emit an instruction to push an immediate short value onto the stack. This instruction lets you push short constants without having to store the value in the constant pool and use ldc. The two bytes of the value are encoded in instructions.- Parameters:
value- The value to push- Returns:
- this instruction generator (for chaining calls)
-
swap
Emit an instruction to swap the top 2 1-slot values on the stack. There is no 2-slot equivalent for this.- Returns:
- this instruction generator (for chaining calls)
-
trycatch
Emit the labels and class name for a try-catch block. For a chain of catches after a try, just generate multiple of these with the same start and end but different handlers and catch classes for each different catch.- Parameters:
start- The label indicating the start of the try blockend- The label indicating the end of the try blockhandler- The label indicating the location of the exception handlercatchClass- The class of exception that the handler catches- Returns:
- this instruction generator (for chaining calls)
-
tableswitch
Emit an instruction to perform a switch using a table lookup. The table of labels should be of the size max-min+1. If the argument to the switch is a value between min and max inclusive, the switch subtracts min from it, and uses it as an index into labels, and jumps to whatever label is at that location. If the value is not between min and max, it jumps to the default label.- Parameters:
min- The minimum value that can matchmax- The maximum value that can matchdefault_label- The label to jump to if the value is < min or > maxlabels- The array of labels indicating where to jump for a matching value- Returns:
- this instruction generator (for chaining calls)
-
return_by_type
Returns the type of return instruction needed for a value of a specific type- Parameters:
type- The type to get a return instruction for- Returns:
- this instruction generator (for chaining calls)
-
generateBox
Generate a box for a type- Parameters:
type- The type to generate the box for- Returns:
- this instruction generator (for chaining calls)
-
rawOpcode
Inserts a raw opcode into the instruction stream- Parameters:
opcode- The opcode to insert- Returns:
- this instruction generator (for chaining calls)
-
rawIntOpcode
Inserts a raw opcode that takes an int argument into the instruction stream- Parameters:
opcode- The opcode to insertindex- The int argument to insert- Returns:
- this instruction generator (for chaining calls)
-
rawJumpOpcode
Inserts a raw opcode for jumping to a label into the instruction stream. This is typically used for if instructions where the opcode is computed based on the kind of test being done.- Parameters:
opcode- The opcode to insertlabel- The label the opcode should jump to under some condition- Returns:
- this instruction generator (for chaining calls)
-
generateLambda
Schedules the generation of a lambda method- Parameters:
lambda- The method to generate- Returns:
- this instruction generator (for chaining calls)
-
generateLocalVariable
public InstructionGenerator generateLocalVariable(String name, Type type, Label startLoc, Label endLoc, int index) Creates a new local variable with a specific name and type, and a particular range of instructions that it is valid over.- Parameters:
name- The name of the variabletype- The type of the variablestartLoc- The label of the first instruction where the variable is validendLoc- The label just past the last instruction where the variable is validindex- The index number of the local variable- Returns:
- this instruction generator (for chaining calls)
-
lineNumber
public void lineNumber(int lineNumber) Generate a line number pseudo instruction for debugging and stack traces. If the line number is 0, no line number pseudo instruction will be generated.- Parameters:
lineNumber- The line number in the source code that this section of code comes from
-