8193434: [GRAAL] Graal classes are not loaded with -Xshare:dump
authorccheung
Fri, 02 Mar 2018 17:33:59 -0800
changeset 49332 cd21aff24069
parent 49331 10b24a3af249
child 49333 489f1dd40582
8193434: [GRAAL] Graal classes are not loaded with -Xshare:dump Summary: allow loading of non-boot classes during CDS dumping but only add boot classes to the archive Reviewed-by: kvn, iklam, jiangli
src/hotspot/share/classfile/systemDictionary.cpp
src/hotspot/share/memory/metaspaceShared.cpp
test/hotspot/jtreg/runtime/appcds/UseAppCDS.java
--- a/src/hotspot/share/classfile/systemDictionary.cpp	Fri Mar 02 21:00:12 2018 +0100
+++ b/src/hotspot/share/classfile/systemDictionary.cpp	Fri Mar 02 17:33:59 2018 -0800
@@ -1056,15 +1056,6 @@
                                                      Handle protection_domain,
                                                      ClassFileStream* st,
                                                      TRAPS) {
-#if INCLUDE_CDS
-  ResourceMark rm(THREAD);
-  if (DumpSharedSpaces && !class_loader.is_null() &&
-      !UseAppCDS && strcmp(class_name->as_C_string(), "Unnamed") != 0) {
-    // If AppCDS is not enabled, don't define the class at dump time (except for the "Unnamed"
-    // class, which is used by MethodHandles).
-    THROW_MSG_NULL(vmSymbols::java_lang_ClassNotFoundException(), class_name->as_C_string());
-  }
-#endif
 
   HandleMark hm(THREAD);
 
@@ -3079,13 +3070,17 @@
     }
 };
 
-// Combining platform and system loader dictionaries into boot loader dictionaries.
+// Combining platform and system loader dictionaries into boot loader dictionary.
 // During run time, we only have one shared dictionary.
 void SystemDictionary::combine_shared_dictionaries() {
   assert(DumpSharedSpaces, "dump time only");
-  Dictionary* master_dictionary = ClassLoaderData::the_null_class_loader_data()->dictionary();
-  CombineDictionariesClosure cdc(master_dictionary);
-  ClassLoaderDataGraph::cld_do(&cdc);
+  // If AppCDS isn't enabled, we only dump the classes in the boot loader dictionary
+  // into the shared archive.
+  if (UseAppCDS) {
+    Dictionary* master_dictionary = ClassLoaderData::the_null_class_loader_data()->dictionary();
+    CombineDictionariesClosure cdc(master_dictionary);
+    ClassLoaderDataGraph::cld_do(&cdc);
+  }
 
   // These tables are no longer valid or necessary. Keeping them around will
   // cause SystemDictionary::verify() to fail. Let's empty them.
--- a/src/hotspot/share/memory/metaspaceShared.cpp	Fri Mar 02 21:00:12 2018 +0100
+++ b/src/hotspot/share/memory/metaspaceShared.cpp	Fri Mar 02 17:33:59 2018 -0800
@@ -450,6 +450,11 @@
 
 class CollectClassesClosure : public KlassClosure {
   void do_klass(Klass* k) {
+    if (!UseAppCDS && !k->class_loader_data()->is_the_null_class_loader_data()) {
+      // AppCDS is not enabled. Let's omit non-boot classes.
+      return;
+    }
+
     if (!(k->is_instance_klass() && InstanceKlass::cast(k)->is_in_error_state())) {
       if (k->is_instance_klass() && InstanceKlass::cast(k)->signers() != NULL) {
         // Mark any class with signers and don't add to the _global_klass_objects
--- a/test/hotspot/jtreg/runtime/appcds/UseAppCDS.java	Fri Mar 02 21:00:12 2018 +0100
+++ b/test/hotspot/jtreg/runtime/appcds/UseAppCDS.java	Fri Mar 02 17:33:59 2018 -0800
@@ -87,8 +87,11 @@
         // Next tests rely on the classlist we just dumped
 
         // Test 3: No AppCDS - "test" classes in classlist ignored when dumping
+        // Although AppCDS isn't used, all classes will be found during dumping
+        // after the fix for JDK-8193434. Classes which are not in the boot
+        // loader dictionary will not be saved into the archive.
         dumpArchive(false, new String[] { BOOTCLASS },
-                    new String[] { TESTNAME});
+                    new String[0]);
 
         // Test 4:    AppCDS - "test" classes in classlist are dumped
         dumpArchive(true, new String[] { BOOTCLASS, TESTNAME },