JDK-8356246 : C2: Compilation fails with "assert(bol->is_Bool()) failed: unexpected if shape" in StringConcat::eliminate_unneeded_control
  • Type: Bug
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 17,21,24,25,26
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2025-05-06
  • Updated: 2025-06-11
  • Resolved: 2025-05-30
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 25
25 b26Fixed
Related Reports
Causes :  
Relates :  
Relates :  
Relates :  
Description
C2 compilation fails during stacked string concatenation optimization in
StringConcat::eliminate_unneeded_control with  "assert(bol->is_Bool()) failed: unexpected if shape".

<...>/java -XX:+PrintOptimizeStringConcat -XX:-TieredCompilation TestStackedConcats.java

====

<...>

stacking would succeed
#
# A fatal error has been detected by the Java Runtime Environment:
#
#  Internal Error (<...>/hotspot/share/opto/stringopts.cpp:259), <...>
#  assert(bol->is_Bool()) failed: unexpected if shape
#
# JRE version: Java(TM) SE Runtime Environment (25.0) (fastdebug build 25-internal-<...>)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (fastdebug 25-internal-<...>, mixed mode, compressed oops, compressed class ptrs, g1 gc, linux-amd64)
# Problematic frame:
V  [libjvm.so+0x17954f1]  StringConcat::eliminate_unneeded_control()+0x2f7  (stringopts.cpp:259)
V  [libjvm.so+0x179d780]  PhaseStringOpts::replace_string_concat(StringConcat*)+0x2cc  (stringopts.cpp:1748)
V  [libjvm.so+0x1797771]  PhaseStringOpts::PhaseStringOpts(PhaseGVN*)+0x5a1  (stringopts.cpp:707)
V  [libjvm.so+0xb0c535]  Compile::inline_string_calls(bool)+0x215  (compile.cpp:2037)
V  [libjvm.so+0xb06055]  Compile::Compile(ciEnv*, ciMethod*, int, Options, DirectiveSet*)+0x1725  (compile.cpp:830)
V  [libjvm.so+0x9b9a14]  C2Compiler::compile_method(ciEnv*, ciMethod*, int, bool, DirectiveSet*)+0x486  (c2compiler.cpp:141)
V  [libjvm.so+0xb2e535]  CompileBroker::invoke_compiler_on_method(CompileTask*)+0xe01  (compileBroker.cpp:2307)
V  [libjvm.so+0xb2c92e]  CompileBroker::compiler_thread_loop()+0x576  (compileBroker.cpp:1951)
V  [libjvm.so+0xb4ec23]  CompilerThread::thread_entry(JavaThread*, JavaThread*)+0x89  (compilerThread.cpp:67)
V  [libjvm.so+0x101bdbc]  JavaThread::thread_main_inner()+0x1b2  (javaThread.cpp:773)
V  [libjvm.so+0x101bc07]  JavaThread::run()+0x1d7  (javaThread.cpp:758)
V  [libjvm.so+0x18c96fd]  Thread::call_run()+0x1b9  (thread.cpp:231)
V  [libjvm.so+0x15ed8ff]  thread_native_entry(Thread*)+0x1f5  (os_linux.cpp:870)

====

bol is 20  ConI  === 0  [[ 118 212 96 315 244 ]]  #int:0
Comments
Changeset: 6f9e1175 Branch: master Author: Daniel Skantz <dskantz@openjdk.org> Date: 2025-05-30 06:23:11 +0000 URL: https://git.openjdk.org/jdk/commit/6f9e1175a983c735c1beed755ec5b14b476858d7
30-05-2025

A pull request was submitted for review. Branch: master URL: https://git.openjdk.org/jdk/pull/25461 Date: 2025-05-27 07:56:59 +0000
27-05-2025

Possible fix: https://github.com/openjdk/jdk/compare/master...danielogh:jdk:stringopts_2?expand=1
22-05-2025

ILW = Assertion failure due to unexpected constant node at an If node, single test, disable compilation of affected method or use -XX:-OptimizeStringConcat = HLM = P3
16-05-2025

Workaround: -XX:-OptimizeStringConcat
16-05-2025

Attached [before_string_opts.png]. After JDK-8291775, the bool input to 283 is a bool 211 which is replaced by a constant zero. 211 is shared by 283 and 212 If and we crash later asserting that we have a bool input to 212 as well (it was just replaced by a Con).
07-05-2025

Could trace it back to JDK-8291775 which went into JDK 20.
06-05-2025

The test case appears to not crash if I back out JDK-8271341.
06-05-2025