diff --git a/src/hotspot/share/cds/dynamicArchive.cpp b/src/hotspot/share/cds/dynamicArchive.cpp index 065597c652d..47c3642ff0e 100644 --- a/src/hotspot/share/cds/dynamicArchive.cpp +++ b/src/hotspot/share/cds/dynamicArchive.cpp @@ -107,9 +107,11 @@ class DynamicArchiveBuilder : public ArchiveBuilder { verify_universe("Before CDS dynamic dump"); DEBUG_ONLY(SystemDictionaryShared::NoClassLoadingMark nclm); - SystemDictionaryShared::check_excluded_classes(); + // Block concurrent class unloading from changing the _dumptime_table MutexLocker ml(DumpTimeTable_lock, Mutex::_no_safepoint_check_flag); + SystemDictionaryShared::check_excluded_classes(); + init_header(); gather_source_objs(); reserve_buffer(); diff --git a/src/hotspot/share/cds/metaspaceShared.cpp b/src/hotspot/share/cds/metaspaceShared.cpp index 0ea1abb2abf..c8ec44aee06 100644 --- a/src/hotspot/share/cds/metaspaceShared.cpp +++ b/src/hotspot/share/cds/metaspaceShared.cpp @@ -484,12 +484,10 @@ void VM_PopulateDumpSharedSpace::doit() { NOT_PRODUCT(SystemDictionary::verify();) - // At this point, many classes have been loaded. - // Gather systemDictionary classes in a global array and do everything to - // that so we don't have to walk the SystemDictionary again. + // Block concurrent class unloading from changing the _dumptime_table + MutexLocker ml(DumpTimeTable_lock, Mutex::_no_safepoint_check_flag); SystemDictionaryShared::check_excluded_classes(); - MutexLocker ml(DumpTimeTable_lock, Mutex::_no_safepoint_check_flag); StaticArchiveBuilder builder; builder.gather_source_objs(); builder.reserve_buffer(); diff --git a/src/hotspot/share/classfile/systemDictionaryShared.cpp b/src/hotspot/share/classfile/systemDictionaryShared.cpp index 811feb30f54..78fcb1bc8e2 100644 --- a/src/hotspot/share/classfile/systemDictionaryShared.cpp +++ b/src/hotspot/share/classfile/systemDictionaryShared.cpp @@ -1485,6 +1485,8 @@ class ExcludeDumpTimeSharedClasses : StackObj { }; void SystemDictionaryShared::check_excluded_classes() { + assert(no_class_loading_should_happen(), "sanity"); + assert_lock_strong(DumpTimeTable_lock); ExcludeDumpTimeSharedClasses excl; _dumptime_table->iterate(&excl); _dumptime_table->update_counts();