JDK-8306042 : C2: failed: Missed optimization opportunity in PhaseCCP (adding LShift->Cast->Add notification)
  • Type: Bug
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 21
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2023-04-16
  • Updated: 2023-07-10
  • Resolved: 2023-05-03
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
21 b21Fixed
Related Reports
Relates :  
Relates :  
Description
Occurred during execution of JavaFuzzer

Missed Value optimization:
dist dump
---------------------------------------------
   1   142  ConI  === 0  [[ 1778 681 228 228 198 200 201 231 3534 657 227 203 1777 204 205 206 233 234 3874 208 209 210 229 217 211 212 213 230 66 232 3884 1776 68 62 1763 1763 1764 1764 1765 1765 1766 1766 1767 1768 1769 972 1770 237 1771 1772 1375 1760 1759 1758 1757 1756 1755 1754 1753 1752 236 235 1364 1751 1750 1749 1748 1747 1746 1745 1744 1743 1742 1741 1773 1377 65 238 3568 1774 1775 4076 ]]  #int:13
   1  3875  CastII  === 3829 188  [[ 3874 ]]  #int unconditional dependency
   0  3874  AndI  === _ 3875 142  [[ 3806 ]]  !orig=[380],[577] !jvms: Test::mainTest @ bci:164 (line 175)
Current type:
int:0
Optimized type:
int:0..13:www


#
# A fatal error has been detected by the Java Runtime Environment:
#
#  Internal Error (c:\sb\prod\1681507186\workspace\open\src\hotspot\share\opto\phaseX.cpp:2010), pid=23224, tid=59124
#  assert(!failure) failed: Missed optimization opportunity in PhaseCCP
#
# JRE version: Java(TM) SE Runtime Environment (21.0+19) (fastdebug build 21-ea+19-LTS-1517)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (fastdebug 21-ea+19-LTS-1517, compiled mode, sharing, tiered, compressed oops, compressed class ptrs, g1 gc, windows-amd64)
# Core dump will be written. Default location: C:\sb\prod\1681642304\testoutput\test-support\jtreg_closed_test_hotspot_jtreg_applications_javafuzzer_BigTest_java\tmp\fuzzer.tmp.J3bHs5hCgO\hs_err_pid23224.mdmp
#
# If you would like to submit a bug report, please visit:
#   https://bugreport.java.com/bugreport/crash.jsp
#

---------------  S U M M A R Y ------------

Command Line: -Xmx1G -Xcomp -Xbatch -XX:CompileOnly=Test -XX:CompileCommand=quiet -XX:MaxRAMPercentage=4.16667 -Dtest.boot.jdk=c:\ade\mesos\work_dir\jib-master\install\jdk\19\36\bundles\windows-x64\jdk-19_windows-x64_bin.zip\jdk-19 -Djava.io.tmpdir=c:\sb\prod\1681642304\testoutput\test-support\jtreg_closed_test_hotspot_jtreg_applications_javafuzzer_BigTest_java\tmp Test

Host: AMD EPYC 7J13 64-Core Processor                , 12 cores, 23G,  Windows Server 2016 , 64 bit Build 14393 (10.0.14393.3630)
Time: Sun Apr 16 16:44:11 2023 /GM elapsed time: 2.077967 seconds (0d 0h 0m 2s)

---------------  T H R E A D  ---------------

Current thread (0x000002ada11b9910):  JavaThread "C2 CompilerThread0" daemon [_thread_in_native, id=59124, stack(0x000000d943d00000,0x000000d943e00000)]


Current CompileTask:
C2:   2078   84   !b  4       Test::mainTest (609 bytes)

Stack: [0x000000d943d00000,0x000000d943e00000]
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
V  [jvm.dll+0xbd5dd1]  os::win32::platform_print_native_stack+0xf1  (os_windows_x86.cpp:236)
V  [jvm.dll+0xe4ef99]  VMError::report+0x1019  (vmError.cpp:815)
V  [jvm.dll+0xe50bf5]  VMError::report_and_die+0x645  (vmError.cpp:1588)
V  [jvm.dll+0xe51304]  VMError::report_and_die+0x64  (vmError.cpp:1353)
V  [jvm.dll+0x53101b]  report_vm_error+0x5b  (debug.cpp:191)
V  [jvm.dll+0xc1adc6]  PhaseCCP::analyze+0x996  (phaseX.cpp:1994)
V  [jvm.dll+0xc17478]  PhaseCCP::PhaseCCP+0xe8  (phaseX.cpp:1933)
V  [jvm.dll+0x4c5415]  Compile::Optimize+0xbb5  (compile.cpp:2373)
V  [jvm.dll+0x4c27e8]  Compile::Compile+0x1458  (compile.cpp:841)
V  [jvm.dll+0x3e0daa]  C2Compiler::compile_method+0x11a  (c2compiler.cpp:121)
V  [jvm.dll+0x4ddcf1]  CompileBroker::invoke_compiler_on_method+0x881  (compileBroker.cpp:2268)
V  [jvm.dll+0x4db2c6]  CompileBroker::compiler_thread_loop+0x396  (compileBroker.cpp:1945)
V  [jvm.dll+0x7af2f4]  JavaThread::thread_main_inner+0x224  (javaThread.cpp:718)
V  [jvm.dll+0xdc56cb]  Thread::call_run+0x1cb  (thread.cpp:229)
V  [jvm.dll+0xbd4700]  os::win32::thread_native_entry+0xa0  (os_windows.cpp:551)
C  [ucrtbase.dll+0x1fb80]
C  [KERNEL32.DLL+0x84d4]
C  [ntdll.dll+0x51791]

Comments
Changeset: e9807a4b Author: Emanuel Peter <epeter@openjdk.org> Date: 2023-05-03 10:45:30 +0000 URL: https://git.openjdk.org/jdk/commit/e9807a4b0f3533512623fba96042472b69d4ac34
03-05-2023

A pull request was submitted for review. URL: https://git.openjdk.org/jdk/pull/13611 Date: 2023-04-24 11:32:48 +0000
25-04-2023

Draft: https://github.com/openjdk/jdk/pull/13611
24-04-2023

I think we should fix it properly and handle an arbitrary chain of CastIIs. Otherwise, we risk issues like JDK-8288683.
19-04-2023

Simplified it just a bit more, and added some comments: ./java -Xcomp -XX:CompileOnly=Test2 -XX:CompileCommand=quiet Test2.java
18-04-2023

Initial analysis: We have a case like this: Phi -> ShiftL -> CastII -> AndI The Phi has an updated type, so we should re-run Value on the AndI. In PhaseCCP::push_and, we do update a similar pattern: X -> ShiftL -> AndI So the missing part is the CastII. The question is if I should fix this by skipping a single CastII, or if we should traverse an arbitrary chain of CastII? Because "shift = shift->uncast();" in MulNode::AndIL_shift_and_mask_is_always_zero skips an arbitrary number of CastII nodes.
18-04-2023

Attached a reduced test: java -Xcomp -XX:CompileOnly=TestReduced -XX:CompileCommand=quiet TestReduced.java
17-04-2023

Reproducible with attached Test.java and "-Xmx1G -Xcomp -Xbatch -XX:CompileOnly=Test -XX:CompileCommand=quiet" Fails since the verification code was introduced with JDK-8257197 and also with latest JDK 21. ILW = Imprecise type information leading to missed optimization opportunities and could hit assertion in CCP verification code, rare, no workaround = MLH = P4
17-04-2023