8036701: Add trace event when a metaspace throws out of memory error
authorehelin
Tue, 18 Mar 2014 08:00:21 +0100
changeset 23469 0a4d02776968
parent 23468 6bb416a59349
child 23470 ff2a7ea4225d
8036701: Add trace event when a metaspace throws out of memory error Reviewed-by: stefank, mgerdin
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
--- a/hotspot/src/share/vm/memory/metaspace.cpp	Tue Mar 18 07:00:06 2014 +0100
+++ b/hotspot/src/share/vm/memory/metaspace.cpp	Tue Mar 18 08:00:21 2014 +0100
@@ -3371,7 +3371,7 @@
   }
 
   if (result == NULL) {
-    report_metadata_oome(loader_data, word_size, mdtype, CHECK_NULL);
+    report_metadata_oome(loader_data, word_size, type, mdtype, CHECK_NULL);
   }
 
   // Zero initialize.
@@ -3385,7 +3385,9 @@
   return class_vsm()->calc_chunk_size(word_size);
 }
 
-void Metaspace::report_metadata_oome(ClassLoaderData* loader_data, size_t word_size, MetadataType mdtype, TRAPS) {
+void Metaspace::report_metadata_oome(ClassLoaderData* loader_data, size_t word_size, MetaspaceObj::Type type, MetadataType mdtype, TRAPS) {
+  tracer()->report_metadata_oom(loader_data, word_size, type, mdtype);
+
   // If result is still null, we are out of memory.
   if (Verbose && TraceMetadataChunkAllocation) {
     gclog_or_tty->print_cr("Metaspace allocation failed for size "
--- a/hotspot/src/share/vm/memory/metaspace.hpp	Tue Mar 18 07:00:06 2014 +0100
+++ b/hotspot/src/share/vm/memory/metaspace.hpp	Tue Mar 18 08:00:21 2014 +0100
@@ -239,7 +239,7 @@
   static void purge();
 
   static void report_metadata_oome(ClassLoaderData* loader_data, size_t word_size,
-                                   MetadataType mdtype, TRAPS);
+                                   MetaspaceObj::Type type, MetadataType mdtype, TRAPS);
 
   static const char* metadata_type_name(Metaspace::MetadataType mdtype);
 
--- a/hotspot/src/share/vm/memory/metaspaceTracer.cpp	Tue Mar 18 07:00:06 2014 +0100
+++ b/hotspot/src/share/vm/memory/metaspaceTracer.cpp	Tue Mar 18 08:00:21 2014 +0100
@@ -44,7 +44,22 @@
                                                           size_t word_size,
                                                           MetaspaceObj::Type objtype,
                                                           Metaspace::MetadataType mdtype) const {
-  EventMetaspaceAllocationFailure event;
+  send_allocation_failure_event<EventMetaspaceAllocationFailure>(cld, word_size, objtype, mdtype);
+}
+
+void MetaspaceTracer::report_metadata_oom(ClassLoaderData *cld,
+                                         size_t word_size,
+                                         MetaspaceObj::Type objtype,
+                                         Metaspace::MetadataType mdtype) const {
+  send_allocation_failure_event<EventMetaspaceOOM>(cld, word_size, objtype, mdtype);
+}
+
+template <typename E>
+void MetaspaceTracer::send_allocation_failure_event(ClassLoaderData *cld,
+                                                    size_t word_size,
+                                                    MetaspaceObj::Type objtype,
+                                                    Metaspace::MetadataType mdtype) const {
+  E event;
   if (event.should_commit()) {
     if (cld->is_anonymous()) {
       event.set_classLoader(NULL);
--- a/hotspot/src/share/vm/memory/metaspaceTracer.hpp	Tue Mar 18 07:00:06 2014 +0100
+++ b/hotspot/src/share/vm/memory/metaspaceTracer.hpp	Tue Mar 18 08:00:21 2014 +0100
@@ -32,6 +32,11 @@
 class ClassLoaderData;
 
 class MetaspaceTracer : public CHeapObj<mtTracing> {
+  template <typename E>
+  void send_allocation_failure_event(ClassLoaderData *cld,
+                                     size_t word_size,
+                                     MetaspaceObj::Type objtype,
+                                     Metaspace::MetadataType mdtype) const;
  public:
   void report_gc_threshold(size_t old_val,
                            size_t new_val,
@@ -40,6 +45,11 @@
                                            size_t word_size,
                                            MetaspaceObj::Type objtype,
                                            Metaspace::MetadataType mdtype) const;
+  void report_metadata_oom(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 07:00:06 2014 +0100
+++ b/hotspot/src/share/vm/trace/trace.xml	Tue Mar 18 08:00:21 2014 +0100
@@ -213,6 +213,14 @@
       <value type="METASPACEOBJTYPE" field="metaspaceObjectType" label="Metaspace Object Type" />
     </event>
 
+    <event id="MetaspaceOOM" path="vm/gc/metaspace/out_of_memory" label="Metaspace Out of Memory" 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" />