< prev index next >

src/hotspot/share/classfile/systemDictionary.cpp

Print this page

  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "cds/aotClassLocation.hpp"
  26 #include "cds/cdsConfig.hpp"
  27 #include "cds/heapShared.hpp"
  28 #include "classfile/classFileParser.hpp"
  29 #include "classfile/classFileStream.hpp"
  30 #include "classfile/classLoader.hpp"
  31 #include "classfile/classLoaderData.inline.hpp"
  32 #include "classfile/classLoaderDataGraph.inline.hpp"
  33 #include "classfile/classLoadInfo.hpp"
  34 #include "classfile/dictionary.hpp"
  35 #include "classfile/javaClasses.inline.hpp"
  36 #include "classfile/klassFactory.hpp"
  37 #include "classfile/loaderConstraints.hpp"

  38 #include "classfile/packageEntry.hpp"
  39 #include "classfile/placeholders.hpp"
  40 #include "classfile/resolutionErrors.hpp"
  41 #include "classfile/stringTable.hpp"
  42 #include "classfile/symbolTable.hpp"
  43 #include "classfile/systemDictionary.hpp"
  44 #include "classfile/vmClasses.hpp"
  45 #include "classfile/vmSymbols.hpp"
  46 #include "gc/shared/gcTraceTime.inline.hpp"
  47 #include "interpreter/bootstrapInfo.hpp"
  48 #include "jfr/jfrEvents.hpp"
  49 #include "jvm.h"
  50 #include "logging/log.hpp"
  51 #include "logging/logStream.hpp"
  52 #include "memory/metaspaceClosure.hpp"
  53 #include "memory/oopFactory.hpp"
  54 #include "memory/resourceArea.hpp"
  55 #include "memory/universe.hpp"
  56 #include "oops/access.inline.hpp"
  57 #include "oops/instanceKlass.hpp"

 975     assert(cl->is_modules_image() || HeapShared::is_a_test_class_in_unnamed_module(ik),
 976            "only these classes can be loaded before the module system is initialized");
 977     assert(class_loader.is_null(), "sanity");
 978     return true;
 979   }
 980 
 981   if (pkg_entry == nullptr) {
 982     // We might have looked up pkg_entry before the module system was initialized.
 983     // Need to reload it now.
 984     TempNewSymbol pkg_name = ClassLoader::package_from_class_name(class_name);
 985     if (pkg_name != nullptr) {
 986       pkg_entry = class_loader_data(class_loader)->packages()->lookup_only(pkg_name);
 987     }
 988   }
 989 
 990   ModuleEntry* mod_entry = (pkg_entry == nullptr) ? nullptr : pkg_entry->module();
 991   bool should_be_in_named_module = (mod_entry != nullptr && mod_entry->is_named());
 992   bool was_archived_from_named_module = !cl->has_unnamed_module();
 993   bool visible;
 994 
 995   if (was_archived_from_named_module) {




 996     if (should_be_in_named_module) {
 997       // Is the module loaded from the same location as during dump time?
 998       visible = mod_entry->shared_path_index() == scp_index;
 999       if (visible) {
1000         assert(!mod_entry->is_patched(), "cannot load archived classes for patched module");
1001       }
1002     } else {
1003       // During dump time, this class was in a named module, but at run time, this class should be
1004       // in an unnamed module.
1005       visible = false;
1006     }
1007   } else {
1008     if (should_be_in_named_module) {
1009       // During dump time, this class was in an unnamed, but at run time, this class should be
1010       // in a named module.
1011       visible = false;
1012     } else {
1013       visible = true;
1014     }
1015   }

1126   {
1127     HandleMark hm(THREAD);
1128     Handle lockObject = get_loader_lock_or_null(class_loader);
1129     ObjectLocker ol(lockObject, THREAD);
1130     // prohibited package check assumes all classes loaded from archive call
1131     // restore_unshareable_info which calls ik->set_package()
1132     ik->restore_unshareable_info(loader_data, protection_domain, pkg_entry, CHECK_NULL);
1133   }
1134 
1135   load_shared_class_misc(ik, loader_data);
1136   return ik;
1137 }
1138 
1139 void SystemDictionary::load_shared_class_misc(InstanceKlass* ik, ClassLoaderData* loader_data) {
1140   ik->print_class_load_logging(loader_data, nullptr, nullptr);
1141 
1142   // For boot loader, ensure that GetSystemPackage knows that a class in this
1143   // package was loaded.
1144   if (loader_data->is_the_null_class_loader_data()) {
1145     s2 path_index = ik->shared_classpath_index();
1146     ik->set_classpath_index(path_index);






1147   }
1148 
1149   // notify a class loaded from shared object
1150   ClassLoadingService::notify_class_loaded(ik, true /* shared class */);
1151 
1152   if (CDSConfig::is_dumping_final_static_archive()) {
1153     SystemDictionaryShared::init_dumptime_info_from_preimage(ik);
1154   }
1155 }
1156 
1157 // This is much more lightweight than SystemDictionary::resolve_or_null
1158 // - There's only a single Java thread at this point. No need for placeholder.
1159 // - All supertypes of ik have been loaded
1160 // - There's no circularity (checked in AOT assembly phase)
1161 // - There's no need to call java.lang.ClassLoader::load_class() because the boot/platform/app
1162 //   loaders are well-behaved
1163 void SystemDictionary::preload_class(Handle class_loader, InstanceKlass* ik, TRAPS) {
1164   precond(Universe::is_bootstrapping());
1165   precond(java_platform_loader() != nullptr && java_system_loader() != nullptr);
1166   precond(class_loader() == nullptr || class_loader() == java_platform_loader() ||class_loader() == java_system_loader());

1261            // If there is no bootclasspath append entry, no need to continue
1262            // searching.
1263            return nullptr;
1264         }
1265         search_only_bootloader_append = true;
1266       }
1267     }
1268 
1269     // Prior to bootstrapping's module initialization, never load a class outside
1270     // of the boot loader's module path
1271     assert(Universe::is_module_initialized() ||
1272            !search_only_bootloader_append,
1273            "Attempt to load a class outside of boot loader's module path");
1274 
1275     // Search for classes in the CDS archive.
1276     InstanceKlass* k = nullptr;
1277 
1278 #if INCLUDE_CDS
1279     if (CDSConfig::is_using_archive())
1280     {
1281       PerfTraceTime vmtimer(ClassLoader::perf_shared_classload_time());
1282       InstanceKlass* ik = SystemDictionaryShared::find_builtin_class(class_name);
1283       if (ik != nullptr && ik->defined_by_boot_loader() && !ik->shared_loading_failed()) {
1284         SharedClassLoadingMark slm(THREAD, ik);
1285         k = load_shared_class(ik, class_loader, Handle(), nullptr,  pkg_entry, CHECK_NULL);
1286       }
1287     }
1288 #endif
1289 
1290     if (k == nullptr) {
1291       // Use VM class loader
1292       PerfTraceTime vmtimer(ClassLoader::perf_sys_classload_time());
1293       k = ClassLoader::load_class(class_name, pkg_entry, search_only_bootloader_append, CHECK_NULL);
1294     }
1295 
1296     // find_or_define_instance_class may return a different InstanceKlass
1297     if (k != nullptr) {
1298       CDS_ONLY(SharedClassLoadingMark slm(THREAD, k);)
1299       k = find_or_define_instance_class(class_name, class_loader, k, CHECK_NULL);
1300     }
1301     return k;
1302   } else {
1303     // Use user specified class loader to load class. Call loadClass operation on class_loader.
1304     ResourceMark rm(THREAD);
1305 
1306     JavaThread* jt = THREAD;
1307 
1308     PerfClassTraceTime vmtimer(ClassLoader::perf_app_classload_time(),
1309                                ClassLoader::perf_app_classload_selftime(),
1310                                ClassLoader::perf_app_classload_count(),
1311                                jt->get_thread_stat()->perf_recursion_counts_addr(),
1312                                jt->get_thread_stat()->perf_timers_addr(),

  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "cds/aotClassLocation.hpp"
  26 #include "cds/cdsConfig.hpp"
  27 #include "cds/heapShared.hpp"
  28 #include "classfile/classFileParser.hpp"
  29 #include "classfile/classFileStream.hpp"
  30 #include "classfile/classLoader.hpp"
  31 #include "classfile/classLoaderData.inline.hpp"
  32 #include "classfile/classLoaderDataGraph.inline.hpp"
  33 #include "classfile/classLoadInfo.hpp"
  34 #include "classfile/dictionary.hpp"
  35 #include "classfile/javaClasses.inline.hpp"
  36 #include "classfile/klassFactory.hpp"
  37 #include "classfile/loaderConstraints.hpp"
  38 #include "classfile/modules.hpp"
  39 #include "classfile/packageEntry.hpp"
  40 #include "classfile/placeholders.hpp"
  41 #include "classfile/resolutionErrors.hpp"
  42 #include "classfile/stringTable.hpp"
  43 #include "classfile/symbolTable.hpp"
  44 #include "classfile/systemDictionary.hpp"
  45 #include "classfile/vmClasses.hpp"
  46 #include "classfile/vmSymbols.hpp"
  47 #include "gc/shared/gcTraceTime.inline.hpp"
  48 #include "interpreter/bootstrapInfo.hpp"
  49 #include "jfr/jfrEvents.hpp"
  50 #include "jvm.h"
  51 #include "logging/log.hpp"
  52 #include "logging/logStream.hpp"
  53 #include "memory/metaspaceClosure.hpp"
  54 #include "memory/oopFactory.hpp"
  55 #include "memory/resourceArea.hpp"
  56 #include "memory/universe.hpp"
  57 #include "oops/access.inline.hpp"
  58 #include "oops/instanceKlass.hpp"

 976     assert(cl->is_modules_image() || HeapShared::is_a_test_class_in_unnamed_module(ik),
 977            "only these classes can be loaded before the module system is initialized");
 978     assert(class_loader.is_null(), "sanity");
 979     return true;
 980   }
 981 
 982   if (pkg_entry == nullptr) {
 983     // We might have looked up pkg_entry before the module system was initialized.
 984     // Need to reload it now.
 985     TempNewSymbol pkg_name = ClassLoader::package_from_class_name(class_name);
 986     if (pkg_name != nullptr) {
 987       pkg_entry = class_loader_data(class_loader)->packages()->lookup_only(pkg_name);
 988     }
 989   }
 990 
 991   ModuleEntry* mod_entry = (pkg_entry == nullptr) ? nullptr : pkg_entry->module();
 992   bool should_be_in_named_module = (mod_entry != nullptr && mod_entry->is_named());
 993   bool was_archived_from_named_module = !cl->has_unnamed_module();
 994   bool visible;
 995 
 996   if (mod_entry != nullptr && mod_entry->location() == nullptr && mod_entry->is_named()) {
 997     // Archived module for dynamic proxies. It's always visible.
 998     assert(Modules::is_dynamic_proxy_module(mod_entry), "must be");
 999     visible = true;
1000   } else if (was_archived_from_named_module) {
1001     if (should_be_in_named_module) {
1002       // Is the module loaded from the same location as during dump time?
1003       visible = mod_entry->shared_path_index() == scp_index;
1004       if (visible) {
1005         assert(!mod_entry->is_patched(), "cannot load archived classes for patched module");
1006       }
1007     } else {
1008       // During dump time, this class was in a named module, but at run time, this class should be
1009       // in an unnamed module.
1010       visible = false;
1011     }
1012   } else {
1013     if (should_be_in_named_module) {
1014       // During dump time, this class was in an unnamed, but at run time, this class should be
1015       // in a named module.
1016       visible = false;
1017     } else {
1018       visible = true;
1019     }
1020   }

1131   {
1132     HandleMark hm(THREAD);
1133     Handle lockObject = get_loader_lock_or_null(class_loader);
1134     ObjectLocker ol(lockObject, THREAD);
1135     // prohibited package check assumes all classes loaded from archive call
1136     // restore_unshareable_info which calls ik->set_package()
1137     ik->restore_unshareable_info(loader_data, protection_domain, pkg_entry, CHECK_NULL);
1138   }
1139 
1140   load_shared_class_misc(ik, loader_data);
1141   return ik;
1142 }
1143 
1144 void SystemDictionary::load_shared_class_misc(InstanceKlass* ik, ClassLoaderData* loader_data) {
1145   ik->print_class_load_logging(loader_data, nullptr, nullptr);
1146 
1147   // For boot loader, ensure that GetSystemPackage knows that a class in this
1148   // package was loaded.
1149   if (loader_data->is_the_null_class_loader_data()) {
1150     s2 path_index = ik->shared_classpath_index();
1151     if (path_index >= 0) { // FIXME ... for lambda form classes
1152       ik->set_classpath_index(path_index);
1153 
1154       if (CDSConfig::is_dumping_final_static_archive()) {
1155         AOTClassLocationConfig::dumptime_update_max_used_index(path_index);
1156       }
1157     }
1158   }
1159 
1160   // notify a class loaded from shared object
1161   ClassLoadingService::notify_class_loaded(ik, true /* shared class */);
1162 
1163   if (CDSConfig::is_dumping_final_static_archive()) {
1164     SystemDictionaryShared::init_dumptime_info_from_preimage(ik);
1165   }
1166 }
1167 
1168 // This is much more lightweight than SystemDictionary::resolve_or_null
1169 // - There's only a single Java thread at this point. No need for placeholder.
1170 // - All supertypes of ik have been loaded
1171 // - There's no circularity (checked in AOT assembly phase)
1172 // - There's no need to call java.lang.ClassLoader::load_class() because the boot/platform/app
1173 //   loaders are well-behaved
1174 void SystemDictionary::preload_class(Handle class_loader, InstanceKlass* ik, TRAPS) {
1175   precond(Universe::is_bootstrapping());
1176   precond(java_platform_loader() != nullptr && java_system_loader() != nullptr);
1177   precond(class_loader() == nullptr || class_loader() == java_platform_loader() ||class_loader() == java_system_loader());

1272            // If there is no bootclasspath append entry, no need to continue
1273            // searching.
1274            return nullptr;
1275         }
1276         search_only_bootloader_append = true;
1277       }
1278     }
1279 
1280     // Prior to bootstrapping's module initialization, never load a class outside
1281     // of the boot loader's module path
1282     assert(Universe::is_module_initialized() ||
1283            !search_only_bootloader_append,
1284            "Attempt to load a class outside of boot loader's module path");
1285 
1286     // Search for classes in the CDS archive.
1287     InstanceKlass* k = nullptr;
1288 
1289 #if INCLUDE_CDS
1290     if (CDSConfig::is_using_archive())
1291     {
1292       PerfTraceElapsedTime vmtimer(ClassLoader::perf_shared_classload_time());
1293       InstanceKlass* ik = SystemDictionaryShared::find_builtin_class(class_name);
1294       if (ik != nullptr && ik->defined_by_boot_loader() && !ik->shared_loading_failed()) {
1295         SharedClassLoadingMark slm(THREAD, ik);
1296         k = load_shared_class(ik, class_loader, Handle(), nullptr,  pkg_entry, CHECK_NULL);
1297       }
1298     }
1299 #endif
1300 
1301     if (k == nullptr) {
1302       // Use VM class loader
1303       PerfTraceElapsedTime vmtimer(ClassLoader::perf_sys_classload_time());
1304       k = ClassLoader::load_class(class_name, pkg_entry, search_only_bootloader_append, CHECK_NULL);
1305     }
1306 
1307     // find_or_define_instance_class may return a different InstanceKlass
1308     if (k != nullptr) {
1309       CDS_ONLY(SharedClassLoadingMark slm(THREAD, k);)
1310       k = find_or_define_instance_class(class_name, class_loader, k, CHECK_NULL);
1311     }
1312     return k;
1313   } else {
1314     // Use user specified class loader to load class. Call loadClass operation on class_loader.
1315     ResourceMark rm(THREAD);
1316 
1317     JavaThread* jt = THREAD;
1318 
1319     PerfClassTraceTime vmtimer(ClassLoader::perf_app_classload_time(),
1320                                ClassLoader::perf_app_classload_selftime(),
1321                                ClassLoader::perf_app_classload_count(),
1322                                jt->get_thread_stat()->perf_recursion_counts_addr(),
1323                                jt->get_thread_stat()->perf_timers_addr(),
< prev index next >