On Fri, 20 Nov 2026 05:03:05 GMT, Dean Long <[email protected]> wrote:
>> Abstract >> -------- >> >> Most `javac` tool calls are short-lived, and for them the cost of the >> default tiered compilation can outweigh what it gives back. This PR adds a >> simple heuristic to the `javac` launcher: when the **total size** of the >> Java source files to be compiled is below a 2 MiB threshold, the launcher >> adds `-XX:TieredStopAtLevel=1` to the JVM options. On the 375 real-world >> projects we measured, all 148 projects that trigger the heuristic (under 2 >> MiB, compiled with `javac` directly) compile at least 5% faster, with >> speedups up to 56%, and no project regresses by 5% or more. >> >> Background >> ---------- >> >> Tiered compilation is costly for short-lived processes and can make up a >> large part of their wall time. For example, a build of tablesaw [1] (398 >> `.java` files, 1.74 MiB of sources) on an AMD Turin machine, with different >> JVM options: >> >> | JIT mode | 1 CPU | 16 CPUs | >> |------------------------------------------------|-------:|--------:| >> | default (C1 with profiling, then C2) | 23.41s | 8.33s | >> | default, speculative traps disabled (*) | 23.35s | 8.24s | >> | C1 with profiling, no C2 (TieredStopAtLevel=3) | 17.78s | 15.71s | >> | C1 only, no profiling (TieredStopAtLevel=1) | 12.07s | 7.42s | >> >> (*) -XX:PerMethodTrapLimit=0 -XX:PerBytecodeTrapLimit=0 >> -XX:PerMethodSpecTrapLimit=0; deoptimizations drop from 593 to 24 >> at 1 CPU and from 1686 to 59 at 16 CPUs. >> >> We can see that tiered compilation accounts for a large share of the cost. >> It first runs slower, profiled code to collect profiles, then spends CPU >> time on C2, and this pays off only over a long run. A short-lived process >> exits before it does. >> >> `javac` is usually such a process: it compiles a set of sources once and >> exits; it is not a long-running service. And while each `javac` run is >> short, frequent invocations in scripts, CI pipelines, and automated >> workflows (such as AI coding agents working on tasks like SWE-bench [2]) >> make the cumulative wall-time overhead significant. >> >> How to fix it >> ------------- >> >> Users expect a fix that works out of the box. The mechanisms that exist >> today do not provide one for `javac`: >> >> - The AOT cache of Project Leyden [3] can hold loaded classes, profiles and >> compiled code, but it has to be created by a training run, and the JDK does >> not ship one for `javac` currently. >> - The default CDS archive that ships with the JDK contains no `javac` >> classes, and ... > > Never mind about using XX:CompilationMode. I forgot that it is already > deprecated. But testing without C1 present is still a good idea. Hi, @dean-long @AlanBateman @lahodaj @jaikiran I have started the discussion in the `hotspot-compiler-dev` mailing list, the subject is `Document the '-XX:TieredStopAtLevel' option for short-lived JVM processes`. I would greatly appreciate if you could share your thoughts on this issue, thanks! ------------- PR Comment: https://git.openjdk.org/jdk/pull/33991#issuecomment-7306925782
