< prev index next >

src/hotspot/share/memory/metaspaceShared.cpp

Print this page

        

@@ -1686,30 +1686,35 @@
   }
   return k;
 }
 
 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; }
 
   void do_klass(Klass* k) {
     if (k->is_instance_klass()) {
       InstanceKlass* ik = InstanceKlass::cast(k);
+      // 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);
     }
   }
+  }
 };
 
 class CheckSharedClassesClosure : public KlassClosure {
   bool    _made_progress;
  public:

@@ -1722,14 +1727,14 @@
       _made_progress = true;
     }
   }
 };
 
-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);
     guarantee(!HAS_PENDING_EXCEPTION, "exception in link_class");
   } while (link_closure.made_progress());

@@ -1813,11 +1818,11 @@
 
     // Link any classes which got missed. This would happen if we have loaded classes that
     // 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()) {
       // Avoid fragmentation while archiving heap objects.
       Universe::heap()->soft_ref_policy()->set_should_clear_all_soft_refs(true);

@@ -1869,11 +1874,11 @@
   return class_count;
 }
 
 // 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) {
       // The verification decision is based on BytecodeVerificationRemote
       // for non-system classes. Since we are using the NULL classloader
< prev index next >