PrintInstructionTracer
public final class PrintInstructionTracer implements InstructionTracer- Inheritance
ObjectPrintInstructionTracer
- Implements
An InstructionTracer implementation that prints a textual trace of executed bytecode instructions.
Each time an instruction is about to execute, this tracer formats a single line containing:
a monotonically increasing instruction counter,
the qualified root name of the
BytecodeNodebeing interpreted, anda human readable representation of the instruction at the current bytecode index.
Output is delivered to a user-supplied Consumer<String> (for example, System.out::println) or to a PrintStream via the newBuilder(PrintStream) convenience factory.
A tracer may optionally be restricted to a subset of bytecode roots by installing a filter predicate. If a BytecodeNode does not match the filter, its instructions are skipped.
This tracer is intended for debugging and profiling during development. It runs on the language execution thread and executes on the hot path before every instruction; it should not be left enabled in production code.
Methods4 + 1 inherited
void onInstructionEnter(InstructionTracer.InstructionAccess, BytecodeNode, int, Frame)
onInstructionEnter
since 25.1public void onInstructionEnter(
InstructionTracer.InstructionAccess access,
BytecodeNode bytecode,
int bytecodeIndex,
Frame frame
)Called immediately before executing the instruction at bytecodeIndex of the given bytecode node.
This implementation formats and emits a single trace line for the current instruction, unless the BytecodeNode is excluded by the active filter.
Parameters
accessInstructionTracer.InstructionAccess- accessor to query information about the current instruction, valid only during this call
bytecodeBytecodeNode- the
BytecodeNodecurrently being interpreted bytecodeIndexint- the bytecode index (BCI) of the instruction to be executed
frameFrame- the current frame for the root being interpreted
Overrides onInstructionEnter().
void reset()
reset
since 25.1public void reset()Resets the internal instruction counter back to zero.
This only affects the counter included in the printed trace lines. It does not clear any output sink or filter configuration.
static PrintInstructionTracer.Builder newBuilder(Consumer<String>)
newBuilder
staticsince 25.1public static PrintInstructionTracer.Builder newBuilder(Consumer< String> out)Creates a new Builder that will emit trace lines to the given consumer.
Each generated line is already formatted. The consumer is typically a logger or System.out::println, but any Consumer is accepted.
Returns
PrintInstructionTracer.Builder- a new builder
static PrintInstructionTracer.Builder newBuilder(PrintStream)
newBuilder
staticsince 25.1public static PrintInstructionTracer.Builder newBuilder(PrintStream out)Convenience overload of newBuilder(Consumer) that writes to a PrintStream.
The resulting tracer will call PrintStream.println(String) for every traced instruction.
Parameters
outPrintStream- a print stream (for example
System.out)
Returns
PrintInstructionTracer.Builder- a new builder
Nested types
public static final class .BuilderBuilder for
PrintInstructionTracerinstances.