Class BytecodeEngine


  • public final class BytecodeEngine
    extends Object
    Interpreter that executes JVM bytecode over an explicit call stack, dispatching each instruction and modeling invocation, field, heap, and exception semantics.
    • Constructor Detail

      • BytecodeEngine

        public BytecodeEngine​(BytecodeContext context)
        Creates an engine configured by the given context, choosing the invocation handler by mode.
        Parameters:
        context - the execution configuration
        Throws:
        IllegalArgumentException - if context is null
    • Method Detail

      • getCallStack

        public CallStack getCallStack()
        Returns:
        the call stack
      • getInstructionCount

        public long getInstructionCount()
        Returns:
        the instruction count
      • getLastReturnValue

        public ConcreteValue getLastReturnValue()
        Returns:
        the last return value
      • execute

        public BytecodeResult execute​(MethodEntry method,
                                      ConcreteValue... args)
        Runs the given method to completion, honoring the instruction budget, depth limit, and interrupt requests.
        Parameters:
        method - the method to execute
        args - argument values for the initial frame
        Returns:
        the execution outcome with statistics
      • step

        public boolean step()
        Executes a single instruction (or completes the top frame) of an in-progress execution.
        Returns:
        true if frames remain on the call stack, false when execution has finished
      • addListener

        public BytecodeEngine addListener​(BytecodeListener listener)
        Registers an execution listener, merging its declared capabilities into the aggregate set.
        Parameters:
        listener - the listener to add; ignored if null
        Returns:
        this engine
      • interrupt

        public void interrupt()
        Requests that the current execution stop at the next instruction boundary.
      • reset

        public void reset()
        Clears all execution state so the engine can run another method.
      • getCurrentFrame

        public StackFrame getCurrentFrame()
        Returns:
        the frame on top of the call stack, or null if the stack is empty
      • ensureClassInitialized

        public boolean ensureClassInitialized​(String className)
        Runs the static initializer of the named class (and its superclasses) at most once, on a fresh engine sharing this engine's initialized-class set.
        Parameters:
        className - internal name of the class to initialize
        Returns:
        true if the class initialized cleanly or needs no initialization, false if its static initializer did not complete