On Mon, 30 Nov 2026 13:46:13 GMT, Jaikiran Pai <[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 ...
>
> Hello Eric,
> 
>> Any suggestions on how we should proceed with this issue?—discussing this on 
>> the mailing list first, or a small doc-only update to the java/javac man 
>> pages? As far as I can see, documenting -XX:TieredStopAtLevel=1 ...
> 
> Whether or not to document the `-XX:TieredStopAtLevel` JVM option in the 
> `java` man page can be discussed in the hotspot-compiler-dev mailing list 
> https://mail.openjdk.org/mail/lists/hotspot-compiler-dev.openjdk.org/. If you 
> would like to start a discussion there, please subscribe to the mailing list 
> if you haven't already (instructions are available in that linked page).

Hi @jaikiran, thank you for your suggestion, I'll start a discussion about this 
issue there.

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

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

Reply via email to