8205064: Fail immediately if an unavailable GC is selected
authorpliden
Tue, 19 Jun 2018 12:11:37 +0200
changeset 50629 645a5962201d
parent 50628 83b1a52f187c
child 50630 4cb865aa94b5
8205064: Fail immediately if an unavailable GC is selected Reviewed-by: rkennke, shade
src/hotspot/share/gc/shared/gcConfig.cpp
src/hotspot/share/gc/shared/gcConfig.hpp
--- a/src/hotspot/share/gc/shared/gcConfig.cpp	Tue Jun 19 11:27:05 2018 +0200
+++ b/src/hotspot/share/gc/shared/gcConfig.cpp	Tue Jun 19 12:11:37 2018 +0200
@@ -76,12 +76,30 @@
          ZGC_ONLY_ARG(SupportedGC(UseZGC,             CollectedHeap::Z,        zArguments,        "z gc"))
 };
 
-#define FOR_EACH_SUPPORTED_GC(var) \
+#define FOR_EACH_SUPPORTED_GC(var)                                          \
   for (const SupportedGC* var = &SupportedGCs[0]; var < &SupportedGCs[ARRAY_SIZE(SupportedGCs)]; var++)
 
+#define FAIL_IF_SELECTED(option, enabled)                                   \
+  if (option == enabled && FLAG_IS_CMDLINE(option)) {                       \
+    vm_exit_during_initialization(enabled ?                                 \
+                                  "Option -XX:+" #option " not supported" : \
+                                  "Option -XX:-" #option " not supported"); \
+  }
+
 GCArguments* GCConfig::_arguments = NULL;
 bool GCConfig::_gc_selected_ergonomically = false;
 
+void GCConfig::fail_if_unsupported_gc_is_selected() {
+  NOT_CMSGC(     FAIL_IF_SELECTED(UseConcMarkSweepGC, true));
+  NOT_EPSILONGC( FAIL_IF_SELECTED(UseEpsilonGC,       true));
+  NOT_G1GC(      FAIL_IF_SELECTED(UseG1GC,            true));
+  NOT_PARALLELGC(FAIL_IF_SELECTED(UseParallelGC,      true));
+  NOT_PARALLELGC(FAIL_IF_SELECTED(UseParallelOldGC,   true));
+  NOT_SERIALGC(  FAIL_IF_SELECTED(UseSerialGC,        true));
+  NOT_SERIALGC(  FAIL_IF_SELECTED(UseParallelOldGC,   false));
+  NOT_ZGC(       FAIL_IF_SELECTED(UseZGC,             true));
+}
+
 void GCConfig::select_gc_ergonomically() {
   if (os::is_server_class_machine()) {
 #if INCLUDE_G1GC
@@ -96,14 +114,6 @@
     FLAG_SET_ERGO_IF_DEFAULT(bool, UseSerialGC, true);
 #endif
   }
-
-  NOT_CMSGC(     UNSUPPORTED_OPTION(UseConcMarkSweepGC));
-  NOT_EPSILONGC( UNSUPPORTED_OPTION(UseEpsilonGC);)
-  NOT_G1GC(      UNSUPPORTED_OPTION(UseG1GC);)
-  NOT_PARALLELGC(UNSUPPORTED_OPTION(UseParallelGC);)
-  NOT_PARALLELGC(UNSUPPORTED_OPTION(UseParallelOldGC));
-  NOT_SERIALGC(  UNSUPPORTED_OPTION(UseSerialGC);)
-  NOT_ZGC(       UNSUPPORTED_OPTION(UseZGC);)
 }
 
 bool GCConfig::is_no_gc_selected() {
@@ -135,6 +145,9 @@
 }
 
 GCArguments* GCConfig::select_gc() {
+  // Fail immediately if an unsupported GC is selected
+  fail_if_unsupported_gc_is_selected();
+
   if (is_no_gc_selected()) {
     // Try select GC ergonomically
     select_gc_ergonomically();
@@ -154,12 +167,6 @@
     vm_exit_during_initialization("Multiple garbage collectors selected", NULL);
   }
 
-#if INCLUDE_PARALLELGC && !INCLUDE_SERIALGC
-  if (FLAG_IS_CMDLINE(UseParallelOldGC) && !UseParallelOldGC) {
-    vm_exit_during_initialization("This JVM build only supports UseParallelOldGC as the full GC");
-  }
-#endif
-
   // Exactly one GC selected
   FOR_EACH_SUPPORTED_GC(gc) {
     if (gc->_flag) {
--- a/src/hotspot/share/gc/shared/gcConfig.hpp	Tue Jun 19 11:27:05 2018 +0200
+++ b/src/hotspot/share/gc/shared/gcConfig.hpp	Tue Jun 19 12:11:37 2018 +0200
@@ -35,6 +35,7 @@
   static GCArguments* _arguments;
   static bool         _gc_selected_ergonomically;
 
+  static void fail_if_unsupported_gc_is_selected();
   static bool is_no_gc_selected();
   static bool is_exactly_one_gc_selected();