JDK-8292590 : Product JVM crashes with FLAG_SET_XXX on notproduct Flag
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: 20
  • Priority: P4
  • Status: New
  • Resolution: Unresolved
  • Submitted: 2022-08-18
  • Updated: 2022-08-18
Description
This was ultimately my error but clearer error handling could have saved me an hour or two.

While working on https://bugs.openjdk.org/browse/JDK-8292561, I tried to make ReplayCompiles a product (diagnostic) switch. Depending on ReplayCompiles, however, we set UseDebuggerErgo. UseDebuggerErgo is a notproduct switch.

So I found that setting a notproduct switch in a product build just crashes. And if that happens before os_init in early arg parsing, we won't even have a signal handler in place, so no hs-err file, just "Segmentation Fault".

You just cannot run a debug VM here to see assert since the error depends on the VM being product. Therefore, a guarantee somewhere would be helpful.

Here's a reproducer:

=====================
diff src/hotspot/share/gc/shared/gcConfig.cpp

 void GCConfig::select_gc_ergonomically() {
+  FLAG_SET_ERGO(CheckCompressedOops, true);
   if (os::is_server_class_machine()) {
=====================

# The VM exits with no apparent error message

$ java -version; echo $?
139

Comments
Proposed fix in src/hotspot/share/runtime/globals_extension.hpp: Do not generate this function for product builds: inline JVMFlag::Error Flag_CheckCompressedOops_set(bool value, JVMFlagOrigin origin) { return JVMFlagAccess::set<bool, JVMFlag::TYPE_bool>(Flag_CheckCompressedOops_enum, value, origin); } That way, the code in the bug Description will fail to compile for the product build.
18-08-2022