Class AbstractState


  • public class AbstractState
    extends Object
    The simulated operand stack and local slots at one point of bytecode lifting.
    • Constructor Detail

      • AbstractState

        public AbstractState()
        Creates an empty state.
      • AbstractState

        public AbstractState​(AbstractState other)
        Creates a deep copy of another state.
        Parameters:
        other - the state to copy
    • Method Detail

      • push

        public void push​(Value value)
        Pushes a value onto the simulated stack.
        Parameters:
        value - the value to push
      • setDebugContext

        public static void setDebugContext​(String blockName,
                                           int offset)
        Records the block and offset reported by stack-underflow errors.
        Parameters:
        blockName - the name of the block being lifted
        offset - the bytecode offset being lifted
      • pop

        public Value pop()
        Pops the top stack value.
        Returns:
        the popped value
        Throws:
        IllegalStateException - if the stack is empty
      • peek

        public Value peek()
        Returns the top stack value without popping it.
        Returns:
        the top value
        Throws:
        IllegalStateException - if the stack is empty
      • peek

        public Value peek​(int depth)
        Returns the stack value a given depth below the top without popping.
        Parameters:
        depth - the number of values below the top, 0 being the top
        Returns:
        the value at that depth
        Throws:
        IllegalStateException - if the stack has no value at that depth
      • getStackSize

        public int getStackSize()
        Returns:
        the number of values on the stack
      • isStackEmpty

        public boolean isStackEmpty()
        Returns:
        true if the stack is empty
      • setLocal

        public void setLocal​(int index,
                             Value value)
        Parameters:
        index - the local slot
        value - the value the slot now holds
      • getLocal

        public Value getLocal​(int index)
        Parameters:
        index - the local slot
        Returns:
        the value in the slot, or null if unset
      • hasLocal

        public boolean hasLocal​(int index)
        Parameters:
        index - the local slot
        Returns:
        true if the slot holds a value
      • getLocalIndices

        public Set<Integer> getLocalIndices()
        Returns:
        a copy of the set of occupied local slots
      • clearStack

        public void clearStack()
        Removes all values from the stack, leaving locals untouched.
      • copy

        public AbstractState copy()
        Creates a deep copy of this state.
        Returns:
        the copy
      • merge

        public void merge​(AbstractState other)
        Adopts locals from another state for slots this state does not yet hold; the stack is untouched.
        Parameters:
        other - the state to merge from
      • getStackValues

        public List<Value> getStackValues()
        Returns:
        a copy of the stack values, top first
      • setStackValue

        public void setStackValue​(int index,
                                  Value value)
        Replaces the value at a stack slot in place.
        Parameters:
        index - stack slot index
        value - replacement value