Class StackFrame


  • public final class StackFrame
    extends Object
    One interpreter activation: a method's operand stack, locals, program counter, and completion state.
    • Constructor Detail

      • StackFrame

        public StackFrame​(MethodEntry method,
                          ConcreteValue[] args)
        Creates a frame for a method invocation with the given arguments bound to locals.
        Parameters:
        method - the method to execute
        args - argument values placed into the leading local slots
        Throws:
        IllegalArgumentException - if the method is null or has no code attribute
    • Method Detail

      • getMethod

        public MethodEntry getMethod()
        Returns:
        the method
      • getCode

        public CodeWriter getCode()
        Returns:
        the code
      • isCompleted

        public boolean isCompleted()
        Returns:
        whether completed
      • getException

        public ObjectInstance getException()
        Returns:
        the exception
      • getPC

        public int getPC()
        Returns:
        the current program counter
      • setPC

        public void setPC​(int pc)
        Moves the program counter to an absolute bytecode offset.
        Parameters:
        pc - the target offset
        Throws:
        IllegalArgumentException - if the offset is negative or beyond the bytecode length
      • advancePC

        public void advancePC​(int delta)
        Advances the program counter past the current instruction.
        Parameters:
        delta - the number of bytes to advance
        Throws:
        IllegalArgumentException - if the delta is negative
      • getCurrentInstruction

        public Instruction getCurrentInstruction()
        Looks up the instruction at the current program counter.
        Returns:
        the instruction at the PC, or null if none exists there
      • getInstructionAt

        public Instruction getInstructionAt​(int offset)
        Looks up the instruction starting at a bytecode offset.
        Parameters:
        offset - the bytecode offset to find
        Returns:
        the instruction at that offset, or null if none starts there
      • hasMoreInstructions

        public boolean hasMoreInstructions()
        Checks whether execution can continue in this frame.
        Returns:
        true if an instruction exists at the PC and the frame is not completed
      • complete

        public void complete​(ConcreteValue returnValue)
        Marks the frame as normally completed.
        Parameters:
        returnValue - the method's return value, or null for void
        Throws:
        IllegalStateException - if the frame is already completed
      • completeExceptionally

        public void completeExceptionally​(ObjectInstance exception)
        Marks the frame as completed by a thrown exception.
        Parameters:
        exception - the exception object terminating the frame
        Throws:
        IllegalStateException - if the frame is already completed
        IllegalArgumentException - if the exception is null
      • getReturnValue

        public ConcreteValue getReturnValue()
        Retrieves the return value of a completed frame.
        Returns:
        the return value, or null for void
        Throws:
        IllegalStateException - if the frame has not completed
      • getMethodSignature

        public String getMethodSignature()
        Returns:
        the owner, name, and descriptor as one signature string
      • getLineNumber

        public int getLineNumber()
        Maps the current PC to a source line via the LineNumberTable attribute.
        Returns:
        the source line for the PC, or -1 if no table entry covers it