Class Instruction

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static InstructionComparator cmp  
      (package private) static Instruction[] EMPTY_ARRAY  
      protected short length
      Deprecated.
      (since 6.0) will be made private; do not access directly, use getter/setter
      protected short opcode
      Deprecated.
      (since 6.0) will be made private; do not access directly, use getter/setter
    • Constructor Summary

      Constructors 
      Constructor Description
      Instruction()
      Empty constructor needed for Instruction.readInstruction.
      Instruction​(short opcode, short length)
      Constructs an Instruction.
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      abstract void accept​(Visitor v)
      Call corresponding visitor method(s).
      int consumeStack​(ConstantPoolGen cpg)
      This method also gives right results for instructions whose effect on the stack depends on the constant pool entry they reference.
      Instruction copy()
      Use with caution, since 'BranchInstruction's have a 'target' reference which is not copied correctly (only basic types are).
      (package private) void dispose()
      Some instructions may be reused, so don't do anything by default.
      void dump​(java.io.DataOutputStream out)
      Dumps instruction as byte code to stream out.
      boolean equals​(java.lang.Object that)
      Tests for equality, delegated to comparator
      static InstructionComparator getComparator()
      Deprecated.
      (6.0) use the built in comparator, or wrap this class in another object that implements these methods
      int getLength()
      Gets the length (in bytes) of instruction.
      java.lang.String getName()
      Gets the name of instruction, that is, opcode name.
      short getOpcode()
      Gets this instruction's opcode.
      int hashCode()
      Gets the hashCode of this object.
      protected void initFromFile​(ByteSequence bytes, boolean wide)
      Reads needed data (for example index) from file.
      static boolean isValidByte​(int value)
      Tests if the value can fit in a byte (signed)
      static boolean isValidShort​(int value)
      Tests if the value can fit in a short (signed)
      int produceStack​(ConstantPoolGen cpg)
      This method also gives right results for instructions whose effect on the stack depends on the constant pool entry they reference.
      static Instruction readInstruction​(ByteSequence bytes)
      Reads an instruction from (byte code) input stream and return the appropriate object.
      static void setComparator​(InstructionComparator c)
      Deprecated.
      (6.0) use the built in comparator, or wrap this class in another object that implements these methods
      (package private) void setLength​(int length)
      Needed in readInstruction and subclasses in this package
      (package private) void setOpcode​(short opcode)
      Needed in readInstruction and subclasses in this package
      java.lang.String toString()  
      java.lang.String toString​(boolean verbose)
      Long output format: <name of opcode> "["<opcode number>"]" "("<length of instruction>")"
      java.lang.String toString​(ConstantPool cp)
      Gets the mnemonic for instruction with symbolic references resolved.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • length

        @Deprecated
        protected short length
        Deprecated.
        (since 6.0) will be made private; do not access directly, use getter/setter
      • opcode

        @Deprecated
        protected short opcode
        Deprecated.
        (since 6.0) will be made private; do not access directly, use getter/setter
    • Constructor Detail

      • Instruction

        Instruction()
        Empty constructor needed for Instruction.readInstruction. Not to be used otherwise.
      • Instruction

        public Instruction​(short opcode,
                           short length)
        Constructs an Instruction.
        Parameters:
        opcode - the opcode.
        length - the instruction length.
    • Method Detail

      • getComparator

        @Deprecated
        public static InstructionComparator getComparator()
        Deprecated.
        (6.0) use the built in comparator, or wrap this class in another object that implements these methods
        Gets Comparator object used in the equals() method to determine equality of instructions.
        Returns:
        currently used comparator for equals().
      • isValidByte

        public static boolean isValidByte​(int value)
        Tests if the value can fit in a byte (signed)
        Parameters:
        value - the value to check.
        Returns:
        true if the value is in range.
        Since:
        6.0
      • isValidShort

        public static boolean isValidShort​(int value)
        Tests if the value can fit in a short (signed)
        Parameters:
        value - the value to check.
        Returns:
        true if the value is in range.
        Since:
        6.0
      • readInstruction

        public static Instruction readInstruction​(ByteSequence bytes)
                                           throws java.io.IOException
        Reads an instruction from (byte code) input stream and return the appropriate object.

        If the Instruction is defined in InstructionConst, then the singleton instance is returned.

        Parameters:
        bytes - input stream bytes.
        Returns:
        instruction object being read.
        Throws:
        java.io.IOException - Thrown when an I/O exception of some sort has occurred.
        See Also:
        InstructionConst.getInstruction(int)
      • setComparator

        @Deprecated
        public static void setComparator​(InstructionComparator c)
        Deprecated.
        (6.0) use the built in comparator, or wrap this class in another object that implements these methods
        Sets comparator to be used for equals().
        Parameters:
        c - the comparator.
      • accept

        public abstract void accept​(Visitor v)
        Call corresponding visitor method(s). The order is: Call visitor methods of implemented interfaces first, then call methods according to the class hierarchy in descending order, that is, the most specific visitXXX() call comes last.
        Parameters:
        v - Visitor object.
      • consumeStack

        public int consumeStack​(ConstantPoolGen cpg)
        This method also gives right results for instructions whose effect on the stack depends on the constant pool entry they reference.
        Parameters:
        cpg - the constant pool generator.
        Returns:
        Number of words consumed from stack by this instruction, or Constants.UNPREDICTABLE, if this cannot be computed statically
      • copy

        public Instruction copy()
        Use with caution, since 'BranchInstruction's have a 'target' reference which is not copied correctly (only basic types are). This also applies for 'Select' instructions with their multiple branch targets.
        Returns:
        (shallow) copy of an instruction.
        See Also:
        BranchInstruction
      • dispose

        void dispose()
        Some instructions may be reused, so don't do anything by default.
      • dump

        public void dump​(java.io.DataOutputStream out)
                  throws java.io.IOException
        Dumps instruction as byte code to stream out.
        Parameters:
        out - Output stream.
        Throws:
        java.io.IOException - Thrown when an I/O exception of some sort has occurred.
      • equals

        public boolean equals​(java.lang.Object that)
        Tests for equality, delegated to comparator
        Overrides:
        equals in class java.lang.Object
        Returns:
        true if that is an Instruction and has the same opcode.
      • getLength

        public int getLength()
        Gets the length (in bytes) of instruction.
        Returns:
        length (in bytes) of instruction.
      • getName

        public java.lang.String getName()
        Gets the name of instruction, that is, opcode name.
        Returns:
        name of instruction, that is, opcode name.
      • getOpcode

        public short getOpcode()
        Gets this instruction's opcode.
        Returns:
        this instruction's opcode.
      • hashCode

        public int hashCode()
        Gets the hashCode of this object.
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        the hashCode.
        Since:
        6.0
      • initFromFile

        protected void initFromFile​(ByteSequence bytes,
                                    boolean wide)
                             throws java.io.IOException
        Reads needed data (for example index) from file.
        Parameters:
        bytes - byte sequence to read from.
        wide - "wide" instruction flag.
        Throws:
        java.io.IOException - may be thrown if the implementation needs to read data from the file
      • produceStack

        public int produceStack​(ConstantPoolGen cpg)
        This method also gives right results for instructions whose effect on the stack depends on the constant pool entry they reference.
        Parameters:
        cpg - the constant pool generator.
        Returns:
        Number of words produced onto stack by this instruction, or Constants.UNPREDICTABLE, if this cannot be computed statically
      • setLength

        final void setLength​(int length)
        Needed in readInstruction and subclasses in this package
        Since:
        6.0
      • setOpcode

        final void setOpcode​(short opcode)
        Needed in readInstruction and subclasses in this package
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
        Returns:
        mnemonic for instruction in verbose format.
      • toString

        public java.lang.String toString​(boolean verbose)
        Long output format: <name of opcode> "["<opcode number>"]" "("<length of instruction>")"
        Parameters:
        verbose - long/short format switch.
        Returns:
        mnemonic for instruction.
      • toString

        public java.lang.String toString​(ConstantPool cp)
        Gets the mnemonic for instruction with symbolic references resolved.
        Parameters:
        cp - the constant pool.
        Returns:
        mnemonic for instruction with symbolic references resolved.