--- old/src/hotspot/share/memory/metaspaceShared.cpp 2020-02-26 18:40:00.043716921 -0800 +++ new/src/hotspot/share/memory/metaspaceShared.cpp 2020-02-26 18:39:59.405691956 -0800 @@ -1688,10 +1688,11 @@ } class LinkSharedClassesClosure : public KlassClosure { + bool _is_static; Thread* THREAD; bool _made_progress; public: - LinkSharedClassesClosure(Thread* thread) : THREAD(thread), _made_progress(false) {} + LinkSharedClassesClosure(bool is_static, Thread* thread) : _is_static(is_static), THREAD(thread), _made_progress(false) {} void reset() { _made_progress = false; } bool made_progress() const { return _made_progress; } @@ -1699,13 +1700,17 @@ void do_klass(Klass* k) { if (k->is_instance_klass()) { InstanceKlass* ik = InstanceKlass::cast(k); - // Link the class to cause the bytecodes to be rewritten and the - // cpcache to be created. Class verification is done according - // to -Xverify setting. - _made_progress |= MetaspaceShared::try_link_class(ik, THREAD); - guarantee(!HAS_PENDING_EXCEPTION, "exception in link_class"); + // For dynamic CDS dump, only link classes loaded by the builtin class loaders. + bool do_linking = _is_static ? true : ik->loader_type() != 0; + if (do_linking) { + // Link the class to cause the bytecodes to be rewritten and the + // cpcache to be created. Class verification is done according + // to -Xverify setting. + _made_progress |= MetaspaceShared::try_link_class(ik, THREAD); + guarantee(!HAS_PENDING_EXCEPTION, "exception in link_class"); - ik->constants()->resolve_class_constants(THREAD); + ik->constants()->resolve_class_constants(THREAD); + } } } }; @@ -1724,10 +1729,10 @@ } }; -void MetaspaceShared::link_and_cleanup_shared_classes(TRAPS) { +void MetaspaceShared::link_and_cleanup_shared_classes(bool is_static, Thread* THREAD) { // We need to iterate because verification may cause additional classes // to be loaded. - LinkSharedClassesClosure link_closure(THREAD); + LinkSharedClassesClosure link_closure(is_static, THREAD); do { link_closure.reset(); ClassLoaderDataGraph::unlocked_loaded_classes_do(&link_closure); @@ -1815,7 +1820,7 @@ // were not explicitly specified in the classlist. E.g., if an interface implemented by class K // fails verification, all other interfaces that were not specified in the classlist but // are implemented by K are not verified. - link_and_cleanup_shared_classes(CATCH); + link_and_cleanup_shared_classes(true, CATCH); log_info(cds)("Rewriting and linking classes: done"); if (HeapShared::is_heap_object_archiving_allowed()) { @@ -1871,7 +1876,7 @@ // Returns true if the class's status has changed bool MetaspaceShared::try_link_class(InstanceKlass* ik, TRAPS) { - assert(DumpSharedSpaces, "should only be called during dumping"); + Arguments::assert_is_dumping_archive(); if (ik->init_state() < InstanceKlass::linked) { bool saved = BytecodeVerificationLocal; if (ik->loader_type() == 0 && ik->class_loader() == NULL) {