cs1302-tracer 4.0.0 API

Embed Java execution tracing in your application with cs1302-tracer. Submit self-contained Java source, discover executable breakpoints, or process batch jobs, and receive Python Tutor or modern JSON output.

Using the Java API

Start with a single trace

Tracer compiles the submitted program, traces it in a guest JVM, and releases the job's resources before returning a detached TraceOutcome. This complete example prints the guest's output, followed by the JSON result envelope:

import cs1302.tracer.api.TraceOutcome;
import cs1302.tracer.api.TraceRequest;
import cs1302.tracer.api.Tracer;

/** Demonstrates tracing a Java program through the library API. */
public class TraceExample {
    public static void main(String[] args) {
        String source = """
            /** Prints a greeting from the traced program. */
            public class Main {
                public static void main(String[] args) {
                    System.out.println("hello");
                } // main
            } // Main
            """;
        TraceOutcome outcome = Tracer.trace(new TraceRequest(source));
        System.out.print(outcome.stdout());
        System.out.println(outcome.json());
    } // main
} // TraceExample

The convenience TraceRequest constructor selects Python Tutor output, main-exit capture, finite instructor budgets, and trusted inspection. Use the full constructor to supply stdin, choose a format and capture settings, or configure TraceLimits and InspectionPolicy. Input is source text, including the documented delimited multi-file syntax; neighboring source files are not discovered automatically.

Choose an entry point

  • Tracer.trace: execute one self-contained tracing request.
  • Tracer.discoverBreakpoints: compile source and discover executable lines without running guest code. Inspect the returned locations and preparation diagnostics.
  • BatchTracer: process the NDJSON batch protocol with reusable workers. Use try-with-resources to release workers; call processStream sequentially. Input and output streams remain caller-owned.

Read the outcome

Expected compilation and execution failures are represented in the outcome. Inspect status(), complete(), stopReason(), and diagnostics() before treating a trace as complete. json() returns the result envelope; traceJson() returns its trace payload, or the JSON literal null when no payload is available. The payload follows batch result-envelope conventions, rather than ordinary CLI selected-breakpoint map presentation. Outcomes remain usable after cleanup and after subsequent jobs.

Runtime and compatibility

Run with a full JDK 21 or later and the tracer's runtime dependencies. The regular JAR is intended for library integration; the dependency-bundled JAR is the executable CLI distribution. Both use the automatic module name cs1302.tracer. Features of submitted programs depend on the active JDK.

API Guardian is a transitive compile dependency. Maven resolves it automatically; manual compilation against the regular JAR also requires the API Guardian JAR to avoid missing annotation warnings. It supplies stability metadata, while supported method and field types remain project-owned or ordinary Java types.

The supported Java interface is cs1302.tracer.api, together with the App launcher. Packages under cs1302.tracer.internal are implementation details outside that contract. Java API compatibility and serialized JSON compatibility are separate concerns. Guest execution is not a sandbox: resource budgets do not replace process or host isolation.

Supported types declare @API(status = STABLE, since = "4.0.0"), promising compatibility throughout the 4.x series. Public implementation types declare INTERNAL. A type's status applies to its public members unless explicitly overridden. The since value dates the stability status, rather than the original introduction of the code.

Further reading

The following links lead to the current development documentation:

Packages
Package
Description
Stable command-line launcher for the tracer.
Supported Java interface for self-contained tracing, breakpoint discovery, and NDJSON batch processing.