Package serp.bytecode

Class TableSwitchInstruction

All Implemented Interfaces:
BCEntity, InstructionPtr, VisitAcceptor

public class TableSwitchInstruction extends JumpInstruction
The tableswitch instruction.
  • Field Details

    • _low

      private int _low
    • _high

      private int _high
    • _cases

      private List _cases
  • Constructor Details

    • TableSwitchInstruction

      TableSwitchInstruction(Code owner)
  • Method Details

    • getOffsets

      public int[] getOffsets()
      Returns the current byte offsets for the different switch cases in this Instruction.
    • setOffsets

      public void setOffsets(int[] offsets)
      Sets the offsets for the instructions representing the different switch statement cases. WARNING: these offsets will not be changed in the event that the code is modified following this call. It is typically a good idea to follow this call with a call to updateTargets as soon as the instructions at the given offsets are valid, at which point the Instructions themselves will be used as the targets and the offsets will be updated as expected.
    • getLength

      int getLength()
      Description copied from class: Instruction
      Return the length in bytes of this opcode, including all arguments. For many opcodes this method relies on an up-to-date byte index.
      Overrides:
      getLength in class Instruction
    • getDefaultTarget

      public Instruction getDefaultTarget()
    • setDefaultTarget

      public TableSwitchInstruction setDefaultTarget(Instruction ins)
    • getDefaultOffset

      public int getDefaultOffset()
    • setDefaultOffset

      public TableSwitchInstruction setDefaultOffset(int offset)
    • getLow

      public int getLow()
    • setLow

      public TableSwitchInstruction setLow(int low)
    • getHigh

      public int getHigh()
    • setHigh

      public TableSwitchInstruction setHigh(int high)
    • getTargets

      public Instruction[] getTargets()
      Return the targets for this switch, or empty array if not set.
    • setTargets

      public TableSwitchInstruction setTargets(Instruction[] targets)
      Set the jump points for this switch.
      Returns:
      this instruction, for method chaining
    • addTarget

      public TableSwitchInstruction addTarget(Instruction target)
      Add a target to this switch.
      Returns:
      this instruction, for method chaining
    • 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
      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
    • findTarget

      private Instruction findTarget(int jumpByteIndex, List inss)
    • updateTargets

      public void updateTargets()
      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 and before it is written after modification.
      Specified by:
      updateTargets in interface InstructionPtr
      Overrides:
      updateTargets in class JumpInstruction
    • replaceTarget

      public void replaceTarget(Instruction oldTarget, Instruction newTarget)
      Description copied from interface: InstructionPtr
      Replace the given old, likely invalid, target with a new target. The new target Instruction is guaranteed to be in the same code block as this InstructionPtr.
      Specified by:
      replaceTarget in interface InstructionPtr
      Overrides:
      replaceTarget in class JumpInstruction
    • 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 one.
      Specified by:
      acceptVisit in interface VisitAcceptor
      Overrides:
      acceptVisit in class JumpInstruction
    • read

      void read(Instruction orig)
      Description copied from class: Instruction
      Copy the given instruction data.
      Overrides:
      read in class JumpInstruction
    • read

      void read(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:
      read in class JumpInstruction
      Throws:
      IOException
    • write

      void write(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:
      write in class JumpInstruction
      Throws:
      IOException