8227032: MetaspaceUtils::print_report crashes when called before initialization
authorstuefe
Mon, 01 Jul 2019 16:28:17 +0200
changeset 55586 014c8cd323af
parent 55585 51ad5ced897a
child 55587 4644b3155fce
8227032: MetaspaceUtils::print_report crashes when called before initialization Reviewed-by: tschatzl, goetz
src/hotspot/share/memory/metaspace.cpp
src/hotspot/share/memory/metaspace.hpp
--- a/src/hotspot/share/memory/metaspace.cpp	Thu Jul 04 11:55:00 2019 +0200
+++ b/src/hotspot/share/memory/metaspace.cpp	Mon Jul 01 16:28:17 2019 +0200
@@ -584,6 +584,11 @@
 // unlike print_report() is guaranteed not to lock or to walk the CLDG.
 void MetaspaceUtils::print_basic_report(outputStream* out, size_t scale) {
 
+  if (!Metaspace::initialized()) {
+    out->print_cr("Metaspace not yet initialized.");
+    return;
+  }
+
   out->cr();
   out->print_cr("Usage:");
 
@@ -672,6 +677,11 @@
 
 void MetaspaceUtils::print_report(outputStream* out, size_t scale, int flags) {
 
+  if (!Metaspace::initialized()) {
+    out->print_cr("Metaspace not yet initialized.");
+    return;
+  }
+
   const bool print_loaders = (flags & rf_show_loaders) > 0;
   const bool print_classes = (flags & rf_show_classes) > 0;
   const bool print_by_chunktype = (flags & rf_break_down_by_chunktype) > 0;
@@ -959,6 +969,8 @@
 ChunkManager* Metaspace::_chunk_manager_metadata = NULL;
 ChunkManager* Metaspace::_chunk_manager_class = NULL;
 
+bool Metaspace::_initialized = false;
+
 #define VIRTUALSPACEMULTIPLIER 2
 
 #ifdef _LP64
@@ -1285,6 +1297,9 @@
   }
 
   _tracer = new MetaspaceTracer();
+
+  _initialized = true;
+
 }
 
 void Metaspace::post_initialize() {
--- a/src/hotspot/share/memory/metaspace.hpp	Thu Jul 04 11:55:00 2019 +0200
+++ b/src/hotspot/share/memory/metaspace.hpp	Mon Jul 01 16:28:17 2019 +0200
@@ -140,6 +140,8 @@
 
   static const MetaspaceTracer* _tracer;
 
+  static bool _initialized;
+
  public:
   static metaspace::VirtualSpaceList* space_list()       { return _space_list; }
   static metaspace::VirtualSpaceList* class_space_list() { return _class_space_list; }
@@ -225,6 +227,8 @@
     return mdType == ClassType && using_class_space();
   }
 
+  static bool initialized() { return _initialized; }
+
 };
 
 // Manages the metaspace portion belonging to a class loader