Package serp.bytecode

Class Instruction

java.lang.Object
serp.bytecode.CodeEntry
serp.bytecode.Instruction
All Implemented Interfaces:
BCEntity, VisitAcceptor
Direct Known Subclasses:
FieldInstruction, JumpInstruction, MethodInstruction, MonitorInstruction, TypedInstruction

public class Instruction extends CodeEntry implements BCEntity, VisitAcceptor
An opcode in a method of a class.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private int
     
    private Code
     

    Fields inherited from class serp.bytecode.CodeEntry

    byteIndex, next, prev
  • Constructor Summary

    Constructors
    Constructor
    Description
     
    Instruction(Code owner, int opcode)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    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.
    boolean
    Instructions are equal if their opcodes are the same.
    int
    Return the index in the method code byte block at which this opcode starts.
    Return the class loader to use when loading related classes.
    Return the code block that owns this instruction.
    (package private) int
    Return the length in bytes of this opcode, including all arguments.
    Return the line number of this instruction, or null if none.
    int
    Return the logical number of stack positions changed by this instruction.
    Return the name of this instruction.
    int
    Return the opcode this instruction represents.
    Return the constant pool of the current class.
    Return the project of the current class.
    int
    Return the number of stack positions this instruction pushes or pops during its execution.
    (package private) void
     
    (package private) void
    Notification that a change has been made to this instruction that alters the structure of the code block, invalidating byte indexes.
    boolean
    Return false if this entity has been removed from its parent; in this case the results of any operations on the entity are undefined.
    (package private) void
    Read the arguments for this opcode from the given stream.
    (package private) void
    Copy the given instruction data.
    (package private) Instruction
    setOpcode(int opcode)
    Set the opcode this instruction represents.
    (package private) void
    Write the arguments for this opcode to the given stream.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • _owner

      private Code _owner
    • _opcode

      private int _opcode
  • Constructor Details

    • Instruction

      Instruction(Code owner)
    • Instruction

      Instruction(Code owner, int opcode)
  • Method Details

    • getCode

      public Code getCode()
      Return the code block that owns this instruction.
    • getName

      public String getName()
      Return the name of this instruction.
    • getOpcode

      public int getOpcode()
      Return the opcode this instruction represents.
    • setOpcode

      Instruction setOpcode(int opcode)
      Set the opcode this instruction represents. For internal use only.
      Returns:
      this instruction, for method chaining
    • getByteIndex

      public int getByteIndex()
      Return the index in the method code byte block at which this opcode starts. Note that this information may be out of date if the code block has been modified since last read/written.
    • invalidateByteIndexes

      void invalidateByteIndexes()
      Notification that a change has been made to this instruction that alters the structure of the code block, invalidating byte indexes.
    • getLineNumber

      public LineNumber getLineNumber()
      Return the line number of this instruction, or null if none. This method is subject to the validity constraints of getByteIndex().
      See Also:
    • getLength

      int getLength()
      Return the length in bytes of this opcode, including all arguments. For many opcodes this method relies on an up-to-date byte index.
    • getLogicalStackChange

      public int getLogicalStackChange()
      Return the logical number of stack positions changed by this instruction. In other words, ignore weirdness with longs and doubles taking two stack positions.
    • getStackChange

      public int getStackChange()
      Return the number of stack positions this instruction pushes or pops during its execution.
      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
    • equalsInstruction

      public boolean equalsInstruction(Instruction other)
      Instructions are equal if their opcodes are the same. Subclasses should override this method to perform a template comparison: instructions should compare equal to other instructions of the same type where the data is either the same or the data is unset.
    • getProject

      public Project getProject()
      Description copied from interface: BCEntity
      Return the project of the current class.
      Specified by:
      getProject in interface BCEntity
    • getPool

      public ConstantPool getPool()
      Description copied from interface: BCEntity
      Return the constant pool of the current class.
      Specified by:
      getPool in interface BCEntity
    • getClassLoader

      public ClassLoader getClassLoader()
      Description copied from interface: BCEntity
      Return the class loader to use when loading related classes.
      Specified by:
      getClassLoader in interface BCEntity
    • isValid

      public boolean isValid()
      Description copied from interface: BCEntity
      Return false if this entity has been removed from its parent; in this case the results of any operations on the entity are undefined.
      Specified by:
      isValid in interface BCEntity
    • 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
    • invalidate

      void invalidate()
    • read

      void read(Instruction orig)
      Copy the given instruction data.
    • read

      void read(DataInput in) throws IOException
      Read the arguments for this opcode from the given stream. This method should be overridden by opcodes that take arguments.
      Throws:
      IOException
    • write

      void write(DataOutput out) throws IOException
      Write the arguments for this opcode to the given stream. This method should be overridden by opcodes that take arguments.
      Throws:
      IOException