|
|||||||||
Home >> All >> org >> apache >> bcel >> [ generic overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: ![]() ![]() ![]() |
DETAIL: FIELD | CONSTR | METHOD |
org.apache.bcel.generic
Class InstructionList

java.lang.Objectorg.apache.bcel.generic.InstructionList
- All Implemented Interfaces:
- java.io.Serializable
- public class InstructionList
- extends java.lang.Object
- implements java.io.Serializable
- extends java.lang.Object
This class is a container for a list of Instruction objects. Instructions can be appended, inserted, moved, deleted, etc.. Instructions are being wrapped into InstructionHandles objects that are returned upon append/insert operations. They give the user (read only) access to the list structure, such that it can be traversed and manipulated in a controlled way. A list is finally dumped to a byte code array with getByteCode.
- Version:
- $Id: InstructionList.java 386056 2006-03-15 11:31:56Z tcurdt $
Field Summary | |
private int[] |
byte_positions
|
private InstructionHandle |
end
|
private int |
length
|
private java.util.List |
observers
|
private InstructionHandle |
start
|
Constructor Summary | |
InstructionList()
Create (empty) instruction list. |
|
InstructionList(BranchInstruction i)
Create instruction list containing one instruction. |
|
InstructionList(byte[] code)
Initialize instruction list from byte array. |
|
InstructionList(CompoundInstruction c)
Initialize list with (nonnull) compound instruction. |
|
InstructionList(Instruction i)
Create instruction list containing one instruction. |
Method Summary | |
void |
addObserver(InstructionListObserver o)
Add observer for this object. |
BranchHandle |
append(BranchInstruction i)
Append a branch instruction to the end of this list. |
InstructionHandle |
append(CompoundInstruction c)
Append a compound instruction. |
InstructionHandle |
append(Instruction i)
Append an instruction to the end of this list. |
InstructionHandle |
append(Instruction i,
CompoundInstruction c)
Append a compound instruction, after instruction i. |
private void |
append(InstructionHandle ih)
Append an instruction to the end of this list. |
BranchHandle |
append(InstructionHandle ih,
BranchInstruction i)
Append an instruction after instruction (handle) ih contained in this list. |
InstructionHandle |
append(InstructionHandle ih,
CompoundInstruction c)
Append a compound instruction. |
InstructionHandle |
append(InstructionHandle ih,
Instruction i)
Append an instruction after instruction (handle) ih contained in this list. |
InstructionHandle |
append(InstructionHandle ih,
InstructionList il)
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. |
private void |
clear()
|
boolean |
contains(Instruction i)
|
boolean |
contains(InstructionHandle i)
|
InstructionList |
copy()
|
void |
delete(Instruction i)
Remove instruction from this list. |
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)
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. |
private InstructionHandle |
findInstruction1(Instruction i)
Search for given Instruction reference, start at beginning of list. |
private InstructionHandle |
findInstruction2(Instruction i)
Search for given Instruction reference, start at end of list |
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()
|
int |
getLength()
|
InstructionHandle |
getStart()
|
BranchHandle |
insert(BranchInstruction i)
Insert a branch instruction at start of this list. |
InstructionHandle |
insert(CompoundInstruction c)
Insert a compound instruction. |
InstructionHandle |
insert(Instruction i)
Insert an instruction at start of this list. |
InstructionHandle |
insert(Instruction i,
CompoundInstruction c)
Insert a compound instruction before instruction i. |
private void |
insert(InstructionHandle ih)
Insert an instruction at start of this list. |
BranchHandle |
insert(InstructionHandle ih,
BranchInstruction i)
Insert an instruction before instruction (handle) ih contained in this list. |
InstructionHandle |
insert(InstructionHandle ih,
CompoundInstruction c)
Insert a compound instruction. |
InstructionHandle |
insert(InstructionHandle ih,
Instruction 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()
Test for empty list. |
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. |
private void |
remove(InstructionHandle prev,
InstructionHandle next)
Remove from instruction `prev' to instruction `next' both contained in this list. |
void |
removeObserver(InstructionListObserver o)
Remove observer for this object. |
void |
replaceConstantPool(ConstantPoolGen old_cp,
ConstantPoolGen 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()
Convert this Object to a human-readable String. |
java.lang.String |
toString(boolean verbose)
|
void |
update()
Call notify() method on all observers. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
start
private InstructionHandle start
end
private InstructionHandle end
length
private int length
byte_positions
private int[] byte_positions
observers
private java.util.List observers
Constructor Detail |
InstructionList
public InstructionList()
- Create (empty) instruction list.
InstructionList
public InstructionList(Instruction i)
- Create instruction list containing one instruction.
InstructionList
public InstructionList(BranchInstruction i)
- Create instruction list containing one instruction.
InstructionList
public InstructionList(CompoundInstruction c)
- Initialize list with (nonnull) compound instruction. Consumes argument
list, i.e., it becomes empty.
InstructionList
public InstructionList(byte[] code)
- Initialize instruction list from byte array.
Method Detail |
isEmpty
public boolean isEmpty()
- Test for empty list.
findHandle
public static InstructionHandle findHandle(InstructionHandle[] ihs, int[] pos, int count, int target)
- Find the target instruction (handle) that corresponds to the given target
position (byte code offset).
findHandle
public InstructionHandle findHandle(int pos)
- Get instruction handle for instruction at byte code position pos.
This only works properly, if the list is freshly initialized from a byte array or
setPositions() has been called before this method.
append
public InstructionHandle append(InstructionHandle ih, InstructionList il)
- Append another list after instruction (handle) ih contained in this list.
Consumes argument list, i.e., it becomes empty.
append
public InstructionHandle append(Instruction i, InstructionList il)
- Append another list after instruction i contained in this list.
Consumes argument list, i.e., it becomes empty.
append
public InstructionHandle append(InstructionList il)
- Append another list to this one.
Consumes argument list, i.e., it becomes empty.
append
private void append(InstructionHandle ih)
- Append an instruction to the end of this list.
append
public InstructionHandle append(Instruction i)
- Append an instruction to the end of this list.
append
public BranchHandle append(BranchInstruction i)
- Append a branch instruction to the end of this list.
append
public InstructionHandle append(Instruction i, Instruction j)
- Append a single instruction j after another instruction i, which
must be in this list of course!
append
public InstructionHandle append(Instruction i, CompoundInstruction c)
- Append a compound instruction, after instruction i.
append
public InstructionHandle append(CompoundInstruction c)
- Append a compound instruction.
append
public InstructionHandle append(InstructionHandle ih, CompoundInstruction c)
- Append a compound instruction.
append
public InstructionHandle append(InstructionHandle ih, Instruction i)
- Append an instruction after instruction (handle) ih contained in this list.
append
public BranchHandle append(InstructionHandle ih, BranchInstruction i)
- Append an instruction after instruction (handle) ih contained in this list.
insert
public InstructionHandle insert(InstructionHandle ih, InstructionList il)
- Insert another list before Instruction handle ih contained in this list.
Consumes argument list, i.e., it becomes empty.
insert
public InstructionHandle insert(InstructionList il)
- Insert another list.
insert
private void insert(InstructionHandle ih)
- Insert an instruction at start of this list.
insert
public InstructionHandle insert(Instruction i, InstructionList il)
- Insert another list before Instruction i contained in this list.
Consumes argument list, i.e., it becomes empty.
insert
public InstructionHandle insert(Instruction i)
- Insert an instruction at start of this list.
insert
public BranchHandle insert(BranchInstruction i)
- Insert a branch instruction at start of this list.
insert
public InstructionHandle insert(Instruction i, Instruction j)
- Insert a single instruction j before another instruction i, which
must be in this list of course!
insert
public InstructionHandle insert(Instruction i, CompoundInstruction c)
- Insert a compound instruction before instruction i.
insert
public InstructionHandle insert(CompoundInstruction c)
- Insert a compound instruction.
insert
public InstructionHandle insert(InstructionHandle ih, Instruction i)
- Insert an instruction before instruction (handle) ih contained in this list.
insert
public InstructionHandle insert(InstructionHandle ih, CompoundInstruction c)
- Insert a compound instruction.
insert
public BranchHandle insert(InstructionHandle ih, BranchInstruction i)
- Insert an instruction before instruction (handle) ih contained in this list.
move
public void move(InstructionHandle start, InstructionHandle end, InstructionHandle target)
- Take all instructions (handles) from "start" to "end" and append them after the
new location "target". Of course, "end" must be after "start" and target must
not be located withing this range. If you want to move something to the start of
the list use null as value for target.
Any instruction targeters pointing to handles within the block, keep their targets.
move
public void move(InstructionHandle ih, InstructionHandle target)
- Move a single instruction (handle) to a new location.
remove
private void remove(InstructionHandle prev, InstructionHandle next) throws TargetLostException
- Remove from instruction `prev' to instruction `next' both contained
in this list. Throws TargetLostException when one of the removed instruction handles
is still being targeted.
delete
public void delete(InstructionHandle ih) throws TargetLostException
- Remove instruction from this list. The corresponding Instruction
handles must not be reused!
delete
public void delete(Instruction i) throws TargetLostException
- Remove instruction from this list. The corresponding Instruction
handles must not be reused!
delete
public void delete(InstructionHandle from, InstructionHandle to) throws TargetLostException
- Remove instructions from instruction `from' to instruction `to' contained
in this list. The user must ensure that `from' is an instruction before
`to', or risk havoc. The corresponding Instruction handles must not be reused!
delete
public void delete(Instruction from, Instruction to) throws TargetLostException
- Remove instructions from instruction `from' to instruction `to' contained
in this list. The user must ensure that `from' is an instruction before
`to', or risk havoc. The corresponding Instruction handles must not be reused!
findInstruction1
private InstructionHandle findInstruction1(Instruction i)
- Search for given Instruction reference, start at beginning of list.
findInstruction2
private InstructionHandle findInstruction2(Instruction i)
- Search for given Instruction reference, start at end of list
contains
public boolean contains(InstructionHandle i)
contains
public boolean contains(Instruction i)
setPositions
public void setPositions()
setPositions
public void setPositions(boolean check)
- Give all instructions their position number (offset in byte stream), i.e.,
make the list ready to be dumped.
getByteCode
public byte[] getByteCode()
- When everything is finished, use this method to convert the instruction
list into an array of bytes.
getInstructions
public Instruction[] getInstructions()
toString
public java.lang.String toString()
- Description copied from class:
java.lang.Object
- Convert this Object to a human-readable String.
There are no limits placed on how long this String
should be or what it should contain. We suggest you
make it as intuitive as possible to be able to place
it into System.out.println() 55
and such.
It is typical, but not required, to ensure that this method never completes abruptly with a java.lang.RuntimeException.
This method will be called when performing string concatenation with this object. If the result is
null
, string concatenation will instead use"null"
.The default implementation returns
getClass().getName() + "@" + Integer.toHexString(hashCode())
.
toString
public java.lang.String toString(boolean verbose)
iterator
public java.util.Iterator iterator()
getInstructionHandles
public InstructionHandle[] getInstructionHandles()
getInstructionPositions
public int[] getInstructionPositions()
- Get positions (offsets) of all instructions in the list. This relies on that
the list has been freshly created from an byte code array, or that setPositions()
has been called. Otherwise this may be inaccurate.
copy
public InstructionList copy()
replaceConstantPool
public void replaceConstantPool(ConstantPoolGen old_cp, ConstantPoolGen new_cp)
- Replace all references to the old constant pool with references to the new
constant pool
clear
private void clear()
dispose
public void dispose()
- Delete contents of list. Provides besser memory utilization,
because the system then may reuse the instruction handles. This
method is typically called right after
MethodGen.getMethod().
getStart
public InstructionHandle getStart()
getEnd
public InstructionHandle getEnd()
getLength
public int getLength()
size
public int size()
redirectBranches
public void redirectBranches(InstructionHandle old_target, InstructionHandle new_target)
- Redirect all references from old_target to new_target, i.e., update targets
of branch instructions.
redirectLocalVariables
public void redirectLocalVariables(LocalVariableGen[] lg, InstructionHandle old_target, InstructionHandle new_target)
- Redirect all references of local variables from old_target to new_target.
redirectExceptionHandlers
public void redirectExceptionHandlers(CodeExceptionGen[] exceptions, InstructionHandle old_target, InstructionHandle new_target)
- Redirect all references of exception handlers from old_target to new_target.
addObserver
public void addObserver(InstructionListObserver o)
- Add observer for this object.
removeObserver
public void removeObserver(InstructionListObserver o)
- Remove observer for this object.
update
public void update()
- Call notify() method on all observers. This method is not called
automatically whenever the state has changed, but has to be
called by the user after he has finished editing the object.
|
|||||||||
Home >> All >> org >> apache >> bcel >> [ generic overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: ![]() ![]() ![]() |
DETAIL: FIELD | CONSTR | METHOD |