org.apache.bcel.generic

Class BranchInstruction

public abstract class BranchInstruction extends Instruction implements InstructionTargeter

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: InstructionList

Field Summary
protected intindex
protected intposition
protected InstructionHandletarget
Constructor Summary
protected BranchInstruction(short opcode, InstructionHandle target)
Common super constructor
Method Summary
booleancontainsTarget(InstructionHandle ih)
voiddump(DataOutputStream out)
Dump instruction as byte code to stream out.
intgetIndex()
InstructionHandlegetTarget()
protected intgetTargetOffset(InstructionHandle _target)
protected intgetTargetOffset()
protected voidinitFromFile(ByteSequence bytes, boolean wide)
Read needed data (e.g. index) from file.
voidsetTarget(InstructionHandle target)
Set branch target
StringtoString(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)

Field Detail

index

protected int index

position

protected int position

target

protected InstructionHandle target

Constructor Detail

BranchInstruction

protected BranchInstruction(short opcode, InstructionHandle target)
Common super constructor

Parameters: opcode Instruction opcode target instruction to branch to

Method Detail

containsTarget

public boolean containsTarget(InstructionHandle ih)

Returns: true, if ih is target of this instruction

dump

public void dump(DataOutputStream out)
Dump instruction as byte code to stream out.

Parameters: out Output stream

getIndex

public final int getIndex()

Returns: target offset in byte code

getTarget

public InstructionHandle getTarget()

Returns: target of branch instruction

getTargetOffset

protected int getTargetOffset(InstructionHandle _target)

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

initFromFile

protected void initFromFile(ByteSequence bytes, boolean wide)
Read needed data (e.g. index) from file. Conversion to a InstructionHandle is done in InstructionList(byte[]).

Parameters: bytes input stream wide wide prefix?

See Also: InstructionList

setTarget

public void setTarget(InstructionHandle target)
Set branch target

Parameters: target branch target

toString

public String toString(boolean verbose)
Long output format: <position in byte code> <name of opcode> "["<opcode number>"]" "("<length of instruction>")" "<"<target instruction>">" "@"<branch target offset>

Parameters: verbose long/short format switch

Returns: mnemonic for instruction

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) instructions max_offset the maximum offset that may be caused by these instructions

Returns: additional offset caused by possible change of this instruction's length

updateTarget

public void updateTarget(InstructionHandle old_ih, InstructionHandle new_ih)

Parameters: old_ih old target new_ih new target