org.cojen.classfile
Class NullCodeAssembler

java.lang.Object
  extended by org.cojen.classfile.AbstractCodeAssembler
      extended by org.cojen.classfile.NullCodeAssembler
All Implemented Interfaces:
CodeAssembler

public class NullCodeAssembler
extends AbstractCodeAssembler

CodeAssembler implementation which discards everything.

Author:
Brian S O'Neill

Field Summary
 
Fields inherited from interface org.cojen.classfile.CodeAssembler
CONVERT_FP_BITS, CONVERT_FP_NORMAL, CONVERT_FP_RAW_BITS
 
Constructor Summary
NullCodeAssembler(MethodInfo mi)
           
 
Method Summary
 void arrayLength()
          Generates code for an arraylength instruction.
 void branch(Location location)
          Generates code that performs an unconditional branch to the specified location.
 void breakpoint()
          Generates a breakpoint instruction for use in a debugging environment.
 void checkCast(TypeDesc type)
          Generates code that performs an object cast operation.
 void convert(TypeDesc fromType, TypeDesc toType)
          Generates code that converts the value of a primitive type already on the stack.
 void convert(TypeDesc fromType, TypeDesc toType, int fpConvertMode)
          Generates code that converts the value of a primitive type already on the stack.
 Label createLabel()
          Creates a label, whose location must be set.
 LocalVariable createLocalVariable(String name, TypeDesc type)
          Creates a LocalVariable reference from a name and type.
 void dup()
          Generates code for the dup instruction, which duplicates the top word on the stack.
 void dup2()
          Generates code for the dup2 instruction, which duplicates the top pair of words on the stack.
 void dup2X1()
          Generates code for the dup2_x1 instruction, which duplicates the top pair of words on the stack and puts it three levels down.
 void dup2X2()
          Generates code for the dup2_x2 instruction, which duplicates the top pair of words on the stack and puts it four levels down.
 void dupX1()
          Generates code for the dup_x1 instruction, which duplicates the top word on the stack and puts it two levels down.
 void dupX2()
          Generates code for the dup_x2 instruction, which duplicates the top word on the stack and puts it three levels down.
 void exceptionHandler(Location startLocation, Location endLocation, String catchClassName)
          Sets up an exception handler located here, the location of the next code to be generated.
protected  int getInstructionsSeen()
           
 LocalVariable getParameter(int index)
          Returns a method input parameter by a zero-based index.
 int getParameterCount()
          Returns the amount of parameters that are accepted by the method being built, not including any "this" reference.
 void ifComparisonBranch(Location location, String choice)
          Generates code the performs a conditional branch based on a comparison between two int values on the stack.
 void ifEqualBranch(Location location, boolean choice)
          Generates code that performs a conditional branch based on the value of two object references on the stack.
 void ifNullBranch(Location location, boolean choice)
          Generates code that performs a conditional branch based on the value of an object on the stack.
 void ifZeroComparisonBranch(Location location, String choice)
          Generates code the performs a conditional branch based on a comparison between an int value on the stack and zero.
 void instanceOf(TypeDesc type)
          Generates code that performs an instanceof operation.
 void integerIncrement(LocalVariable local, int amount)
          Generates code that increments a local integer variable by a signed constant amount.
 void invokeConstructor(String className, TypeDesc[] params)
          Generates code to invoke a class constructor in any class.
 void invokeConstructor(TypeDesc[] params)
          Generates code to invoke a class constructor in this class.
 void invokeConstructor(TypeDesc classDesc, TypeDesc[] params)
          Generates code to invoke a class constructor in any class.
 void invokeInterface(String className, String methodName, TypeDesc ret, TypeDesc[] params)
          Generates code to invoke an interface method in any class.
 void invokeInterface(TypeDesc classDesc, String methodName, TypeDesc ret, TypeDesc[] params)
          Generates code to invoke an interface method in any class.
 void invokePrivate(String methodName, TypeDesc ret, TypeDesc[] params)
          Generates code to invoke a private method in this class.
 void invokeStatic(String className, String methodName, TypeDesc ret, TypeDesc[] params)
          Generates code to invoke a static method in any class.
 void invokeStatic(String methodName, TypeDesc ret, TypeDesc[] params)
          Generates code to invoke a static method in this class.
 void invokeStatic(TypeDesc classDesc, String methodName, TypeDesc ret, TypeDesc[] params)
          Generates code to invoke a static method in any class.
 void invokeSuper(String superClassName, String methodName, TypeDesc ret, TypeDesc[] params)
          Generates code to invoke a method in the super class.
 void invokeSuper(TypeDesc superClassDesc, String methodName, TypeDesc ret, TypeDesc[] params)
          Generates code to invoke a method in the super class.
 void invokeSuperConstructor(TypeDesc[] params)
          Generates code to invoke a super class constructor.
 void invokeVirtual(String className, String methodName, TypeDesc ret, TypeDesc[] params)
          Generates code to invoke a virtual method in any class.
 void invokeVirtual(String methodName, TypeDesc ret, TypeDesc[] params)
          Generates code to invoke a virtual method in this class.
 void invokeVirtual(TypeDesc classDesc, String methodName, TypeDesc ret, TypeDesc[] params)
          Generates code to invoke a virtual method in any class.
 void jsr(Location location)
          Generates code that performs a subroutine branch to the specified location.
 void loadConstant(boolean value)
          Generates code that loads a constant boolean value onto the stack.
 void loadConstant(double value)
          Generates code that loads a constant double value onto the stack.
 void loadConstant(float value)
          Generates code that loads a constant float value onto the stack.
 void loadConstant(int value)
          Generates code that loads a constant int, char, short or byte value onto the stack.
 void loadConstant(long value)
          Generates code that loads a constant long value onto the stack.
 void loadConstant(String value)
          Generates code that loads a constant string value onto the stack.
 void loadConstant(TypeDesc type)
          Generates code that loads a constant class value onto the stack.
 void loadField(String className, String fieldName, TypeDesc type)
          Generates code that loads a value from a field from any class.
 void loadField(String fieldName, TypeDesc type)
          Generates code that loads a value from a field from this class.
 void loadField(TypeDesc classDesc, String fieldName, TypeDesc type)
          Generates code that loads a value from a field from any class.
 void loadFromArray(TypeDesc type)
          Generates code that loads a value from an array.
 void loadLocal(LocalVariable local)
          Generates code that loads a local variable onto the stack.
 void loadNull()
          Generates code that loads a null reference onto the stack.
 void loadStaticField(String className, String fieldName, TypeDesc type)
          Generates code that loads a value from a static field from any class.
 void loadStaticField(String fieldName, TypeDesc type)
          Generates code that loads a value from a static field from this class.
 void loadStaticField(TypeDesc classDesc, String fieldName, TypeDesc type)
          Generates code that loads a value from a static field from any class.
 void loadThis()
          Loads a reference to "this" onto the stack.
 void mapLineNumber(int lineNumber)
          Map the location of the next code to be generated to a line number in source code.
 void math(byte opcode)
          Generates code for either a unary or binary math operation on one or two values pushed on the stack.
 void monitorEnter()
          Generates code to enter the monitor on an object loaded on the stack.
 void monitorExit()
          Generates code to exit the monitor on an object loaded on the stack.
 void newObject(TypeDesc type)
          Generates code to create a new object.
 void newObject(TypeDesc type, int dimensions)
          Generates code to create a new array.
 void nop()
          Generates an instruction that does nothing.
 void pop()
          Generates code for the pop instruction, which simply discards the top word on the stack.
 void pop2()
          Generates code for the pop2 instruction, which simply discards the top two words on the stack.
 void ret(LocalVariable local)
          Generates code that returns from a subroutine invoked by jsr.
 void returnValue(TypeDesc type)
          Generates code that returns an object or primitive type.
 void returnVoid()
          Generates code that returns void.
 void storeField(String className, String fieldName, TypeDesc type)
          Generates code that stores a value into a field from any class.
 void storeField(String fieldName, TypeDesc type)
          Generates code that stores a value into a field from this class.
 void storeField(TypeDesc classDesc, String fieldName, TypeDesc type)
          Generates code that stores a value into a field from any class.
 void storeLocal(LocalVariable local)
          Generates code that pops a value off of the stack into a local variable.
 void storeStaticField(String className, String fieldName, TypeDesc type)
          Generates code that stores a value into a field from any class.
 void storeStaticField(String fieldName, TypeDesc type)
          Generates code that stores a value into a field from this class.
 void storeStaticField(TypeDesc classDesc, String fieldName, TypeDesc type)
          Generates code that stores a value into a field from any class.
 void storeToArray(TypeDesc type)
          Generates code that stores a value to an array.
 void swap()
          Generates code for the swap instruction, which swaps to the top two words on the stack.
 void swap2()
          Generates code for a swap2 instruction, which swaps to the top two pair of words on the stack.
 void switchBranch(int[] cases, Location[] locations, Location defaultLocation)
          Generates code for a switch statement.
 void throwObject()
          Generates code that throws an exception.
 
Methods inherited from class org.cojen.classfile.AbstractCodeAssembler
createLocalVariable, ifComparisonBranch, inline, invoke, invoke, invokeSuper
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NullCodeAssembler

public NullCodeAssembler(MethodInfo mi)
Method Detail

getInstructionsSeen

protected int getInstructionsSeen()

getParameterCount

public int getParameterCount()
Description copied from interface: CodeAssembler
Returns the amount of parameters that are accepted by the method being built, not including any "this" reference.


getParameter

public LocalVariable getParameter(int index)
Description copied from interface: CodeAssembler
Returns a method input parameter by a zero-based index. Parameter zero always refers to the first parameter in the method signature. If defining a non-static method, the "this" variable is accessed by calling CodeAssembler.loadThis().


createLocalVariable

public LocalVariable createLocalVariable(String name,
                                         TypeDesc type)
Description copied from interface: CodeAssembler
Creates a LocalVariable reference from a name and type. Although name is optional, it is encouraged that a name be provided. Names do not need to be unique.

Parameters:
name - Optional name for the LocalVariable.
type - The type of data that the requested LocalVariable can store.

createLabel

public Label createLabel()
Description copied from interface: CodeAssembler
Creates a label, whose location must be set. To create a label and locate it here, the following example demonstrates how the call to setLocation can be chained:
 CodeBuilder builder;
 ...
 Label label = builder.createLabel().setLocation();
 

See Also:
Label.setLocation()

exceptionHandler

public void exceptionHandler(Location startLocation,
                             Location endLocation,
                             String catchClassName)
Description copied from interface: CodeAssembler
Sets up an exception handler located here, the location of the next code to be generated.

Parameters:
startLocation - Location at the start of the section of code to be wrapped by an exception handler.
endLocation - Location directly after the end of the section of code.
catchClassName - The class name of exception to be caught; if null, then catch every object.

mapLineNumber

public void mapLineNumber(int lineNumber)
Description copied from interface: CodeAssembler
Map the location of the next code to be generated to a line number in source code. This enables line numbers in a stack trace from the generated code.


loadNull

public void loadNull()
Description copied from interface: CodeAssembler
Generates code that loads a null reference onto the stack.


loadConstant

public void loadConstant(String value)
Description copied from interface: CodeAssembler
Generates code that loads a constant string value onto the stack. If value is null, the generated code loads a null onto the stack. Strings that exceed 65535 UTF encoded bytes in length are loaded by creating a StringBuffer (or a StringBuilder), appending substrings, and then converting it to a String.


loadConstant

public void loadConstant(TypeDesc type)
Description copied from interface: CodeAssembler
Generates code that loads a constant class value onto the stack. If value is null, the generated code loads a null onto the stack.

Parameters:
type - any object or primitive type

loadConstant

public void loadConstant(boolean value)
Description copied from interface: CodeAssembler
Generates code that loads a constant boolean value onto the stack.


loadConstant

public void loadConstant(int value)
Description copied from interface: CodeAssembler
Generates code that loads a constant int, char, short or byte value onto the stack.


loadConstant

public void loadConstant(long value)
Description copied from interface: CodeAssembler
Generates code that loads a constant long value onto the stack.


loadConstant

public void loadConstant(float value)
Description copied from interface: CodeAssembler
Generates code that loads a constant float value onto the stack.


loadConstant

public void loadConstant(double value)
Description copied from interface: CodeAssembler
Generates code that loads a constant double value onto the stack.


loadLocal

public void loadLocal(LocalVariable local)
Description copied from interface: CodeAssembler
Generates code that loads a local variable onto the stack. Parameters passed to a method and the "this" reference are all considered local variables, as well as any that were created.

Parameters:
local - The local variable reference

loadThis

public void loadThis()
Description copied from interface: CodeAssembler
Loads a reference to "this" onto the stack. Static methods have no "this" reference, and an exception is thrown when attempting to generate "this" in a static method.


storeLocal

public void storeLocal(LocalVariable local)
Description copied from interface: CodeAssembler
Generates code that pops a value off of the stack into a local variable. Parameters passed to a method and the "this" reference are all considered local variables, as well as any that were created.

Parameters:
local - The local variable reference
See Also:
CodeAssembler.getParameter(int), CodeAssembler.createLocalVariable(java.lang.String, org.cojen.classfile.TypeDesc)

loadFromArray

public void loadFromArray(TypeDesc type)
Description copied from interface: CodeAssembler
Generates code that loads a value from an array. An array reference followed by an index must be on the stack. The array reference and index are replaced by the value retrieved from the array after the generated instruction has executed.

The type doesn't need to be an exact match for objects. TypeDesc.OBJECT works fine for all objects. For primitive types, use the appropriate TypeDesc. For an int, the type is TypeDesc.INT.

Parameters:
type - The type of data stored in the array.

storeToArray

public void storeToArray(TypeDesc type)
Description copied from interface: CodeAssembler
Generates code that stores a value to an array. An array reference followed by an index, followed by a value (or two if a long or double) must be on the stack. All items on the stack are gone after the generated instruction has executed.

The type doesn't need to be an exact match for objects. TypeDesc.OBJECT works fine for all objects. For primitive types, use the appropriate TypeDesc. For an int, the type is TypeDesc.INT.

Parameters:
type - The type of data stored in the array.

loadField

public void loadField(String fieldName,
                      TypeDesc type)
Description copied from interface: CodeAssembler
Generates code that loads a value from a field from this class. An object reference must be on the stack. After the generated code has executed, the object reference is replaced by the value retrieved from the field.


loadField

public void loadField(String className,
                      String fieldName,
                      TypeDesc type)
Description copied from interface: CodeAssembler
Generates code that loads a value from a field from any class. An object reference must be on the stack. After the generated code has executed, the object reference is replaced by the value retrieved from the field.


loadField

public void loadField(TypeDesc classDesc,
                      String fieldName,
                      TypeDesc type)
Description copied from interface: CodeAssembler
Generates code that loads a value from a field from any class. An object reference must be on the stack. After the generated code has executed, the object reference is replaced by the value retrieved from the field.


loadStaticField

public void loadStaticField(String fieldName,
                            TypeDesc type)
Description copied from interface: CodeAssembler
Generates code that loads a value from a static field from this class. After the generated code has executed, the value retrieved is placed on the stack.


loadStaticField

public void loadStaticField(String className,
                            String fieldName,
                            TypeDesc type)
Description copied from interface: CodeAssembler
Generates code that loads a value from a static field from any class. After the generated code has executed, the value retrieved is placed on the stack.


loadStaticField

public void loadStaticField(TypeDesc classDesc,
                            String fieldName,
                            TypeDesc type)
Description copied from interface: CodeAssembler
Generates code that loads a value from a static field from any class. After the generated code has executed, the value retrieved is placed on the stack.


storeField

public void storeField(String fieldName,
                       TypeDesc type)
Description copied from interface: CodeAssembler
Generates code that stores a value into a field from this class. An object reference and value must be on the stack. After the generated code has executed, the object reference and value are gone from the stack.


storeField

public void storeField(String className,
                       String fieldName,
                       TypeDesc type)
Description copied from interface: CodeAssembler
Generates code that stores a value into a field from any class. An object reference and value must be on the stack. After the generated code has executed, the object reference and value are gone from the stack.


storeField

public void storeField(TypeDesc classDesc,
                       String fieldName,
                       TypeDesc type)
Description copied from interface: CodeAssembler
Generates code that stores a value into a field from any class. An object reference and value must be on the stack. After the generated code has executed, the object reference and value are gone from the stack.


storeStaticField

public void storeStaticField(String fieldName,
                             TypeDesc type)
Description copied from interface: CodeAssembler
Generates code that stores a value into a field from this class. A value must be on the stack. After the generated code has executed, the value is gone from the stack.


storeStaticField

public void storeStaticField(String className,
                             String fieldName,
                             TypeDesc type)
Description copied from interface: CodeAssembler
Generates code that stores a value into a field from any class. A value must be on the stack. After the generated code has executed, the value is gone from the stack.


storeStaticField

public void storeStaticField(TypeDesc classDesc,
                             String fieldName,
                             TypeDesc type)
Description copied from interface: CodeAssembler
Generates code that stores a value into a field from any class. A value must be on the stack. After the generated code has executed, the value is gone from the stack.


returnVoid

public void returnVoid()
Description copied from interface: CodeAssembler
Generates code that returns void.


returnValue

public void returnValue(TypeDesc type)
Description copied from interface: CodeAssembler
Generates code that returns an object or primitive type. The value to return must be on the stack.

The type doesn't need to be an exact match for objects. TypeDesc.OBJECT works fine for all objects. For primitive types, use the appropriate TypeDesc. For an int, the type is TypeDesc.INT.


convert

public void convert(TypeDesc fromType,
                    TypeDesc toType)
Description copied from interface: CodeAssembler
Generates code that converts the value of a primitive type already on the stack. Conversions between all primitive types are supported as well as boxing and unboxing conversions. Some example conversions:
 int to char
 byte to double
 Double to double
 Float to boolean
 long to Long
 Double to Short
 
In all, 240 conversions are supported.


convert

public void convert(TypeDesc fromType,
                    TypeDesc toType,
                    int fpConvertMode)
Description copied from interface: CodeAssembler
Generates code that converts the value of a primitive type already on the stack. Conversions between all primitive types are supported as well as boxing and unboxing conversions. Some example conversions:
 int to char
 byte to double
 Double to double
 Float to boolean
 long to Long
 Double to Short
 
In all, 240 conversions are supported.

fpConvertMode - controls floating point conversion if converting float <--> int or double <--> long

invokeVirtual

public void invokeVirtual(String methodName,
                          TypeDesc ret,
                          TypeDesc[] params)
Description copied from interface: CodeAssembler
Generates code to invoke a virtual method in this class. The object reference and the method's argument(s) must be on the stack.

ret - May be null if method returns void.
params - May be null if method takes no parameters.

invokeVirtual

public void invokeVirtual(String className,
                          String methodName,
                          TypeDesc ret,
                          TypeDesc[] params)
Description copied from interface: CodeAssembler
Generates code to invoke a virtual method in any class. The object reference and the method's argument(s) must be on the stack.

ret - May be null if method returns void.
params - May be null if method takes no parameters.

invokeVirtual

public void invokeVirtual(TypeDesc classDesc,
                          String methodName,
                          TypeDesc ret,
                          TypeDesc[] params)
Description copied from interface: CodeAssembler
Generates code to invoke a virtual method in any class. The object reference and the method's argument(s) must be on the stack.

ret - May be null if method returns void.
params - May be null if method takes no parameters.

invokeStatic

public void invokeStatic(String methodName,
                         TypeDesc ret,
                         TypeDesc[] params)
Description copied from interface: CodeAssembler
Generates code to invoke a static method in this class. The method's argument(s) must be on the stack.

ret - May be null if method returns void.
params - May be null if method takes no parameters.

invokeStatic

public void invokeStatic(String className,
                         String methodName,
                         TypeDesc ret,
                         TypeDesc[] params)
Description copied from interface: CodeAssembler
Generates code to invoke a static method in any class. The method's argument(s) must be on the stack.

ret - May be null if method returns void.
params - May be null if method takes no parameters.

invokeStatic

public void invokeStatic(TypeDesc classDesc,
                         String methodName,
                         TypeDesc ret,
                         TypeDesc[] params)
Description copied from interface: CodeAssembler
Generates code to invoke a static method in any class. The method's argument(s) must be on the stack.

ret - May be null if method returns void.
params - May be null if method takes no parameters.

invokeInterface

public void invokeInterface(String className,
                            String methodName,
                            TypeDesc ret,
                            TypeDesc[] params)
Description copied from interface: CodeAssembler
Generates code to invoke an interface method in any class. The object reference and the method's argument(s) must be on the stack.

ret - May be null if method returns void.
params - May be null if method takes no parameters.

invokeInterface

public void invokeInterface(TypeDesc classDesc,
                            String methodName,
                            TypeDesc ret,
                            TypeDesc[] params)
Description copied from interface: CodeAssembler
Generates code to invoke an interface method in any class. The object reference and the method's argument(s) must be on the stack.

ret - May be null if method returns void.
params - May be null if method takes no parameters.

invokePrivate

public void invokePrivate(String methodName,
                          TypeDesc ret,
                          TypeDesc[] params)
Description copied from interface: CodeAssembler
Generates code to invoke a private method in this class. The object reference and the method's argument(s) must be on the stack.

ret - May be null if method returns void.
params - May be null if method takes no parameters.

invokeSuper

public void invokeSuper(String superClassName,
                        String methodName,
                        TypeDesc ret,
                        TypeDesc[] params)
Description copied from interface: CodeAssembler
Generates code to invoke a method in the super class. The object reference and the method's argument(s) must be on the stack.

ret - May be null if method returns void.
params - May be null if method takes no parameters.

invokeSuper

public void invokeSuper(TypeDesc superClassDesc,
                        String methodName,
                        TypeDesc ret,
                        TypeDesc[] params)
Description copied from interface: CodeAssembler
Generates code to invoke a method in the super class. The object reference and the method's argument(s) must be on the stack.

ret - May be null if method returns void.
params - May be null if method takes no parameters.

invokeConstructor

public void invokeConstructor(TypeDesc[] params)
Description copied from interface: CodeAssembler
Generates code to invoke a class constructor in this class. The object reference and the constructor's argument(s) must be on the stack.

Parameters:
params - May be null if constructor takes no parameters.

invokeConstructor

public void invokeConstructor(String className,
                              TypeDesc[] params)
Description copied from interface: CodeAssembler
Generates code to invoke a class constructor in any class. The object reference and the constructor's argument(s) must be on the stack.

params - May be null if constructor takes no parameters.

invokeConstructor

public void invokeConstructor(TypeDesc classDesc,
                              TypeDesc[] params)
Description copied from interface: CodeAssembler
Generates code to invoke a class constructor in any class. The object reference and the constructor's argument(s) must be on the stack.

params - May be null if constructor takes no parameters.

invokeSuperConstructor

public void invokeSuperConstructor(TypeDesc[] params)
Description copied from interface: CodeAssembler
Generates code to invoke a super class constructor. The object reference and the constructor's argument(s) must be on the stack.

Parameters:
params - May be null if constructor takes no parameters.

newObject

public void newObject(TypeDesc type)
Description copied from interface: CodeAssembler
Generates code to create a new object. Unless the new object is an array, it is invalid until a constructor method is invoked on it.

If the specified type is an array, this call is equivalent to newObject(type, 1). The size of the dimension must be on the operand stack. To create multi-dimensional arrays, call newObject(type, dimensions).

See Also:
CodeAssembler.invokeConstructor(org.cojen.classfile.TypeDesc[])

newObject

public void newObject(TypeDesc type,
                      int dimensions)
Description copied from interface: CodeAssembler
Generates code to create a new array. The type descriptor specifies the type of array to create. The dimensions parameter specifies the amount of dimensions that will initialized, which may not be larger than the amount of dimensions specified in the type.

For each dimension, its size must be on the operand stack. If the specified dimensions is 0 and the type is not an array, then this call is equivalent to newObject(type).


dup

public void dup()
Description copied from interface: CodeAssembler
Generates code for the dup instruction, which duplicates the top word on the stack. For duplicating double and long types, use the dup2 instruction.


dupX1

public void dupX1()
Description copied from interface: CodeAssembler
Generates code for the dup_x1 instruction, which duplicates the top word on the stack and puts it two levels down. For duplicating double and long types, use the dup2_x1 instruction.


dupX2

public void dupX2()
Description copied from interface: CodeAssembler
Generates code for the dup_x2 instruction, which duplicates the top word on the stack and puts it three levels down. For duplicating double and long types, use the dup2_x2 instruction.


dup2

public void dup2()
Description copied from interface: CodeAssembler
Generates code for the dup2 instruction, which duplicates the top pair of words on the stack. For duplicating single-word types, like int and object references, use the dup instruction.


dup2X1

public void dup2X1()
Description copied from interface: CodeAssembler
Generates code for the dup2_x1 instruction, which duplicates the top pair of words on the stack and puts it three levels down. For duplicating single-word types, like int and object references, use the dup_x1 instruction.


dup2X2

public void dup2X2()
Description copied from interface: CodeAssembler
Generates code for the dup2_x2 instruction, which duplicates the top pair of words on the stack and puts it four levels down. For duplicating single-word types, like int and object references, use the dup_x2 instruction.


pop

public void pop()
Description copied from interface: CodeAssembler
Generates code for the pop instruction, which simply discards the top word on the stack. For popping double and long types, use the pop2 instruction.


pop2

public void pop2()
Description copied from interface: CodeAssembler
Generates code for the pop2 instruction, which simply discards the top two words on the stack. For popping single-word types, like int and object references, use the pop instruction.


swap

public void swap()
Description copied from interface: CodeAssembler
Generates code for the swap instruction, which swaps to the top two words on the stack. For swapping double and long types, use the swap2 pseudo instruction.


swap2

public void swap2()
Description copied from interface: CodeAssembler
Generates code for a swap2 instruction, which swaps to the top two pair of words on the stack. For swapping single-word types, like int and object references, use the swap instruction.


branch

public void branch(Location location)
Description copied from interface: CodeAssembler
Generates code that performs an unconditional branch to the specified location.

Parameters:
location - The location to branch to

ifNullBranch

public void ifNullBranch(Location location,
                         boolean choice)
Description copied from interface: CodeAssembler
Generates code that performs a conditional branch based on the value of an object on the stack. A branch is performed based on whether the object reference on the stack is null or not.

The generated instruction consumes the value on the stack.

Parameters:
location - The location to branch to
choice - If true, do branch when null, else branch when not null

ifEqualBranch

public void ifEqualBranch(Location location,
                          boolean choice)
Description copied from interface: CodeAssembler
Generates code that performs a conditional branch based on the value of two object references on the stack. A branch is performed based on whether the two objects are exactly the same.

The generated instruction consumes the two values on the stack.

Parameters:
location - The location to branch to
choice - If true, branch when equal, else branch when not equal

ifZeroComparisonBranch

public void ifZeroComparisonBranch(Location location,
                                   String choice)
Description copied from interface: CodeAssembler
Generates code the performs a conditional branch based on a comparison between an int value on the stack and zero. The int value on the stack is on the left side of the comparison expression.

The generated instruction consumes the value on the stack.

Parameters:
location - The location to branch to
choice - One of "==", "!=", "<", ">=", ">" or "<="

ifComparisonBranch

public void ifComparisonBranch(Location location,
                               String choice)
Description copied from interface: CodeAssembler
Generates code the performs a conditional branch based on a comparison between two int values on the stack. The first int value on the stack is on the left side of the comparison expression.

The generated instruction consumes the two values on the stack.

Parameters:
location - The location to branch to
choice - One of "==", "!=", "<", ">=", ">" or "<="

switchBranch

public void switchBranch(int[] cases,
                         Location[] locations,
                         Location defaultLocation)
Description copied from interface: CodeAssembler
Generates code for a switch statement. The generated code is either a lookupswitch or tableswitch. The choice of which switch type to generate is made based on the amount of bytes to be generated. A tableswitch is usually smaller, unless the cases are sparse.

The key value to switch on must already be on the stack when this instruction executes. It is consumed by the instruction.

Parameters:
cases - The values to match on. The array length must be the same as for locations.
locations - The locations to branch to for each case. The array length must be the same as for cases.
defaultLocation - The location to branch to if the key on the stack was not matched.

jsr

public void jsr(Location location)
Description copied from interface: CodeAssembler
Generates code that performs a subroutine branch to the specified location. The instruction generated is either jsr or jsr_w. It is most often used for implementing a finally block.

Parameters:
location - The location to branch to

ret

public void ret(LocalVariable local)
Description copied from interface: CodeAssembler
Generates code that returns from a subroutine invoked by jsr.

Parameters:
local - The local variable reference that contains the return address. The local variable must be of an object type.

math

public void math(byte opcode)
Description copied from interface: CodeAssembler
Generates code for either a unary or binary math operation on one or two values pushed on the stack. Pass in one of the following math opcodes:
 IADD  - add top two int operands
 ISUB  - subtract top two int operands (topmost is subtrahend)
 IMUL  - multiply top two int operands
 IDIV  - divide top two int operands (topmost is divisor)
 IREM  - remainder of top two int operands (topmost is divisor)
 INEG  - negate top int operand
 IAND  - logical 'and' of top two int operands
 IOR   - logical 'or' of top two int operands
 IXOR  - logical 'exclusive or' of top two int operands
 ISHL  - shift left of int operand by topmost int shift amount
 ISHR  - signed shift right of int operand by topmost int shift amount
 IUSHR - unsigned shift right of int operand by topmost int shift amount

 LADD  - add top two long operands
 LSUB  - subtract top two long operands (topmost is subtrahend)
 LMUL  - multiply top two long operands
 LDIV  - divide top two long operands (topmost is divisor)
 LREM  - remainder of top two long operands (topmost is divisor)
 LNEG  - negate top long operand
 LAND  - logical 'and' of top two long operands
 LOR   - logical 'or' of top two long operands
 LXOR  - logical 'exclusive or' of top two long operands
 LSHL  - shift left of long operand by topmost int shift amount
 LSHR  - signed shift right of long operand by topmost int shift amount
 LUSHR - unsigned shift right of long operand by topmost int shift amount

 FADD  - add top two float operands
 FSUB  - subtract top two float operands (topmost is subtrahend)
 FMUL  - multiply top two float operands
 FDIV  - divide top two float operands (topmost is divisor)
 FREM  - remainder of top two float operands (topmost is divisor)
 FNEG  - negate top float operand

 DADD  - add top two double operands
 DSUB  - subtract top two double operands (topmost is subtrahend)
 DMUL  - multiply top two double operands
 DDIV  - divide top two double operands (topmost is divisor)
 DREM  - remainder of top two double operands (topmost is divisor)
 DNEG  - negate top double operand

 LCMP  - compare top two long operands, yielding an int -1, 0 or 1
 FCMPG - compare top two float operands, yielding an int -1, 0 or 1 (NaN -> 1)
 FCMPL - compare top two float operands, yielding an int -1, 0 or 1 (NaN -> -1)
 DCMPG - compare top two double operands, yielding an int -1, 0 or 1 (NaN -> 1)
 DCMPL - compare top two double operands, yielding an int -1, 0 or 1 (NaN -> -1)
 
A not operation (~) is performed by doing a loadConstant with either -1 or -1L followed by math(Opcode.IXOR) or math(Opcode.LXOR).

Parameters:
opcode - An opcode from the Opcode class.
See Also:
Opcode

arrayLength

public void arrayLength()
Description copied from interface: CodeAssembler
Generates code for an arraylength instruction. The object to get the length from must already be on the stack.


throwObject

public void throwObject()
Description copied from interface: CodeAssembler
Generates code that throws an exception. The object to throw must already be on the stack.


checkCast

public void checkCast(TypeDesc type)
Description copied from interface: CodeAssembler
Generates code that performs an object cast operation. The object to check must already be on the stack.


instanceOf

public void instanceOf(TypeDesc type)
Description copied from interface: CodeAssembler
Generates code that performs an instanceof operation. The object to check must already be on the stack.


integerIncrement

public void integerIncrement(LocalVariable local,
                             int amount)
Description copied from interface: CodeAssembler
Generates code that increments a local integer variable by a signed constant amount.


monitorEnter

public void monitorEnter()
Description copied from interface: CodeAssembler
Generates code to enter the monitor on an object loaded on the stack.


monitorExit

public void monitorExit()
Description copied from interface: CodeAssembler
Generates code to exit the monitor on an object loaded on the stack.


nop

public void nop()
Description copied from interface: CodeAssembler
Generates an instruction that does nothing. (No-OPeration)


breakpoint

public void breakpoint()
Description copied from interface: CodeAssembler
Generates a breakpoint instruction for use in a debugging environment.



Copyright © 2004-2011 Brian S O'Neill. All Rights Reserved.