8036699: Add trace event when a metaspace allocation fails
authorehelin
Tue, 18 Mar 2014 07:00:06 +0100
changeset 23468 6bb416a59349
parent 23467 5bbc17380f6c
child 23469 0a4d02776968
8036699: Add trace event when a metaspace allocation fails Reviewed-by: jmasa, stefank
hotspot/src/share/vm/memory/metaspace.cpp
hotspot/src/share/vm/memory/metaspace.hpp
hotspot/src/share/vm/memory/metaspaceTracer.cpp
hotspot/src/share/vm/memory/metaspaceTracer.hpp
hotspot/src/share/vm/trace/trace.xml
hotspot/src/share/vm/trace/tracetypes.xml
--- a/hotspot/src/share/vm/memory/metaspace.cpp	Tue Mar 18 06:15:45 2014 +0100
+++ b/hotspot/src/share/vm/memory/metaspace.cpp	Tue Mar 18 07:00:06 2014 +0100
@@ -3358,6 +3358,8 @@
   MetaWord* result = loader_data->metaspace_non_null()->allocate(word_size, mdtype);
 
   if (result == NULL) {
+    tracer()->report_metaspace_allocation_failure(loader_data, word_size, type, mdtype);
+
     // Allocation failed.
     if (is_init_completed()) {
       // Only start a GC if the bootstrapping has completed.
@@ -3426,6 +3428,16 @@
   }
 }
 
+const char* Metaspace::metadata_type_name(Metaspace::MetadataType mdtype) {
+  switch (mdtype) {
+    case Metaspace::ClassType: return "Class";
+    case Metaspace::NonClassType: return "Metadata";
+    default:
+      assert(false, err_msg("Got bad mdtype: %d", (int) mdtype));
+      return NULL;
+  }
+}
+
 void Metaspace::record_allocation(void* ptr, MetaspaceObj::Type type, size_t word_size) {
   assert(DumpSharedSpaces, "sanity");
 
--- a/hotspot/src/share/vm/memory/metaspace.hpp	Tue Mar 18 06:15:45 2014 +0100
+++ b/hotspot/src/share/vm/memory/metaspace.hpp	Tue Mar 18 07:00:06 2014 +0100
@@ -241,6 +241,8 @@
   static void report_metadata_oome(ClassLoaderData* loader_data, size_t word_size,
                                    MetadataType mdtype, TRAPS);
 
+  static const char* metadata_type_name(Metaspace::MetadataType mdtype);
+
   void print_on(outputStream* st) const;
   // Debugging support
   void verify();
--- a/hotspot/src/share/vm/memory/metaspaceTracer.cpp	Tue Mar 18 06:15:45 2014 +0100
+++ b/hotspot/src/share/vm/memory/metaspaceTracer.cpp	Tue Mar 18 07:00:06 2014 +0100
@@ -23,6 +23,7 @@
  */
 
 #include "precompiled.hpp"
+#include "classfile/classLoaderData.hpp"
 #include "memory/metaspaceTracer.hpp"
 #include "trace/tracing.hpp"
 #include "trace/traceBackend.hpp"
@@ -38,3 +39,28 @@
     event.commit();
   }
 }
+
+void MetaspaceTracer::report_metaspace_allocation_failure(ClassLoaderData *cld,
+                                                          size_t word_size,
+                                                          MetaspaceObj::Type objtype,
+                                                          Metaspace::MetadataType mdtype) const {
+  EventMetaspaceAllocationFailure event;
+  if (event.should_commit()) {
+    if (cld->is_anonymous()) {
+      event.set_classLoader(NULL);
+      event.set_anonymousClassLoader(true);
+    } else {
+      if (cld->is_the_null_class_loader_data()) {
+        event.set_classLoader((Klass*) NULL);
+      } else {
+        event.set_classLoader(cld->class_loader()->klass());
+      }
+      event.set_anonymousClassLoader(false);
+    }
+
+    event.set_size(word_size * BytesPerWord);
+    event.set_metadataType((u1) mdtype);
+    event.set_metaspaceObjectType((u1) objtype);
+    event.commit();
+  }
+}
--- a/hotspot/src/share/vm/memory/metaspaceTracer.hpp	Tue Mar 18 06:15:45 2014 +0100
+++ b/hotspot/src/share/vm/memory/metaspaceTracer.hpp	Tue Mar 18 07:00:06 2014 +0100
@@ -26,13 +26,20 @@
 #define SHARE_VM_MEMORY_METASPACE_TRACER_HPP
 
 #include "memory/allocation.hpp"
+#include "memory/metaspace.hpp"
 #include "memory/metaspaceGCThresholdUpdater.hpp"
 
+class ClassLoaderData;
+
 class MetaspaceTracer : public CHeapObj<mtTracing> {
  public:
   void report_gc_threshold(size_t old_val,
                            size_t new_val,
                            MetaspaceGCThresholdUpdater::Type updater) const;
+  void report_metaspace_allocation_failure(ClassLoaderData *cld,
+                                           size_t word_size,
+                                           MetaspaceObj::Type objtype,
+                                           Metaspace::MetadataType mdtype) const;
 };
 
 #endif // SHARE_VM_MEMORY_METASPACE_TRACER_HPP
--- a/hotspot/src/share/vm/trace/trace.xml	Tue Mar 18 06:15:45 2014 +0100
+++ b/hotspot/src/share/vm/trace/trace.xml	Tue Mar 18 07:00:06 2014 +0100
@@ -205,6 +205,14 @@
       <value type="GCTHRESHOLDUPDATER" field="updater" label="Updater" />
     </event>
 
+    <event id="MetaspaceAllocationFailure" path="vm/gc/metaspace/allocation_failure" label="Metaspace Allocation Failure" is_instant="true" has_stacktrace="true">
+      <value type="CLASS" field="classLoader" label="Class Loader" />
+      <value type="BOOLEAN" field="anonymousClassLoader" label="Anonymous Class Loader" />
+      <value type="BYTES64" field="size" label="Size" />
+      <value type="METADATATYPE" field="metadataType" label="Metadata Type" />
+      <value type="METASPACEOBJTYPE" field="metaspaceObjectType" label="Metaspace Object Type" />
+    </event>
+
     <event id="PSHeapSummary" path="vm/gc/heap/ps_summary" label="Parallel Scavenge Heap Summary" is_instant="true">
       <value type="UINT" field="gcId" label="GC ID" relation="GC_ID"/>
       <value type="GCWHEN" field="when" label="When" />
--- a/hotspot/src/share/vm/trace/tracetypes.xml	Tue Mar 18 06:15:45 2014 +0100
+++ b/hotspot/src/share/vm/trace/tracetypes.xml	Tue Mar 18 07:00:06 2014 +0100
@@ -140,6 +140,16 @@
       <value type="UTF8" field="type" label="type" />
     </content_type>
 
+    <content_type id="MetadataType" hr_name="Metadata Type"
+                  type="U1" jvm_type="METADATATYPE">
+      <value type="UTF8" field="type" label="type" />
+    </content_type>
+
+    <content_type id="MetaspaceObjectType" hr_name="Metaspace Object Type"
+                  type="U1" jvm_type="METASPACEOBJTYPE">
+      <value type="UTF8" field="type" label="type" />
+    </content_type>
+
     <content_type id="NARROW_OOP_MODE" hr_name="Narrow Oop Mode"
                   type="U1" jvm_type="NARROWOOPMODE">
       <value type="UTF8" field="mode" label="mode" />
@@ -337,6 +347,14 @@
     <primary_type symbol="REFERENCETYPE" datatype="U1"
                   contenttype="REFERENCETYPE" type="u1" sizeop="sizeof(u1)" />
 
+    <!-- METADATATYPE -->
+    <primary_type symbol="METADATATYPE" datatype="U1"
+                  contenttype="METADATATYPE" type="u1" sizeop="sizeof(u1)" />
+
+    <!-- METADATAOBJTYPE -->
+    <primary_type symbol="METASPACEOBJTYPE" datatype="U1"
+                  contenttype="METASPACEOBJTYPE" type="u1" sizeop="sizeof(u1)" />
+
     <!-- NARROWOOPMODE -->
     <primary_type symbol="NARROWOOPMODE" datatype="U1"
                   contenttype="NARROWOOPMODE" type="u1" sizeop="sizeof(u1)" />