From b81066f57e54b3ba358f70b03eebf10ce37ec080 Mon Sep 17 00:00:00 2001 From: ehelin Date: Fri, 21 Mar 2014 10:20:00 +0100 Subject: [PATCH] 8036699: Add trace event when a metaspace allocation fails Reviewed-by: jmasa, stefank --- src/share/vm/memory/metaspace.cpp | 12 ++++++++++++ src/share/vm/memory/metaspace.hpp | 2 ++ src/share/vm/memory/metaspaceTracer.cpp | 26 +++++++++++++++++++++++++ src/share/vm/memory/metaspaceTracer.hpp | 7 +++++++ src/share/vm/trace/trace.xml | 8 ++++++++ src/share/vm/trace/tracetypes.xml | 18 +++++++++++++++++ 6 files changed, 73 insertions(+) diff --git a/src/share/vm/memory/metaspace.cpp b/src/share/vm/memory/metaspace.cpp index 23dfe34d6..a84ab9893 100644 --- a/src/share/vm/memory/metaspace.cpp +++ b/src/share/vm/memory/metaspace.cpp @@ -3357,6 +3357,8 @@ MetaWord* Metaspace::allocate(ClassLoaderData* loader_data, size_t word_size, 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. @@ -3425,6 +3427,16 @@ void Metaspace::report_metadata_oome(ClassLoaderData* loader_data, size_t word_s } } +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"); diff --git a/src/share/vm/memory/metaspace.hpp b/src/share/vm/memory/metaspace.hpp index bdcb6e60a..26465706b 100644 --- a/src/share/vm/memory/metaspace.hpp +++ b/src/share/vm/memory/metaspace.hpp @@ -240,6 +240,8 @@ class Metaspace : public CHeapObj { 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(); diff --git a/src/share/vm/memory/metaspaceTracer.cpp b/src/share/vm/memory/metaspaceTracer.cpp index 6cb3f4d39..93bfda3a3 100644 --- a/src/share/vm/memory/metaspaceTracer.cpp +++ b/src/share/vm/memory/metaspaceTracer.cpp @@ -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 @@ void MetaspaceTracer::report_gc_threshold(size_t old_val, 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(); + } +} diff --git a/src/share/vm/memory/metaspaceTracer.hpp b/src/share/vm/memory/metaspaceTracer.hpp index 84d92a985..4e5352b3c 100644 --- a/src/share/vm/memory/metaspaceTracer.hpp +++ b/src/share/vm/memory/metaspaceTracer.hpp @@ -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 { 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 diff --git a/src/share/vm/trace/trace.xml b/src/share/vm/trace/trace.xml index 71d284ef7..9f3206e00 100644 --- a/src/share/vm/trace/trace.xml +++ b/src/share/vm/trace/trace.xml @@ -205,6 +205,14 @@ Declares a structure type that can be used in other events. + + + + + + + + diff --git a/src/share/vm/trace/tracetypes.xml b/src/share/vm/trace/tracetypes.xml index b61959469..eb1c708ea 100644 --- a/src/share/vm/trace/tracetypes.xml +++ b/src/share/vm/trace/tracetypes.xml @@ -140,6 +140,16 @@ Now we can use the content + data type in declaring event fields. + + + + + + + + @@ -337,6 +347,14 @@ Now we can use the content + data type in declaring event fields. + + + + + + -- GitLab