public class InstructionList
extends java.lang.Object
implements java.io.Serializable
Instruction
,
InstructionHandle
,
BranchHandle
,
Serialized FormConstructor and Description |
---|
InstructionList() |
InstructionList(byte[] code)
Initialize instruction list from byte array.
|
InstructionList(Instruction i) |
Modifier and Type | Method and Description |
---|---|
InstructionHandle |
append(Instruction i)
Append an instruction to the end of this list.
|
BranchHandle |
append(InstructionBranch i)
Append a branch instruction to the end of this list.
|
InstructionHandle |
append(InstructionHandle ih,
Instruction i)
Append an instruction after instruction (handle) ih contained in this list.
|
BranchHandle |
append(InstructionHandle ih,
InstructionBranch i)
Append an instruction after instruction (handle) ih contained in this list.
|
InstructionHandle |
append(InstructionHandle appendTo,
InstructionList appendee)
Append another list after instruction (handle) ih contained in this list.
|
InstructionHandle |
append(Instruction i,
Instruction j)
Append a single instruction j after another instruction i, which must be in this list of course!
|
InstructionHandle |
append(Instruction i,
InstructionList il)
Append another list after instruction i contained in this list.
|
InstructionHandle |
append(InstructionList il)
Append another list to this one.
|
InstructionHandle |
appendDUP() |
InstructionHandle |
appendNOP() |
InstructionHandle |
appendPOP() |
boolean |
contains(Instruction i) |
boolean |
contains(InstructionHandle i) |
InstructionList |
copy() |
void |
delete(InstructionHandle ih)
Remove instruction from this list.
|
void |
delete(InstructionHandle from,
InstructionHandle to)
Remove instructions from instruction `from' to instruction `to' contained in this list.
|
void |
delete(Instruction from,
Instruction to)
Remove instructions from instruction `from' to instruction `to' contained in this list.
|
void |
dispose()
Delete contents of list.
|
static InstructionHandle |
findHandle(InstructionHandle[] ihs,
int[] pos,
int count,
int target) |
static InstructionHandle |
findHandle(InstructionHandle[] ihs,
int[] pos,
int count,
int target,
boolean returnClosestIfNoExactMatch)
Find the target instruction (handle) that corresponds to the given target position (byte code offset).
|
InstructionHandle |
findHandle(int pos)
Get instruction handle for instruction at byte code position pos.
|
InstructionHandle |
findHandle(int pos,
InstructionHandle[] instructionArray) |
InstructionHandle |
findHandle(int pos,
InstructionHandle[] instructionArray,
boolean useClosestApproximationIfNoExactFound) |
byte[] |
getByteCode()
When everything is finished, use this method to convert the instruction list into an array of bytes.
|
InstructionHandle |
getEnd() |
InstructionHandle[] |
getInstructionHandles() |
int[] |
getInstructionPositions()
Get positions (offsets) of all instructions in the list.
|
Instruction[] |
getInstructions() |
InstructionHandle[] |
getInstructionsAsArray() |
int |
getLength() |
InstructionHandle |
getStart() |
InstructionHandle |
insert(Instruction i)
Insert an instruction at start of this list.
|
BranchHandle |
insert(InstructionBranch i)
Insert a branch instruction at start of this list.
|
InstructionHandle |
insert(InstructionHandle ih,
Instruction i)
Insert an instruction before instruction (handle) ih contained in this list.
|
BranchHandle |
insert(InstructionHandle ih,
InstructionBranch i)
Insert an instruction before instruction (handle) ih contained in this list.
|
InstructionHandle |
insert(InstructionHandle ih,
InstructionList il)
Insert another list before Instruction handle ih contained in this list.
|
InstructionHandle |
insert(Instruction i,
Instruction j)
Insert a single instruction j before another instruction i, which must be in this list of course!
|
InstructionHandle |
insert(Instruction i,
InstructionList il)
Insert another list before Instruction i contained in this list.
|
InstructionHandle |
insert(InstructionList il)
Insert another list.
|
boolean |
isEmpty() |
java.util.Iterator |
iterator() |
void |
move(InstructionHandle ih,
InstructionHandle target)
Move a single instruction (handle) to a new location.
|
void |
move(InstructionHandle start,
InstructionHandle end,
InstructionHandle target)
Take all instructions (handles) from "start" to "end" and append them after the new location "target".
|
void |
redirectBranches(InstructionHandle old_target,
InstructionHandle new_target)
Redirect all references from old_target to new_target, i.e., update targets of branch instructions.
|
void |
redirectExceptionHandlers(CodeExceptionGen[] exceptions,
InstructionHandle old_target,
InstructionHandle new_target)
Redirect all references of exception handlers from old_target to new_target.
|
void |
redirectLocalVariables(LocalVariableGen[] lg,
InstructionHandle old_target,
InstructionHandle new_target)
Redirect all references of local variables from old_target to new_target.
|
void |
replaceConstantPool(ConstantPool old_cp,
ConstantPool new_cp)
Replace all references to the old constant pool with references to the new constant pool
|
void |
setPositions() |
void |
setPositions(boolean check)
Give all instructions their position number (offset in byte stream), i.e., make the list ready to be dumped.
|
int |
size() |
java.lang.String |
toString() |
java.lang.String |
toString(boolean verbose) |
public InstructionList()
public InstructionList(Instruction i)
public InstructionList(byte[] code)
code
- byte array containing the instructionspublic boolean isEmpty()
public static InstructionHandle findHandle(InstructionHandle[] ihs, int[] pos, int count, int target)
public static InstructionHandle findHandle(InstructionHandle[] ihs, int[] pos, int count, int target, boolean returnClosestIfNoExactMatch)
ihs
- array of instruction handles, i.e. il.getInstructionHandles()pos
- array of positions corresponding to ihs, i.e. il.getInstructionPositions()count
- length of arraystarget
- target position to search forpublic InstructionHandle findHandle(int pos)
pos
- byte code position to search forpublic InstructionHandle[] getInstructionsAsArray()
public InstructionHandle findHandle(int pos, InstructionHandle[] instructionArray)
public InstructionHandle findHandle(int pos, InstructionHandle[] instructionArray, boolean useClosestApproximationIfNoExactFound)
public InstructionHandle append(InstructionHandle appendTo, InstructionList appendee)
appendTo
- where to append the instruction listappendee
- Instruction list to append to this onepublic InstructionHandle append(Instruction i, InstructionList il)
i
- where to append the instruction listil
- Instruction list to append to this onepublic InstructionHandle append(InstructionList il)
il
- list to append to end of this listpublic InstructionHandle append(Instruction i)
i
- instruction to appendpublic InstructionHandle appendDUP()
public InstructionHandle appendNOP()
public InstructionHandle appendPOP()
public BranchHandle append(InstructionBranch i)
i
- branch instruction to appendpublic InstructionHandle append(Instruction i, Instruction j)
i
- Instruction in listj
- Instruction to append after i in listpublic InstructionHandle append(InstructionHandle ih, Instruction i)
ih
- where to append the instruction listi
- Instruction to appendpublic BranchHandle append(InstructionHandle ih, InstructionBranch i)
ih
- where to append the instruction listi
- Instruction to appendpublic InstructionHandle insert(InstructionHandle ih, InstructionList il)
i
- where to append the instruction listil
- Instruction list to insertpublic InstructionHandle insert(InstructionList il)
il
- list to insert before start of this listpublic InstructionHandle insert(Instruction i, InstructionList il)
i
- where to append the instruction listil
- Instruction list to insertpublic InstructionHandle insert(Instruction i)
i
- instruction to insertpublic BranchHandle insert(InstructionBranch i)
i
- branch instruction to insertpublic InstructionHandle insert(Instruction i, Instruction j)
i
- Instruction in listj
- Instruction to insert before i in listpublic InstructionHandle insert(InstructionHandle ih, Instruction i)
ih
- where to insert to the instruction listi
- Instruction to insertpublic BranchHandle insert(InstructionHandle ih, InstructionBranch i)
ih
- where to insert to the instruction listi
- Instruction to insertpublic void move(InstructionHandle start, InstructionHandle end, InstructionHandle target)
start
- of moved blockend
- of moved blocktarget
- of moved blockpublic void move(InstructionHandle ih, InstructionHandle target)
ih
- moved instructiontarget
- new location of moved instructionpublic void delete(InstructionHandle ih) throws TargetLostException
ih
- instruction (handle) to removeTargetLostException
public void delete(InstructionHandle from, InstructionHandle to) throws TargetLostException
from
- where to start deleting (inclusive)to
- where to end deleting (inclusive)TargetLostException
public void delete(Instruction from, Instruction to) throws TargetLostException
from
- where to start deleting (inclusive)to
- where to end deleting (inclusive)TargetLostException
public boolean contains(InstructionHandle i)
public boolean contains(Instruction i)
public void setPositions()
public void setPositions(boolean check)
check
- Perform sanity checks, e.g. if all targeted instructions really belong to this listpublic byte[] getByteCode()
public Instruction[] getInstructions()
public java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String toString(boolean verbose)
verbose
- toggle output formatpublic java.util.Iterator iterator()
public InstructionHandle[] getInstructionHandles()
public int[] getInstructionPositions()
public InstructionList copy()
public void replaceConstantPool(ConstantPool old_cp, ConstantPool new_cp)
public void dispose()
public InstructionHandle getStart()
public InstructionHandle getEnd()
public int getLength()
public int size()
public void redirectBranches(InstructionHandle old_target, InstructionHandle new_target)
old_target
- the old target instruction handlenew_target
- the new target instruction handlepublic void redirectLocalVariables(LocalVariableGen[] lg, InstructionHandle old_target, InstructionHandle new_target)
lg
- array of local variablesold_target
- the old target instruction handlenew_target
- the new target instruction handleMethodGen
public void redirectExceptionHandlers(CodeExceptionGen[] exceptions, InstructionHandle old_target, InstructionHandle new_target)
exceptions
- array of exception handlersold_target
- the old target instruction handlenew_target
- the new target instruction handleMethodGen