Class InstructionHandle
java.lang.Object
org.apache.bcel.generic.InstructionHandle
- Direct Known Subclasses:
BranchHandle
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, 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:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final InstructionHandle[]Empty array.protected intDeprecated.(since 6.0) will be made private; do not access directly, use getter/setter -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedConstructs an InstructionHandle. -
Method Summary
Modifier and TypeMethodDescriptionvoidConvenience method, simply calls accept() on the contained instruction.voidaddAttribute(Object key, Object attr) Add an attribute to an instruction handle.protected voidDeprecated.Does nothing as of 6.3.1.voidDenote this handle is being referenced by t.getAttribute(Object key) Gets attribute of an instruction handle.Gets all attributes associated with this handle.final InstructionGets the instruction.final InstructionHandlegetNext()Gets the next instruction handle.intGets the position.final InstructionHandlegetPrev()Gets the previous instruction handle.Gets the targeters.booleanChecks if this handle has targeters.voidRemove all targeters, if any.voidremoveAttribute(Object key) Delete an attribute of an instruction handle.voidDenote this handle isn't referenced anymore by t.voidReplace current instruction contained in this handle.Temporarily swap the current instruction, without disturbing anything.toString()Gets a string representation of the contained instruction.toString(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 Details
-
EMPTY_ARRAY
-
i_position
Deprecated.(since 6.0) will be made private; do not access directly, use getter/setter
-
-
Constructor Details
-
InstructionHandle
Constructs an InstructionHandle.- Parameters:
i- the instruction.
-
-
Method Details
-
accept
-
addAttribute
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
-
addTargeter
Denote this handle is being referenced by t.- Parameters:
t- the instruction targeter.
-
getAttribute
Gets attribute of an instruction handle.- Parameters:
key- the key object to store/retrieve the attribute.- Returns:
- the attribute value.
-
getAttributes
Gets all attributes associated with this handle.- Returns:
- all attributes associated with this handle.
-
getInstruction
-
getNext
Gets the next instruction handle.- Returns:
- the next instruction handle.
-
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
Gets the previous instruction handle.- Returns:
- the previous instruction handle.
-
getTargeters
Gets the targeters.- Returns:
- null, if there are no targeters.
-
hasTargeters
Checks if this handle has targeters.- Returns:
- true if this handle has targeters, false otherwise.
-
removeAllTargeters
Remove all targeters, if any. -
removeAttribute
Delete an attribute of an instruction handle.- Parameters:
key- the key object to retrieve the attribute.
-
removeTargeter
Denote this handle isn't referenced anymore by t.- Parameters:
t- the instruction targeter.
-
setInstruction
Replace current instruction contained in this handle. Old instruction is disposed using Instruction.dispose().- Parameters:
i- the new instruction.
-
swapInstruction
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
-
toString
-
updatePosition
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.
-