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  The PR was verified across **Zero**, **Minimal**, **Client**, 
and **C2-only** builds, as well as **Server** with `-J-Xint`, 
`-J-XX:-TieredCompilation`, `-J-Xcomp`, and `-J-XX:CompilationMode=quick-only`: 
all compile normally with no warnings or failures.

In HotSpot (`CompilationPolicy::highest_compile_level`), `TieredStopAtLevel=1` 
only takes effect when TieredCompilation is enabled, which defaults to false on 
**Zero**, **Minimal**, **Client**, and **C2-only** builds.

The only two edge cases are **C2-only** with explicit 
`-J-XX:+TieredCompilation` and **Server** with 
`-J-XX:CompilationMode=high-only`, where clamping to level 1 drops to 
interpreted mode (still exiting cleanly). I did not add special handling in the 
launcher for these because:

- **libjli** does not know the JVM compiler variant at argument-parsing time 
(and `-J-XX:+TieredCompilation` is a normal no-op on Server builds),
- `-XX:CompilationMode` is already deprecated, and
- both are **uncommon explicit** flag combinations that can be overridden 
directly with `-J-XX:TieredStopAtLevel=4` if needed.

So I didn't special handle these two edge cases though handling them would be 
simple (just declining those options). Please let me know if you think 
otherwise.

-------------

PR Comment: https://git.openjdk.org/jdk/pull/33991#issuecomment-7032171178

Reply via email to