Package cs1302.tracer.execution
Class TraceSession
java.lang.Object
cs1302.tracer.execution.TraceSession
- All Implemented Interfaces:
AutoCloseable
Owns a single tracing operation and its cancellation/retention budgets.
The thread-local binding bridges existing extraction helpers; it is never inherited.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classControlled non-success exit from extraction or event handling. -
Constructor Summary
ConstructorsConstructorDescriptionTraceSession(TraceLimits limits, InspectionPolicy inspection, boolean accumulate) Binds a session to the calling thread until closed.TraceSession(TraceLimits limits, InspectionPolicy inspection, boolean accumulate, boolean evalEnumHash) Binds a session to the calling thread until closed with enum hash configuration. -
Method Summary
Modifier and TypeMethodDescriptionbooleanReports whether all captured states are retained.voidallocate(long bytes) Accounts estimated extraction storage before allocation.voidattach(VirtualMachine vm) Attaches a launched guest, handling cancellation during launch.voidAttaches a launched guest process with control over destruction on normal close.voidBegins an atomic snapshot extraction.voidcancel()Requests cancellation from any thread.voidcheck()Checks cancellation and the monotonic tracing deadline.voidcheckThreadCounts(long threads, long frames) Enforces live thread and total frame ceilings before reading stack frames.voidclose()voidcommit(ExecutionSnapshot snapshot) Commits a completed snapshot, retaining only the latest when requested.static TraceSessioncurrent()Returns the calling thread's session, or null for legacy API calls.static voidelements(long count) Accounts element storage before fetching or allocating it.voidEnables chronological thread capture without invoking guest methods.booleanencounter(long id) Accounts a reachable reference before queueing it.voidApplies a resource ceiling, permitting values exactly at the boundary.voidRefreshes final output on the last complete snapshot after successful execution.voidfinishOutput(OutputSlice stdout, OutputSlice stderr) Refreshes final output on the last complete snapshot using explicit slices.voidguestException(String description) Records an observed uncaught exception without losing later output.booleanReturns whether this session has been stopped or cancelled.voidMaterializes all completed snapshot output slices into self-contained buffers.voidmaterializeSnapshots(byte[] sharedStdout, byte[] sharedStderr) Materializes all completed snapshot output slices using shared output buffers.static booleanReturns whether helpers may invoke guest methods.longReturns the per-stream output cap.voidStarts the independent watchdog before guest launch.voidregister(StreamDrainer drainer) Registers an output drainer for session cleanup and counters.Builds a result after tracing or a recoverable failure.voidsetCapturedOutput(String stdout, String stderr, long stdoutBytes, long stderrBytes) Sets isolated guest process output explicitly.static booleanReturns whether helpers should evaluate lazy enum hash codes.Returns a copy of committed snapshots for serialization.voidStops this job; the first observed reason wins.Returns the machine-readable stop reason if stopped, or null.Returns thread capture state, or null for legacy capture.booleanReturns whether a guest was launched, even if it produced no snapshots.static AutoCloseablewithEvalEnumHash(boolean evalEnumHash) Temporarily sets enum hash evaluation setting when running outside a session.
-
Constructor Details
-
TraceSession
Binds a session to the calling thread until closed.- Parameters:
limits- Effective budgets.inspection- Guest inspection policy.accumulate- Whether every snapshot is retained.
-
TraceSession
public TraceSession(TraceLimits limits, InspectionPolicy inspection, boolean accumulate, boolean evalEnumHash) Binds a session to the calling thread until closed with enum hash configuration.- Parameters:
limits- Effective budgets.inspection- Guest inspection policy.accumulate- Whether every snapshot is retained.evalEnumHash- Whether lazy enum hash codes should be evaluated.
-
-
Method Details
-
current
Returns the calling thread's session, or null for legacy API calls.- Returns:
- Current session.
-
enableMultithread
public void enableMultithread()Enables chronological thread capture without invoking guest methods. Use DebugTraceHelper.traceChronological with this accumulating session. -
threadCapture
Returns thread capture state, or null for legacy capture.- Returns:
- Per-job thread capture.
-
checkThreadCounts
public void checkThreadCounts(long threads, long frames) Enforces live thread and total frame ceilings before reading stack frames.- Parameters:
threads- Live application threads.frames- Total frames across these threads.
-
withEvalEnumHash
Temporarily sets enum hash evaluation setting when running outside a session.- Parameters:
evalEnumHash- Whether lazy enum hash codes should be evaluated.- Returns:
- AutoCloseable scope restoring previous setting.
-
mayInvoke
public static boolean mayInvoke()Returns whether helpers may invoke guest methods.- Returns:
- True for trusted inspection.
-
shouldEvalEnumHash
public static boolean shouldEvalEnumHash()Returns whether helpers should evaluate lazy enum hash codes.- Returns:
- True if enabled and methods may be invoked.
-
check
public void check()Checks cancellation and the monotonic tracing deadline. -
phase
Starts the independent watchdog before guest launch.- Parameters:
value- Current execution phase.
-
attach
Attaches a launched guest, handling cancellation during launch.- Parameters:
vm- Guest debugger connection.
-
attach
Attaches a launched guest process with control over destruction on normal close.- Parameters:
guest- Launched process.destroyOnClose- Whether process should be forcibly destroyed on normal close.
-
register
Registers an output drainer for session cleanup and counters.- Parameters:
drainer- Guest stream drainer.
-
outputLimit
public long outputLimit()Returns the per-stream output cap.- Returns:
- Byte limit, or zero for unlimited.
-
cancel
public void cancel()Requests cancellation from any thread. -
isStopped
public boolean isStopped()Returns whether this session has been stopped or cancelled.- Returns:
- True if stopped.
-
stopReason
Returns the machine-readable stop reason if stopped, or null.- Returns:
- Machine-readable stop reason.
-
stop
Stops this job; the first observed reason wins.- Parameters:
value- Machine-readable stop reason.
-
beginSnapshot
public void beginSnapshot()Begins an atomic snapshot extraction. -
elements
public static void elements(long count) Accounts element storage before fetching or allocating it.- Parameters:
count- Elements to inspect.
-
allocate
public void allocate(long bytes) Accounts estimated extraction storage before allocation.- Parameters:
bytes- Conservative storage units.
-
encounter
public boolean encounter(long id) Accounts a reachable reference before queueing it.- Parameters:
id- Guest object identity.- Returns:
- True if this is the first encounter in this snapshot.
-
enforce
Applies a resource ceiling, permitting values exactly at the boundary.- Parameters:
used- Accounted usage.limit- Zero or finite ceiling.failure- Stop reason.
-
commit
Commits a completed snapshot, retaining only the latest when requested.- Parameters:
snapshot- Fully extracted state.
-
guestException
Records an observed uncaught exception without losing later output.- Parameters:
description- Exception type and source location.
-
setCapturedOutput
Sets isolated guest process output explicitly.- Parameters:
stdout- Captured standard output string.stderr- Captured standard error string.stdoutBytes- Total standard output bytes.stderrBytes- Total standard error bytes.
-
traceAvailable
public boolean traceAvailable()Returns whether a guest was launched, even if it produced no snapshots.- Returns:
- Whether trace capture was available.
-
accumulates
public boolean accumulates()Reports whether all captured states are retained.- Returns:
- True for chronological or accumulating jobs.
-
snapshots
Returns a copy of committed snapshots for serialization.- Returns:
- Completed snapshots only.
-
result
Builds a result after tracing or a recoverable failure.- Parameters:
format- Payload format name.payload- Trace or null when unavailable.failure- Optional caught failure.- Returns:
- Versioned result.
-
finishOutput
public void finishOutput()Refreshes final output on the last complete snapshot after successful execution. -
finishOutput
Refreshes final output on the last complete snapshot using explicit slices.- Parameters:
stdout- Captured standard output slice.stderr- Captured standard error slice.
-
materializeSnapshots
public void materializeSnapshots()Materializes all completed snapshot output slices into self-contained buffers. -
materializeSnapshots
public void materializeSnapshots(byte[] sharedStdout, byte[] sharedStderr) Materializes all completed snapshot output slices using shared output buffers.- Parameters:
sharedStdout- Shared standard output buffer.sharedStderr- Shared standard error buffer.
-
close
public void close()- Specified by:
closein interfaceAutoCloseable
-