JDK-8300823 : UB: Compile::_phase_optimize_finished is initialized too late
  • Type: Bug
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 17,20,21
  • Priority: P5
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2023-01-22
  • Updated: 2023-04-27
  • Resolved: 2023-01-27
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 17 JDK 20 JDK 21
17.0.8-oracleFixed 20.0.2Fixed 21 b08Fixed
Related Reports
Relates :  
Description
Undefined Behavior discovered after turning "UndefinedBehaviorSanitizer" in Xcode running simple HelloWorld java app. More info on clang undefined behavior sanitizer can be found https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html 

/Users/gerard/Work/tmp/jdk/src/hotspot/share/opto/compile.hpp:811 Load of value 32, which is not a valid value for type 'bool'

Invalid bool load
#0	0x0000000111b0de77 in Compile::phase_optimize_finished() const at /Users/gerard/Work/tmp/jdk/src/hotspot/share/opto/compile.hpp:811
#1	0x0000000111b0dc5f in Node::verify_construction() at /Users/gerard/Work/tmp/jdk/src/hotspot/share/opto/node.cpp:89
#2	0x0000000111b0fba3 in Node::Node(unsigned int) at /Users/gerard/Work/tmp/jdk/src/hotspot/share/opto/node.cpp:338
#3	0x0000000111887883 in RegionNode::RegionNode(unsigned int) at /Users/gerard/Work/tmp/jdk/src/hotspot/share/opto/cfgnode.hpp:79
#4	0x0000000111887763 in LoopNode::LoopNode(Node*, Node*) at /Users/gerard/Work/tmp/jdk/src/hotspot/share/opto/loopnode.hpp:143
#5	0x0000000111c43b4b in RootNode::RootNode() at /Users/gerard/Work/tmp/jdk/src/hotspot/share/opto/rootnode.hpp:37
#6	0x0000000111c26958 in RootNode::RootNode() at /Users/gerard/Work/tmp/jdk/src/hotspot/share/opto/rootnode.hpp:37
#7	0x0000000111c2301f in Compile::Init(bool) at /Users/gerard/Work/tmp/jdk/src/hotspot/share/opto/compile.cpp:983
#8	0x0000000111c26427 in Compile::Compile(ciEnv*, TypeFunc const* (*)(), unsigned char*, char const*, int, bool, bool, DirectiveSet*) at /Users/gerard/Work/tmp/jdk/src/hotspot/share/opto/compile.cpp:940
#9	0x0000000111ceb407 in OptoRuntime::generate_stub(ciEnv*, TypeFunc const* (*)(), unsigned char*, char const*, int, bool, bool) at /Users/gerard/Work/tmp/jdk/src/hotspot/share/opto/runtime.cpp:175
#10	0x0000000111ceb093 in OptoRuntime::generate(ciEnv*) at /Users/gerard/Work/tmp/jdk/src/hotspot/share/opto/runtime.cpp:143
#11	0x0000000111cad217 in C2Compiler::init_c2_runtime() at /Users/gerard/Work/tmp/jdk/src/hotspot/share/opto/c2compiler.cpp:82
#12	0x0000000111cad2cf in C2Compiler::initialize() at /Users/gerard/Work/tmp/jdk/src/hotspot/share/opto/c2compiler.cpp:95
#13	0x0000000111e8437b in CompileBroker::init_compiler_runtime() at /Users/gerard/Work/tmp/jdk/src/hotspot/share/compiler/compileBroker.cpp:1730
#14	0x0000000111e8504f in CompileBroker::compiler_thread_loop() at /Users/gerard/Work/tmp/jdk/src/hotspot/share/compiler/compileBroker.cpp:1867
#15	0x0000000110eed6cb in JavaThread::thread_main_inner() at /Users/gerard/Work/tmp/jdk/src/hotspot/share/runtime/javaThread.cpp:710
#16	0x0000000110eed4bb in JavaThread::run() at /Users/gerard/Work/tmp/jdk/src/hotspot/share/runtime/javaThread.cpp:695
#17	0x0000000110d9837b in Thread::call_run() at /Users/gerard/Work/tmp/jdk/src/hotspot/share/runtime/thread.cpp:224
#18	0x00000001109abd1f in thread_native_entry(Thread*) at /Users/gerard/Work/tmp/jdk/src/hotspot/os/bsd/os_bsd.cpp:572
#19	0x00000001000995d3 in _pthread_start ()
Comments
Fix request [17u] I backport this for parity with 17.0.8-oracle. No risk, only a change to debug coding. Clean backport except for Copyright. SAP nightly testing passed.
20-04-2023

A pull request was submitted for review. URL: https://git.openjdk.org/jdk17u-dev/pull/1271 Date: 2023-04-19 09:47:51 +0000
19-04-2023

A pull request was submitted for review. URL: https://git.openjdk.org/jdk20u/pull/30 Date: 2023-03-29 11:03:04 +0000
29-03-2023

Fix Request (JDK 20u) Resolves an issue with potential undefined behavior due to an uninitialized field. The fix is low risk, was already backported to Oracle JDK 17u and tested in the JDK 21 and 17u CIs. The backport applies cleanly.
29-03-2023

Changeset: e4252bb9 Author: Damon Fenacci <damon.fenacci@oracle.com> Committer: Tobias Hartmann <thartmann@openjdk.org> Date: 2023-01-27 12:14:07 +0000 URL: https://git.openjdk.org/jdk/commit/e4252bb91478e9c2f0a5bbdae7cd663838d91b1b
27-01-2023

A pull request was submitted for review. URL: https://git.openjdk.org/jdk/pull/12192 Date: 2023-01-25 12:17:52 +0000
26-01-2023

The issue is indeed due to _phase_optimize_finished being initialized too late.
25-01-2023

Damon, could you please have a look? Thanks.
23-01-2023

Code was introduced by JDK-8244724. I think the issue is that _phase_optimize_finished is not always initialized.
23-01-2023

Initial ILW = Potential undefined behavior in node verification code in C2 (debug only code), found with UndefinedBehaviorSanitizer in Xcode - never observed any issues, no known workaround = LLH = P5
23-01-2023