Package org.apache.bcel.generic
Class InstructionHandle
- java.lang.Object
-
- org.apache.bcel.generic.InstructionHandle
-
- Direct Known Subclasses:
BranchHandle
public class InstructionHandle extends java.lang.ObjectInstances of this class give users a handle to the instructions contained in an InstructionList. Instruction objects may be used more than once within a list, this is useful because it saves memory and may be much faster. Within an InstructionList an InstructionHandle object is wrapped around all instructions, that is, it implements a cell in a doubly-linked list. From the outside only the next and the previous instruction (handle) are accessible. One can traverse the list via an Enumeration returned by InstructionList.elements().- See Also:
Instruction,BranchHandle,InstructionList
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<java.lang.Object,java.lang.Object>attributesstatic InstructionHandle[]EMPTY_ARRAYEmpty array.(package private) static InstructionTargeter[]EMPTY_INSTRUCTION_TARGETER_ARRAYEmpty array.protected inti_positionDeprecated.(since 6.0) will be made private; do not access directly, use getter/setterprivate Instructioninstructionprivate InstructionHandlenextprivate InstructionHandleprevprivate java.util.Set<InstructionTargeter>targeters
-
Constructor Summary
Constructors Modifier Constructor Description protectedInstructionHandle(Instruction i)Constructs an InstructionHandle.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaccept(Visitor v)Convenience method, simply calls accept() on the contained instruction.voidaddAttribute(java.lang.Object key, java.lang.Object attr)Add an attribute to an instruction handle.protected voidaddHandle()Deprecated.Does nothing as of 6.3.1.voidaddTargeter(InstructionTargeter t)Denote this handle is being referenced by t.(package private) voiddispose()Delete contents, removes user access.java.lang.ObjectgetAttribute(java.lang.Object key)Gets attribute of an instruction handle.java.util.Collection<java.lang.Object>getAttributes()Gets all attributes associated with this handle.InstructiongetInstruction()Gets the instruction.(package private) static InstructionHandlegetInstructionHandle(Instruction i)Factory method.InstructionHandlegetNext()Gets the next instruction handle.intgetPosition()Gets the position.InstructionHandlegetPrev()Gets the previous instruction handle.InstructionTargeter[]getTargeters()Gets the targeters.booleanhasTargeters()Checks if this handle has targeters.voidremoveAllTargeters()Remove all targeters, if any.voidremoveAttribute(java.lang.Object key)Delete an attribute of an instruction handle.voidremoveTargeter(InstructionTargeter t)Denote this handle isn't referenced anymore by t.voidsetInstruction(Instruction i)Replace current instruction contained in this handle.(package private) InstructionHandlesetNext(InstructionHandle next)Sets the next instruction handle.(package private) voidsetPosition(int pos)Sets the position, the byte code offset of the contained instruction.(package private) InstructionHandlesetPrev(InstructionHandle prev)Sets the previous instruction handle.InstructionswapInstruction(Instruction i)Temporarily swap the current instruction, without disturbing anything.java.lang.StringtoString()Gets a string representation of the contained instruction.java.lang.StringtoString(boolean verbose)Gets a verbose string representation of the contained instruction.protected intupdatePosition(int offset, int maxOffset)Called by InstructionList.setPositions when setting the position for every instruction.
-
-
-
Field Detail
-
EMPTY_ARRAY
public static final InstructionHandle[] EMPTY_ARRAY
Empty array.- Since:
- 6.6.0
-
EMPTY_INSTRUCTION_TARGETER_ARRAY
static final InstructionTargeter[] EMPTY_INSTRUCTION_TARGETER_ARRAY
Empty array.
-
next
private InstructionHandle next
-
prev
private InstructionHandle prev
-
instruction
private Instruction instruction
-
i_position
@Deprecated protected int i_position
Deprecated.(since 6.0) will be made private; do not access directly, use getter/setter
-
targeters
private java.util.Set<InstructionTargeter> targeters
-
attributes
private java.util.Map<java.lang.Object,java.lang.Object> attributes
-
-
Constructor Detail
-
InstructionHandle
protected InstructionHandle(Instruction i)
Constructs an InstructionHandle.- Parameters:
i- the instruction.
-
-
Method Detail
-
getInstructionHandle
static InstructionHandle getInstructionHandle(Instruction i)
Factory method.
-
accept
public void accept(Visitor v)
Convenience method, simply calls accept() on the contained instruction.- Parameters:
v- Visitor object.
-
addAttribute
public void addAttribute(java.lang.Object key, java.lang.Object attr)Add an attribute to an instruction handle.- Parameters:
key- the key object to store/retrieve the attribute.attr- the attribute to associate with this handle.
-
addHandle
@Deprecated protected void addHandle()
Deprecated.Does nothing as of 6.3.1.Does nothing.
-
addTargeter
public void addTargeter(InstructionTargeter t)
Denote this handle is being referenced by t.- Parameters:
t- the instruction targeter.
-
dispose
void dispose()
Delete contents, removes user access.
-
getAttribute
public java.lang.Object getAttribute(java.lang.Object key)
Gets attribute of an instruction handle.- Parameters:
key- the key object to store/retrieve the attribute.- Returns:
- the attribute value.
-
getAttributes
public java.util.Collection<java.lang.Object> getAttributes()
Gets all attributes associated with this handle.- Returns:
- all attributes associated with this handle.
-
getInstruction
public final Instruction getInstruction()
Gets the instruction.- Returns:
- the instruction.
-
getNext
public final InstructionHandle getNext()
Gets the next instruction handle.- Returns:
- the next instruction handle.
-
getPosition
public int getPosition()
Gets the position.- Returns:
- the position, the byte code offset of the contained instruction. This is accurate only after InstructionList.setPositions() has been called.
-
getPrev
public final InstructionHandle getPrev()
Gets the previous instruction handle.- Returns:
- the previous instruction handle.
-
getTargeters
public InstructionTargeter[] getTargeters()
Gets the targeters.- Returns:
- null, if there are no targeters.
-
hasTargeters
public boolean hasTargeters()
Checks if this handle has targeters.- Returns:
- true if this handle has targeters, false otherwise.
-
removeAllTargeters
public void removeAllTargeters()
Remove all targeters, if any.
-
removeAttribute
public void removeAttribute(java.lang.Object key)
Delete an attribute of an instruction handle.- Parameters:
key- the key object to retrieve the attribute.
-
removeTargeter
public void removeTargeter(InstructionTargeter t)
Denote this handle isn't referenced anymore by t.- Parameters:
t- the instruction targeter.
-
setInstruction
public void setInstruction(Instruction i)
Replace current instruction contained in this handle. Old instruction is disposed using Instruction.dispose().- Parameters:
i- the new instruction.
-
setNext
final InstructionHandle setNext(InstructionHandle next)
Sets the next instruction handle.- Parameters:
next- the next to set.- Returns:
- the next instruction handle.
- Since:
- 6.0
-
setPosition
void setPosition(int pos)
Sets the position, the byte code offset of the contained instruction.- Parameters:
pos- the position.
-
setPrev
final InstructionHandle setPrev(InstructionHandle prev)
Sets the previous instruction handle.- Parameters:
prev- the prev to set.- Returns:
- the previous instruction handle.
- Since:
- 6.0
-
swapInstruction
public Instruction swapInstruction(Instruction i)
Temporarily swap the current instruction, without disturbing anything. Meant to be used by a debugger, implementing breakpoints. Current instruction is returned.Warning: if this is used on a BranchHandle then some methods such as getPosition() will still refer to the original cached instruction, whereas other BH methods may affect the cache and the replacement instruction.
- Parameters:
i- the replacement instruction.- Returns:
- the old instruction.
-
toString
public java.lang.String toString()
Gets a string representation of the contained instruction.- Overrides:
toStringin classjava.lang.Object- Returns:
- a string representation of the contained instruction.
-
toString
public java.lang.String toString(boolean verbose)
Gets a verbose string representation of the contained instruction.- Parameters:
verbose- whether to be verbose.- Returns:
- a (verbose) string representation of the contained instruction.
-
updatePosition
protected int updatePosition(int offset, int maxOffset)Called by InstructionList.setPositions when setting the position for every instruction. In the presence of variable length instructions 'setPositions()' performs multiple passes over the instruction list to calculate the correct (byte) positions and offsets by calling this function.- Parameters:
offset- additional offset caused by preceding (variable length) instructions.maxOffset- the maximum offset that may be caused by these instructions.- Returns:
- additional offset caused by possible change of this instruction's length.
-
-