Class BytecodeEngine
- java.lang.Object
-
- com.tonic.analysis.execution.core.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 Summary
Constructors Constructor Description BytecodeEngine(BytecodeContext context)Creates an engine configured by the given context, choosing the invocation handler by mode.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description BytecodeEngineaddListener(BytecodeListener listener)Registers an execution listener, merging its declared capabilities into the aggregate set.booleanensureClassInitialized(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.BytecodeResultexecute(MethodEntry method, ConcreteValue... args)Runs the given method to completion, honoring the instruction budget, depth limit, and interrupt requests.CallStackgetCallStack()StackFramegetCurrentFrame()longgetInstructionCount()ConcreteValuegetLastReturnValue()voidinterrupt()Requests that the current execution stop at the next instruction boundary.voidreset()Clears all execution state so the engine can run another method.booleanstep()Executes a single instruction (or completes the top frame) of an in-progress execution.
-
-
-
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 executeargs- 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
-
-