JDK-8284944 : assert(cnt++ < 40) failed: infinite cycle in loop optimization
  • Type: Bug
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 8,11,17.0.2,18
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2022-04-14
  • Updated: 2022-07-18
  • Resolved: 2022-05-25
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 11 JDK 17 JDK 19
11.0.17-oracleFixed 17.0.5-oracleFixed 19 b24Fixed
Related Reports
Relates :  
Relates :  
Relates :  
Description
ADDITIONAL SYSTEM INFORMATION :
OS: Ubuntu18.04

JDK8
$ java -version
openjdk version "1.8.0-internal-fastdebug"
OpenJDK Runtime Environment (build 1.8.0-internal-fastdebug-user_2022_03_11_16_03-b00)
OpenJDK 64-Bit Server VM (build 25.71-b00-fastdebug, mixed mode)

JDK11
$ java -version
openjdk version "11.0.15-internal" 2022-04-19
OpenJDK Runtime Environment (fastdebug build 11.0.15-internal+0-adhoc.user.jdk11u)
OpenJDK 64-Bit Server VM (fastdebug build 11.0.15-internal+0-adhoc.user.jdk11u, mixed mode, sharing)

JDK17
$ java -version
openjdk version "17.0.3-internal" 2022-04-19
OpenJDK Runtime Environment (fastdebug build 17.0.3-internal+0-adhoc.user.jdk17u)
OpenJDK 64-Bit Server VM (fastdebug build 17.0.3-internal+0-adhoc.user.jdk17u, mixed mode, sharing)

A DESCRIPTION OF THE PROBLEM :
JVM crashed when running the test case with option -XX:-PartialPeelLoop under jdk8, jdk11, jdk17.

Reproduce:
$ java -Xcomp -XX:-PartialPeelLoop Test
i i10 i11 = 125,270,93
i12 i13 i14 = 72879,2,2
i15 i16 i17 = 174,0,148
i18 fArr iArr1 = 173,-4543399874554511360,-327513
Test.instanceCount Test.fFld Test.bFld = 6542009568855372046,1092616192,1
dFld Test.dArrFld Test.lArrFld = 4613701581922619432,4668565628057730655,-6269174457476628831
vMeth1_check_sum: -27854160
lMeth_check_sum: 1587511662398500560
vMeth_check_sum: 2853594718
i i10 i11 = 125,270,93
i12 i13 i14 = 72879,2,2
i15 i16 i17 = 174,0,148
i18 fArr iArr1 = 173,-4543399874554511360,-327513
Test.instanceCount Test.fFld Test.bFld = 6542009568855372046,1092616192,1
dFld Test.dArrFld Test.lArrFld = 4615953381736304680,4668565628057730655,-6269174457476628831
vMeth1_check_sum: -55708320
lMeth_check_sum: 3175023324796980640
vMeth_check_sum: 5707189439
# To suppress the following error report, specify this argument
# after -XX: or in .hotspotrc:  SuppressErrorAt=/compile.cpp:2021
#
# A fatal error has been detected by the Java Runtime Environment:
#
#  Internal Error (/home/user/jdk_source/jdk17u/src/hotspot/share/opto/compile.cpp:2021), pid=44309, tid=44322
#  assert(cnt++ < 40) failed: infinite cycle in loop optimization
#
# JRE version: OpenJDK Runtime Environment (17.0.3) (fastdebug build 17.0.3-internal+0-adhoc.user.jdk17u)
# Java VM: OpenJDK 64-Bit Server VM (fastdebug 17.0.3-internal+0-adhoc.user.jdk17u, compiled mode, sharing, tiered, compressed oops, compressed class ptrs, g1 gc, linux-amd64)
# Problematic frame:
# V  [libjvm.so+0x950bc6]  Compile::Optimize()+0x1006
#
# No core dump will be written. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
# An error report file with more information is saved as:
# /home/user/hs_err_pid44309.log
#
# Compiler replay data is saved as:
# /home/user/replay_pid44309.log
#
# If you would like to submit a bug report, please visit:
#   https://bugreport.java.com/bugreport/crash.jsp
#

hs_err.log:
---------------  T H R E A D  ---------------

Current thread (0x00007f5cf021c000):  JavaThread "C2 CompilerThread6" daemon [_thread_in_native, id=44761, stack(0x00007f5c3a456000,0x00007f5c3a556000)]

Stack: [0x00007f5c3a456000,0x00007f5c3a556000],  sp=0x00007f5c3a550ab0,  free space=1002k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
V  [libjvm.so+0x121fcac]  VMError::report_and_die()+0x2ec
V  [libjvm.so+0x797f81]  report_vm_error(char const*, int, char const*, char const*)+0x61
V  [libjvm.so+0x6fcb74]  Compile::Optimize()+0xcf4
V  [libjvm.so+0x6fe9c5]  Compile::Compile(ciEnv*, C2Compiler*, ciMethod*, int, bool, bool, bool)+0xe05
V  [libjvm.so+0x59ba70]  C2Compiler::compile_method(ciEnv*, ciMethod*, int)+0xe0
V  [libjvm.so+0x70bdf2]  CompileBroker::invoke_compiler_on_method(CompileTask*)+0x8b2
V  [libjvm.so+0x70d3e0]  CompileBroker::compiler_thread_loop()+0x710
V  [libjvm.so+0x118b188]  JavaThread::thread_main_inner()+0x1c8
V  [libjvm.so+0x118b54d]  JavaThread::run()+0x37d
V  [libjvm.so+0xf19ca2]  java_start(Thread*)+0x102
C  [libpthread.so.0+0x76db]  start_thread+0xdb


Current CompileTask:
C2:   6921 1042   !b  4       Test::mainTest (767 bytes)




FREQUENCY : always



Comments
Fix request [11u] I backport this for parity with 11.0.17-oracle. No risk, debug only. Trivial resolve. SAP nightly testing passed.
18-07-2022

A pull request was submitted for review. URL: https://git.openjdk.org/jdk11u-dev/pull/1200 Date: 2022-07-05 13:59:32 +0000
05-07-2022

Fix request [17u] I backport this for parity with 17.0.5-oracle. No risk, debug only. Clean backport. Test passes. SAP niglty testing passed.
28-06-2022

A pull request was submitted for review. URL: https://git.openjdk.org/jdk17u-dev/pull/513 Date: 2022-06-27 14:52:08 +0000
27-06-2022

A pull request was submitted for review. URL: https://git.openjdk.org/jdk18u/pull/163 Date: 2022-06-21 07:48:38 +0000
21-06-2022

Changeset: 796494d0 Author: Tobias Holenstein <tobias.holenstein@oracle.com> Committer: Christian Hagedorn <chagedorn@openjdk.org> Date: 2022-05-25 13:48:19 +0000 URL: https://git.openjdk.java.net/jdk/commit/796494d0fecfb9587e8b68ff1d5c09411cb82f89
25-05-2022

The last optimizations were: Unroll 4( 2) Loop: N51962/N1912 counted [int,6),+2 (2147483648 iters) main sfpts={ 225 } Empty without zero trip guard Loop: N5343/N2671 limit_check profile_predicated predicated counted [0,int),+1 (2147483648 iters) has_sfpt strip_mined Peel Loop: N5343/N2671 limit_check profile_predicated predicated counted [0,int),+1 (2147483648 iters) has_sfpt strip_mined Empty without zero trip guard Loop: N5359/N2761 limit_check profile_predicated predicated counted [0,int),+1 (2147483648 iters) has_sfpt strip_mined Peel Loop: N5359/N2761 limit_check profile_predicated predicated counted [0,int),+1 (2147483648 iters) has_sfpt strip_mined Empty without zero trip guard Loop: N5370/N2626 limit_check profile_predicated predicated counted [0,int),+1 (2147483648 iters) has_sfpt strip_mined Peel Loop: N5370/N2626 limit_check profile_predicated predicated counted [0,int),+1 (2147483648 iters) has_sfpt strip_mined
23-05-2022

I modified code (increased LoopOptsCount flags limit) to print how many iterations needed to complete TestMaxLoopOptsCountReached::test compilation. With LoopOptsCount=100 I got: === optimize_loops cnt = 52, _loop_opts_cnt = 46 ===
23-05-2022

Switching off Strip Mining `-XX:-UseCountedLoopSafepoints` helps Reproducer.java to pass similar to jdk8u. But it did not help TestMaxLoopOptsCountReached.java
23-05-2022

About TestMaxLoopOptsCountReached.java. Can it be modified to compile with JDK 11? I got error:TestMaxLoopOptsCountReached.java:40: error: Illegal static declaration in inner class TestMaxLoopOptsCountReached.A static String e(long f, boolean b, String g, Level h, String s, ^ modifier 'static' is only allowed in constant variable declarations 1 error It is too complex to see what is going on.
23-05-2022

Very interesting test Reproducer.java It does not show any loop optimizations with -XX:+TraceLoopOpts. With -XX:+PrintOpto I see it grow internal loop body. Also it failed with -XX:+VerifyLoopOptimizations (I know that this flag is not reliable but ...). I tested with jdk8u-cpu and test passed. It did: Counted Loop: N126/N68 counted [0,20001),+1 (-1 iters) Parallel IV: 110 Loop: N126/N68 counted [0,20001),+1 (-1 iters) has_sfpt PreMainPost Loop: N126/N68 counted [0,20001),+1 (30229 iters) has_sfpt Unroll 2 Loop: N126/N68 counted [int,20001),+1 (30229 iters) main has_sfpt Unroll 4 Loop: N199/N68 counted [int,20000),+2 (30229 iters) main has_sfpt Unroll 8 Loop: N260/N68 counted [int,19998),+4 (30229 iters) main has_sfpt Unroll 16 Loop: N298/N68 counted [int,19994),+8 (30229 iters) main has_sfpt I would assume that internal loop could be folded into simple expression `cnt += 40000`. We are missing some optimization or check. May be because `cnt` is static.
23-05-2022

In the PR I added a jtreg test TestMaxLoopOptsCountReached.java that also triggers the assert after JDK-8273612. There it seems that Compile::optimize_loops does all valid optimizations. The output of TestMaxLoopOptsCountReached.java run with -XX:+TraceLoopOpts is attached in Output TraceLoopOpts.txt.
23-05-2022

The bug was hidden by JDK-8273612. Without the changes in JDK-8273612 the bug still reproduces in mainline (git revert -n 83b22192)
23-05-2022

Can also be reproduced with a smaller reproducer: java -XX:-PartialPeelLoop -XX:CompileCommand=compileonly,Reproducer::run Reproducer.java
23-05-2022

A pull request was submitted for review. URL: https://git.openjdk.java.net/jdk/pull/8767 Date: 2022-05-18 12:33:24 +0000
18-05-2022

Does not reproduce with JDK 19, we need to check which changeset fixed it.
27-04-2022

ILW = assert w/ non-default flag value; medium; no workaround if non-default flags are really needed = MMH = P3
21-04-2022

Issue is reproduced with the latest test sample on fastdebug builds OS: Windows 10 JDK 8u321 fastdebug: Fail JDK 17.0.3 fastdebug: Fail JDK 18 fastdebug: Fail additional-information from submitter: ================================== Test.class uploaded before is incorrect, I re-uploaded the new test sample in the same link Crash can be reproduced in fastdebug versions of JDK8, JDK11, and JDK17. OS: Ubuntu18.04 ==================================
20-04-2022

Moving from hotspot/runtime -> hotspot/compiler.
18-04-2022

Issue is not reproducible. Program executes fine, crash is not observed. OS: Linux(Ubuntu 20.04) JDK 8u321: Pass JDK 11.0.4: Pass JDK 17.0.2: Pass JDK 18: Pass
18-04-2022