Class InstructionHandle

  • Direct Known Subclasses:
    BranchHandle

    public class InstructionHandle
    extends java.lang.Object
    Instances of this class give users a handle to the instructions contained in an InstructionList. Instruction objects may be used more than once within a list, this is useful because it saves memory and may be much faster. Within an InstructionList an InstructionHandle object is wrapped around all instructions, that is, it implements a cell in a doubly-linked list. From the outside only the next and the previous instruction (handle) are accessible. One can traverse the list via an Enumeration returned by InstructionList.elements().
    See Also:
    Instruction, BranchHandle, InstructionList
    • Field Detail

      • i_position

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

    • Method Detail

      • accept

        public void accept​(Visitor v)
        Convenience method, simply calls accept() on the contained instruction.
        Parameters:
        v - Visitor object.
      • addAttribute

        public void addAttribute​(java.lang.Object key,
                                 java.lang.Object attr)
        Add an attribute to an instruction handle.
        Parameters:
        key - The key object to store/retrieve the attribute.
        attr - The attribute to associate with this handle.
      • addHandle

        @Deprecated
        protected void addHandle()
        Deprecated.
        Does nothing as of 6.3.1.
        Does nothing.
      • addTargeter

        public void addTargeter​(InstructionTargeter t)
        Denote this handle is being referenced by t.
        Parameters:
        t - The instruction targeter.
      • getAttribute

        public java.lang.Object getAttribute​(java.lang.Object key)
        Gets attribute of an instruction handle.
        Parameters:
        key - The key object to store/retrieve the attribute.
        Returns:
        The attribute value.
      • getAttributes

        public java.util.Collection<java.lang.Object> getAttributes()
        Gets all attributes associated with this handle.
        Returns:
        all attributes associated with this handle.
      • getNext

        public final InstructionHandle getNext()
        Gets the next instruction handle.
        Returns:
        The next instruction handle.
      • getPosition

        public int getPosition()
        Gets the position.
        Returns:
        The position, the byte code offset of the contained instruction. This is accurate only after InstructionList.setPositions() has been called.
      • getPrev

        public final InstructionHandle getPrev()
        Gets the previous instruction handle.
        Returns:
        The previous instruction handle.
      • hasTargeters

        public boolean hasTargeters()
        Checks if this handle has targeters.
        Returns:
        true if this handle has targeters, false otherwise.
      • removeAttribute

        public void removeAttribute​(java.lang.Object key)
        Delete an attribute of an instruction handle.
        Parameters:
        key - The key object to retrieve the attribute.
      • setInstruction

        public void setInstruction​(Instruction i)
        Replace current instruction contained in this handle. Old instruction is disposed using Instruction.dispose().
        Parameters:
        i - The new instruction.
      • swapInstruction

        public Instruction swapInstruction​(Instruction i)
        Temporarily swap the current instruction, without disturbing anything. Meant to be used by a debugger, implementing breakpoints. Current instruction is returned.

        Warning: if this is used on a BranchHandle then some methods such as getPosition() will still refer to the original cached instruction, whereas other BH methods may affect the cache and the replacement instruction.

        Parameters:
        i - The replacement instruction.
        Returns:
        The old instruction.
      • toString

        public java.lang.String toString()
        Gets a string representation of the contained instruction.
        Overrides:
        toString in class java.lang.Object
        Returns:
        A string representation of the contained instruction.
      • toString

        public java.lang.String toString​(boolean verbose)
        Gets a verbose string representation of the contained instruction.
        Parameters:
        verbose - whether to be verbose.
        Returns:
        A (verbose) string representation of the contained instruction.
      • updatePosition

        protected int updatePosition​(int offset,
                                     int maxOffset)
        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.
        maxOffset - The maximum offset that may be caused by these instructions.
        Returns:
        additional offset caused by possible change of this instruction's length.