Class Tracer

java.lang.Object
cs1302.tracer.api.Tracer

@API(status=STABLE, since="4.0.0") public final class Tracer extends Object
Executes submitted-source trace jobs with optional binary dependencies while owning preparation and guest cleanup. Requires a full JDK 21 or later and the tracer's runtime dependencies. Submitted-source language features depend on the active JDK and the tracer's parser support. Guest execution is not a sandbox.

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 Details

    • trace

      public static TraceOutcome trace(TraceRequest request)
      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; use trace(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

      public static TraceOutcome trace(TraceRequest request, boolean includePrimitiveBits)
      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) and Double.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

      public static TraceOutcome trace(TraceRequest request, TraceClassPath dependencies)
      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 of trace(TraceRequest, TraceClassPath) and the binary encoding rules of trace(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

      public static BreakpointDiscovery discoverBreakpoints(String source)
      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 from SourceBundle logical paths. Use these paths for the file-qualified breakpoint syntax in TraceRequest. 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

      public static BreakpointDiscovery discoverBreakpoints(String source, TraceClassPath dependencies)
      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 follow discoverBreakpoints(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