RFR: 8354727: CompilationPolicy creates too many compiler threads when code cache space is scarce [v5]

Aleksey Shipilev shade at openjdk.org
Wed Jun 25 09:55:30 UTC 2025


On Mon, 23 Jun 2025 06:58:08 GMT, Manuel Hässig <mhaessig at openjdk.org> wrote:

>> Running
>> 
>> 
>> java -XX:+SegmentedCodeCache -XX:ReservedCodeCacheSize=10M -XX:NonNMethodCodeHeapSize=6M \
>>      -XX:ProfiledCodeHeapSize=5M -XX:NonProfiledCodeHeapSize=5M -version
>> 
>> 
>> on a machine with more than 285 cores, this would fail with the message that the specified `NonNMethodCodeHeapSize` is too small to fit all compiler buffers (instead of failing because the sum of the heaps is larger than the `ReservedCodeCacheSize`). Hence, the calculated compiler count is too high. This is due to CompilationPolicy::initialize() checking how many compiler buffers fit into the `ReservedCodeCacheSize`. However, in the case above, this is significantly larger than `NonNMethodCodeHeapSize` (especially on a debug build) and causes a check changed in #17244 to fail. That check was changed to check that all compiler buffers fit into the `NonNMethodCodeHeap` instead of the `NonNMethodCodeHeap` having at least a size of `CodeCacheMinimumUseSpace`.
>> 
>> # Changes
>> 
>> This PR fixes the calculation of the `CICompilerCount` ergonomic. Firstly, @shipilev kindly provided a fix for the compiler buffer size used in the calculation is also correct if we only have C2. Secondly, `NonNMethodHeapSize` is used as the maximum buffer size available for compilers buffers in the calculation of the maximum number of compiler threads instead of `ReservedCodeCacheSize`. Therefore, the check failing in the explanation above can never fail because we set the number of compiler threads only so high that they will always fit into the `NonNMethodCodeHeap`.
>> 
>> This change changes how many compiler threads are created by the `CICompilerCount` ergonomic. For the default value `NonNMethodCodeHeapSize=5M`this limit is 24 compiler threads on a system 285 cores or more for product builds and 20 threads for debug builds on a system with 145 cores or more.
>> 
>> # Testing
>> 
>> - [x] [Github Actions](https://github.com/mhaessig/jdk/actions/runs/15733154809)
>> - [x] tier1 through tier3 plus Oracle internal testing on our supported platforms
>
> Manuel Hässig has updated the pull request with a new target base due to a merge or a rebase. The pull request now contains 16 commits:
> 
>  - Merge branch 'master' into JDK-8354727-policy
>  - Fix merge conflict resolution
>  - Merge branch 'master' into JDK-8354727-policy
>  - Calculate buffer size correctly for c2_only
>    
>    Co-authored-by: Aleksey Shipilev <shade at openjdk.org>
>  - Caclulate how many compiler buffers fit into NonNMethodCodeHeap
>  - Clarify endif
>  - update copyrights
>  - remove leftover <type_traits> include
>  - fix whitebox access to code cache size configs
>  - VMPageSizeConstraintFunc
>  - ... and 6 more: https://git.openjdk.org/jdk/compare/de34bb8e...689b4ea8

Marked as reviewed by shade (Reviewer).

If you merge from current master, windows builds are going to be fixed as well.

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

PR Review: https://git.openjdk.org/jdk/pull/25872#pullrequestreview-2957489922
PR Comment: https://git.openjdk.org/jdk/pull/25872#issuecomment-3004154002


More information about the hotspot-compiler-dev mailing list