Class InstructionBranch

java.lang.Object
org.aspectj.apache.bcel.generic.Instruction
org.aspectj.apache.bcel.generic.InstructionBranch
All Implemented Interfaces:
Serializable, Cloneable, Constants, InstructionTargeter
Direct Known Subclasses:
InstructionSelect

public class InstructionBranch 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. A branch instruction may be talking in terms of absolute destination (targetIndex) or about an instruction it doesnt yet know the position if (targetInstruction). targetInstruction (if set) overrides targetIndex
Version:
$Id: InstructionBranch.java,v 1.6 2009/10/05 17:35:36 aclement Exp $
Author:
M. Dahm
See Also:
InstructionList, Serialized Form
  • Field Details

    • targetIndex

      protected int targetIndex
    • targetInstruction

      protected InstructionHandle targetInstruction
    • positionOfThisInstruction

      protected int positionOfThisInstruction
  • Constructor Details

    • InstructionBranch

      public InstructionBranch(short opcode, InstructionHandle target)
    • InstructionBranch

      public InstructionBranch(short opcode, int index)
    • InstructionBranch

      public InstructionBranch(short opcode)
  • Method Details

    • dump

      public void dump(DataOutputStream out) throws IOException
      Overrides:
      dump in class Instruction
      Throws:
      IOException
    • getTargetOffset

      protected int getTargetOffset()
    • 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
    • toString

      public String toString(boolean verbose)
      Long output format:
      Overrides:
      toString in class Instruction
      Parameters:
      verbose - long/short format switch
      Returns:
      mnemonic for instruction
    • getIndex

      public final int getIndex()
      Overrides:
      getIndex in class Instruction
      Returns:
      target offset in byte code
    • getTarget

      public InstructionHandle getTarget()
      Returns:
      target of branch instruction
    • setTarget

      public void setTarget(InstructionHandle target)
      Set branch target
      Parameters:
      target - branch target
    • updateTarget

      public void updateTarget(InstructionHandle oldHandle, InstructionHandle newHandle)
      Update the target destination for this instruction. If an oldHandle is provided it is checked to verify that is where the target currently points to before changing it.
      Specified by:
      updateTarget in interface InstructionTargeter
      Parameters:
      oldHandle - old target
      newHandle - new target
    • containsTarget

      public boolean containsTarget(InstructionHandle ih)
      Specified by:
      containsTarget in interface InstructionTargeter
      Returns:
      true, if ih is target of this instruction
    • getType

      public Type getType(ConstantPool cp)
      Overrides:
      getType in class Instruction
    • physicalSuccessor

      public InstructionHandle physicalSuccessor()
      Returns an InstructionHandle to the physical successor of this JsrInstruction. For this method to work, this JsrInstruction object must not be shared between multiple InstructionHandle objects! Formally, there must not be InstructionHandle objects i, j where i != j and i.getInstruction() == this == j.getInstruction().
      Returns:
      an InstructionHandle to the "next" instruction that will be executed when RETurned from a subroutine.
    • isIfInstruction

      public boolean isIfInstruction()
    • equals

      public boolean equals(Object other)
      Only equal if they are the same branch instruction - otherwise too risky as the targets may only temporarily be pointing at the same destination.
      Overrides:
      equals in class Instruction
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Instruction