Source compilation requires the JDK's jdk.compiler module. Tracing also requires jdk.jdi
and permission to launch a child JVM through JDI's default launching connector, using the host JVM's
java.home. The tracer implementation must be available as a direct filesystem JAR or class directory;
nested-archive and other non-filesystem code-source locations are not supported for guest launch.
discoverBreakpoints(String) compiles and inspects submitted classes without launching a guest.
Each trace call owns its worker and releases guest and preparation resources before returning.
Single-stack requests use reusable-guest execution semantics: the job ends when its entry point returns,
and lingering job threads are interrupted. Unexpected reusable-guest termination, including
System.exit(0), is reported as guest_exit unless an earlier stop or failure takes precedence.
Multithread requests use a fresh dedicated guest instead.
Both forms return detached TraceOutcome metadata and JSON. Expected validation, preparation,
and execution failures are reported in that outcome rather than as checked exceptions.
Every trace and discoverBreakpoints overload may be called concurrently from multiple
threads in one JVM, and each call is independent. A call owns its temporary compilation files and parser
state and, when tracing, its trace session, worker, and guest JVM; its outcome does not depend on other calls
in progress. Requests, limits, dependency selections, outcomes, and discovery results are immutable and may be
shared between threads; builders are not thread-safe. Calls that borrow the same dependency files require
those files to remain available and unchanged until every such call returns. This class applies no
concurrency limit: each concurrent trace launches its own guest JVM, so bound concurrency to the host's
process, memory, and CPU capacity. Concurrent calls in one process are not isolated from each other or
from the host.
Completion metadata reflects failures observed by the tracer. In single-stack reusable-guest execution,
an uncaught exception thrown inside JDK or precompiled dependency code can be printed to captured stderr
while the outcome still reports completed and complete=true. An uncaught throw directly
from submitted code is recognized as guest_exception. Do not treat completion metadata
alone as proof of successful guest execution.
-
Method Summary
Modifier and TypeMethodDescriptionstatic BreakpointDiscoverydiscoverBreakpoints(String source) Compiles submitted sources and discovers executable lines without running guest code.static BreakpointDiscoverydiscoverBreakpoints(String source, TraceClassPath dependencies) Compiles submitted sources with binary dependencies and discovers their executable lines.static TraceOutcometrace(TraceRequest request) Traces a program and returns a detached result in the existing result-envelope format.static TraceOutcometrace(TraceRequest request, boolean includePrimitiveBits) Traces a program with optional binary metadata alongside primitive literal values.static TraceOutcometrace(TraceRequest request, TraceClassPath dependencies) Traces submitted sources with binary dependencies available to compilation and execution.static TraceOutcometrace(TraceRequest request, TraceClassPath dependencies, boolean includePrimitiveBits) Traces submitted sources with binary dependencies and optional primitive binary metadata.
-
Method Details
-
trace
Traces a program and returns a detached result in the existing result-envelope format. Uses the request's limits and inspection policy;TraceRequest(String)supplies finite instructor limits and trusted inspection. See the class contract for outcome limitations. Primitive binary metadata is omitted; usetrace(TraceRequest, boolean)to include it.- Parameters:
request- Source, capture selection, and resource policy.- Returns:
- Detached completed, stopped, or failed outcome, valid after guest cleanup.
- Throws:
NullPointerException- If the request is null.
-
trace
Traces a program with optional binary metadata alongside primitive literal values. Existing values and capture budgets are unchanged; enabled output is larger. Binary encodings describe the values received through JDI, not physical guest storage. Expected validation, compilation, and execution failures are represented by the outcome, subject to the class contract's single-stack exception-recognition limitation. Source preparation and guest resources are released before return. Submitted sources may use the documented multi-file delimiters; neighboring filesystem sources are not discovered.See the encoding definitions and references for normative specifications, informative explanations, and tracer-defined conventions. Floating-point conversion follows the contracts of
Float.floatToRawIntBits(float)andDouble.doubleToRawLongBits(double).- Parameters:
request- Source, capture selection, and resource policy.includePrimitiveBits- Whether to include primitive binary metadata in either format.- Returns:
- Detached completed, stopped, or failed outcome, valid after guest cleanup.
- Throws:
NullPointerException- If the request is null.- Since:
- 4.1.0
-
trace
Traces submitted sources with binary dependencies available to compilation and execution. Dependencies do not receive source-line breakpoints. Filesystem selection and optional copying occur afresh for this call; borrowed dependencies must remain available and unchanged until return. Expected preparation and execution failures are represented by the outcome, subject to the class contract's single-stack exception-recognition limitation.- Parameters:
request- Source, capture selection, and resource policy.dependencies- Ordered binary dependency selections and ownership policy.- Returns:
- Completed, stopped, or failed job outcome, without primitive binary metadata.
- Throws:
NullPointerException- If either argument is null.- Since:
- 4.1.0
-
trace
public static TraceOutcome trace(TraceRequest request, TraceClassPath dependencies, boolean includePrimitiveBits) Traces submitted sources with binary dependencies and optional primitive binary metadata. Uses the dependency ownership and preparation rules oftrace(TraceRequest, TraceClassPath)and the binary encoding rules oftrace(TraceRequest, boolean). Annotation processing is disabled during guest compilation. Source, dependency, and guest resources are released before return. See the class contract for host-runtime requirements and outcome limitations.- Parameters:
request- Source, capture selection, and resource policy.dependencies- Ordered binary dependency selections and ownership policy.includePrimitiveBits- Whether to include primitive binary metadata in either format.- Returns:
- Detached completed, stopped, or failed outcome, valid after guest cleanup.
- Throws:
NullPointerException- If the request or dependencies are null.- Since:
- 4.1.0
-
discoverBreakpoints
Compiles submitted sources and discovers executable lines without running guest code. Only submitted sources participate in discovery. Locations are sorted by package-relative source path and then line number. Preparation failures produce diagnostics instead of locations, and temporary compilation resources are released before return. Source compilation requires a full JDK; discovery does not launch a guest JVM or execute submitted code. Returned paths use the compiled classes' package and debug source-file name, which can differ fromSourceBundlelogical paths. Use these paths for the file-qualified breakpoint syntax inTraceRequest. Discovery uses the same entry-point preparation as tracing: the first submitted file with a recognized main-method candidate must contain exactly one such candidate. Missing or ambiguous entry points produce preparation diagnostics, even when the source is otherwise compilable.- Parameters:
source- Single-file or delimited multi-file source text.- Returns:
- Executable locations or preparation diagnostics.
-
discoverBreakpoints
Compiles submitted sources with binary dependencies and discovers their executable lines. Dependency classes are not scanned for breakpoints, and no guest is launched. Dependency selection and optional copying occur afresh for this call; all owned resources are released before return. Preparation failures produce diagnostics instead of locations. Returned locations followdiscoverBreakpoints(String)path and line conventions.- Parameters:
source- Single-file or delimited multi-file source text.dependencies- Ordered binary dependency selections and ownership policy.- Returns:
- Executable submitted-source locations or preparation diagnostics.
- Throws:
NullPointerException- If dependencies are null.- Since:
- 4.1.0
-