JDK-8310130 : C2: assert(false) failed: scalar_input is neither phi nor a matchin reduction
  • Type: Bug
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 21,22
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2023-06-15
  • Updated: 2023-07-12
  • Resolved: 2023-06-28
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 21 JDK 22
21Fixed 22 b04Fixed
Related Reports
Relates :  
Description
The attached Java Fuzzer test starts to fail after JDK-8302652:

To reproduce:
$ java -Xcomp -XX:CompileCommand=compileonly,Test::* Test.java
$ java -Xcomp -XX:CompileCommand=compileonly,Reduced::* Reduced.java

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  Internal Error (/opt/mach5/mesos/work_dir/slaves/cd627e65-f015-4fb1-a1d2-b6c9b8127f98-S9638/frameworks/1735e8a2-a1db-478c-8104-60c8b0af87dd-0196/executors/7cab5968-cfac-4917-b50c-ee11433deb3c/runs/89e28e37-02bc-4ad0-8809-7a3c3140d816/workspace/open/src/hotspot/share/opto/loopopts.cpp:4249), pid=1696577, tid=1696600
#  assert(false) failed: scalar_input is neither phi nor a matchin reduction
#
# JRE version: Java(TM) SE Runtime Environment (21.0+26) (fastdebug build 21-ea+26-LTS-2328)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (fastdebug 21-ea+26-LTS-2328, compiled mode, sharing, tiered, compressed oops, compressed class ptrs, g1 gc, linux-amd64)
# Problematic frame:
# V  [libjvm.so+0x12b07f6]  PhaseIdealLoop::move_unordered_reduction_out_of_loop(IdealLoopTree*)+0x896
..........
Command Line: -Xmx1G -Xcomp -Xbatch -XX:CompileOnly=Test -XX:CompileCommand=quiet -XX:MaxRAMPercentage=4.16667 -Dtest.boot.jdk=/opt/mach5/mesos/work_dir/jib-master/install/jdk/20/36/bundles/linux-x64/jdk-20_linux-x64_bin.tar.gz/jdk-20 -Djava.io.tmpdir=/opt/mach5/mesos/work_dir/slaves/741e9afd-8c02-45c3-b2e2-9db1450d0832-S161740/frameworks/1735e8a2-a1db-478c-8104-60c8b0af87dd-0196/executors/a03df349-195e-43a5-997a-9d6208db5f95/runs/30281575-d526-4e59-b473-1cda18ba846e/testoutput/test-support/jtreg_closed_test_hotspot_jtreg_applications_javafuzzer_BigTest_java/tmp Test
........
Current CompileTask:
C2:    471    8    b  4       Test::vMeth (313 bytes)

Stack: [0x00007f0aeda00000,0x00007f0aedb00000],  sp=0x00007f0aedafac00,  free space=1003k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
V  [libjvm.so+0x12b07f6]  PhaseIdealLoop::move_unordered_reduction_out_of_loop(IdealLoopTree*)+0x896  (loopopts.cpp:4249)
V  [libjvm.so+0x1296c54]  PhaseIdealLoop::build_and_optimize()+0x1414  (loopnode.cpp:4673)
V  [libjvm.so+0x9f2939]  PhaseIdealLoop::optimize(PhaseIterGVN&, LoopOptsMode)+0x3b9  (loopnode.hpp:1124)
V  [libjvm.so+0x9ef4a7]  Compile::Optimize()+0xe97  (compile.cpp:2156)
V  [libjvm.so+0x9f16d6]  Compile::Compile(ciEnv*, ciMethod*, int, Options, DirectiveSet*)+0x1b96  (compile.cpp:842)
V  [libjvm.so+0x84b3e4]  C2Compiler::compile_method(ciEnv*, ciMethod*, int, bool, DirectiveSet*)+0x3c4  (c2compiler.cpp:118)
V  [libjvm.so+0x9fd5e0]  CompileBroker::invoke_compiler_on_method(CompileTask*)+0xa00  (compileBroker.cpp:2265)
V  [libjvm.so+0x9fe468]  CompileBroker::compiler_thread_loop()+0x618  (compileBroker.cpp:1944)
V  [libjvm.so+0xeb651c]  JavaThread::thread_main_inner()+0xcc  (javaThread.cpp:719)
V  [libjvm.so+0x1795d7a]  Thread::call_run()+0xba  (thread.cpp:217)
V  [libjvm.so+0x149623c]  thread_native_entry(Thread*)+0x11c  (os_linux.cpp:778)

Comments
A pull request was submitted for review. URL: https://git.openjdk.org/jdk21/pull/77 Date: 2023-06-28 14:38:43 +0000
28-06-2023

Changeset: 526dba1a Author: Emanuel Peter <epeter@openjdk.org> Date: 2023-06-28 05:52:26 +0000 URL: https://git.openjdk.org/jdk/commit/526dba1a2942e444bf11d03d8eaf014b5ef20ccf
28-06-2023

A pull request was submitted for review. URL: https://git.openjdk.org/jdk/pull/14494 Date: 2023-06-15 14:42:14 +0000
19-06-2023

Constructed a quite different example of the same issue: ./java -Xcomp -XX:-TieredCompilation -XX:CompileCommand=compileonly,Reduced3::test -XX:+TraceNewVectors -XX:+TraceSuperWord -XX:+TraceLoopOpts -XX:MaxVectorSize=16 Reduced3.java
15-06-2023

Reduced it a bit more: java -Xcomp -XX:-TieredCompilation -XX:CompileCommand=compileonly,Reduced2::test -XX:+TraceNewVectors -XX:+TraceSuperWord -XX:UseAVX=2 -XX:+TraceLoopOpts Reduced2.java
15-06-2023

ILW = C2 assertion failure, single Java Fuzzer test, use -XX:-UseSuperWord or disable compilation of affected method = HLM = P3
15-06-2023

Had a quick look. The reduction loop looks like this: (rr) p current->dump_bfs(10,current,"#dA") dist apd dump --------------------------------------------- 5 6 852 Phi === 844 497 999 [[ 834 ]] #long !orig=[752],[683],[641],[331],253 !jvms: Reduced::test @ bci:36 (line 16) 4 6 834 OrL === _ 852 835 [[ 828 ]] !orig=[742],[668],[321],255 !jvms: Reduced::test @ bci:39 (line 16) 3 6 828 OrL === _ 834 829 [[ 817 ]] !orig=[734],[321],255 !jvms: Reduced::test @ bci:39 (line 16) 2 6 817 OrL === _ 828 818 [[ 816 ]] !orig=[668],[321],255 !jvms: Reduced::test @ bci:39 (line 16) 1 6 816 OrL === _ 817 824 [[ 999 ]] !orig=[321],255 !jvms: Reduced::test @ bci:39 (line 16) 0 0 999 OrReductionV === _ 816 998 [[ 320 852 ]] !orig=[742],[668],[321],255 !jvms: Reduced::test @ bci:39 (line 16) This means we have a mix of scalar and vector reductions. This is probably due to partial reduction. I added the assert we hit here because I was not sure if something like this could ever happen. Now we have an example. I'll investigate more, but most likely we will just remove the assert and accept the bailout of this specific optimization.
15-06-2023