Class BytecodeStream

java.lang.Object
com.ibm.wala.core.util.bytecode.BytecodeStream
All Implemented Interfaces:
BytecodeConstants

public class BytecodeStream extends Object implements BytecodeConstants
Provides minimal abstraction layer to a stream of bytecodes from the code attribute of a method.
  • Constructor Details Link icon

  • Method Details Link icon

    • method Link icon

      public final IMethod method()
      Returns the method that this bytecode stream is from
    • declaringClass Link icon

      public final IClass declaringClass()
      Returns the declaring class that this bytecode stream is from
    • length Link icon

      public final int length()
      Returns the length of the bytecode stream Returns 0 if the method doesn't have any bytecodes (i.e. is abstract or native)
    • index Link icon

      public final int index()
      Returns the current bytecode index
    • reset Link icon

      public final void reset()
      Resets the stream to the beginning
    • reset Link icon

      public final void reset(int index)
      Resets the stream to a given position Use with caution
      Parameters:
      index - the position to reset the stream to
    • hasMoreBytecodes Link icon

      public final boolean hasMoreBytecodes()
      Does the stream have more bytecodes in it?
    • peekNextOpcode Link icon

      public final int peekNextOpcode()
      Returns the opcode of the next instruction in the sequence without advancing to it
      Returns:
      the opcode of the next instruction
      See Also:
    • nextInstruction Link icon

      public final int nextInstruction()
      Sets up the next instruction in the sequence
      Returns:
      the opcode of the next instruction
      See Also:
    • getOpcode Link icon

      public final int getOpcode()
      Returns the opcode of the current instruction in the sequence Note: if skipInstruction has been called, but nextInstruction has not, this method will return the opcode of the skipped instruction!
      Returns:
      the opcode of the current instruction
      See Also:
    • isWide Link icon

      public final boolean isWide()
      Are we currently processing a wide instruction?
      Returns:
      true if current instruction is wide
      See Also:
    • skipInstruction Link icon

      public final void skipInstruction()
      Skips the current instruction
      See Also:
    • skipInstruction Link icon

      public final void skipInstruction(int opc, boolean w)
      Skips the current instruction (without using the opcode field) A slightly optimized version of skipInstruction()
      Parameters:
      opc - current opcode
      w - whether current instruction follows wide
      See Also:
    • getByteValue Link icon

      public final int getByteValue()
      Returns a signed byte value Used for bipush
      Returns:
      signed byte value
    • getShortValue Link icon

      public final int getShortValue()
      Returns a signed short value Used for sipush
      Returns:
      signed short value
    • getLocalNumber Link icon

      public final int getLocalNumber()
      Returns the number of the local (as an unsigned byte) Used for iload, lload, fload, dload, aload, istore, lstore, fstore, dstore, astore, iinc, ret
      Returns:
      local number
      See Also:
    • getWideLocalNumber Link icon

      public final int getWideLocalNumber()
      Returns the wide number of the local (as an unsigned short) Used for iload, lload, fload, dload, aload, istore, lstore, fstore, dstore, astore, iinc prefixed by wide
      Returns:
      wide local number
      See Also:
    • getIncrement Link icon

      public final int getIncrement()
      Returns an increment value (as a signed byte) Used for iinc
      Returns:
      increment
      See Also:
    • getWideIncrement Link icon

      public final int getWideIncrement()
      Returns an increment value (as a signed short) Used for iinc prefixed by wide
      Returns:
      wide increment
      See Also:
    • getBranchOffset Link icon

      public final int getBranchOffset()
      Returns the offset of the branch (as a signed short) Used for if<cond>, ificmp<cond>, ifacmp<cond>, goto, jsr
      Returns:
      branch offset
      See Also:
    • getWideBranchOffset Link icon

      public final int getWideBranchOffset()
      Returns the wide offset of the branch (as a signed int) Used for goto_w, jsr_w
      Returns:
      wide branch offset
      See Also:
    • alignSwitch Link icon

      public final void alignSwitch()
      Skips the padding of a switch instruction Used for tableswitch, lookupswitch
    • getDefaultSwitchOffset Link icon

      public final int getDefaultSwitchOffset()
      Returns the default offset of the switch (as a signed int) Used for tableswitch, lookupswitch
      Returns:
      default switch offset
    • getLowSwitchValue Link icon

      public final int getLowSwitchValue()
      Returns the lowest value of the tableswitch (as a signed int) Used for tableswitch
      Returns:
      lowest switch value
      See Also:
    • getHighSwitchValue Link icon

      public final int getHighSwitchValue()
      Returns the highest value of the tableswitch (as a signed int) Used for tableswitch
      Returns:
      highest switch value
      See Also:
    • skipTableSwitchOffsets Link icon

      public final void skipTableSwitchOffsets(int num)
      Skips the offsets of a tableswitch instruction Used for tableswitch
      Parameters:
      num - the number of offsets to skip
      See Also:
    • getTableSwitchOffset Link icon

      public final int getTableSwitchOffset(int num)
      Returns the numbered offset of the tableswitch (as a signed int) Used for tableswitch The "cursor" has to be positioned at the start of the offset table NOTE: Will NOT advance cursor
      Parameters:
      num - the number of the offset to retrieve
      Returns:
      switch offset
    • computeTableSwitchOffset Link icon

      public final int computeTableSwitchOffset(int value, int low, int high)
      Returns the offset for a given value of the tableswitch (as a signed int) or 0 if the value is out of range. Used for tableswitch The "cursor" has to be positioned at the start of the offset table NOTE: Will NOT advance cursor
      Parameters:
      value - the value to retrieve offset for
      low - the lowest value of the tableswitch
      high - the highest value of the tableswitch
      Returns:
      switch offset
    • getSwitchLength Link icon

      public final int getSwitchLength()
      Returns the number of match-offset pairs in the lookupswitch (as a signed int) Used for lookupswitch
      Returns:
      number of switch pairs
    • skipLookupSwitchPairs Link icon

      public final void skipLookupSwitchPairs(int num)
      Skips the match-offset pairs of a lookupswitch instruction Used for lookupswitch
      Parameters:
      num - the number of match-offset pairs to skip
      See Also:
    • getLookupSwitchOffset Link icon

      public final int getLookupSwitchOffset(int num)
      Returns the numbered offset of the lookupswitch (as a signed int) Used for lookupswitch The "cursor" has to be positioned at the start of the pair table NOTE: Will NOT advance cursor
      Parameters:
      num - the number of the offset to retrieve
      Returns:
      switch offset
      See Also:
    • getLookupSwitchValue Link icon

      public final int getLookupSwitchValue(int num)
      Returns the numbered value of the lookupswitch (as a signed int) Used for lookupswitch The "cursor" has to be positioned at the start of the pair table NOTE: Will NOT advance cursor
      Parameters:
      num - the number of the value to retrieve
      Returns:
      switch value
      See Also:
    • computeLookupSwitchOffset Link icon

      public final int computeLookupSwitchOffset(int value, int num)
      Returns the offset for a given value of the lookupswitch (as a signed int) or 0 if the value is not in the table. Used for lookupswitch The "cursor" has to be positioned at the start of the offset table NOTE: Will NOT advance cursor WARNING: Uses LINEAR search. Whoever has time on their hands can re-implement this as a binary search.
      Parameters:
      value - the value to retrieve offset for
      num - the number of match-offset pairs in the lookupswitch
      Returns:
      switch offset
    • alignInvokeInterface Link icon

      public final void alignInvokeInterface()
      Skips the extra stuff after an invokeinterface instruction Used for invokeinterface
    • getArrayElementType Link icon

      public final int getArrayElementType()
      Returns the element type (primitive) of the array (as an unsigned byte) Used for newarray
      Returns:
      array element type
    • getArrayDimension Link icon

      public final int getArrayDimension()
      Returns the dimension of the array (as an unsigned byte) Used for multianewarray
      Returns:
      array dimension
    • getWideOpcode Link icon

      public final int getWideOpcode()
      Returns the opcode of the wide instruction Used for wide Can be one of iload, lload, fload, dload, aload, istore, lstore, fstore, dstore, astore, iinc
      Returns:
      the opcode of the wide instruction
    • getConstantIndex Link icon

      public final int getConstantIndex()
      Returns the constant pool index of a constant (as an unsigned byte) Used for ldc
      Returns:
      constant index
      See Also:
    • getWideConstantIndex Link icon

      public final int getWideConstantIndex()
      Returns the wide constant pool index of a constant (as an unsigned short) Used for ldc_w, ldc2_w
      Returns:
      wide constant index
      See Also: