8202364: Add GCConfig::hs_err_name() to avoid GC-specific code in error reporting
authorpliden
Mon, 30 Apr 2018 12:19:53 +0200
changeset 49922 3a64eea72624
parent 49921 b708a1e34fcc
child 49923 764aea6237ad
8202364: Add GCConfig::hs_err_name() to avoid GC-specific code in error reporting Reviewed-by: eosterlund, shade
src/hotspot/share/gc/shared/gcConfig.cpp
src/hotspot/share/gc/shared/gcConfig.hpp
src/hotspot/share/utilities/vmError.cpp
--- a/src/hotspot/share/gc/shared/gcConfig.cpp	Mon Apr 30 11:48:03 2018 +0200
+++ b/src/hotspot/share/gc/shared/gcConfig.cpp	Mon Apr 30 12:19:53 2018 +0200
@@ -38,9 +38,10 @@
   bool&               _flag;
   CollectedHeap::Name _name;
   GCArguments&        _arguments;
+  const char*         _hs_err_name;
 
-  SupportedGC(bool& flag, CollectedHeap::Name name, GCArguments& arguments) :
-      _flag(flag), _name(name), _arguments(arguments) {}
+  SupportedGC(bool& flag, CollectedHeap::Name name, GCArguments& arguments, const char* hs_err_name) :
+      _flag(flag), _name(name), _arguments(arguments), _hs_err_name(hs_err_name) {}
 };
 
 static SerialArguments   serialArguments;
@@ -53,12 +54,12 @@
 // Table of supported GCs, for translating between command
 // line flag, CollectedHeap::Name and GCArguments instance.
 static const SupportedGC SupportedGCs[] = {
-  SupportedGC(UseSerialGC,        CollectedHeap::Serial,   serialArguments),
+  SupportedGC(UseSerialGC,        CollectedHeap::Serial,   serialArguments,   "serial gc"),
 #if INCLUDE_ALL_GCS
-  SupportedGC(UseParallelGC,      CollectedHeap::Parallel, parallelArguments),
-  SupportedGC(UseParallelOldGC,   CollectedHeap::Parallel, parallelArguments),
-  SupportedGC(UseConcMarkSweepGC, CollectedHeap::CMS,      cmsArguments),
-  SupportedGC(UseG1GC,            CollectedHeap::G1,       g1Arguments),
+  SupportedGC(UseParallelGC,      CollectedHeap::Parallel, parallelArguments, "parallel gc"),
+  SupportedGC(UseParallelOldGC,   CollectedHeap::Parallel, parallelArguments, "parallel gc"),
+  SupportedGC(UseConcMarkSweepGC, CollectedHeap::CMS,      cmsArguments,      "concurrent mark sweep gc"),
+  SupportedGC(UseG1GC,            CollectedHeap::G1,       g1Arguments,       "g1 gc"),
 #endif // INCLUDE_ALL_GCS
 };
 
@@ -172,6 +173,20 @@
   return _gc_selected_ergonomically;
 }
 
+const char* GCConfig::hs_err_name() {
+  if (is_exactly_one_gc_selected()) {
+    // Exacly one GC selected
+    for (size_t i = 0; i < ARRAY_SIZE(SupportedGCs); i++) {
+      if (SupportedGCs[i]._flag) {
+        return SupportedGCs[i]._hs_err_name;
+      }
+    }
+  }
+
+  // Zero or more than one GC selected
+  return "unknown gc";
+}
+
 GCArguments* GCConfig::arguments() {
   assert(_arguments != NULL, "Not initialized");
   return _arguments;
--- a/src/hotspot/share/gc/shared/gcConfig.hpp	Mon Apr 30 11:48:03 2018 +0200
+++ b/src/hotspot/share/gc/shared/gcConfig.hpp	Mon Apr 30 12:19:53 2018 +0200
@@ -48,6 +48,8 @@
   static bool is_gc_selected(CollectedHeap::Name name);
   static bool is_gc_selected_ergonomically();
 
+  static const char* hs_err_name();
+
   static GCArguments* arguments();
 };
 
--- a/src/hotspot/share/utilities/vmError.cpp	Mon Apr 30 11:48:03 2018 +0200
+++ b/src/hotspot/share/utilities/vmError.cpp	Mon Apr 30 12:19:53 2018 +0200
@@ -27,7 +27,7 @@
 #include "code/codeCache.hpp"
 #include "compiler/compileBroker.hpp"
 #include "compiler/disassembler.hpp"
-#include "gc/shared/collectedHeap.hpp"
+#include "gc/shared/gcConfig.hpp"
 #include "logging/logConfiguration.hpp"
 #include "memory/resourceArea.hpp"
 #include "prims/whitebox.hpp"
@@ -304,14 +304,6 @@
   st->print_cr("# This output file may be truncated or incomplete.");
 }
 
-static const char* gc_mode() {
-  if (UseG1GC)            return "g1 gc";
-  if (UseParallelGC)      return "parallel gc";
-  if (UseConcMarkSweepGC) return "concurrent mark sweep gc";
-  if (UseSerialGC)        return "serial gc";
-  return "ERROR in GC mode";
-}
-
 static void report_vm_version(outputStream* st, char* buf, int buflen) {
    // VM version
    st->print_cr("#");
@@ -340,7 +332,7 @@
                  "", "",
 #endif
                  UseCompressedOops ? ", compressed oops" : "",
-                 gc_mode(),
+                 GCConfig::hs_err_name(),
                  Abstract_VM_Version::vm_platform_string()
                );
 }