JDK-8245051 : c1 is broken if it is compiled by gcc without -fno-lifetime-dse
  • Type: Bug
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 8,11,15
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • CPU: generic
  • Submitted: 2020-05-14
  • Updated: 2021-01-14
  • Resolved: 2020-05-20
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 15
11.0.10Fixed 15 b24Fixed
Description
 Both release build and fastdebug generate broken c1 if the building toolchain are gcc6+.  The reason that slowdebug is fine because it doesn't use gcc optimizations.

Here is the configure which can produce the broken c1.
--enable-option-checking=fatal --with-debug-level=fastdebug --with-native-debug-symbols=internal --with-extra-cxxflags="-g -pipe -Wformat -Wno-cpp -Wp,-D_FORTIFY_SOURCE=2  -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -std=gnu++98 -fno-delete-null-pointer-checks" --with-extra-cflags="-g -pipe -Wformat -Wno-cpp -Wp,-D_FORTIFY_SOURCE=2  -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -std=gnu++98 -Wno-error -fno-delete-null-pointer-checks" --with-extra-asflags="-g -pipe -Wformat -Wno-cpp -Wp,-D_FORTIFY_SOURCE=2  -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -std=gnu++98 -Wno-error -fno-delete-null-pointer-checks" --with-extra-ldflags=-Wl,-z,relro  --with-num-cores=16 --disable-javac-server --with-jvm-features=zgc --disable-warnings-as-errors

The trigger is '-std=gnu++98' in --with-extra-cflags. it's not a valid option for cc1, so it will disturb configure from detecting the availability of -fno-lifetime-dse.  As a result, JVM_CFLAGS of spec.mk misses -fno-lifetime-dse.

The generated c1 is broken so the whole 'make images'  can't complete. sanity test like '-version' would fail.

./jdk/bin/java -version
# To suppress the following error report, specify this argument
# after -XX: or in .hotspotrc:  SuppressErrorAt=/bitMap.cpp:186
#
# A fatal error has been detected by the Java Runtime Environment:
#
#  Internal Error (/home/ubuntu/build/jdk/src/hotspot/share/utilities/bitMap.cpp:186), pid=34159, tid=34172
#  assert(bit < _size) failed: BitMap index out of bounds: 18446744072294738859 >= 26
#
# JRE version: OpenJDK Runtime Environment (15.0) (fastdebug build 15-internal+0-adhoc.ubuntu.jdk)
# Java VM: OpenJDK 64-Bit Server VM (fastdebug 15-internal+0-adhoc.ubuntu.jdk, mixed mode, tiered, compressed oops, g1 gc, linux-amd64)
# Problematic frame:
# V  [libjvm.so+0x55e764]  BitMap::verify_index(unsigned long) const+0x34
#
# Core dump will be written. Default location: Core dumps may be processed with "/usr/share/apport/apport %p %s %c %d %P %E" (or dumping to /backup/undefinedC1/core.34159)
#
# An error report file with more information is saved as:
# /backup/undefinedC1/hs_err_pid34159.log
[thread 34175 also had an error]
#
# Compiler replay data is saved as:
# /backup/undefinedC1/replay_pid34159.log
#
# If you would like to submit a bug report, please visit:
#   https://bugreport.java.com/bugreport/crash.jsp
#
Aborted (core dumped)
Comments
Yes, that dates back to before the upstream fix was added and needs removing: https://src.fedoraproject.org/rpms/java-11-openjdk/c/9c6396e9b323a51057535fe297db3bc069c3a796?branch=master
14-01-2021

the -std=gnu++98 is passed from the rpm spec files in some jdk11 distributions. eg. https://git.centos.org/rpms/java-11-openjdk/blob/c8/f/SPECS/java-11-openjdk.spec#_1669
13-01-2021

While it is good that this has been fixed (and looks also applicable to 8u), the original problematic ./configure is clearly invalid and may break other configure tests. It also should be unnecessary to add -std=gnu++98 at all, as configure should add this itself.
12-01-2021

Fix Request (11u) This fixes UBs, crashes in non-standard build configurations. Patch does not apply cleanly to 11u, 11u RFR (acked by aph): https://mail.openjdk.java.net/pipermail/jdk-updates-dev/2020-September/003861.html
11-11-2020

URL: https://hg.openjdk.java.net/jdk/jdk/rev/497fd9f9129c User: phh Date: 2020-05-20 19:00:58 +0000
20-05-2020

ILW = C1 crashes, with non-default build configuration, use default configuration = HLM = P3
15-05-2020

It looks that there are 2 potential issues in c1. 1) it's undefined behavior to initialize member variable before construction. c1_instruction.hpp, the statement _id = c->get_next_id() is UB. gcc can optimize it out in silence if -flifetime-dse > 0. void* operator new(size_t size) throw() { Compilation* c = Compilation::current(); void* res = c->arena()->Amalloc(size); ((Instruction*)res)->_id = c->get_next_id(); return res; } 2. member variable _has_substitutions may be uninitialized. http://hg.openjdk.java.net/jdk/jdk/file/748fedeb7cc1/src/hotspot/share/c1/c1_ValueMap.cpp#l574 default initialization of the primitive types are indeterminate.
15-05-2020