diff --git a/src/hotspot/share/memory/metaspace/runningCounters.cpp b/src/hotspot/share/memory/metaspace/runningCounters.cpp index 08dffc5c64c..323862ac02f 100644 --- a/src/hotspot/share/memory/metaspace/runningCounters.cpp +++ b/src/hotspot/share/memory/metaspace/runningCounters.cpp @@ -45,6 +45,7 @@ size_t RunningCounters::reserved_words_class() { } size_t RunningCounters::reserved_words_nonclass() { + assert(VirtualSpaceList::vslist_nonclass() != nullptr, "Metaspace not yet initialized"); return VirtualSpaceList::vslist_nonclass()->reserved_words(); } @@ -59,6 +60,7 @@ size_t RunningCounters::committed_words_class() { } size_t RunningCounters::committed_words_nonclass() { + assert(VirtualSpaceList::vslist_nonclass() != nullptr, "Metaspace not yet initialized"); return VirtualSpaceList::vslist_nonclass()->committed_words(); } @@ -90,6 +92,7 @@ size_t RunningCounters::free_chunks_words_class() { } size_t RunningCounters::free_chunks_words_nonclass() { + assert(ChunkManager::chunkmanager_nonclass() != nullptr, "Metaspace not yet initialized"); return ChunkManager::chunkmanager_nonclass()->total_word_size(); } diff --git a/src/hotspot/share/nmt/memReporter.cpp b/src/hotspot/share/nmt/memReporter.cpp index 96ad3c5cb1a..d1de2863749 100644 --- a/src/hotspot/share/nmt/memReporter.cpp +++ b/src/hotspot/share/nmt/memReporter.cpp @@ -272,6 +272,13 @@ void MemSummaryReporter::report_summary_of_type(MEMFLAGS flag, } void MemSummaryReporter::report_metadata(Metaspace::MetadataType type) const { + + // NMT reports may be triggered (as part of error handling) very early. Make sure + // Metaspace is already initialized. + if (!Metaspace::initialized()) { + return; + } + assert(type == Metaspace::NonClassType || type == Metaspace::ClassType, "Invalid metadata type"); const char* name = (type == Metaspace::NonClassType) ?