RFR: 8353290: C2: Refactor PhaseIdealLoop::is_counted_loop() [v28]
Christian Hagedorn
chagedorn at openjdk.org
Fri Jan 9 22:47:33 UTC 2026
On Wed, 7 Jan 2026 17:08:57 GMT, Kangcheng Xu <kxu at openjdk.org> wrote:
>> This PR refactors `PhaseIdealLoop::is_counted_loop()` into (mostly) `CountedLoopConverter::is_counted_loop()` and `CountedLoopConverter::convert()` to decouple the detection and conversion code. This enables us to try different loop configurations easily and finally convert once a counted loop is found.
>>
>> A nested `PhaseIdealLoop::CountedLoopConverter` class is created to handle the context, but I'm not if this is the best name or place for it. Please let me know what you think.
>>
>> Blocks [JDK-8336759](https://bugs.openjdk.org/browse/JDK-8336759).
>
> Kangcheng Xu has updated the pull request with a new target base due to a merge or a rebase. The pull request now contains 50 commits:
>
> - Merge remote-tracking branch 'origin/master' into counted-loop-refactor
> - Update license header years
> - Merge remote-tracking branch 'origin/master' into counted-loop-refactor
> - remove trailing whitespaces
> - Merge remote-tracking branch 'origin/master' into counted-loop-refactor
> - additional suggestions from code review
> - Apply suggestions from code review
>
> Co-authored-by: Christian Hagedorn <christian.hagedorn at oracle.com>
> - fix trip counter loop-variant detection
> - fix bad merge with ctrl_is_member()
> - Merge remote-tracking branch 'origin/master' into counted-loop-refactor
>
> # Conflicts:
> # src/hotspot/share/opto/loopnode.cpp
> - ... and 40 more: https://git.openjdk.org/jdk/compare/640343f7...7783d609
There are quite some failures with the same assert (probably all related). Can be triggered, for example, by running `compiler/predicates/assertion/TestAssertionPredicates.java#NoLoopPredicationXbatch` with `-XX:+UseSerialGC`:
#
# A fatal error has been detected by the Java Runtime Environment:
#
# Internal Error (/opt/mach5/mesos/work_dir/slaves/da1065b5-7b94-4f0d-85e9-a3a252b9a32e-S11864/frameworks/1735e8a2-a1db-478c-8104-60c8b0af87dd-0196/executors/c6afc1de-b432-44d4-bd71-2c035e46dc9e/runs/88cff2b5-6582-4c32-8cb2-92c8c5d2feeb/workspace/open/src/hotspot/share/opto/loopnode.hpp:1450), pid=182310, tid=182326
# Error: assert(!has_ctrl(n)) failed
..........
Current CompileTask:
C2:300 95 b 4 compiler.predicates.assertion.TestAssertionPredicates::testTrySplitUpNonOpaqueExpressionNode (163 bytes)
Stack: [0x00007f27d75cc000,0x00007f27d76cc000], sp=0x00007f27d76c6b00, free space=1002k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
V [libjvm.so+0x156bff8] PhaseIdealLoop::get_loop(Node const*) const+0x68 (loopnode.hpp:1450)
V [libjvm.so+0x15a07f7] IdealLoopTree::remove_safepoints(PhaseIdealLoop*, bool)+0x167 (loopnode.cpp:4672)
V [libjvm.so+0x15b7dee] IdealLoopTree::counted_loop(PhaseIdealLoop*)+0x11e (loopnode.cpp:4700)
V [libjvm.so+0x15b7d7a] IdealLoopTree::counted_loop(PhaseIdealLoop*)+0xaa (loopnode.cpp:4719)
V [libjvm.so+0x15b7d7a] IdealLoopTree::counted_loop(PhaseIdealLoop*)+0xaa (loopnode.cpp:4719)
V [libjvm.so+0x15bcc07] PhaseIdealLoop::build_and_optimize()+0xaf7 (loopnode.cpp:5285)
V [libjvm.so+0xbb8130] PhaseIdealLoop::optimize(PhaseIterGVN&, LoopOptsMode)+0x4c0 (loopnode.hpp:1226)
V [libjvm.so+0xbb1995] Compile::Optimize()+0x685 (compile.cpp:2466)
V [libjvm.so+0xbb5173] Compile::Compile(ciEnv*, ciMethod*, int, Options, DirectiveSet*)+0x2023 (compile.cpp:862)
V [libjvm.so+0x9cc3e8] C2Compiler::compile_method(ciEnv*, ciMethod*, int, bool, DirectiveSet*)+0x498 (c2compiler.cpp:147)
V [libjvm.so+0xbc4660] CompileBroker::invoke_compiler_on_method(CompileTask*)+0x780 (compileBroker.cpp:2345)
V [libjvm.so+0xbc5ec0] CompileBroker::compiler_thread_loop()+0x530 (compileBroker.cpp:1989)
V [libjvm.so+0x112635b] JavaThread::thread_main_inner()+0x13b (javaThread.cpp:776)
V [libjvm.so+0x1bb30b6] Thread::call_run()+0xb6 (thread.cpp:242)
V [libjvm.so+0x1808c98] thread_native_entry(Thread*)+0x118 (os_linux.cpp:860)
The branch with the old vs. new code also hit the diff assert for a closed test. I will check next week if I can extract a reproducer to share.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/24458#issuecomment-3730828674
More information about the hotspot-compiler-dev
mailing list