Class InstructionGenerator

java.lang.Object
org.jfuncmachine.compiler.classgen.InstructionGenerator

public class InstructionGenerator extends Object
A wrapper to emit Java byte codes.

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,

iadd
takes 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 Details

    • aaload

      public InstructionGenerator aaload()
      Emit an instruction to load an object from an array
      Returns:
      this instruction generator (for chaining calls)
    • aastore

      public InstructionGenerator aastore()
      Emit an instruction to store an object into an array
      Returns:
      this instruction generator (for chaining calls)
    • aconst_null

      public InstructionGenerator aconst_null()
      Emit an instruction to push a null constant onto the stack
      Returns:
      this instruction generator (for chaining calls)
    • aload

      public InstructionGenerator aload(int index)
      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

      public InstructionGenerator anewarray(String type)
      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

      public InstructionGenerator areturn()
      Emit an instruction to return an object from the current method
      Returns:
      this instruction generator (for chaining calls)
    • arraylength

      public InstructionGenerator arraylength()
      Emit an instruction to retrieve the length of an array
      Returns:
      this instruction generator (for chaining calls)
    • astore

      public InstructionGenerator astore(int index)
      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

      public InstructionGenerator athrow()
      Emit an instruction to throw an exception
      Returns:
      this instruction generator (for chaining calls)
    • baload

      public InstructionGenerator baload()
      Emit an instruction to fetch a value from a byte array
      Returns:
      this instruction generator (for chaining calls)
    • bastore

      public InstructionGenerator bastore()
      Emit an instruction to store a value in a byte array
      Returns:
      this instruction generator (for chaining calls)
    • bipush

      public InstructionGenerator bipush(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)
      Parameters:
      value - The value that should be pushed onto the stack
      Returns:
      this instruction generator (for chaining calls)
    • caload

      public InstructionGenerator caload()
      Emit an instruction to fetch a value from a char array
      Returns:
      this instruction generator (for chaining calls)
    • castore

      public InstructionGenerator castore()
      Emit an instruction to store a value in a char array
      Returns:
      this instruction generator (for chaining calls)
    • checkcast

      public InstructionGenerator checkcast(String type)
      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

      public InstructionGenerator d2f()
      Emit an instruction to convert a double value to a float
      Returns:
      this instruction generator (for chaining calls)
    • d2i

      public InstructionGenerator d2i()
      Emit an instruction to convert a double value to an int
      Returns:
      this instruction generator (for chaining calls)
    • d2l

      public InstructionGenerator d2l()
      Emit an instruction to convert a double value to a long
      Returns:
      this instruction generator (for chaining calls)
    • dadd

      public InstructionGenerator dadd()
      Emit an instruction to add two doubles
      Returns:
      this instruction generator (for chaining calls)
    • daload

      public InstructionGenerator daload()
      Emit an instruction to fetch a value from an array of doubles
      Returns:
      this instruction generator (for chaining calls)
    • dastore

      public InstructionGenerator dastore()
      Emit an instruction to store a value in an array of doubles
      Returns:
      this instruction generator (for chaining calls)
    • dcmpg

      public InstructionGenerator dcmpg()
      Emit an instruction to compare two doubles where NaN is greater than a value
      Returns:
      this instruction generator (for chaining calls)
    • dcmpl

      public InstructionGenerator dcmpl()
      Emit an instruction to compare two doubles where NaN is less than a value
      Returns:
      this instruction generator (for chaining calls)
    • dconst_0

      public InstructionGenerator 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

      public InstructionGenerator dconst_1()
      Emit an instruction to push a double value of 1.0 onto the stack
      Returns:
      this instruction generator (for chaining calls)
    • ddiv

      public InstructionGenerator ddiv()
      Emit an instruction to divide a double value by a double value
      Returns:
      this instruction generator (for chaining calls)
    • dload

      public InstructionGenerator dload(int index)
      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

      public InstructionGenerator dmul()
      Emit an instruction to multiply two double values
      Returns:
      this instruction generator (for chaining calls)
    • dneg

      public InstructionGenerator dneg()
      Emit an instruction to negate a double value
      Returns:
      this instruction generator (for chaining calls)
    • drem

      public InstructionGenerator drem()
      Emit an instruction to compute the remainder when dividing one double value by another
      Returns:
      this instruction generator (for chaining calls)
    • dreturn

      public InstructionGenerator dreturn()
      Emit an instruction to return a double value from the current method
      Returns:
      this instruction generator (for chaining calls)
    • dstore

      public InstructionGenerator dstore(int index)
      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

      public InstructionGenerator dsub()
      Emit an instruction to subtract two double values
      Returns:
      this instruction generator (for chaining calls)
    • dup

      public InstructionGenerator 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

      public InstructionGenerator 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

      public InstructionGenerator 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 back

      The 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

      public InstructionGenerator 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

      public InstructionGenerator 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

      public InstructionGenerator 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

      public InstructionGenerator f2d()
      Emit an instruction to convert a float to a double
      Returns:
      this instruction generator (for chaining calls)
    • f2i

      public InstructionGenerator f2i()
      Emit an instruction to convert a float to an int
      Returns:
      this instruction generator (for chaining calls)
    • f2l

      public InstructionGenerator f2l()
      Emit an instruction to convert a float to a long
      Returns:
      this instruction generator (for chaining calls)
    • fadd

      public InstructionGenerator fadd()
      Emit an instruction to add two float values
      Returns:
      this instruction generator (for chaining calls)
    • faload

      public InstructionGenerator faload()
      Emit an instruction to fetch a float value from an array
      Returns:
      this instruction generator (for chaining calls)
    • fastore

      public InstructionGenerator fastore()
      Emit an instruction to store a float value in an array
      Returns:
      this instruction generator (for chaining calls)
    • fcmpg

      public InstructionGenerator fcmpg()
      Emit an instruction to compare two floats where NaN is greater than a value
      Returns:
      this instruction generator (for chaining calls)
    • fcmpl

      public InstructionGenerator fcmpl()
      Emit an instruction to compare two floats where NaN is less than a value
      Returns:
      this instruction generator (for chaining calls)
    • fconst_0

      public InstructionGenerator fconst_0()
      Emit an instruction to push a float constant 0.0 onto the stack
      Returns:
      this instruction generator (for chaining calls)
    • fconst_1

      public InstructionGenerator fconst_1()
      Emit an instruction to push a float constant 1.0 onto the stack
      Returns:
      this instruction generator (for chaining calls)
    • fconst_2

      public InstructionGenerator fconst_2()
      Emit an instruction to push a float constant 2.0 onto the stack
      Returns:
      this instruction generator (for chaining calls)
    • fdiv

      public InstructionGenerator fdiv()
      Emit an instruction to divide two float values
      Returns:
      this instruction generator (for chaining calls)
    • fload

      public InstructionGenerator fload(int index)
      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

      public InstructionGenerator fmul()
      Emit an instruction to multiple two float values
      Returns:
      this instruction generator (for chaining calls)
    • fneg

      public InstructionGenerator fneg()
      Emit an instruction to negate a float value
      Returns:
      this instruction generator (for chaining calls)
    • frem

      public InstructionGenerator frem()
      Emit an instruction to compute the remainder when dividing two float values
      Returns:
      this instruction generator (for chaining calls)
    • freturn

      public InstructionGenerator freturn()
      Emit an instruction to return a float value from the current method
      Returns:
      this instruction generator (for chaining calls)
    • fstore

      public InstructionGenerator fstore(int index)
      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

      public InstructionGenerator fsub()
      Emit an instruction to two subtract two float values
      Returns:
      this instruction generator (for chaining calls)
    • getfield

      public InstructionGenerator getfield(String owner, String name, String descriptor)
      Emit an instruction to fetch the value of a field
      Parameters:
      owner - The class to which the field belongs
      name - The name of the field
      descriptor - The type descriptor of the field
      Returns:
      this instruction generator (for chaining calls)
    • getstatic

      public InstructionGenerator getstatic(String owner, String name, String descriptor)
      Emit an instruction to fetch the value of a static field
      Parameters:
      owner - The class to which the field belongs
      name - The name of the field
      descriptor - The type descriptor of the field
      Returns:
      this instruction generator (for chaining calls)
    • gotolabel

      public InstructionGenerator gotolabel(Label label)
      Emit an instruction to jump to a label
      Parameters:
      label - The label to jump to
      Returns:
      this instruction generator (for chaining calls)
    • i2b

      public InstructionGenerator i2b()
      Emit an instruction to convert an int to a byte
      Returns:
      this instruction generator (for chaining calls)
    • i2c

      public InstructionGenerator i2c()
      Emit an instruction to convert an int to a char
      Returns:
      this instruction generator (for chaining calls)
    • i2d

      public InstructionGenerator i2d()
      Emit an instruction to convert an int to a double
      Returns:
      this instruction generator (for chaining calls)
    • i2f

      public InstructionGenerator i2f()
      Emit an instruction to convert an int to a float
      Returns:
      this instruction generator (for chaining calls)
    • i2l

      public InstructionGenerator i2l()
      Emit an instruction to convert an int to a long
      Returns:
      this instruction generator (for chaining calls)
    • i2s

      public InstructionGenerator i2s()
      Emit an instruction to convert an int to a short
      Returns:
      this instruction generator (for chaining calls)
    • iadd

      public InstructionGenerator iadd()
      Emit an instruction to add two integers
      Returns:
      this instruction generator (for chaining calls)
    • iaload

      public InstructionGenerator iaload()
      Emit an instruction to fetch a value from an array of ints
      Returns:
      this instruction generator (for chaining calls)
    • iand

      public InstructionGenerator iand()
      Emit an instruction to perform a bitwise and between two integers
      Returns:
      this instruction generator (for chaining calls)
    • iastore

      public InstructionGenerator iastore()
      Emit an instruction to store a value into an array of ints
      Returns:
      this instruction generator (for chaining calls)
    • iconst_m1

      public InstructionGenerator iconst_m1()
      Emit an instruction to push the int constant -1 onto the stack
      Returns:
      this instruction generator (for chaining calls)
    • iconst_0

      public InstructionGenerator iconst_0()
      Emit an instruction to push the int constant 0 onto the stack
      Returns:
      this instruction generator (for chaining calls)
    • iconst_1

      public InstructionGenerator iconst_1()
      Emit an instruction to push the int constant 1 onto the stack
      Returns:
      this instruction generator (for chaining calls)
    • iconst_2

      public InstructionGenerator iconst_2()
      Emit an instruction to push the int constant 2 onto the stack
      Returns:
      this instruction generator (for chaining calls)
    • iconst_3

      public InstructionGenerator iconst_3()
      Emit an instruction to push the int constant 3 onto the stack
      Returns:
      this instruction generator (for chaining calls)
    • iconst_4

      public InstructionGenerator iconst_4()
      Emit an instruction to push the int constant 4 onto the stack
      Returns:
      this instruction generator (for chaining calls)
    • iconst_5

      public InstructionGenerator iconst_5()
      Emit an instruction to push the int constant 5 onto the stack
      Returns:
      this instruction generator (for chaining calls)
    • idiv

      public InstructionGenerator idiv()
      Emit an instruction to divide two integers
      Returns:
      this instruction generator (for chaining calls)
    • if_acmpeq

      public InstructionGenerator if_acmpeq(Label label)
      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

      public InstructionGenerator if_acmpne(Label label)
      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

      public InstructionGenerator if_icmpeq(Label label)
      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

      public InstructionGenerator if_icmpne(Label label)
      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

      public InstructionGenerator if_icmplt(Label label)
      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

      public InstructionGenerator if_icmpge(Label label)
      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

      public InstructionGenerator if_icmpgt(Label label)
      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

      public InstructionGenerator if_icmple(Label label)
      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

      public InstructionGenerator ifeq(Label label)
      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

      public InstructionGenerator ifne(Label label)
      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

      public InstructionGenerator iflt(Label label)
      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

      public InstructionGenerator ifge(Label label)
      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

      public InstructionGenerator ifgt(Label label)
      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

      public InstructionGenerator ifle(Label label)
      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

      public InstructionGenerator ifnonnull(Label label)
      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

      public InstructionGenerator ifnull(Label label)
      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

      public InstructionGenerator iinc(int index, int incr)
      Emit an instruction to increment a local variable by an amount specified by a byte
      Parameters:
      index - The index of the local variable
      incr - The byte value to add to the local variable
      Returns:
      this instruction generator (for chaining calls)
    • iload

      public InstructionGenerator iload(int index)
      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

      public InstructionGenerator imul()
      Emit an instruction to multiple to int values
      Returns:
      this instruction generator (for chaining calls)
    • ineg

      public InstructionGenerator ineg()
      Emit an instruction to negate an int value
      Returns:
      this instruction generator (for chaining calls)
    • instance_of

      public InstructionGenerator instance_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. 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 invoke
      descriptor - The type descriptor of the method
      handle - A handle to the bootstrap method
      bootstrapArgs - The arguments for the bootstrap method
      Returns:
      this instruction generator (for chaining calls)
    • invokeinterface

      public InstructionGenerator invokeinterface(String owner, String name, String descriptor)
      Emit an instruction to invoke an interface method
      Parameters:
      owner - The class/interface that owns the method
      name - The name of the method
      descriptor - The type descriptor of the method
      Returns:
      this instruction generator (for chaining calls)
    • invokespecial

      public InstructionGenerator invokespecial(String owner, String name, String descriptor)
      Emit an instruction to invoke a constructor, super, or private method
      Parameters:
      owner - The class that owns the method
      name - The name of the method
      descriptor - The type descriptor of the method
      Returns:
      this instruction generator (for chaining calls)
    • invokestatic

      public InstructionGenerator invokestatic(String owner, String name, String descriptor)
      Emit an instruction to invoke a static method
      Parameters:
      owner - The class that owns the method
      name - The name of the method
      descriptor - The type descriptor of the method
      Returns:
      this instruction generator (for chaining calls)
    • invokevirtual

      public InstructionGenerator invokevirtual(String owner, String name, String descriptor)
      Emit an instruction to invoke a virtual method
      Parameters:
      owner - The class that owns the method
      name - The name of the method
      descriptor - The type descriptor of the method
      Returns:
      this instruction generator (for chaining calls)
    • ior

      public InstructionGenerator ior()
      Emit an instruction to perform a bitwise or of two ints
      Returns:
      this instruction generator (for chaining calls)
    • irem

      public InstructionGenerator irem()
      Emit an instruction to compute the remainder from dividing two ints
      Returns:
      this instruction generator (for chaining calls)
    • ireturn

      public InstructionGenerator ireturn()
      Emit an instruction to return an int value from the current method
      Returns:
      this instruction generator (for chaining calls)
    • ishl

      public InstructionGenerator ishl()
      Emit an instruction to shift an int left by a number of bits
      Returns:
      this instruction generator (for chaining calls)
    • ishr

      public InstructionGenerator 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

      public InstructionGenerator istore(int index)
      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

      public InstructionGenerator isub()
      Emit an instruction to subtract two ints
      Returns:
      this instruction generator (for chaining calls)
    • iushr

      public InstructionGenerator 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

      public InstructionGenerator ixor()
      Emit an instruction to perform a bitwise exclusive-or on two ints
      Returns:
      this instruction generator (for chaining calls)
    • jsr

      public InstructionGenerator jsr(Label label)
      Emit an instruction to jump to a subroutine
      Parameters:
      label - The label to jump to
      Returns:
      this instruction generator (for chaining calls)
    • l2d

      public InstructionGenerator l2d()
      Emit an instruction to convert a long to a double
      Returns:
      this instruction generator (for chaining calls)
    • l2f

      public InstructionGenerator l2f()
      Emit an instruction to convert a long to a float
      Returns:
      this instruction generator (for chaining calls)
    • l2i

      public InstructionGenerator l2i()
      Emit an instruction to convert a long to an int
      Returns:
      this instruction generator (for chaining calls)
    • label

      public InstructionGenerator label(Label 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

      public InstructionGenerator ladd()
      Emit an instruction to add to longs
      Returns:
      this instruction generator (for chaining calls)
    • laload

      public InstructionGenerator laload()
      Emit an instruction to fetch a value from an array of longs
      Returns:
      this instruction generator (for chaining calls)
    • land

      public InstructionGenerator land()
      Emit an instruction to do a bitwise and of two longs
      Returns:
      this instruction generator (for chaining calls)
    • lastore

      public InstructionGenerator lastore()
      Emit an instruction to store a value in an array of longs
      Returns:
      this instruction generator (for chaining calls)
    • lcmp

      public InstructionGenerator lcmp()
      Emit an instruction to compare two long values
      Returns:
      this instruction generator (for chaining calls)
    • lconst_0

      public InstructionGenerator lconst_0()
      Emit an instruction to push a long constant 0 onto the stack
      Returns:
      this instruction generator (for chaining calls)
    • lconst_1

      public InstructionGenerator lconst_1()
      Emit an instruction to push a long constant 1 onto the stack
      Returns:
      this instruction generator (for chaining calls)
    • ldc

      public InstructionGenerator ldc(double d)
      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

      public InstructionGenerator ldc(int i)
      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

      public InstructionGenerator ldc(float f)
      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

      public InstructionGenerator ldc(long l)
      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

      public InstructionGenerator ldc(String s)
      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

      public InstructionGenerator ldc(Method m)
      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

      public InstructionGenerator ldc(Handle h)
      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 stack

      A 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

      public InstructionGenerator ldc(Object o)
      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

      public InstructionGenerator ldiv()
      Emit an instruction to divide two longs
      Returns:
      this instruction generator (for chaining calls)
    • lload

      public InstructionGenerator lload(int index)
      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

      public InstructionGenerator lmul()
      Emit an instruction to multiple two longs
      Returns:
      this instruction generator (for chaining calls)
    • lneg

      public InstructionGenerator lneg()
      Emit an instruction to negate a long value
      Returns:
      this instruction generator (for chaining calls)
    • lookupswitch

      public InstructionGenerator lookupswitch(Label default_label, int[] keys, Label[] labels)
      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 found
      keys - A sorted list of integer keys
      labels - The corresponding label for each key
      Returns:
      this instruction generator (for chaining calls)
    • lor

      public InstructionGenerator lor()
      Emit an instruction to perform a bitwise or between two longs
      Returns:
      this instruction generator (for chaining calls)
    • lrem

      public InstructionGenerator lrem()
      Emit an instruction to compute the remainder of dividing two longs
      Returns:
      this instruction generator (for chaining calls)
    • lreturn

      public InstructionGenerator lreturn()
      Emit an instruction to return a long value from the current method
      Returns:
      this instruction generator (for chaining calls)
    • lshl

      public InstructionGenerator 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

      public InstructionGenerator 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

      public InstructionGenerator lstore(int index)
      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

      public InstructionGenerator lsub()
      Emit an instruction to subtract two longs
      Returns:
      this instruction generator (for chaining calls)
    • lushr

      public InstructionGenerator 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

      public InstructionGenerator lxor()
      Emit an instruction to perform a bitwise exclusive-or on two longs
      Returns:
      this instruction generator (for chaining calls)
    • monitorenter

      public InstructionGenerator monitorenter()
      Emit an instruction to enter a monitor (i.e. synchronize on an object)
      Returns:
      this instruction generator (for chaining calls)
    • monitorexit

      public InstructionGenerator monitorexit()
      Emit an instruction to exit a monitor (i.e. synchronize on an object)
      Returns:
      this instruction generator (for chaining calls)
    • multianewarray

      public InstructionGenerator multianewarray(String descriptor, int dims)
      Create a multi-dimentional array
      Parameters:
      descriptor - The type descriptor of the array
      dims - The number of dimensions
      Returns:
      this instruction generator (for chaining calls)
    • new_object

      public InstructionGenerator new_object(String type)
      Emit an instruction to allocate a new object

      Note: 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

      public InstructionGenerator newarray(Type type)
      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

      public InstructionGenerator nop()
      Emit an instruction to do nothing
      Returns:
      this instruction generator (for chaining calls)
    • pop

      public InstructionGenerator pop()
      Emit an instruction to pop a value off the stack
      Returns:
      this instruction generator (for chaining calls)
    • pop2

      public InstructionGenerator pop2()
      Emit an instruction to pop two values off the stack (or one 2-slot value)
      Returns:
      this instruction generator (for chaining calls)
    • putfield

      public InstructionGenerator putfield(String owner, String name, String descriptor)
      Emit an instruction to store a value in a field
      Parameters:
      owner - The class that owns the field
      name - The name of the field
      descriptor - The type descriptor of the field
      Returns:
      this instruction generator (for chaining calls)
    • putstatic

      public InstructionGenerator putstatic(String owner, String name, String descriptor)
      Emit an instruction to store a value in a static field
      Parameters:
      owner - The class that owns the field
      name - The name of the field
      descriptor - The type descriptor of the field
      Returns:
      this instruction generator (for chaining calls)
    • ret

      public InstructionGenerator ret(int index)
      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

      public InstructionGenerator return_void()
      Returns from the current method without returning a value
      Returns:
      this instruction generator (for chaining calls)
    • saload

      public InstructionGenerator saload()
      Emit an instruction to load a value from an array of shorts
      Returns:
      this instruction generator (for chaining calls)
    • sastore

      public InstructionGenerator sastore()
      Emit an instruction to store a value in an array of shorts
      Returns:
      this instruction generator (for chaining calls)
    • sipush

      public InstructionGenerator sipush(int value)
      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

      public InstructionGenerator 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

      public InstructionGenerator trycatch(Label start, Label end, Label handler, String catchClass)
      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 block
      end - The label indicating the end of the try block
      handler - The label indicating the location of the exception handler
      catchClass - The class of exception that the handler catches
      Returns:
      this instruction generator (for chaining calls)
    • tableswitch

      public InstructionGenerator tableswitch(int min, int max, Label default_label, Label[] labels)
      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 match
      max - The maximum value that can match
      default_label - The label to jump to if the value is < min or > max
      labels - The array of labels indicating where to jump for a matching value
      Returns:
      this instruction generator (for chaining calls)
    • return_by_type

      public InstructionGenerator return_by_type(Type 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

      public InstructionGenerator generateBox(Type type)
      Generate a box for a type
      Parameters:
      type - The type to generate the box for
      Returns:
      this instruction generator (for chaining calls)
    • rawOpcode

      public InstructionGenerator rawOpcode(int opcode)
      Inserts a raw opcode into the instruction stream
      Parameters:
      opcode - The opcode to insert
      Returns:
      this instruction generator (for chaining calls)
    • rawIntOpcode

      public InstructionGenerator rawIntOpcode(int opcode, int index)
      Inserts a raw opcode that takes an int argument into the instruction stream
      Parameters:
      opcode - The opcode to insert
      index - The int argument to insert
      Returns:
      this instruction generator (for chaining calls)
    • rawJumpOpcode

      public InstructionGenerator rawJumpOpcode(int opcode, Label label)
      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 insert
      label - The label the opcode should jump to under some condition
      Returns:
      this instruction generator (for chaining calls)
    • generateLambda

      public InstructionGenerator generateLambda(MethodDef lambda)
      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 variable
      type - The type of the variable
      startLoc - The label of the first instruction where the variable is valid
      endLoc - The label just past the last instruction where the variable is valid
      index - 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