8222015: Small VM.metaspace improvements
authorstuefe
Fri, 05 Apr 2019 11:52:32 +0200
changeset 54820 fcf83b204c27
parent 54819 c2551d161358
child 54821 85ccac8a8c13
8222015: Small VM.metaspace improvements Reviewed-by: jiangli, coleenp
src/hotspot/share/memory/metaspace.cpp
src/hotspot/share/memory/metaspace/metaspaceCommon.cpp
src/hotspot/share/memory/metaspace/metaspaceCommon.hpp
src/hotspot/share/memory/metaspace/printCLDMetaspaceInfoClosure.cpp
src/hotspot/share/memory/metaspace/printCLDMetaspaceInfoClosure.hpp
src/hotspot/share/memory/metaspace/printMetaspaceInfoKlassClosure.cpp
src/hotspot/share/memory/metaspace/printMetaspaceInfoKlassClosure.hpp
--- a/src/hotspot/share/memory/metaspace.cpp	Fri May 10 17:47:42 2019 -0700
+++ b/src/hotspot/share/memory/metaspace.cpp	Fri Apr 05 11:52:32 2019 +0200
@@ -667,12 +667,19 @@
     for (int space_type = (int)Metaspace::ZeroMetaspaceType;
          space_type < (int)Metaspace::MetaspaceTypeCount; space_type ++)
     {
-      uintx num = cl._num_loaders_by_spacetype[space_type];
-      out->print("%s (" UINTX_FORMAT " loader%s)%c",
+      uintx num_loaders = cl._num_loaders_by_spacetype[space_type];
+      uintx num_classes = cl._num_classes_by_spacetype[space_type];
+      out->print("%s - " UINTX_FORMAT " %s",
         space_type_name((Metaspace::MetaspaceType)space_type),
-        num, (num == 1 ? "" : "s"), (num > 0 ? ':' : '.'));
-      if (num > 0) {
+        num_loaders, loaders_plural(num_loaders));
+      if (num_classes > 0) {
+        out->print(", ");
+        print_number_of_classes(out, num_classes, cl._num_classes_shared_by_spacetype[space_type]);
+        out->print(":");
         cl._stats_by_spacetype[space_type].print_on(out, scale, print_by_chunktype);
+      } else {
+        out->print(".");
+        out->cr();
       }
       out->cr();
     }
@@ -680,10 +687,15 @@
 
   // Print totals for in-use data:
   out->cr();
-  out->print_cr("Total Usage ( " UINTX_FORMAT " loader%s)%c",
-      cl._num_loaders, (cl._num_loaders == 1 ? "" : "s"), (cl._num_loaders > 0 ? ':' : '.'));
-
-  cl._stats_total.print_on(out, scale, print_by_chunktype);
+  {
+    uintx num_loaders = cl._num_loaders;
+    out->print("Total Usage - " UINTX_FORMAT " %s, ",
+      num_loaders, loaders_plural(num_loaders));
+    print_number_of_classes(out, cl._num_classes, cl._num_classes_shared);
+    out->print(":");
+    cl._stats_total.print_on(out, scale, print_by_chunktype);
+    out->cr();
+  }
 
   // -- Print Virtual space.
   out->cr();
--- a/src/hotspot/share/memory/metaspace/metaspaceCommon.cpp	Fri May 10 17:47:42 2019 -0700
+++ b/src/hotspot/share/memory/metaspace/metaspaceCommon.cpp	Fri Apr 05 11:52:32 2019 +0200
@@ -194,6 +194,20 @@
   return (ChunkIndex) (i-1);
 }
 
+const char* loaders_plural(uintx num) {
+  return num == 1 ? "loader" : "loaders";
+}
+
+const char* classes_plural(uintx num) {
+  return num == 1 ? "class" : "classes";
+}
+
+void print_number_of_classes(outputStream* out, uintx classes, uintx classes_shared) {
+  out->print(UINTX_FORMAT " %s", classes, classes_plural(classes));
+  if (classes_shared > 0) {
+    out->print(" (" UINTX_FORMAT " shared)", classes_shared);
+  }
+}
 
 } // namespace metaspace
 
--- a/src/hotspot/share/memory/metaspace/metaspaceCommon.hpp	Fri May 10 17:47:42 2019 -0700
+++ b/src/hotspot/share/memory/metaspace/metaspaceCommon.hpp	Fri Apr 05 11:52:32 2019 +0200
@@ -140,6 +140,11 @@
   return is_valid_chunktype(index) && index != HumongousIndex;
 }
 
+// Pretty printing helpers
+const char* classes_plural(uintx num);
+const char* loaders_plural(uintx num);
+void print_number_of_classes(outputStream* out, uintx classes, uintx classes_shared);
+
 } // namespace metaspace
 
 #endif // SHARE_MEMORY_METASPACE_METASPACECOMMON_HPP
--- a/src/hotspot/share/memory/metaspace/printCLDMetaspaceInfoClosure.cpp	Fri May 10 17:47:42 2019 -0700
+++ b/src/hotspot/share/memory/metaspace/printCLDMetaspaceInfoClosure.cpp	Fri Apr 05 11:52:32 2019 +0200
@@ -26,6 +26,7 @@
 #include "classfile/javaClasses.hpp"
 #include "memory/metaspace/printCLDMetaspaceInfoClosure.hpp"
 #include "memory/metaspace/printMetaspaceInfoKlassClosure.hpp"
+#include "memory/metaspaceShared.hpp"
 #include "memory/resourceArea.hpp"
 #include "runtime/safepoint.hpp"
 #include "utilities/globalDefinitions.hpp"
@@ -39,13 +40,29 @@
 : _out(out), _scale(scale), _do_print(do_print), _do_print_classes(do_print_classes)
 , _break_down_by_chunktype(break_down_by_chunktype)
 , _num_loaders(0), _num_loaders_without_metaspace(0), _num_loaders_unloading(0)
+,  _num_classes(0), _num_classes_shared(0)
 {
   memset(_num_loaders_by_spacetype, 0, sizeof(_num_loaders_by_spacetype));
+  memset(_num_classes_by_spacetype, 0, sizeof(_num_classes_by_spacetype));
+  memset(_num_classes_shared_by_spacetype, 0, sizeof(_num_classes_shared_by_spacetype));
 }
 
-static const char* classes_plural(uintx num) {
-  return num == 1 ? "" : "es";
-}
+// A closure just to count classes
+class CountKlassClosure : public KlassClosure {
+public:
+
+  uintx _num_classes;
+  uintx _num_classes_shared;
+
+  CountKlassClosure() : _num_classes(0), _num_classes_shared(0) {}
+  void do_klass(Klass* k) {
+    _num_classes ++;
+    if (k->is_shared()) {
+      _num_classes_shared ++;
+    }
+  }
+
+}; // end: PrintKlassInfoClosure
 
 void PrintCLDMetaspaceInfoClosure::do_cld(ClassLoaderData* cld) {
 
@@ -72,7 +89,16 @@
   _stats_by_spacetype[msp->space_type()].add(this_cld_stat);
   _num_loaders_by_spacetype[msp->space_type()] ++;
 
-  // Optionally, print.
+  // Count classes loaded by this CLD.
+  CountKlassClosure ckc;
+  cld->classes_do(&ckc);
+  // accumulate.
+  _num_classes += ckc._num_classes;
+  _num_classes_by_spacetype[msp->space_type()] += ckc._num_classes;
+  _num_classes_shared += ckc._num_classes_shared;
+  _num_classes_shared_by_spacetype[msp->space_type()] += ckc._num_classes_shared;
+
+  // Optionally, print
   if (_do_print) {
 
     _out->print(UINTX_FORMAT_W(4) ": ", _num_loaders);
@@ -113,36 +139,25 @@
     }
 
     if (_do_print_classes) {
+      // Print a detailed description of all loaded classes.
       streamIndentor sti(_out, 6);
       _out->cr_indent();
-      _out->print("Loaded classes: ");
+      _out->print("Loaded classes");
+      if (ckc._num_classes_shared > 0) {
+        _out->print("('s' = shared)");
+      }
+      _out->print(":");
       PrintMetaspaceInfoKlassClosure pkic(_out, true);
       cld->classes_do(&pkic);
       _out->cr_indent();
       _out->print("-total-: ");
-      _out->print(UINTX_FORMAT " class%s", pkic._num_classes, classes_plural(pkic._num_classes));
-      if (pkic._num_instance_classes > 0 || pkic._num_array_classes > 0) {
-        _out->print(" (");
-        if (pkic._num_instance_classes > 0) {
-          _out->print(UINTX_FORMAT " instance class%s", pkic._num_instance_classes,
-              classes_plural(pkic._num_instance_classes));
-        }
-        if (pkic._num_array_classes > 0) {
-          if (pkic._num_instance_classes > 0) {
-            _out->print(", ");
-          }
-          _out->print(UINTX_FORMAT " array class%s", pkic._num_array_classes,
-              classes_plural(pkic._num_array_classes));
-        }
-        _out->print(").");
-      }
+      print_number_of_classes(_out, ckc._num_classes, ckc._num_classes_shared);
+    } else {
+      // Just print a summary about how many classes have been loaded.
+      _out->print(", ");
+      print_number_of_classes(_out, ckc._num_classes, ckc._num_classes_shared);
     }
 
-    _out->cr();
-
-
-    _out->cr();
-
     // Print statistics
     this_cld_stat.print_on(_out, _scale, _break_down_by_chunktype);
     _out->cr();
--- a/src/hotspot/share/memory/metaspace/printCLDMetaspaceInfoClosure.hpp	Fri May 10 17:47:42 2019 -0700
+++ b/src/hotspot/share/memory/metaspace/printCLDMetaspaceInfoClosure.hpp	Fri Apr 05 11:52:32 2019 +0200
@@ -52,6 +52,11 @@
   uintx                           _num_loaders_by_spacetype [Metaspace::MetaspaceTypeCount];
   ClassLoaderMetaspaceStatistics  _stats_by_spacetype [Metaspace::MetaspaceTypeCount];
 
+  uintx                           _num_classes_by_spacetype [Metaspace::MetaspaceTypeCount];
+  uintx                           _num_classes_shared_by_spacetype [Metaspace::MetaspaceTypeCount];
+  uintx                           _num_classes;
+  uintx                           _num_classes_shared;
+
   PrintCLDMetaspaceInfoClosure(outputStream* out, size_t scale, bool do_print,
       bool do_print_classes, bool break_down_by_chunktype);
   void do_cld(ClassLoaderData* cld);
--- a/src/hotspot/share/memory/metaspace/printMetaspaceInfoKlassClosure.cpp	Fri May 10 17:47:42 2019 -0700
+++ b/src/hotspot/share/memory/metaspace/printMetaspaceInfoKlassClosure.cpp	Fri Apr 05 11:52:32 2019 +0200
@@ -24,6 +24,7 @@
  */
 #include "precompiled.hpp"
 
+#include "memory/metaspaceShared.hpp"
 #include "memory/metaspace/printMetaspaceInfoKlassClosure.hpp"
 #include "memory/resourceArea.hpp"
 #include "oops/reflectionAccessorImplKlassHelper.hpp"
@@ -34,30 +35,25 @@
 namespace metaspace {
 
 PrintMetaspaceInfoKlassClosure::PrintMetaspaceInfoKlassClosure(outputStream* out, bool do_print)
-: _out(out), _do_print(do_print)
-, _num_classes(0), _num_instance_classes(0), _num_array_classes(0) {
-}
+: _out(out), _cnt(0)
+{}
 
 void PrintMetaspaceInfoKlassClosure::do_klass(Klass* k) {
-  _num_classes ++;
-  if (k->is_instance_klass()) {
-    _num_instance_classes ++;
-  } else if (k->is_array_klass()) {
-    _num_array_classes ++;
-  }
-  if (_do_print) {
-    _out->cr_indent();
-    _out->print(UINTX_FORMAT_W(4) ": ", _num_classes);
-    ResourceMark rm;
-    _out->print("%s", k->external_name());
+  _cnt ++;
+  _out->cr_indent();
+  _out->print(UINTX_FORMAT_W(4) ": ", _cnt);
+
+  // Print a 's' for shared classes
+  _out->put(k->is_shared() ? 's': ' ');
 
-    // Special treatment for generated core reflection accessor classes: print invocation target.
-    if (ReflectionAccessorImplKlassHelper::is_generated_accessor(k)) {
-      _out->print(" (invokes: ");
-      ReflectionAccessorImplKlassHelper::print_invocation_target(_out, k);
-      _out->print(")");
-    }
+  ResourceMark rm;
+  _out->print("  %s", k->external_name());
 
+  // Special treatment for generated core reflection accessor classes: print invocation target.
+  if (ReflectionAccessorImplKlassHelper::is_generated_accessor(k)) {
+    _out->print(" (invokes: ");
+    ReflectionAccessorImplKlassHelper::print_invocation_target(_out, k);
+    _out->print(")");
   }
 }
 
--- a/src/hotspot/share/memory/metaspace/printMetaspaceInfoKlassClosure.hpp	Fri May 10 17:47:42 2019 -0700
+++ b/src/hotspot/share/memory/metaspace/printMetaspaceInfoKlassClosure.hpp	Fri Apr 05 11:52:32 2019 +0200
@@ -38,16 +38,12 @@
 class PrintMetaspaceInfoKlassClosure : public KlassClosure {
 private:
   outputStream* const _out;
-  const bool          _do_print;
+  uintx _cnt;
 
   bool print_reflection_invocation_target(outputStream* out, InstanceKlass* magic_accessor_impl_class);
 
 public:
 
-  uintx _num_classes;
-  uintx _num_instance_classes;
-  uintx _num_array_classes;
-
   PrintMetaspaceInfoKlassClosure(outputStream* out, bool do_print);
   void do_klass(Klass* k);