8068579: Running with -XX:-UseParallelGC does not turn ParalleGC off
authorpliden
Tue, 29 Mar 2016 08:42:22 +0200
changeset 37199 74703ea13069
parent 37198 b96542d1afa1
child 37200 e601cf49b2d8
8068579: Running with -XX:-UseParallelGC does not turn ParalleGC off Reviewed-by: jmasa, dfazunen, brutisso
hotspot/src/share/vm/runtime/arguments.cpp
hotspot/src/share/vm/runtime/arguments.hpp
hotspot/src/share/vm/runtime/globals_extension.hpp
hotspot/test/gc/arguments/TestDisableDefaultGC.java
--- a/hotspot/src/share/vm/runtime/arguments.cpp	Wed Mar 23 09:00:22 2016 -0700
+++ b/hotspot/src/share/vm/runtime/arguments.cpp	Tue Mar 29 08:42:22 2016 +0200
@@ -66,15 +66,15 @@
 #define DEFAULT_VENDOR_URL_BUG "http://bugreport.java.com/bugreport/crash.jsp"
 #define DEFAULT_JAVA_LAUNCHER  "generic"
 
-#define UNSUPPORTED_GC_OPTION(gc)                                     \
-do {                                                                  \
-  if (gc) {                                                           \
-    if (FLAG_IS_CMDLINE(gc)) {                                        \
-      warning(#gc " is not supported in this VM.  Using Serial GC."); \
-    }                                                                 \
-    FLAG_SET_DEFAULT(gc, false);                                      \
-  }                                                                   \
-} while(0)
+#define UNSUPPORTED_GC_OPTION(gc)                         \
+  do {                                                    \
+    if (gc) {                                             \
+      if (FLAG_IS_CMDLINE(gc)) {                          \
+        warning("-XX:+" #gc " not supported in this VM"); \
+      }                                                   \
+      FLAG_SET_DEFAULT(gc, false);                        \
+    }                                                     \
+  } while(0)
 
 char*  Arguments::_jvm_flags_file               = NULL;
 char** Arguments::_jvm_flags_array              = NULL;
@@ -1936,26 +1936,45 @@
                                           CollectorPolicy::compute_heap_alignment());
 }
 
+bool Arguments::gc_selected() {
+#if INCLUDE_ALL_GCS
+  return UseSerialGC || UseParallelGC || UseParallelOldGC || UseConcMarkSweepGC || UseG1GC;
+#else
+  return UseSerialGC;
+#endif // INCLUDE_ALL_GCS
+}
+
 void Arguments::select_gc_ergonomically() {
+#if INCLUDE_ALL_GCS
   if (os::is_server_class_machine()) {
     if (should_auto_select_low_pause_collector()) {
-      FLAG_SET_ERGO(bool, UseConcMarkSweepGC, true);
+      FLAG_SET_ERGO_IF_DEFAULT(bool, UseConcMarkSweepGC, true);
     } else {
 #if defined(JAVASE_EMBEDDED)
-      FLAG_SET_ERGO(bool, UseParallelGC, true);
+      FLAG_SET_ERGO_IF_DEFAULT(bool, UseParallelGC, true);
 #else
-      FLAG_SET_ERGO(bool, UseG1GC, true);
+      FLAG_SET_ERGO_IF_DEFAULT(bool, UseG1GC, true);
 #endif
     }
   } else {
-    FLAG_SET_ERGO(bool, UseSerialGC, true);
-  }
+    FLAG_SET_ERGO_IF_DEFAULT(bool, UseSerialGC, true);
+  }
+#else
+  UNSUPPORTED_GC_OPTION(UseG1GC);
+  UNSUPPORTED_GC_OPTION(UseParallelGC);
+  UNSUPPORTED_GC_OPTION(UseParallelOldGC);
+  UNSUPPORTED_GC_OPTION(UseConcMarkSweepGC);
+  UNSUPPORTED_GC_OPTION(UseParNewGC);
+  FLAG_SET_ERGO_IF_DEFAULT(bool, UseSerialGC, true);
+#endif // INCLUDE_ALL_GCS
 }
 
 void Arguments::select_gc() {
   if (!gc_selected()) {
     select_gc_ergonomically();
-    guarantee(gc_selected(), "No GC selected");
+    if (!gc_selected()) {
+      vm_exit_during_initialization("Garbage collector not selected (default collector explicitly disabled)", NULL);
+    }
   }
 }
 
@@ -2080,16 +2099,6 @@
   log_trace(gc)("ConcGCThreads: %u", ConcGCThreads);
 }
 
-#if !INCLUDE_ALL_GCS
-#ifdef ASSERT
-static bool verify_serial_gc_flags() {
-  return (UseSerialGC &&
-        !(UseParNewGC || (UseConcMarkSweepGC) || UseG1GC ||
-          UseParallelGC || UseParallelOldGC));
-}
-#endif // ASSERT
-#endif // INCLUDE_ALL_GCS
-
 void Arguments::set_gc_specific_flags() {
 #if INCLUDE_ALL_GCS
   // Set per-collector flags
@@ -2111,8 +2120,6 @@
     // Keeping the heap 100% free is hard ;-) so limit it to 99%.
     FLAG_SET_ERGO(uintx, MinHeapFreeRatio, 99);
   }
-#else // INCLUDE_ALL_GCS
-  assert(verify_serial_gc_flags(), "SerialGC unset");
 #endif // INCLUDE_ALL_GCS
 }
 
@@ -3955,17 +3962,6 @@
   }
 }
 
-#if !INCLUDE_ALL_GCS
-static void force_serial_gc() {
-  FLAG_SET_DEFAULT(UseSerialGC, true);
-  UNSUPPORTED_GC_OPTION(UseG1GC);
-  UNSUPPORTED_GC_OPTION(UseParallelGC);
-  UNSUPPORTED_GC_OPTION(UseParallelOldGC);
-  UNSUPPORTED_GC_OPTION(UseConcMarkSweepGC);
-  UNSUPPORTED_GC_OPTION(UseParNewGC);
-}
-#endif // INCLUDE_ALL_GCS
-
 // Sharing support
 // Construct the path to the archive
 static char* get_shared_archive_path() {
@@ -4360,9 +4356,6 @@
   // Set object alignment values.
   set_object_alignment();
 
-#if !INCLUDE_ALL_GCS
-  force_serial_gc();
-#endif // INCLUDE_ALL_GCS
 #if !INCLUDE_CDS
   if (DumpSharedSpaces || RequireSharedSpaces) {
     jio_fprintf(defaultStream::error_stream(),
--- a/hotspot/src/share/vm/runtime/arguments.hpp	Wed Mar 23 09:00:22 2016 -0700
+++ b/hotspot/src/share/vm/runtime/arguments.hpp	Tue Mar 29 08:42:22 2016 +0200
@@ -567,7 +567,7 @@
   static jint adjust_after_os();
 
   static void set_gc_specific_flags();
-  static inline bool gc_selected(); // whether a gc has been selected
+  static bool gc_selected(); // whether a gc has been selected
   static void select_gc_ergonomically();
 #if INCLUDE_JVMCI
   // Check consistency of jvmci vm argument settings.
@@ -732,10 +732,6 @@
   static void check_unsupported_dumping_properties() NOT_CDS_RETURN;
 };
 
-bool Arguments::gc_selected() {
-  return UseConcMarkSweepGC || UseG1GC || UseParallelGC || UseParallelOldGC || UseSerialGC;
-}
-
 // Disable options not supported in this release, with a warning if they
 // were explicitly requested on the command-line
 #define UNSUPPORTED_OPTION(opt, description)                    \
--- a/hotspot/src/share/vm/runtime/globals_extension.hpp	Wed Mar 23 09:00:22 2016 -0700
+++ b/hotspot/src/share/vm/runtime/globals_extension.hpp	Tue Mar 29 08:42:22 2016 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -290,6 +290,12 @@
 
 #define FLAG_SET_CMDLINE(type, name, value) (CommandLineFlagsEx::type##AtPut(FLAG_MEMBER_WITH_TYPE(name,type), (type)(value), Flag::COMMAND_LINE))
 #define FLAG_SET_ERGO(type, name, value)    (CommandLineFlagsEx::type##AtPut(FLAG_MEMBER_WITH_TYPE(name,type), (type)(value), Flag::ERGONOMIC))
+#define FLAG_SET_ERGO_IF_DEFAULT(type, name, value) \
+  do {                                              \
+    if (FLAG_IS_DEFAULT(name)) {                    \
+      FLAG_SET_ERGO(type, name, value);             \
+    }                                               \
+  } while (0)
 
 // Can't put the following in CommandLineFlags because
 // of a circular dependency on the enum definition.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/gc/arguments/TestDisableDefaultGC.java	Tue Mar 29 08:42:22 2016 +0200
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test TestDisableDefaultGC
+ * @summary Test that the VM complains when the default GC is disabled and no other GC is specified
+ * @bug 8068579
+ * @key gc
+ * @library /testlibrary
+ * @requires vm.gc=="null"
+ * @modules java.base/sun.misc
+ *          java.management
+ * @run driver TestDisableDefaultGC
+ */
+
+import jdk.test.lib.ProcessTools;
+import jdk.test.lib.OutputAnalyzer;
+
+public class TestDisableDefaultGC {
+    public static void main(String[] args) throws Exception {
+        // Start VM, disabling all possible default GCs
+        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:-UseSerialGC",
+                                                                  "-XX:-UseParallelGC",
+                                                                  "-XX:-UseG1GC",
+                                                                  "-XX:-UseConcMarkSweepGC",
+                                                                  "-version");
+        OutputAnalyzer output = new OutputAnalyzer(pb.start());
+        output.shouldMatch("Garbage collector not selected");
+        output.shouldHaveExitValue(1);
+    }
+}