--- old/src/hotspot/share/memory/metaspaceShared.cpp 2018-11-01 21:23:12.651927898 -0700 +++ new/src/hotspot/share/memory/metaspaceShared.cpp 2018-11-01 21:23:12.295914331 -0700 @@ -1207,10 +1207,6 @@ public: static void copy_and_compact() { - // We should no longer allocate anything from the metaspace, so that - // we can have a stable set of MetaspaceObjs to work with. - Metaspace::freeze(); - ResourceMark rm; SortedSymbolClosure the_ssc; // StackObj _ssc = &the_ssc; @@ -1357,6 +1353,14 @@ } void VM_PopulateDumpSharedSpace::doit() { + // We should no longer allocate anything from the metaspace, so that: + // + // (1) Metaspace::allocate might trigger GC if we have run out of + // committed metaspace, but we can't GC because we're running + // in the VM thread. + // (2) ArchiveCompactor needs to work with a stable set of MetaspaceObjs. + Metaspace::freeze(); + Thread* THREAD = VMThread::vm_thread(); FileMapInfo::check_nonempty_dir_in_shared_path_table(); @@ -1421,8 +1425,6 @@ // any dictionaries. NOT_PRODUCT(assert_no_unsafe_anonymous_classes_in_dictionaries()); - SystemDictionaryShared::finalize_verification_constraints(); - ArchiveCompactor::initialize(); ArchiveCompactor::copy_and_compact();