You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docs: update Java tracer documentation to match verified behavior
Add mvn/gradle test suite examples, fix replay test description,
document current limitations (void methods, mvnw search, --add-opens).
Remove unverified claims.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@@ -221,21 +224,27 @@ The JavaScript tracer uses Babel instrumentation to capture function calls durin
221
224
</Tab>
222
225
<Tabtitle="Java">
223
226
224
-
The Java tracer uses a **two-stage approach**: JFR (Java Flight Recorder) for accurate profiling, then a bytecode instrumentation agent for argument capture.
227
+
The Java tracer uses a **two-stage approach**: JFR (Java Flight Recorder) for profiling, then a bytecode instrumentation agent for argument capture.
225
228
226
229
1.**Trace and optimize a Java program**
227
230
228
-
Replace your `java` command with`codeflash optimize java`:
Codeflash will run your program twice (once for profiling, once for argument capture), generate JUnit replay tests, then optimize the most impactful functions.
247
+
Codeflash runs your command twice (once for profiling, once for argument capture), generates JUnit replay tests from captured inputs, then optimizes the highest-impact functions.
239
248
240
249
2.**Long-running programs**
241
250
@@ -245,30 +254,40 @@ The Java tracer uses a **two-stage approach**: JFR (Java Flight Recorder) for ac
Each stage runs for at most 30 seconds, then the program is terminated and captured data is processed.
257
+
Each stage runs for at most the specified seconds, then the program receives SIGTERM (allowing JFR dump and shutdown hooks to run), followed by SIGKILL if it doesn't exit within 5 seconds.
This generates replay tests in `src/test/java/codeflash/replay/` without running the optimizer.
265
+
This generates replay tests in `src/test/java/codeflash/replay/` without running the optimizer. You can inspect the generated tests and run the optimizer later with `codeflash --replay-test path/to/ReplayTest.java`.
257
266
258
-
More Options:
267
+
Options:
259
268
260
269
-`--timeout`: Maximum time (seconds) for each tracing stage.
261
270
-`--max-function-count`: Maximum captures per method (default: 100).
262
271
263
272
<Info>
264
273
**How the Java tracer works:**
265
274
266
-
-**Stage 1 (JFR)**: Runs your program with Java Flight Recorder enabled. JFR is built into the JVM (Java 11+), has ~1% overhead, and doesn't interfere with JIT compilation. This produces accurate method-level CPU profiling data.
275
+
-**Stage 1 (JFR profiling)**: Runs your command with Java Flight Recorder enabled via `JAVA_TOOL_OPTIONS`. JFR is built into the JVM (Java 11+)and produces method-level CPU sampling data used to rank functions by impact.
267
276
268
-
-**Stage 2 (Agent)**: Runs your program with a bytecode instrumentation agent injected via `JAVA_TOOL_OPTIONS`. The agent intercepts method entry points, serializes arguments using Kryo, and writes them to an SQLite database. A 500ms timeout perserialization prevents hangs on complex object graphs.
277
+
-**Stage 2 (argument capture)**: Runs your command again with a bytecode instrumentation agent (`codeflash-runtime`) injected via `JAVA_TOOL_OPTIONS`. The agent uses ASM to intercept method entries, serializes arguments with Kryo, and writes them to an SQLite database. A per-serialization timeout prevents hangs on complex object graphs. Constructors and synthetic methods are skipped.
269
278
270
-
-**Replay Tests**: Generated JUnit 5 test classes that deserialize captured arguments and invoke the original methods via reflection. These tests exercise your code with real-world inputs.
279
+
-**Replay tests**: Generated JUnit test classes (JUnit 5 by default, JUnit 4 if detected in the project) that use `ReplayHelper` to deserialize captured arguments from the trace database and invoke the original methods. Each captured invocation becomes a separate test method. These tests exercise your code with the exact inputs observed during tracing.
280
+
281
+
-**Optimization**: Functions are ranked by JFR addressable time. For each function, Codeflash generates optimization candidates, verifies correctness against both replay tests and AI-generated regression tests, then benchmarks performance to select the best candidate.
271
282
</Info>
272
283
284
+
<Warning>
285
+
**Current limitations:**
286
+
287
+
- The tracer captures arguments for methods that return values. Void methods are traced for profiling (Stage 1) but argument capture may not produce usable replay tests for them.
288
+
- The `--add-opens` JVM flags are automatically injected for Java 16+ compatibility with Kryo serialization.
289
+
- For Maven projects, the Maven wrapper (`mvnw`) is preferred over system Maven. Codeflash searches parent directories to find it in multi-module projects.
0 commit comments