TechTrader Bytecode Toolkit

com.techtrader.modules.tools.bytecode
Class JumpInstruction

java.lang.Object
  |
  +--com.techtrader.modules.tools.bytecode.Instruction
        |
        +--com.techtrader.modules.tools.bytecode.JumpInstruction
Direct Known Subclasses:
LookupSwitchInstruction, TableSwitchInstruction

public class JumpInstruction
extends Instruction
implements InstructionPtr

Represents an IF, GOTO, JSR, or similar instruction that specifies as its argument a position in the code block to jump to.

Author:
Abe White

Field Summary
protected  int _offset
           
protected  Instruction _target
           
 
Fields inherited from class com.techtrader.modules.tools.bytecode.Instruction
_byteIndex, _opcode, _opcodeTypes, _owner
 
Constructor Summary
protected JumpInstruction(Code owner, int opcode)
           
 
Method Summary
 void acceptVisit(BCVisitor visit)
          Accept a visit from a BCVisitor, calling the appropriate methods to notify the visitor that it has entered this entity, and to provide it with the proper callbacks for each sub-entity owned by this object.
protected  void copy(Instruction orig)
           
 boolean equals(Object other)
          JumpInstructions are equal if they represent the same operation and the Instruction they jump to is the same, or if the jump Instruction of either is unset.
 int getLength()
          Return the length in bytes of this opcode, including all arguments.
 int getOffset()
          Get the byte offset for the jump instruction.
 int getStackChange()
          Return the number of stack positions this instruction pushes or pops during its execution.
 Instruction getTarget()
          Get the current target instruction to jump to, if it has been set.
protected  void readData(DataInput in)
          Read the arguments for this opcode from the given stream.
 void setMarkers(List instructions)
          Use the byte indexes read from the .class file to calculate and set references to the target instruction(s) for this ptr.
 void setOffset(int offset)
          Set the byte offset for the jump instruction.
 JumpInstruction setTarget(Instruction instruction)
          Set the instruction to jump to; the instruction must already be added to the code block.
protected  void writeData(DataOutput out)
          Write the arguments for this opcode to the given stream.
 
Methods inherited from class com.techtrader.modules.tools.bytecode.Instruction
getByteIndex, getName, getOpCode, getOwner, invalidate, setByteIndex, setOpCode
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_offset

protected int _offset

_target

protected Instruction _target
Constructor Detail

JumpInstruction

protected JumpInstruction(Code owner,
                          int opcode)
Method Detail

setOffset

public void setOffset(int offset)
Set the byte offset for the jump instruction.

getOffset

public int getOffset()
Get the byte offset for the jump instruction.

setTarget

public JumpInstruction setTarget(Instruction instruction)
Set the instruction to jump to; the instruction must already be added to the code block. WARNING: if this instruction is later deleted from the code block, the results are undefined.
Returns:
this Instruction, for method chaining

getTarget

public Instruction getTarget()
Get the current target instruction to jump to, if it has been set. WARNING: if this instruction is later deleted from the code block, the results are undefined.

setMarkers

public void setMarkers(List instructions)
Description copied from interface: InstructionPtr
Use the byte indexes read from the .class file to calculate and set references to the target instruction(s) for this ptr. This method will be called after the byte code has been read in for the first time.
Specified by:
setMarkers in interface InstructionPtr
Tags copied from interface: InstructionPtr
Parameters:
codes - the list of opcodes in the method

equals

public boolean equals(Object other)
JumpInstructions are equal if they represent the same operation and the Instruction they jump to is the same, or if the jump Instruction of either is unset.
Overrides:
equals in class Instruction

getLength

public int getLength()
Description copied from class: Instruction
Return the length in bytes of this opcode, including all arguments. This method should be overridden by opcodes that take arguments.
Overrides:
getLength in class Instruction

getStackChange

public int getStackChange()
Description copied from class: Instruction
Return the number of stack positions this instruction pushes or pops during its execution.
Overrides:
getStackChange in class Instruction
Tags copied from class: Instruction
Returns:
0 if the stack is not affected by this instruction, a positive number if it pushes onto the stack, and a negative number if it pops from the stack

copy

protected void copy(Instruction orig)
Overrides:
copy in class Instruction

readData

protected void readData(DataInput in)
                 throws IOException
Description copied from class: Instruction
Read the arguments for this opcode from the given stream. This method should be overridden by opcodes that take arguments.
Overrides:
readData in class Instruction

writeData

protected void writeData(DataOutput out)
                  throws IOException
Description copied from class: Instruction
Write the arguments for this opcode to the given stream. This method should be overridden by opcodes that take arguments.
Overrides:
writeData in class Instruction

acceptVisit

public void acceptVisit(BCVisitor visit)
Description copied from interface: VisitAcceptor
Accept a visit from a BCVisitor, calling the appropriate methods to notify the visitor that it has entered this entity, and to provide it with the proper callbacks for each sub-entity owned by this object.
Overrides:
acceptVisit in class Instruction

TechTrader Bytecode Toolkit