8155678: ClassLoader::initialize_module_loader_map should only be called when dumping CDS archive.
authorjiangli
Wed, 04 May 2016 17:32:08 -0400
changeset 38192 05ab1ee04bf2
parent 38187 f1879f6d7e63
child 38193 18d7062e9ece
8155678: ClassLoader::initialize_module_loader_map should only be called when dumping CDS archive. Summary: Make ClassLoader::initialize_module_loader_map explicitly CDS dump time only. Reviewed-by: ccheung, lfoltan
hotspot/src/share/vm/classfile/classLoader.cpp
hotspot/src/share/vm/classfile/classLoader.hpp
hotspot/src/share/vm/classfile/classLoaderExt.hpp
hotspot/src/share/vm/oops/instanceKlass.hpp
--- a/hotspot/src/share/vm/classfile/classLoader.cpp	Wed May 04 17:47:05 2016 +0300
+++ b/hotspot/src/share/vm/classfile/classLoader.cpp	Wed May 04 17:32:08 2016 -0400
@@ -941,6 +941,10 @@
 
 #if INCLUDE_CDS
 void ClassLoader::initialize_module_loader_map(JImageFile* jimage) {
+  if (!DumpSharedSpaces) {
+    return; // only needed for CDS dump time
+  }
+
   jlong size;
   JImageLocationRef location = (*JImageFindResource)(jimage, "java.base", get_jimage_version_string(), MODULE_LOADER_MAP, &size);
   if (location == 0) {
@@ -1085,6 +1089,7 @@
 #if INCLUDE_CDS
 s2 ClassLoader::module_to_classloader(const char* module_name) {
 
+  assert(DumpSharedSpaces, "dump time only");
   assert(_boot_modules_array != NULL, "_boot_modules_array is NULL");
   assert(_platform_modules_array != NULL, "_platform_modules_array is NULL");
 
@@ -1104,11 +1109,11 @@
 
   return APP_LOADER;
 }
-#endif
 
 s2 ClassLoader::classloader_type(Symbol* class_name, ClassPathEntry* e,
                                      int classpath_index, TRAPS) {
-#if INCLUDE_CDS
+  assert(DumpSharedSpaces, "Only used for CDS dump time");
+
   // obtain the classloader type based on the class name.
   // First obtain the package name based on the class name. Then obtain
   // the classloader type based on the package name from the jimage using
@@ -1133,10 +1138,8 @@
     loader_type = ClassLoader::BOOT_LOADER;
   }
   return loader_type;
+}
 #endif
-  return ClassLoader::BOOT_LOADER; // the classloader type is ignored in non-CDS cases
-}
-
 
 // caller needs ResourceMark
 const char* ClassLoader::file_name_for_class_name(const char* class_name,
@@ -1253,8 +1256,7 @@
     return NULL;
   }
 
-  jshort loader_type = classloader_type(name, e, classpath_index, CHECK_NULL);
-  return context.record_result(classpath_index, loader_type, e, result, THREAD);
+  return context.record_result(name, e, classpath_index, result, THREAD);
 }
 
 // Initialize the class loader's access to methods in libzip.  Parse and
--- a/hotspot/src/share/vm/classfile/classLoader.hpp	Wed May 04 17:47:05 2016 +0300
+++ b/hotspot/src/share/vm/classfile/classLoader.hpp	Wed May 04 17:32:08 2016 -0400
@@ -379,9 +379,9 @@
 
   static s2 module_to_classloader(const char* module_name);
   static void initialize_module_loader_map(JImageFile* jimage);
+  static s2 classloader_type(Symbol* class_name, ClassPathEntry* e,
+                             int classpath_index, TRAPS);
 #endif
-  static s2 classloader_type(Symbol* class_name, ClassPathEntry* e,
-                                 int classpath_index, TRAPS);
 
   static void  trace_class_path(const char* msg, const char* name = NULL);
 
--- a/hotspot/src/share/vm/classfile/classLoaderExt.hpp	Wed May 04 17:47:05 2016 +0300
+++ b/hotspot/src/share/vm/classfile/classLoaderExt.hpp	Wed May 04 17:32:08 2016 -0400
@@ -49,12 +49,14 @@
       return false;
     }
 
-    instanceKlassHandle record_result(const s2 classpath_index,
-                                      const jshort classloader_type,
-                                      const ClassPathEntry* e,
+    instanceKlassHandle record_result(Symbol* class_name,
+                                      ClassPathEntry* e,
+                                      const s2 classpath_index,
                                       instanceKlassHandle result, TRAPS) {
       if (ClassLoader::add_package(_file_name, classpath_index, THREAD)) {
         if (DumpSharedSpaces) {
+          s2 classloader_type = ClassLoader::classloader_type(
+                          class_name, e, classpath_index, CHECK_(result));
           result->set_shared_classpath_index(classpath_index);
           result->set_class_loader_type(classloader_type);
         }
--- a/hotspot/src/share/vm/oops/instanceKlass.hpp	Wed May 04 17:47:05 2016 +0300
+++ b/hotspot/src/share/vm/oops/instanceKlass.hpp	Wed May 04 17:32:08 2016 -0400
@@ -321,7 +321,7 @@
     return (_misc_flags & _misc_is_shared_app_class) != 0;
   }
 
-  void set_class_loader_type(jshort loader_type) {
+  void set_class_loader_type(s2 loader_type) {
     assert(( _misc_flags & loader_type_bits()) == 0,
            "Should only be called once for each class.");
     switch (loader_type) {