Class Code
- java.lang.Object
-
- serp.bytecode.Attributes
-
- serp.bytecode.Attribute
-
- serp.bytecode.Code
-
- All Implemented Interfaces:
BCEntity
,VisitAcceptor
public class Code extends Attribute
Representation of a code block of a class. The methods of this class mimic those of the same name in theListIterator
class. Note that the size and index information of the code block will change as opcodes are added.Code blocks are usually obtained from a
BCMethod
, but can also be constructed via the default constructor. Blocks created this way can be used to provide template instructions to the various search/replace methods in this class.The code class contains methods named after most JVM instructions, each of which adds the matching opcode to the code block at the current iterator position. It also contains generic versions of various JVM instructions whose opcodes are not set until their properties are set with additional information. Almost all instruction types are able to 'morph' their opcode on the fly as the arguments to the instruction change. Thus the developer can initially call, for example, the
aload
opcode, but later change the type to load toint
and the opcode will automatically morph to theiload
opcode.- Author:
- Abe White
-
-
Constructor Summary
Constructors Constructor Description Code()
The public constructor is for creating template code modules that produceInstruction
s used in matching through the varioussearch
andreplace
methods.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ArrayLoadInstruction
aaload()
Load an object array value onto the stack; theaaload
opcode.ArrayStoreInstruction
aastore()
Store an object value from the stack into an array; theaastore
opcode.void
acceptVisit(BCVisitor visit)
Accept a visit from aBCVisitor
, calling the appropriate methods to notify the visitor that it has entered this entity, and to provide it with the proper callbacks for each sub-entity owned by this one.Instruction
add(Instruction ins)
Adds a copy of the given instruction.ExceptionHandler
addExceptionHandler()
Add an exception handler to this code block.ExceptionHandler
addExceptionHandler(ExceptionHandler handler)
Import the given exception handler from another code block.ExceptionHandler
addExceptionHandler(Instruction tryStart, Instruction tryEnd, Instruction handlerStart, java.lang.Class catchType)
Add an exception handler to this code block.ExceptionHandler
addExceptionHandler(Instruction tryStart, Instruction tryEnd, Instruction handlerStart, java.lang.String catchType)
Add an exception handler to this code block.ExceptionHandler
addExceptionHandler(Instruction tryStart, Instruction tryEnd, Instruction handlerStart, BCClass catchType)
Add an exception handler to this code block.void
after(int index)
Place the iterator after the given list index.void
after(Instruction ins)
Position the iterator just after the given instruction.void
afterLast()
Set the position of the instruction iterator to after the last opcode.LoadInstruction
aload()
Load an object local variable onto the stack.ClassInstruction
anew()
Create a new instance of an object; thenew
opcode.ClassInstruction
anewarray()
Create a new instance of an object array; theanew
opcode.ReturnInstruction
areturn()
Return an object from a method; theareturn
opcode.Instruction
arraylength()
Get the length of an array on the stack; thearraylength
opcode.StoreInstruction
astore()
Store an object value from the stack into a local variable.Instruction
athrow()
Throw an exception; theathrow
opcode.ArrayLoadInstruction
baload()
Load a byte array value onto the stack; thebaload
opcode.ArrayStoreInstruction
bastore()
Store a byte value from the stack into an array; thebastore
opcode.void
before(int index)
Place the iterator before the given list index.void
before(Instruction ins)
Position the iterator just before the given instruction.void
beforeFirst()
Reset the position of the instruction iterator to the first opcode.void
calculateMaxLocals()
Calculate and set the number of locals needed based on the instructions used and the parameters of the method this code block is a part of.void
calculateMaxStack()
Calculate and set the maximum stack depth needed for the instructions used.ArrayLoadInstruction
caload()
Load a char array value onto the stack; thecaload
opcode.ArrayStoreInstruction
castore()
Store a char value from the stack into an array; thecastore
opcode.ClassInstruction
checkcast()
Cast an object on the stack to another type; thecheckcast
opcode.ClassConstantInstruction
classconstant()
Load a class constant onto the stack.void
clearExceptionHandlers()
Clear all exception handlers.ConstantInstruction
constant()
Load some constant onto the stack.ConvertInstruction
convert()
Convert the top stack value to another type.MathInstruction
dadd()
Add the top two stack double values; thedadd
opcode.ArrayLoadInstruction
daload()
Load a double array value onto the stack; thedaload
opcode.ArrayStoreInstruction
dastore()
Store a double value from the stack into an array; thedastore
opcode.CmpInstruction
dcmpg()
Compare the top two stack values; thedcmpg
opcode.CmpInstruction
dcmpl()
Compare the top two stack values; thedcmpl
opcode.MathInstruction
ddiv()
Divide the top two stack double values; theddiv
opcode.LoadInstruction
dload()
Load a double local variable onto the stack.MathInstruction
dmul()
Multiply the top two stack double values; thedmul
opcode.MathInstruction
dneg()
Negate the top stack double value; thedneg
opcode.MathInstruction
drem()
Take the remainder of the top two double stack values; thedrem
opcode.ReturnInstruction
dreturn()
Return a double from a method; thedreturn
opcode.StoreInstruction
dstore()
Store a double value from the stack into a local variable.MathInstruction
dsub()
Subtract the top two stack double values; thedsub
opcode.StackInstruction
dup()
Thedup
opcode.StackInstruction
dup2()
Thedup2
opcode.StackInstruction
dup2x1()
Thedup2x1
opcode.StackInstruction
dup2x2()
Thedup2x2
opcode.StackInstruction
dupx1()
Thedupx1
opcode.StackInstruction
dupx2()
Thedupx2
opcode.MathInstruction
fadd()
Add the top two stack float values; thefadd
opcode.ArrayLoadInstruction
faload()
Load a float array value onto the stack; thefaload
opcode.ArrayStoreInstruction
fastore()
Store a float value from the stack into an array; thefastore
opcode.CmpInstruction
fcmpg()
Compare the top two stack values; thefcmpg
opcode.CmpInstruction
fcmpl()
Compare the top two stack values; thefcmpl
opcode.MathInstruction
fdiv()
Divide the top two stack float values; thefdiv
opcode.LoadInstruction
fload()
Load a float local variable onto the stack.MathInstruction
fmul()
Multiply the top two stack float values; thefmul
opcode.MathInstruction
fneg()
Negate the top stack float value; thefneg
opcode.MathInstruction
frem()
Take the remainder of the top two float stack values; thefrem
opcode.ReturnInstruction
freturn()
Return a float from a method; thefreturn
opcode.StoreInstruction
fstore()
Store a float value from the stack into a local variable.MathInstruction
fsub()
Subtract the top two stack float values; thefsub
opcode.ExceptionHandler
getExceptionHandler(java.lang.Class catchType)
Return the exception handler that catches the given exception type; if multiple handlers catch the given type, which is returned is undefined.ExceptionHandler
getExceptionHandler(java.lang.String catchType)
Return the exception handler that catches the given exception type; if multiple handlers catch the given type, which is returned is undefined.ExceptionHandler
getExceptionHandler(BCClass catchType)
Return the exception handler that catches the given exception type; if multiple handlers catch the given type, which is returned is undefined.ExceptionHandler[]
getExceptionHandlers()
Return the exception handlers active in this code block, or an empty array if none.ExceptionHandler[]
getExceptionHandlers(java.lang.Class catchType)
Return all exception handlers that catch the given exception type, or an empty array if none.ExceptionHandler[]
getExceptionHandlers(java.lang.String catchType)
Return all exception handlers that catch the given exception type, or an empty array if none.ExceptionHandler[]
getExceptionHandlers(BCClass catchType)
Return all exception handlers that catch the given exception type, or an empty array if none.GetFieldInstruction
getfield()
Load the value from a field onto the stack; thegetfield
opcode.Instruction[]
getInstructions()
Return all the Instructions of this method.LineNumberTable
getLineNumberTable(boolean add)
Return line number information for the code.int
getLocalsIndex(int paramIndex)
Return the local variable index for the paramIndex'th parameter to the method.LocalVariableTable
getLocalVariableTable(boolean add)
Return local variable information for the code.LocalVariableTypeTable
getLocalVariableTypeTable(boolean add)
Return local variable generics information for the code.int
getMaxLocals()
Return the maximum number of local variables (including params) set for this method.int
getMaxStack()
Return the maximum stack depth set for this code block.BCMethod
getMethod()
The owning method.int
getNextLocalsIndex()
Return the next available local variable index.int
getParamsIndex(int localIndex)
Return the parameter index for the given local index, or -1 if the given local does not reference a param.GetFieldInstruction
getstatic()
Load the value from a static field onto the stack; thegetstatic
opcode.JumpInstruction
go2()
Thego2
opcode.boolean
hasNext()
Return true if a subsequent call tonext()
will return an instruction.boolean
hasPrevious()
Return true if a subsequent call toprevious()
will return an instruction.MathInstruction
iadd()
Add the top two stack int values; theiadd
opcode.ArrayLoadInstruction
iaload()
Load an int array value onto the stack; theiaload
opcode.MathInstruction
iand()
Take the mathematical and of the top two stack int values; theiand
opcode.ArrayStoreInstruction
iastore()
Store an int value from the stack into an array; theiastore
opcode.MathInstruction
idiv()
Divide the top two stack int values; theidiv
opcode.IfInstruction
ifacmpeq()
Theifacmpeq
opcode.IfInstruction
ifacmpne()
Theifacmpne
opcode.IfInstruction
ifeq()
Theifeq
opcode.IfInstruction
ifge()
Theifge
opcode.IfInstruction
ifgt()
Theifgt
opcode.IfInstruction
ificmpeq()
Theificmpeq
opcode.IfInstruction
ificmpge()
Theificmpge
opcode.IfInstruction
ificmpgt()
Theificmpgt
opcode.IfInstruction
ificmple()
Theificmple
opcode.IfInstruction
ificmplt()
Theificmplt
opcode.IfInstruction
ificmpne()
Theificmpne
opcode.IfInstruction
ifle()
Theifle
opcode.IfInstruction
iflt()
Theiflt
opcode.IfInstruction
ifne()
Theifne
opcode.IfInstruction
ifnonnull()
Theifnonnull
opcode.IfInstruction
ifnull()
Theifnull
opcode.IIncInstruction
iinc()
Add theiinc
opcode.LoadInstruction
iload()
Load an int local variable onto the stack.MathInstruction
imul()
Multiply the top two stack int values; theimul
opcode.MathInstruction
ineg()
Negate the top stack int value; theineg
opcode.MethodInstruction
invokedynamic()
Invoke a dynamic method; theinvokedynamic
opcode.MethodInstruction
invokeinterface()
Invoke a method on an interface; theinvokeinterface
opcode.MethodInstruction
invokespecial()
Invoke a method non-virtually, as for constructors and superclass methods; theinvokespecial
opcode.MethodInstruction
invokestatic()
Invoke a static method; theinvokestatic
opcode.MethodInstruction
invokevirtual()
Invoke a virtual method; theinvokevirtual
opcode.MathInstruction
ior()
Take the mathematical or of the top two stack int values; theior
opcode.MathInstruction
irem()
Take the remainder of the top two int stack values; theirem
opcode.ReturnInstruction
ireturn()
Return an int from a method; theireturn
opcode.MathInstruction
ishl()
Shift the top stack int values; theishl
opcode.MathInstruction
ishr()
Shift the top stack int values; theishr
opcode.ClassInstruction
isinstance()
Test if a stack object is an instance of a class; theinstanceof
opcode.StoreInstruction
istore()
Store an int value from the stack into a local variable.MathInstruction
isub()
Subtract the top two stack int values; theisub
opcode.MathInstruction
iushr()
Shift the top stack int values; theiushr
opcode.MathInstruction
ixor()
Take the mathematical xor of the top two stack int values; theixor
opcode.JumpInstruction
jsr()
Thejsr
opcode used in implementingfinally
clauses.MathInstruction
ladd()
Add the top two stack long values; theladd
opcode.ArrayLoadInstruction
laload()
Load a long array value onto the stack; thelaload
opcode.MathInstruction
land()
Take the mathematical and of the top two stack long values; theland
opcode.ArrayStoreInstruction
lastore()
Store a long value from the stack into an array; thelastore
opcode.CmpInstruction
lcmp()
Compare the top two stack values; thelcmp
opcode.MathInstruction
ldiv()
Divide the top two stack long values; theldiv
opcode.java.util.ListIterator
listIterator()
Returns another listIterator view of the Instructions in this code block.LoadInstruction
lload()
Load a long local variable onto the stack.MathInstruction
lmul()
Multiply the top two stack long values; thelmul
opcode.MathInstruction
lneg()
Negate the top stack long value; thelneg
opcode.LookupSwitchInstruction
lookupswitch()
Thelookupswitch
opcode.MathInstruction
lor()
Take the mathematical or of the top two stack long values; thelor
opcode.MathInstruction
lrem()
Take the remainder of the top two long stack values; thelrem
opcode.ReturnInstruction
lreturn()
Return a long from a method; thelreturn
opcode.MathInstruction
lshl()
Shift the top stack long values; thelshl
opcode.MathInstruction
lshr()
Shift the top stack long values; thelshr
opcode.StoreInstruction
lstore()
Store a long value from the stack into a local variable.MathInstruction
lsub()
Subtract the top two stack long values; thelsub
opcode.MathInstruction
lushr()
Shift the top stack long values; thelushr
opcode.MathInstruction
lxor()
Take the mathematical xor of the top two stack long values; thelxor
opcode.MathInstruction
math()
Perform some math operation on the stack items.MonitorEnterInstruction
monitorenter()
Themonitorenter
opcode.MonitorExitInstruction
monitorexit()
Themonitorexit
opcode.MultiANewArrayInstruction
multianewarray()
Create a new multidimensional array; themultianewarray
opcode.NewArrayInstruction
newarray()
Create a new array of a primitive type; thenewarray
opcode.Instruction
next()
Return the next instruction.int
nextIndex()
Return the index of the next instruction, orsize()
if at end.Instruction
nop()
Add thenop
opcode.StackInstruction
pop()
Thepop
opcode.StackInstruction
pop2()
Thepop2
opcode.Instruction
previous()
Return the previous instruction.int
previousIndex()
Return the index of the previous instruction, or -1 if at beginning.PutFieldInstruction
putfield()
Place the value of a field onto the stack; theputfield
opcode.PutFieldInstruction
putstatic()
Place the value of a static field onto the stack; theputstatic
opcode.void
remove()
Remove the last iterated instruction.boolean
removeExceptionHandler(java.lang.Class catchType)
Remove the exception handler that catches the given type.boolean
removeExceptionHandler(java.lang.String catchType)
Remove the exception handler that catches the given type.boolean
removeExceptionHandler(BCClass catchType)
Remove the exception handler that catches the given type.boolean
removeExceptionHandler(ExceptionHandler handler)
Remove an exception handler from this code block.boolean
removeLineNumberTable()
Remove the line number table for the code.boolean
removeLocalVariableTables()
Remove the local variable table for the code.boolean
removeLocalVariableTypeTables()
Remove the local variable type table for the code.int
replace(Instruction[] templates, Instruction[] with)
Equivalent to looping over each given template/replacement pair and callingreplace(Instruction,Instruction)
for each.int
replace(Instruction template, Instruction with)
Replaces all the instructions in this code block that match the given template with the given instruction.RetInstruction
ret()
Add theret
opcode, used in implementingfinally
clauses.ArrayLoadInstruction
saload()
Load a short array value onto the stack; thesaload
opcode.ArrayStoreInstruction
sastore()
Store a short value from the stack into an array; thesastore
opcode.boolean
searchBackward(Instruction template)
Find the closest previous instruction from the current iterator position that matches the given one, according to theObject.equals(java.lang.Object)
methods of the instruction types.boolean
searchForward(Instruction template)
Find the next instruction from the current iterator position that matches the given one, according to theObject.equals(java.lang.Object)
methods of the instruction types.Instruction
set(Instruction ins)
Replaces the last iterated instruction with a copy of the given one.void
setExceptionHandlers(ExceptionHandler[] handlers)
Set the exception handlers for this code block.void
setMaxLocals(int max)
Set the maximum number of local variables (including params) in this method.void
setMaxStack(int max)
Set the maximum stack depth for this code block.int
size()
Return the number of instructions in the method.StackInstruction
swap()
Theswap
opcode.TableSwitchInstruction
tableswitch()
Thetableswitch
opcode.ReturnInstruction
vreturn()
Return void from a method; thereturn
opcode.WideInstruction
wide()
Add thewide
opcode.MathInstruction
xadd()
Add the top two stack values.ArrayLoadInstruction
xaload()
Load an array value onto the stack.MathInstruction
xand()
Take the mathematical and of the top two stack values.ArrayStoreInstruction
xastore()
Store a value from the stack into an array.CmpInstruction
xcmp()
Compare the top two stack values.MathInstruction
xdiv()
Divide the top two stack values.LoadInstruction
xload()
Load a local variable onto the stack.MathInstruction
xmul()
Multiply the top two stack values.MathInstruction
xneg()
Negate the top stack value.MathInstruction
xor()
Take the mathematical or of the top two stack values.MathInstruction
xrem()
Take the remainder of the top two stack values.ReturnInstruction
xreturn()
Return from a method.MathInstruction
xshl()
Shift the top stack values.MathInstruction
xshr()
Shift the top stack values.StoreInstruction
xstore()
Store a value from the stack into a local variable.MathInstruction
xsub()
Subtract the top two stack values.MathInstruction
xushr()
Shift the top stack values.MathInstruction
xxor()
Take the mathematical xor of the top two stack values.-
Methods inherited from class serp.bytecode.Attribute
getClassLoader, getName, getNameIndex, getOwner, getPool, getProject, isValid
-
Methods inherited from class serp.bytecode.Attributes
addAttribute, addAttribute, clearAttributes, getAttribute, getAttributes, getAttributes, removeAttribute, removeAttribute, setAttributes
-
-
-
-
Constructor Detail
-
Code
public Code()
The public constructor is for creating template code modules that produceInstruction
s used in matching through the varioussearch
andreplace
methods.
-
-
Method Detail
-
getMethod
public BCMethod getMethod()
The owning method.
-
getMaxStack
public int getMaxStack()
Return the maximum stack depth set for this code block.
-
setMaxStack
public void setMaxStack(int max)
Set the maximum stack depth for this code block.
-
getMaxLocals
public int getMaxLocals()
Return the maximum number of local variables (including params) set for this method.
-
setMaxLocals
public void setMaxLocals(int max)
Set the maximum number of local variables (including params) in this method.
-
getLocalsIndex
public int getLocalsIndex(int paramIndex)
Return the local variable index for the paramIndex'th parameter to the method. Local variable indexes differ from parameter indexes because: a) non-static methods use the 0th local variable for the 'this' ptr, and b) double and long values occupy two spots in the local variable array. Returns -1 if the given index is not valid.
-
getParamsIndex
public int getParamsIndex(int localIndex)
Return the parameter index for the given local index, or -1 if the given local does not reference a param.- See Also:
getLocalsIndex(int)
-
getNextLocalsIndex
public int getNextLocalsIndex()
Return the next available local variable index.
-
calculateMaxLocals
public void calculateMaxLocals()
Calculate and set the number of locals needed based on the instructions used and the parameters of the method this code block is a part of.- See Also:
setMaxLocals(int)
-
calculateMaxStack
public void calculateMaxStack()
Calculate and set the maximum stack depth needed for the instructions used.- See Also:
setMaxStack(int)
-
getExceptionHandlers
public ExceptionHandler[] getExceptionHandlers()
Return the exception handlers active in this code block, or an empty array if none.
-
getExceptionHandler
public ExceptionHandler getExceptionHandler(java.lang.String catchType)
Return the exception handler that catches the given exception type; if multiple handlers catch the given type, which is returned is undefined.
-
getExceptionHandler
public ExceptionHandler getExceptionHandler(java.lang.Class catchType)
Return the exception handler that catches the given exception type; if multiple handlers catch the given type, which is returned is undefined.
-
getExceptionHandler
public ExceptionHandler getExceptionHandler(BCClass catchType)
Return the exception handler that catches the given exception type; if multiple handlers catch the given type, which is returned is undefined.
-
getExceptionHandlers
public ExceptionHandler[] getExceptionHandlers(java.lang.String catchType)
Return all exception handlers that catch the given exception type, or an empty array if none.
-
getExceptionHandlers
public ExceptionHandler[] getExceptionHandlers(java.lang.Class catchType)
Return all exception handlers that catch the given exception type, or an empty array if none.
-
getExceptionHandlers
public ExceptionHandler[] getExceptionHandlers(BCClass catchType)
Return all exception handlers that catch the given exception type, or an empty array if none.
-
setExceptionHandlers
public void setExceptionHandlers(ExceptionHandler[] handlers)
Set the exception handlers for this code block. This method is useful for importing all handlers from another code block. Set to null or empty array if none.
-
addExceptionHandler
public ExceptionHandler addExceptionHandler(ExceptionHandler handler)
Import the given exception handler from another code block.
-
addExceptionHandler
public ExceptionHandler addExceptionHandler()
Add an exception handler to this code block.
-
addExceptionHandler
public ExceptionHandler addExceptionHandler(Instruction tryStart, Instruction tryEnd, Instruction handlerStart, java.lang.String catchType)
Add an exception handler to this code block.- Parameters:
tryStart
- the first instruction of the try {} blocktryEnd
- the last instruction of the try {} blockhandlerStart
- the first instruction of the catch {} blockcatchType
- the type of exception being caught
-
addExceptionHandler
public ExceptionHandler addExceptionHandler(Instruction tryStart, Instruction tryEnd, Instruction handlerStart, java.lang.Class catchType)
Add an exception handler to this code block.- Parameters:
tryStart
- the first instruction of the try {} blocktryEnd
- the last instruction of the try {} blockhandlerStart
- the first instruction of the catch {} blockcatchType
- the type of exception being caught
-
addExceptionHandler
public ExceptionHandler addExceptionHandler(Instruction tryStart, Instruction tryEnd, Instruction handlerStart, BCClass catchType)
Add an exception handler to this code block.- Parameters:
tryStart
- the first instruction of the try {} blocktryEnd
- the last instruction of the try {} blockhandlerStart
- the first instruction of the catch {} blockcatchType
- the type of exception being caught
-
clearExceptionHandlers
public void clearExceptionHandlers()
Clear all exception handlers.
-
removeExceptionHandler
public boolean removeExceptionHandler(java.lang.String catchType)
Remove the exception handler that catches the given type.
-
removeExceptionHandler
public boolean removeExceptionHandler(java.lang.Class catchType)
Remove the exception handler that catches the given type.- Returns:
- true if the handler was removed, false otherwise
-
removeExceptionHandler
public boolean removeExceptionHandler(BCClass catchType)
Remove the exception handler that catches the given type.- Returns:
- true if the handler was removed, false otherwise
-
removeExceptionHandler
public boolean removeExceptionHandler(ExceptionHandler handler)
Remove an exception handler from this code block. The given handler must belong to this code block.
-
size
public int size()
Return the number of instructions in the method.
-
beforeFirst
public void beforeFirst()
Reset the position of the instruction iterator to the first opcode.
-
afterLast
public void afterLast()
Set the position of the instruction iterator to after the last opcode.
-
before
public void before(Instruction ins)
Position the iterator just before the given instruction. The instruction must belong to this method.
-
after
public void after(Instruction ins)
Position the iterator just after the given instruction. The instruction must belong to this method.
-
hasNext
public boolean hasNext()
Return true if a subsequent call tonext()
will return an instruction.
-
hasPrevious
public boolean hasPrevious()
Return true if a subsequent call toprevious()
will return an instruction.
-
next
public Instruction next()
Return the next instruction.
-
nextIndex
public int nextIndex()
Return the index of the next instruction, orsize()
if at end.
-
previous
public Instruction previous()
Return the previous instruction.
-
previousIndex
public int previousIndex()
Return the index of the previous instruction, or -1 if at beginning.
-
before
public void before(int index)
Place the iterator before the given list index.
-
after
public void after(int index)
Place the iterator after the given list index.
-
searchForward
public boolean searchForward(Instruction template)
Find the next instruction from the current iterator position that matches the given one, according to theObject.equals(java.lang.Object)
methods of the instruction types. This allows for matching based on template instructions, as the equals methods of most instructions return true if the information for the given instruction has not been filled in. If a match is found, the iterator is placed after the matching Instruction. If no match is found, moves the iterator toafterLast()
.- Returns:
- true if match found
-
searchBackward
public boolean searchBackward(Instruction template)
Find the closest previous instruction from the current iterator position that matches the given one, according to theObject.equals(java.lang.Object)
methods of the instruction types. This allows for matching based on template instructions, as the equals methods of most instructions return true if the information for the given instruction has not been filled in. If a match is found, the iterator is placed before the matching Instruction. If no match is found, moves the iterator tobeforeFirst()
.- Returns:
- true if match found
-
add
public Instruction add(Instruction ins)
Adds a copy of the given instruction.- Returns:
- the newly added instruction
-
set
public Instruction set(Instruction ins)
Replaces the last iterated instruction with a copy of the given one. This method will also make sure that all jump points that referenced the old opcode are updated correctly.- Returns:
- the newly added instruction
- See Also:
ListIterator.set(E)
-
replace
public int replace(Instruction template, Instruction with)
Replaces all the instructions in this code block that match the given template with the given instruction. After this method, the iterator will beafterLast()
.- Returns:
- the number of substitutions made
-
replace
public int replace(Instruction[] templates, Instruction[] with)
Equivalent to looping over each given template/replacement pair and callingreplace(Instruction,Instruction)
for each.
-
remove
public void remove()
Remove the last iterated instruction.- See Also:
ListIterator.remove()
-
classconstant
public ClassConstantInstruction classconstant()
Load a class constant onto the stack. For primitive types, this translates into a getstatic for the TYPE field of the primitive's wrapper type. For non-primitives, things get much more complex. Suffice it to say that the operation involves adding synthetic static fields and even methods to the class. Note that this instruction requires up to 3 stack positions to execute.
-
nop
public Instruction nop()
Add thenop
opcode.
-
constant
public ConstantInstruction constant()
Load some constant onto the stack. TheConstantInstruction
type takes any constant and correctly translates it into the proper opcode, depending on the constant type and value. For example, if the constant value is set to 0L, the opcode will be set tolconst0
.
-
xload
public LoadInstruction xload()
Load a local variable onto the stack. This instruction will result in anop
until its type and local index are set.
-
iload
public LoadInstruction iload()
Load an int local variable onto the stack. This instruction will result in anop
until its local index is set.
-
lload
public LoadInstruction lload()
Load a long local variable onto the stack. This instruction will result in anop
until its local index is set.
-
fload
public LoadInstruction fload()
Load a float local variable onto the stack. This instruction will result in anop
until its local index is set.
-
dload
public LoadInstruction dload()
Load a double local variable onto the stack. This instruction will result in anop
until its local index is set.
-
aload
public LoadInstruction aload()
Load an object local variable onto the stack. This instruction will result in anop
until its local index is set.
-
xstore
public StoreInstruction xstore()
Store a value from the stack into a local variable. This instruction will result in anop
until its type and local index are set.
-
istore
public StoreInstruction istore()
Store an int value from the stack into a local variable. This instruction will result in anop
until its local index is set.
-
lstore
public StoreInstruction lstore()
Store a long value from the stack into a local variable. This instruction will resultin anop
until its local index is set.
-
fstore
public StoreInstruction fstore()
Store a float value from the stack into a local variable. This instruction will result in anop
until its local index is set.
-
dstore
public StoreInstruction dstore()
Store a double value from the stack into a local variable. This instruction will result in anop
until its local index is set.
-
astore
public StoreInstruction astore()
Store an object value from the stack into a local variable. This instruction will result in anop
until its local index is set.
-
ret
public RetInstruction ret()
Add theret
opcode, used in implementingfinally
clauses.
-
iinc
public IIncInstruction iinc()
Add theiinc
opcode.
-
wide
public WideInstruction wide()
Add thewide
opcode.
-
xaload
public ArrayLoadInstruction xaload()
Load an array value onto the stack. This instruction will result in anop
until its type is set.
-
iaload
public ArrayLoadInstruction iaload()
Load an int array value onto the stack; theiaload
opcode.
-
laload
public ArrayLoadInstruction laload()
Load a long array value onto the stack; thelaload
opcode.
-
faload
public ArrayLoadInstruction faload()
Load a float array value onto the stack; thefaload
opcode.
-
daload
public ArrayLoadInstruction daload()
Load a double array value onto the stack; thedaload
opcode.
-
aaload
public ArrayLoadInstruction aaload()
Load an object array value onto the stack; theaaload
opcode.
-
baload
public ArrayLoadInstruction baload()
Load a byte array value onto the stack; thebaload
opcode.
-
caload
public ArrayLoadInstruction caload()
Load a char array value onto the stack; thecaload
opcode.
-
saload
public ArrayLoadInstruction saload()
Load a short array value onto the stack; thesaload
opcode.
-
xastore
public ArrayStoreInstruction xastore()
Store a value from the stack into an array. This instruction will result in anop
until its type is set.
-
iastore
public ArrayStoreInstruction iastore()
Store an int value from the stack into an array; theiastore
opcode.
-
lastore
public ArrayStoreInstruction lastore()
Store a long value from the stack into an array; thelastore
opcode.
-
fastore
public ArrayStoreInstruction fastore()
Store a float value from the stack into an array; thefastore
opcode.
-
dastore
public ArrayStoreInstruction dastore()
Store a double value from the stack into an array; thedastore
opcode.
-
aastore
public ArrayStoreInstruction aastore()
Store an object value from the stack into an array; theaastore
opcode.
-
bastore
public ArrayStoreInstruction bastore()
Store a byte value from the stack into an array; thebastore
opcode.
-
castore
public ArrayStoreInstruction castore()
Store a char value from the stack into an array; thecastore
opcode.
-
sastore
public ArrayStoreInstruction sastore()
Store a short value from the stack into an array; thesastore
opcode.
-
pop
public StackInstruction pop()
Thepop
opcode.
-
pop2
public StackInstruction pop2()
Thepop2
opcode.
-
dup
public StackInstruction dup()
Thedup
opcode.
-
dupx1
public StackInstruction dupx1()
Thedupx1
opcode.
-
dupx2
public StackInstruction dupx2()
Thedupx2
opcode.
-
dup2
public StackInstruction dup2()
Thedup2
opcode.
-
dup2x1
public StackInstruction dup2x1()
Thedup2x1
opcode.
-
dup2x2
public StackInstruction dup2x2()
Thedup2x2
opcode.
-
swap
public StackInstruction swap()
Theswap
opcode.
-
math
public MathInstruction math()
Perform some math operation on the stack items. This instruction will result in anop
until its operation and type are set.
-
xadd
public MathInstruction xadd()
Add the top two stack values. This instruction will result in anop
until its type is set.
-
iadd
public MathInstruction iadd()
Add the top two stack int values; theiadd
opcode.
-
ladd
public MathInstruction ladd()
Add the top two stack long values; theladd
opcode.
-
fadd
public MathInstruction fadd()
Add the top two stack float values; thefadd
opcode.
-
dadd
public MathInstruction dadd()
Add the top two stack double values; thedadd
opcode.
-
xsub
public MathInstruction xsub()
Subtract the top two stack values. This instruction will result in anop
until its type is set.
-
isub
public MathInstruction isub()
Subtract the top two stack int values; theisub
opcode.
-
lsub
public MathInstruction lsub()
Subtract the top two stack long values; thelsub
opcode.
-
fsub
public MathInstruction fsub()
Subtract the top two stack float values; thefsub
opcode.
-
dsub
public MathInstruction dsub()
Subtract the top two stack double values; thedsub
opcode.
-
xmul
public MathInstruction xmul()
Multiply the top two stack values. This instruction will result in anop
until its type is set.
-
imul
public MathInstruction imul()
Multiply the top two stack int values; theimul
opcode.
-
lmul
public MathInstruction lmul()
Multiply the top two stack long values; thelmul
opcode.
-
fmul
public MathInstruction fmul()
Multiply the top two stack float values; thefmul
opcode.
-
dmul
public MathInstruction dmul()
Multiply the top two stack double values; thedmul
opcode.
-
xdiv
public MathInstruction xdiv()
Divide the top two stack values. This instruction will result in anop
until its type is set.
-
idiv
public MathInstruction idiv()
Divide the top two stack int values; theidiv
opcode.
-
ldiv
public MathInstruction ldiv()
Divide the top two stack long values; theldiv
opcode.
-
fdiv
public MathInstruction fdiv()
Divide the top two stack float values; thefdiv
opcode.
-
ddiv
public MathInstruction ddiv()
Divide the top two stack double values; theddiv
opcode.
-
xrem
public MathInstruction xrem()
Take the remainder of the top two stack values. This instruction will result in anop
until its type is set.
-
irem
public MathInstruction irem()
Take the remainder of the top two int stack values; theirem
opcode.
-
lrem
public MathInstruction lrem()
Take the remainder of the top two long stack values; thelrem
opcode.
-
frem
public MathInstruction frem()
Take the remainder of the top two float stack values; thefrem
opcode.
-
drem
public MathInstruction drem()
Take the remainder of the top two double stack values; thedrem
opcode.
-
xneg
public MathInstruction xneg()
Negate the top stack value. This instruction will result in anop
until its type is set.
-
ineg
public MathInstruction ineg()
Negate the top stack int value; theineg
opcode.
-
lneg
public MathInstruction lneg()
Negate the top stack long value; thelneg
opcode.
-
fneg
public MathInstruction fneg()
Negate the top stack float value; thefneg
opcode.
-
dneg
public MathInstruction dneg()
Negate the top stack double value; thedneg
opcode.
-
xshl
public MathInstruction xshl()
Shift the top stack values. This instruction will result in anop
until its type is set.
-
ishl
public MathInstruction ishl()
Shift the top stack int values; theishl
opcode.
-
lshl
public MathInstruction lshl()
Shift the top stack long values; thelshl
opcode.
-
xshr
public MathInstruction xshr()
Shift the top stack values. This instruction will result in anop
until its type is set.
-
ishr
public MathInstruction ishr()
Shift the top stack int values; theishr
opcode.
-
lshr
public MathInstruction lshr()
Shift the top stack long values; thelshr
opcode.
-
xushr
public MathInstruction xushr()
Shift the top stack values. This instruction will result in anop
until its type is set.
-
iushr
public MathInstruction iushr()
Shift the top stack int values; theiushr
opcode.
-
lushr
public MathInstruction lushr()
Shift the top stack long values; thelushr
opcode.
-
xand
public MathInstruction xand()
Take the mathematical and of the top two stack values. This instruction results in anop
until its type is set.
-
iand
public MathInstruction iand()
Take the mathematical and of the top two stack int values; theiand
opcode.
-
land
public MathInstruction land()
Take the mathematical and of the top two stack long values; theland
opcode.
-
xor
public MathInstruction xor()
Take the mathematical or of the top two stack values. This instruction results in anop
until its type is set.
-
ior
public MathInstruction ior()
Take the mathematical or of the top two stack int values; theior
opcode.
-
lor
public MathInstruction lor()
Take the mathematical or of the top two stack long values; thelor
opcode.
-
xxor
public MathInstruction xxor()
Take the mathematical xor of the top two stack values. This instruction results in anop
until its type is set.
-
ixor
public MathInstruction ixor()
Take the mathematical xor of the top two stack int values; theixor
opcode.
-
lxor
public MathInstruction lxor()
Take the mathematical xor of the top two stack long values; thelxor
opcode.
-
convert
public ConvertInstruction convert()
Convert the top stack value to another type. This instruction will result in anop
until the types to convert between are set.
-
xcmp
public CmpInstruction xcmp()
Compare the top two stack values. This instruction will result in anop
until its type is set.
-
lcmp
public CmpInstruction lcmp()
Compare the top two stack values; thelcmp
opcode.
-
fcmpl
public CmpInstruction fcmpl()
Compare the top two stack values; thefcmpl
opcode.
-
fcmpg
public CmpInstruction fcmpg()
Compare the top two stack values; thefcmpg
opcode.
-
dcmpl
public CmpInstruction dcmpl()
Compare the top two stack values; thedcmpl
opcode.
-
dcmpg
public CmpInstruction dcmpg()
Compare the top two stack values; thedcmpg
opcode.
-
ifeq
public IfInstruction ifeq()
Theifeq
opcode.
-
ifne
public IfInstruction ifne()
Theifne
opcode.
-
iflt
public IfInstruction iflt()
Theiflt
opcode.
-
ifge
public IfInstruction ifge()
Theifge
opcode.
-
ifgt
public IfInstruction ifgt()
Theifgt
opcode.
-
ifle
public IfInstruction ifle()
Theifle
opcode.
-
ificmpeq
public IfInstruction ificmpeq()
Theificmpeq
opcode.
-
ificmpne
public IfInstruction ificmpne()
Theificmpne
opcode.
-
ificmplt
public IfInstruction ificmplt()
Theificmplt
opcode.
-
ificmpge
public IfInstruction ificmpge()
Theificmpge
opcode.
-
ificmpgt
public IfInstruction ificmpgt()
Theificmpgt
opcode.
-
ificmple
public IfInstruction ificmple()
Theificmple
opcode.
-
ifacmpeq
public IfInstruction ifacmpeq()
Theifacmpeq
opcode.
-
ifacmpne
public IfInstruction ifacmpne()
Theifacmpne
opcode.
-
ifnull
public IfInstruction ifnull()
Theifnull
opcode.
-
ifnonnull
public IfInstruction ifnonnull()
Theifnonnull
opcode.
-
go2
public JumpInstruction go2()
Thego2
opcode.
-
jsr
public JumpInstruction jsr()
Thejsr
opcode used in implementingfinally
clauses.
-
tableswitch
public TableSwitchInstruction tableswitch()
Thetableswitch
opcode.
-
lookupswitch
public LookupSwitchInstruction lookupswitch()
Thelookupswitch
opcode.
-
xreturn
public ReturnInstruction xreturn()
Return from a method. This method will result in anop
until its type is set.
-
vreturn
public ReturnInstruction vreturn()
Return void from a method; thereturn
opcode.
-
ireturn
public ReturnInstruction ireturn()
Return an int from a method; theireturn
opcode.
-
lreturn
public ReturnInstruction lreturn()
Return a long from a method; thelreturn
opcode.
-
freturn
public ReturnInstruction freturn()
Return a float from a method; thefreturn
opcode.
-
dreturn
public ReturnInstruction dreturn()
Return a double from a method; thedreturn
opcode.
-
areturn
public ReturnInstruction areturn()
Return an object from a method; theareturn
opcode.
-
getfield
public GetFieldInstruction getfield()
Load the value from a field onto the stack; thegetfield
opcode.
-
getstatic
public GetFieldInstruction getstatic()
Load the value from a static field onto the stack; thegetstatic
opcode.
-
putfield
public PutFieldInstruction putfield()
Place the value of a field onto the stack; theputfield
opcode.
-
putstatic
public PutFieldInstruction putstatic()
Place the value of a static field onto the stack; theputstatic
opcode.
-
invokevirtual
public MethodInstruction invokevirtual()
Invoke a virtual method; theinvokevirtual
opcode.
-
invokespecial
public MethodInstruction invokespecial()
Invoke a method non-virtually, as for constructors and superclass methods; theinvokespecial
opcode.
-
invokeinterface
public MethodInstruction invokeinterface()
Invoke a method on an interface; theinvokeinterface
opcode.
-
invokestatic
public MethodInstruction invokestatic()
Invoke a static method; theinvokestatic
opcode.
-
invokedynamic
public MethodInstruction invokedynamic()
Invoke a dynamic method; theinvokedynamic
opcode.
-
anew
public ClassInstruction anew()
Create a new instance of an object; thenew
opcode.
-
anewarray
public ClassInstruction anewarray()
Create a new instance of an object array; theanew
opcode.
-
checkcast
public ClassInstruction checkcast()
Cast an object on the stack to another type; thecheckcast
opcode.
-
isinstance
public ClassInstruction isinstance()
Test if a stack object is an instance of a class; theinstanceof
opcode.
-
multianewarray
public MultiANewArrayInstruction multianewarray()
Create a new multidimensional array; themultianewarray
opcode.
-
newarray
public NewArrayInstruction newarray()
Create a new array of a primitive type; thenewarray
opcode.
-
arraylength
public Instruction arraylength()
Get the length of an array on the stack; thearraylength
opcode.
-
athrow
public Instruction athrow()
Throw an exception; theathrow
opcode.
-
monitorenter
public MonitorEnterInstruction monitorenter()
Themonitorenter
opcode.
-
monitorexit
public MonitorExitInstruction monitorexit()
Themonitorexit
opcode.
-
getInstructions
public Instruction[] getInstructions()
Return all the Instructions of this method.
-
acceptVisit
public void acceptVisit(BCVisitor visit)
Description copied from interface:VisitAcceptor
Accept a visit from aBCVisitor
, calling the appropriate methods to notify the visitor that it has entered this entity, and to provide it with the proper callbacks for each sub-entity owned by this one.
-
getLineNumberTable
public LineNumberTable getLineNumberTable(boolean add)
Return line number information for the code. Acts internally through theAttributes
interface.- Parameters:
add
- if true, a new line number table will be added if not already present- Returns:
- the line number information, or null if none
and the
add
param is set to false
-
removeLineNumberTable
public boolean removeLineNumberTable()
Remove the line number table for the code. Acts internally through theAttributes
interface.- Returns:
- true if there was a table to remove
-
getLocalVariableTable
public LocalVariableTable getLocalVariableTable(boolean add)
Return local variable information for the code. Acts internally through theAttributes
interface.- Parameters:
add
- if true, a new local variable table will be added if not already present- Returns:
- the local variable information, or null if none
and the
add
param is set to false
-
removeLocalVariableTables
public boolean removeLocalVariableTables()
Remove the local variable table for the code. Acts internally through theAttributes
interface.- Returns:
- true if there was a table to remove
-
getLocalVariableTypeTable
public LocalVariableTypeTable getLocalVariableTypeTable(boolean add)
Return local variable generics information for the code. Acts internally through theAttributes
interface.- Parameters:
add
- if true, a new local variable type table will be added if not already present- Returns:
- the local variable type information, or null if none
and the
add
param is set to false
-
removeLocalVariableTypeTables
public boolean removeLocalVariableTypeTables()
Remove the local variable type table for the code. Acts internally through theAttributes
interface.- Returns:
- true if there was a table to remove
-
listIterator
public java.util.ListIterator listIterator()
Returns another listIterator view of the Instructions in this code block. Useful for performing read-only searches through Instructions without effecting the pointer location of the main code block.
-
-