src/share/vm/classfile/systemDictionary.cpp

Print this page
rev 9227 : [mq] cds

@@ -320,10 +320,21 @@
                                                  Symbol* class_name,
                                                  Handle class_loader,
                                                  Handle protection_domain,
                                                  bool is_superclass,
                                                  TRAPS) {
+#if INCLUDE_CDS
+  if (DumpSharedSpaces) {
+    // Special processing for CDS dump time.
+    Klass* k = SystemDictionaryShared::dump_time_resolve_super_or_fail(child_name,
+        class_name, class_loader, protection_domain, is_superclass, CHECK_NULL);
+    if (k) {
+      return k;
+    }
+  }
+#endif
+
   // Double-check, if child class is already loaded, just return super-class,interface
   // Don't add a placedholder if already loaded, i.e. already in system dictionary
   // Make sure there's a placeholder for the *child* before resolving.
   // Used as a claim that this thread is currently loading superclass/classloader
   // Used here for ClassCircularity checks and also for heap verification

@@ -1069,10 +1080,39 @@
   // Make sure we are synchronized on the class loader before we proceed
   Handle lockObject = compute_loader_lock_object(class_loader, THREAD);
   check_loader_lock_contention(lockObject, THREAD);
   ObjectLocker ol(lockObject, THREAD, DoObjectLock);
 
+#if INCLUDE_CDS
+  instanceKlassHandle sk = 
+    SystemDictionaryShared::resolve_from_shared_space(class_name,
+                                                      class_loader,
+                                                      protection_domain,
+                                                      st,
+                                                      verify,
+                                                      CHECK_NULL);
+  if (sk.not_null()) {
+    assert(MetaspaceShared::is_in_shared_space(sk()), "must be");
+
+    // Make sure we have an entry in the SystemDictionary on success
+    debug_only( {
+      Symbol*  h_name    = sk->name();
+      ClassLoaderData *defining_loader_data = sk->class_loader_data();
+
+      MutexLocker mu(SystemDictionary_lock, THREAD);
+
+      Klass* check = find_class(h_name, loader_data);
+      assert(check == sk(), "should be present in the dictionary");
+
+      Klass* check2 = find_class(h_name, defining_loader_data);
+      assert(check == check2, "name inconsistancy in SystemDictionary");
+    } );
+
+    return sk();
+  }
+#endif
+
   TempNewSymbol parsed_name = NULL;
 
   // Parse the stream. Note that we do this even though this klass might
   // already be present in the SystemDictionary, otherwise we would not
   // throw potential ClassFormatErrors.

@@ -1199,12 +1239,17 @@
     // are shared, add them to the main system dictionary and reset
     // their hierarchy references (supers, subs, and interfaces).
 
     if (ik->super() != NULL) {
       Symbol*  cn = ik->super()->name();
-      resolve_super_or_fail(class_name, cn,
+      Klass *s = resolve_super_or_fail(class_name, cn,
                             class_loader, protection_domain, true, CHECK_(nh));
+      if (s != ik->super()) {
+        // The dynamically resolved super class is not the same as the one we used during dump time,
+        // so we cannot use ik.
+        return nh;
+      }
     }
 
     Array<Klass*>* interfaces = ik->local_interfaces();
     int num_interfaces = interfaces->length();
     for (int index = 0; index < num_interfaces; index++) {

@@ -1213,11 +1258,16 @@
       // Note: can not use InstanceKlass::cast here because
       // interfaces' InstanceKlass's C++ vtbls haven't been
       // reinitialized yet (they will be once the interface classes
       // are loaded)
       Symbol*  name  = k->name();
-      resolve_super_or_fail(class_name, name, class_loader, protection_domain, false, CHECK_(nh));
+      Klass* i = resolve_super_or_fail(class_name, name, class_loader, protection_domain, false, CHECK_(nh));
+      if (k != i) {
+        // The dynamically resolved interface class is not the same as the one we used during dump time,
+        // so we cannot use ik.
+        return nh;
+      }
     }
 
     // Adjust methods to recover missing data.  They need addresses for
     // interpreter entry points and their default native method address
     // must be reset.