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.Object
Instances 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, i.e., 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>
attributes
protected int
i_position
Deprecated.(since 6.0) will be made private; do not access directly, use getter/setterprivate Instruction
instruction
private InstructionHandle
next
private InstructionHandle
prev
private java.util.Set<InstructionTargeter>
targeters
-
Constructor Summary
Constructors Modifier Constructor Description protected
InstructionHandle(Instruction i)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
accept(Visitor v)
Convenience method, simply calls accept() on the contained instruction.void
addAttribute(java.lang.Object key, java.lang.Object attr)
Add an attribute to an instruction handle.protected void
addHandle()
Deprecated.Does nothing as of 6.3.1.void
addTargeter(InstructionTargeter t)
Denote this handle is being referenced by t.(package private) void
dispose()
Delete contents, i.e., remove user access.java.lang.Object
getAttribute(java.lang.Object key)
Get attribute of an instruction handle.java.util.Collection<java.lang.Object>
getAttributes()
Instruction
getInstruction()
(package private) static InstructionHandle
getInstructionHandle(Instruction i)
Factory method.InstructionHandle
getNext()
int
getPosition()
InstructionHandle
getPrev()
InstructionTargeter[]
getTargeters()
boolean
hasTargeters()
void
removeAllTargeters()
Remove all targeters, if any.void
removeAttribute(java.lang.Object key)
Delete an attribute of an instruction handle.void
removeTargeter(InstructionTargeter t)
Denote this handle isn't referenced anymore by t.void
setInstruction(Instruction i)
Replace current instruction contained in this handle.(package private) InstructionHandle
setNext(InstructionHandle next)
(package private) void
setPosition(int pos)
Set the position, i.e., the byte code offset of the contained instruction.(package private) InstructionHandle
setPrev(InstructionHandle prev)
Instruction
swapInstruction(Instruction i)
Temporarily swap the current instruction, without disturbing anything.java.lang.String
toString()
java.lang.String
toString(boolean verbose)
protected int
updatePosition(int offset, int max_offset)
Called by InstructionList.setPositions when setting the position for every instruction.
-
-
-
Field Detail
-
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)
-
-
Method Detail
-
addHandle
@Deprecated protected void addHandle()
Deprecated.Does nothing as of 6.3.1.Does nothing.
-
getNext
public final InstructionHandle getNext()
-
getPrev
public final InstructionHandle getPrev()
-
getInstruction
public final Instruction getInstruction()
-
setInstruction
public void setInstruction(Instruction i)
Replace current instruction contained in this handle. Old instruction is disposed using Instruction.dispose().
-
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.
-
getInstructionHandle
static InstructionHandle getInstructionHandle(Instruction i)
Factory method.
-
updatePosition
protected int updatePosition(int offset, int max_offset)
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) instructionsmax_offset
- the maximum offset that may be caused by these instructions- Returns:
- additional offset caused by possible change of this instruction's length
-
getPosition
public int getPosition()
- Returns:
- the position, i.e., the byte code offset of the contained instruction. This is accurate only after InstructionList.setPositions() has been called.
-
setPosition
void setPosition(int pos)
Set the position, i.e., the byte code offset of the contained instruction.
-
dispose
void dispose()
Delete contents, i.e., remove user access.
-
removeAllTargeters
public void removeAllTargeters()
Remove all targeters, if any.
-
removeTargeter
public void removeTargeter(InstructionTargeter t)
Denote this handle isn't referenced anymore by t.
-
addTargeter
public void addTargeter(InstructionTargeter t)
Denote this handle is being referenced by t.
-
hasTargeters
public boolean hasTargeters()
-
getTargeters
public InstructionTargeter[] getTargeters()
- Returns:
- null, if there are no targeters
-
toString
public java.lang.String toString(boolean verbose)
- Returns:
- a (verbose) string representation of the contained instruction.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
- Returns:
- a string representation of the contained instruction.
-
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 attributeattr
- the attribute to associate with this handle
-
removeAttribute
public void removeAttribute(java.lang.Object key)
Delete an attribute of an instruction handle.- Parameters:
key
- the key object to retrieve the attribute
-
getAttribute
public java.lang.Object getAttribute(java.lang.Object key)
Get attribute of an instruction handle.- Parameters:
key
- the key object to store/retrieve the attribute
-
getAttributes
public java.util.Collection<java.lang.Object> getAttributes()
- Returns:
- all attributes associated with this handle
-
accept
public void accept(Visitor v)
Convenience method, simply calls accept() on the contained instruction.- Parameters:
v
- Visitor object
-
setNext
final InstructionHandle setNext(InstructionHandle next)
- Parameters:
next
- the next to set- Since:
- 6.0
-
setPrev
final InstructionHandle setPrev(InstructionHandle prev)
- Parameters:
prev
- the prev to set- Since:
- 6.0
-
-