Top Description Fields Constructors Methods
org.aspectj.apache.bcel.generic

public Class InstructionFactory

extends Object
implements InstructionConstants
Class Inheritance
All Implemented Interfaces
org.aspectj.apache.bcel.generic.InstructionConstants
Imports
org.aspectj.apache.bcel.Constants, org.aspectj.apache.bcel.classfile.ConstantPool, .Utility

Instances of this class may be used, e.g., to generate typed versions of instructions. Its main purpose is to be used as the byte code generating backend of a compiler. You can subclass it to add your own create methods.
Author
M. Dahm
Version
$Id: InstructionFactory.java,v 1.7 2010/08/23 20:44:10 aclement Exp $
See Also
Constants

Field Summary

Modifier and TypeField and Description
protected ClassGen
protected ConstantPool
private static final char[]

Constructor Summary

AccessConstructor and Description
public
public
public

Method Summary

Modifier and TypeMethod and Description
public static Instruction
createALOAD(int n)

public static Instruction
createArrayLoad(Type
type of elements of array, i.e., array.getElementType()
type
)

public static Instruction
createArrayStore(Type
type of elements of array, i.e., array.getElementType()
type
)

public static Instruction
createASTORE(int n)

public static InstructionBranch
createBranchInstruction(short opcode, InstructionHandle target)

Create branch instruction by given opcode, except LOOKUPSWITCH and TABLESWITCH.

public Instruction
createCast(Type src_type, Type dest_type)

Create conversion operation for two stack operands, this may be an I2C, instruction, e.g., if the operands are basic types and CHECKCAST if they are reference types.

public Instruction
public Instruction
createConstant(Object
must be of type Number, Boolean, Character or String
value
)

Uses PUSH to push a constant value onto the stack.

public static Instruction
createDup(int
size of operand, either 1 (int, e.g.) or 2 (double)
size
)

public static Instruction
createDup_1(int
size of operand, either 1 (int, e.g.) or 2 (double)
size
)

public static Instruction
createDup_2(int
size of operand, either 1 (int, e.g.) or 2 (double)
size
)

public FieldInstruction
createFieldAccess(String
name of the accessed class
class_name
,
String
name of the referenced field
name
,
Type
type of field
type
,
short
how to access, i.e., GETFIELD, PUTFIELD, GETSTATIC, PUTSTATIC
kind
)

Create a field instruction.

public FieldInstruction
createGetField(String class_name, String name, Type t)

public FieldInstruction
createGetStatic(String class_name, String name, Type t)

public Instruction
public InvokeInstruction
createInvoke(String class_name, String name, Type ret_type, Type[] arg_types, short kind)

public InvokeInstruction
createInvoke(String
name of the called class
class_name
,
String
name of the called method
name
,
Type
return type of method
ret_type
,
Type[]
argument types of method
arg_types
,
short
how to invoke, i.e., INVOKEINTERFACE, INVOKESTATIC, INVOKEVIRTUAL, or INVOKESPECIAL
kind
,
boolean
for an invokestatic on an interface allows us to tell this method the target is an interface
isInterface
)

Create an invoke instruction.

public InvokeInstruction
createInvoke(String class_name, String name, String signature, short kind)

public static InstructionLV
createLoad(Type type, int
index of local variable
index
)

public Instruction
public Instruction
public Instruction

Returns:

an instruction that creates the corresponding array at runtime, i.e. is an AllocationInstruction
createNewArray
(Type t, short dim)

Create new array of given size and type.

public static Instruction
createNull(Type type)

Create "null" value for reference types, 0 for basic types like int

public static Instruction
createPop(int
size of operand, either 1 (int, e.g.) or 2 (double)
size
)

public FieldInstruction
createPutField(String class_name, String name, Type t)

public FieldInstruction
createPutStatic(String class_name, String name, Type t)

public static Instruction
createReturn(Type type)

Create typed return

public static InstructionLV
createStore(Type type, int
index of local variable
index
)

public static Instruction
createThis()

Create reference to `this'

public ClassGen
public ConstantPool
public static Instruction
PUSH(ConstantPool cp, int value)

Returns the right instruction for putting whatever you want onto the stack

public static Instruction
public static Instruction
PUSH(ConstantPool cp, boolean value)

public static Instruction
PUSH(ConstantPool cp, float value)

public static Instruction
PUSH(ConstantPool cp, long value)

public static Instruction
PUSH(ConstantPool cp, double value)

public static Instruction
public static Instruction
public static Instruction
public static Instruction
public InstructionList
PUSHCLASS(ConstantPool cp, String className)

Return a list that will load the Class object - on 1.5 or later use the class variant of ldc, whilst on earlier JVMs use the regular Class.forName.

public void
public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

cgback to summary
protected ClassGen cg
cpback to summary
protected ConstantPool cp
shortNamesback to summary
private static final char[] shortNames

Constructor Detail

InstructionFactoryback to summary
public InstructionFactory(ClassGen cg, ConstantPool cp)
InstructionFactoryback to summary
public InstructionFactory(ClassGen cg)
InstructionFactoryback to summary
public InstructionFactory(ConstantPool cp)

Method Detail

createALOADback to summary
public static Instruction createALOAD(int n)
createArrayLoadback to summary
public static Instruction createArrayLoad(Type type)
Parameters
type:Type

type of elements of array, i.e., array.getElementType()

createArrayStoreback to summary
public static Instruction createArrayStore(Type type)
Parameters
type:Type

type of elements of array, i.e., array.getElementType()

createASTOREback to summary
public static Instruction createASTORE(int n)
createBranchInstructionback to summary
public static InstructionBranch createBranchInstruction(short opcode, InstructionHandle target)

Create branch instruction by given opcode, except LOOKUPSWITCH and TABLESWITCH. For those you should use the SWITCH compound instruction.

createCastback to summary
public Instruction createCast(Type src_type, Type dest_type)

Create conversion operation for two stack operands, this may be an I2C, instruction, e.g., if the operands are basic types and CHECKCAST if they are reference types.

createCheckCastback to summary
public Instruction createCheckCast(ReferenceType t)
createConstantback to summary
public Instruction createConstant(Object value)

Uses PUSH to push a constant value onto the stack.

Parameters
value:Object

must be of type Number, Boolean, Character or String

createDupback to summary
public static Instruction createDup(int size)
Parameters
size:int

size of operand, either 1 (int, e.g.) or 2 (double)

createDup_1back to summary
public static Instruction createDup_1(int size)
Parameters
size:int

size of operand, either 1 (int, e.g.) or 2 (double)

createDup_2back to summary
public static Instruction createDup_2(int size)
Parameters
size:int

size of operand, either 1 (int, e.g.) or 2 (double)

createFieldAccessback to summary
public FieldInstruction createFieldAccess(String class_name, String name, Type type, short kind)

Create a field instruction.

Parameters
class_name:String

name of the accessed class

name:String

name of the referenced field

type:Type

type of field

kind:short

how to access, i.e., GETFIELD, PUTFIELD, GETSTATIC, PUTSTATIC

See Also
Constants
createGetFieldback to summary
public FieldInstruction createGetField(String class_name, String name, Type t)
createGetStaticback to summary
public FieldInstruction createGetStatic(String class_name, String name, Type t)
createInstanceOfback to summary
public Instruction createInstanceOf(ReferenceType t)
createInvokeback to summary
public InvokeInstruction createInvoke(String class_name, String name, Type ret_type, Type[] arg_types, short kind)
createInvokeback to summary
public InvokeInstruction createInvoke(String class_name, String name, Type ret_type, Type[] arg_types, short kind, boolean isInterface)

Create an invoke instruction.

Parameters
class_name:String

name of the called class

name:String

name of the called method

ret_type:Type

return type of method

arg_types:Type[]

argument types of method

kind:short

how to invoke, i.e., INVOKEINTERFACE, INVOKESTATIC, INVOKEVIRTUAL, or INVOKESPECIAL

isInterface:boolean

for an invokestatic on an interface allows us to tell this method the target is an interface

See Also
Constants
createInvokeback to summary
public InvokeInstruction createInvoke(String class_name, String name, String signature, short kind)
createLoadback to summary
public static InstructionLV createLoad(Type type, int index)
Parameters
index:int

index of local variable

createNewback to summary
public Instruction createNew(ObjectType t)
createNewback to summary
public Instruction createNew(String s)
createNewArrayback to summary
public Instruction createNewArray(Type t, short dim)

Create new array of given size and type.

Returns:Instruction

an instruction that creates the corresponding array at runtime, i.e. is an AllocationInstruction

createNullback to summary
public static Instruction createNull(Type type)

Create "null" value for reference types, 0 for basic types like int

createPopback to summary
public static Instruction createPop(int size)
Parameters
size:int

size of operand, either 1 (int, e.g.) or 2 (double)

createPutFieldback to summary
public FieldInstruction createPutField(String class_name, String name, Type t)
createPutStaticback to summary
public FieldInstruction createPutStatic(String class_name, String name, Type t)
createReturnback to summary
public static Instruction createReturn(Type type)

Create typed return

createStoreback to summary
public static InstructionLV createStore(Type type, int index)
Parameters
index:int

index of local variable

createThisback to summary
public static Instruction createThis()

Create reference to `this'

getClassGenback to summary
public ClassGen getClassGen()
getConstantPoolback to summary
public ConstantPool getConstantPool()
PUSHback to summary
public static Instruction PUSH(ConstantPool cp, int value)

Returns the right instruction for putting whatever you want onto the stack

PUSHback to summary
public static Instruction PUSH(ConstantPool cp, ObjectType t)
PUSHback to summary
public static Instruction PUSH(ConstantPool cp, boolean value)
PUSHback to summary
public static Instruction PUSH(ConstantPool cp, float value)
PUSHback to summary
public static Instruction PUSH(ConstantPool cp, long value)
PUSHback to summary
public static Instruction PUSH(ConstantPool cp, double value)
PUSHback to summary
public static Instruction PUSH(ConstantPool cp, String value)
PUSHback to summary
public static Instruction PUSH(ConstantPool cp, Number value)
PUSHback to summary
public static Instruction PUSH(ConstantPool cp, Character value)
PUSHback to summary
public static Instruction PUSH(ConstantPool cp, Boolean value)
PUSHCLASSback to summary
public InstructionList PUSHCLASS(ConstantPool cp, String className)

Return a list that will load the Class object - on 1.5 or later use the class variant of ldc, whilst on earlier JVMs use the regular Class.forName.

setClassGenback to summary
public void setClassGen(ClassGen c)
setConstantPoolback to summary
public void setConstantPool(ConstantPool c)