Class BranchInstruction
java.lang.Object
org.apache.bcel.generic.Instruction
org.apache.bcel.generic.BranchInstruction
- All Implemented Interfaces:
Serializable, Cloneable, InstructionTargeter
- Direct Known Subclasses:
GotoInstruction, IfInstruction, JsrInstruction, Select
Abstract super class for branching instructions like GOTO, IFEQ, etc..
Branch instructions may have a variable length, namely GOTO, JSR,
LOOKUPSWITCH and TABLESWITCH.
- See Also:
-
Field Summary
FieldsFields inherited from class Instruction
length, opcode -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedBranchInstruction(short opcode, InstructionHandle target) Common super constructor -
Method Summary
Modifier and TypeMethodDescriptionbooleanvoiddump(DataOutputStream out) Dump instruction as byte code to stream out.final intgetIndex()protected intprotected intgetTargetOffset(InstructionHandle _target) protected voidinitFromFile(ByteSequence bytes, boolean wide) Read needed data (e.g.voidsetTarget(InstructionHandle target) Set branch targettoString(boolean verbose) Long output format: <position in byte code> <name of opcode> "["<opcode number>"]" "("<length of instruction>")" "<"<target instruction>">" "@"<branch target offset>protected intupdatePosition(int offset, int max_offset) Called by InstructionList.setPositions when setting the position for every instruction.voidupdateTarget(InstructionHandle old_ih, InstructionHandle new_ih) Methods inherited from class Instruction
accept, consumeStack, copy, equals, getComparator, getLength, getName, getOpcode, hashCode, produceStack, readInstruction, setComparator, toString, toString
-
Field Details
-
index
protected int index -
target
-
position
protected int position
-
-
Constructor Details
-
BranchInstruction
Common super constructor- Parameters:
opcode- Instruction opcodetarget- instruction to branch to
-
-
Method Details
-
dump
Dump instruction as byte code to stream out.- Overrides:
dumpin classInstruction- Parameters:
out- Output stream- Throws:
IOException
-
getTargetOffset
- Parameters:
_target- branch target- Returns:
- the offset to `target' relative to this instruction
-
getTargetOffset
protected int getTargetOffset()- Returns:
- the offset to this instruction's target
-
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
-
toString
Long output format: <position in byte code> <name of opcode> "["<opcode number>"]" "("<length of instruction>")" "<"<target instruction>">" "@"<branch target offset>- Overrides:
toStringin classInstruction- Parameters:
verbose- long/short format switch- Returns:
- mnemonic for instruction
-
initFromFile
Read needed data (e.g. index) from file. Conversion to a InstructionHandle is done in InstructionList(byte[]).- Overrides:
initFromFilein classInstruction- Parameters:
bytes- input streamwide- wide prefix?- Throws:
IOException- may be thrown if the implementation needs to read data from the file- See Also:
-
getIndex
public final int getIndex()- Returns:
- target offset in byte code
-
getTarget
- Returns:
- target of branch instruction
-
setTarget
Set branch target- Parameters:
target- branch target
-
updateTarget
- Specified by:
updateTargetin interfaceInstructionTargeter- Parameters:
old_ih- old targetnew_ih- new target
-
containsTarget
- Specified by:
containsTargetin interfaceInstructionTargeter- Returns:
- true, if ih is target of this instruction
-