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
@@ -224,27 +221,21 @@ The JavaScript tracer uses Babel instrumentation to capture function calls durin
224
221
</Tab>
225
222
<Tabtitle="Java">
226
223
227
-
The Java tracer uses a **two-stage approach**: JFR (Java Flight Recorder) for profiling, then a bytecode instrumentation agent for argument capture.
224
+
The Java tracer uses a **two-stage approach**: JFR (Java Flight Recorder) for accurate profiling, then a bytecode instrumentation agent for argument capture.
228
225
229
226
1.**Trace and optimize a Java program**
230
227
231
-
Pass your Java command after`codeflash optimize`:
228
+
Replace your `java` command with`codeflash optimize java`:
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.
238
+
Codeflash will run your program twice (once for profiling, once for argument capture), generate JUnit replay tests, then optimize the most impactful functions.
248
239
249
240
2.**Long-running programs**
250
241
@@ -254,40 +245,30 @@ The Java tracer uses a **two-stage approach**: JFR (Java Flight Recorder) for pr
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.
248
+
Each stage runs for at most 30 seconds, then the program is terminated and captured data is processed.
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`.
256
+
This generates replay tests in `src/test/java/codeflash/replay/` without running the optimizer.
266
257
267
-
Options:
258
+
More Options:
268
259
269
260
-`--timeout`: Maximum time (seconds) for each tracing stage.
270
261
-`--max-function-count`: Maximum captures per method (default: 100).
271
262
272
263
<Info>
273
264
**How the Java tracer works:**
274
265
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.
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.
276
267
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.
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 per serialization prevents hangs on complex object graphs.
278
269
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.
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.
282
271
</Info>
283
272
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