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/classLoaderExt.hpp"
34 #include "classfile/classLoadInfo.hpp"
35 #include "classfile/dictionary.hpp"
36 #include "classfile/javaClasses.inline.hpp"
37 #include "classfile/klassFactory.hpp"
38 #include "classfile/loaderConstraints.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"
973 assert(cl->is_modules_image() || HeapShared::is_a_test_class_in_unnamed_module(ik),
974 "only these classes can be loaded before the module system is initialized");
975 assert(class_loader.is_null(), "sanity");
976 return true;
977 }
978
979 if (pkg_entry == nullptr) {
980 // We might have looked up pkg_entry before the module system was initialized.
981 // Need to reload it now.
982 TempNewSymbol pkg_name = ClassLoader::package_from_class_name(class_name);
983 if (pkg_name != nullptr) {
984 pkg_entry = class_loader_data(class_loader)->packages()->lookup_only(pkg_name);
985 }
986 }
987
988 ModuleEntry* mod_entry = (pkg_entry == nullptr) ? nullptr : pkg_entry->module();
989 bool should_be_in_named_module = (mod_entry != nullptr && mod_entry->is_named());
990 bool was_archived_from_named_module = !cl->has_unnamed_module();
991 bool visible;
992
993 if (was_archived_from_named_module) {
994 if (should_be_in_named_module) {
995 // Is the module loaded from the same location as during dump time?
996 visible = mod_entry->shared_path_index() == scp_index;
997 if (visible) {
998 assert(!mod_entry->is_patched(), "cannot load archived classes for patched module");
999 }
1000 } else {
1001 // During dump time, this class was in a named module, but at run time, this class should be
1002 // in an unnamed module.
1003 visible = false;
1004 }
1005 } else {
1006 if (should_be_in_named_module) {
1007 // During dump time, this class was in an unnamed, but at run time, this class should be
1008 // in a named module.
1009 visible = false;
1010 } else {
1011 visible = true;
1012 }
1013 }
1155 {
1156 HandleMark hm(THREAD);
1157 Handle lockObject = get_loader_lock_or_null(class_loader);
1158 ObjectLocker ol(lockObject, THREAD);
1159 // prohibited package check assumes all classes loaded from archive call
1160 // restore_unshareable_info which calls ik->set_package()
1161 ik->restore_unshareable_info(loader_data, protection_domain, pkg_entry, CHECK_NULL);
1162 }
1163
1164 load_shared_class_misc(ik, loader_data);
1165 return ik;
1166 }
1167
1168 void SystemDictionary::load_shared_class_misc(InstanceKlass* ik, ClassLoaderData* loader_data) {
1169 ik->print_class_load_logging(loader_data, nullptr, nullptr);
1170
1171 // For boot loader, ensure that GetSystemPackage knows that a class in this
1172 // package was loaded.
1173 if (loader_data->is_the_null_class_loader_data()) {
1174 s2 path_index = ik->shared_classpath_index();
1175 ik->set_classpath_index(path_index);
1176 }
1177
1178 // notify a class loaded from shared object
1179 ClassLoadingService::notify_class_loaded(ik, true /* shared class */);
1180
1181 if (CDSConfig::is_dumping_final_static_archive()) {
1182 SystemDictionaryShared::init_dumptime_info_from_preimage(ik);
1183 }
1184 }
1185
1186 #endif // INCLUDE_CDS
1187
1188 InstanceKlass* SystemDictionary::load_instance_class_impl(Symbol* class_name, Handle class_loader, TRAPS) {
1189
1190 if (class_loader.is_null()) {
1191 ResourceMark rm(THREAD);
1192 PackageEntry* pkg_entry = nullptr;
1193 bool search_only_bootloader_append = false;
1194
1195 // Find the package in the boot loader's package entry table.
1238 // If there is no bootclasspath append entry, no need to continue
1239 // searching.
1240 return nullptr;
1241 }
1242 search_only_bootloader_append = true;
1243 }
1244 }
1245
1246 // Prior to bootstrapping's module initialization, never load a class outside
1247 // of the boot loader's module path
1248 assert(Universe::is_module_initialized() ||
1249 !search_only_bootloader_append,
1250 "Attempt to load a class outside of boot loader's module path");
1251
1252 // Search for classes in the CDS archive.
1253 InstanceKlass* k = nullptr;
1254
1255 #if INCLUDE_CDS
1256 if (CDSConfig::is_using_archive())
1257 {
1258 PerfTraceTime vmtimer(ClassLoader::perf_shared_classload_time());
1259 InstanceKlass* ik = SystemDictionaryShared::find_builtin_class(class_name);
1260 if (ik != nullptr && ik->is_shared_boot_class() && !ik->shared_loading_failed()) {
1261 SharedClassLoadingMark slm(THREAD, ik);
1262 k = load_shared_class(ik, class_loader, Handle(), nullptr, pkg_entry, CHECK_NULL);
1263 }
1264 }
1265 #endif
1266
1267 if (k == nullptr) {
1268 // Use VM class loader
1269 PerfTraceTime vmtimer(ClassLoader::perf_sys_classload_time());
1270 k = ClassLoader::load_class(class_name, pkg_entry, search_only_bootloader_append, CHECK_NULL);
1271 }
1272
1273 // find_or_define_instance_class may return a different InstanceKlass
1274 if (k != nullptr) {
1275 CDS_ONLY(SharedClassLoadingMark slm(THREAD, k);)
1276 k = find_or_define_instance_class(class_name, class_loader, k, CHECK_NULL);
1277 }
1278 return k;
1279 } else {
1280 // Use user specified class loader to load class. Call loadClass operation on class_loader.
1281 ResourceMark rm(THREAD);
1282
1283 JavaThread* jt = THREAD;
1284
1285 PerfClassTraceTime vmtimer(ClassLoader::perf_app_classload_time(),
1286 ClassLoader::perf_app_classload_selftime(),
1287 ClassLoader::perf_app_classload_count(),
1288 jt->get_thread_stat()->perf_recursion_counts_addr(),
1289 jt->get_thread_stat()->perf_timers_addr(),
|
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/classLoaderExt.hpp"
34 #include "classfile/classLoadInfo.hpp"
35 #include "classfile/dictionary.hpp"
36 #include "classfile/javaClasses.inline.hpp"
37 #include "classfile/klassFactory.hpp"
38 #include "classfile/loaderConstraints.hpp"
39 #include "classfile/modules.hpp"
40 #include "classfile/packageEntry.hpp"
41 #include "classfile/placeholders.hpp"
42 #include "classfile/resolutionErrors.hpp"
43 #include "classfile/stringTable.hpp"
44 #include "classfile/symbolTable.hpp"
45 #include "classfile/systemDictionary.hpp"
46 #include "classfile/vmClasses.hpp"
47 #include "classfile/vmSymbols.hpp"
48 #include "gc/shared/gcTraceTime.inline.hpp"
49 #include "interpreter/bootstrapInfo.hpp"
50 #include "jfr/jfrEvents.hpp"
51 #include "jvm.h"
52 #include "logging/log.hpp"
53 #include "logging/logStream.hpp"
54 #include "memory/metaspaceClosure.hpp"
55 #include "memory/oopFactory.hpp"
56 #include "memory/resourceArea.hpp"
57 #include "memory/universe.hpp"
58 #include "oops/access.inline.hpp"
59 #include "oops/instanceKlass.hpp"
974 assert(cl->is_modules_image() || HeapShared::is_a_test_class_in_unnamed_module(ik),
975 "only these classes can be loaded before the module system is initialized");
976 assert(class_loader.is_null(), "sanity");
977 return true;
978 }
979
980 if (pkg_entry == nullptr) {
981 // We might have looked up pkg_entry before the module system was initialized.
982 // Need to reload it now.
983 TempNewSymbol pkg_name = ClassLoader::package_from_class_name(class_name);
984 if (pkg_name != nullptr) {
985 pkg_entry = class_loader_data(class_loader)->packages()->lookup_only(pkg_name);
986 }
987 }
988
989 ModuleEntry* mod_entry = (pkg_entry == nullptr) ? nullptr : pkg_entry->module();
990 bool should_be_in_named_module = (mod_entry != nullptr && mod_entry->is_named());
991 bool was_archived_from_named_module = !cl->has_unnamed_module();
992 bool visible;
993
994 if (mod_entry != nullptr && mod_entry->location() == nullptr && mod_entry->is_named()) {
995 // Archived module for dynamic proxies. It's always visible.
996 assert(Modules::is_dynamic_proxy_module(mod_entry), "must be");
997 visible = true;
998 } else if (was_archived_from_named_module) {
999 if (should_be_in_named_module) {
1000 // Is the module loaded from the same location as during dump time?
1001 visible = mod_entry->shared_path_index() == scp_index;
1002 if (visible) {
1003 assert(!mod_entry->is_patched(), "cannot load archived classes for patched module");
1004 }
1005 } else {
1006 // During dump time, this class was in a named module, but at run time, this class should be
1007 // in an unnamed module.
1008 visible = false;
1009 }
1010 } else {
1011 if (should_be_in_named_module) {
1012 // During dump time, this class was in an unnamed, but at run time, this class should be
1013 // in a named module.
1014 visible = false;
1015 } else {
1016 visible = true;
1017 }
1018 }
1160 {
1161 HandleMark hm(THREAD);
1162 Handle lockObject = get_loader_lock_or_null(class_loader);
1163 ObjectLocker ol(lockObject, THREAD);
1164 // prohibited package check assumes all classes loaded from archive call
1165 // restore_unshareable_info which calls ik->set_package()
1166 ik->restore_unshareable_info(loader_data, protection_domain, pkg_entry, CHECK_NULL);
1167 }
1168
1169 load_shared_class_misc(ik, loader_data);
1170 return ik;
1171 }
1172
1173 void SystemDictionary::load_shared_class_misc(InstanceKlass* ik, ClassLoaderData* loader_data) {
1174 ik->print_class_load_logging(loader_data, nullptr, nullptr);
1175
1176 // For boot loader, ensure that GetSystemPackage knows that a class in this
1177 // package was loaded.
1178 if (loader_data->is_the_null_class_loader_data()) {
1179 s2 path_index = ik->shared_classpath_index();
1180 if (path_index >= 0) { // FIXME ... for lambda form classes
1181 ik->set_classpath_index(path_index);
1182
1183 if (CDSConfig::is_dumping_final_static_archive()) {
1184 AOTClassLocationConfig::dumptime_update_max_used_index(path_index);
1185 }
1186 }
1187 }
1188
1189 // notify a class loaded from shared object
1190 ClassLoadingService::notify_class_loaded(ik, true /* shared class */);
1191
1192 if (CDSConfig::is_dumping_final_static_archive()) {
1193 SystemDictionaryShared::init_dumptime_info_from_preimage(ik);
1194 }
1195 }
1196
1197 #endif // INCLUDE_CDS
1198
1199 InstanceKlass* SystemDictionary::load_instance_class_impl(Symbol* class_name, Handle class_loader, TRAPS) {
1200
1201 if (class_loader.is_null()) {
1202 ResourceMark rm(THREAD);
1203 PackageEntry* pkg_entry = nullptr;
1204 bool search_only_bootloader_append = false;
1205
1206 // Find the package in the boot loader's package entry table.
1249 // If there is no bootclasspath append entry, no need to continue
1250 // searching.
1251 return nullptr;
1252 }
1253 search_only_bootloader_append = true;
1254 }
1255 }
1256
1257 // Prior to bootstrapping's module initialization, never load a class outside
1258 // of the boot loader's module path
1259 assert(Universe::is_module_initialized() ||
1260 !search_only_bootloader_append,
1261 "Attempt to load a class outside of boot loader's module path");
1262
1263 // Search for classes in the CDS archive.
1264 InstanceKlass* k = nullptr;
1265
1266 #if INCLUDE_CDS
1267 if (CDSConfig::is_using_archive())
1268 {
1269 PerfTraceElapsedTime vmtimer(ClassLoader::perf_shared_classload_time());
1270 InstanceKlass* ik = SystemDictionaryShared::find_builtin_class(class_name);
1271 if (ik != nullptr && ik->is_shared_boot_class() && !ik->shared_loading_failed()) {
1272 SharedClassLoadingMark slm(THREAD, ik);
1273 k = load_shared_class(ik, class_loader, Handle(), nullptr, pkg_entry, CHECK_NULL);
1274 }
1275 }
1276 #endif
1277
1278 if (k == nullptr) {
1279 // Use VM class loader
1280 PerfTraceElapsedTime vmtimer(ClassLoader::perf_sys_classload_time());
1281 k = ClassLoader::load_class(class_name, pkg_entry, search_only_bootloader_append, CHECK_NULL);
1282 }
1283
1284 // find_or_define_instance_class may return a different InstanceKlass
1285 if (k != nullptr) {
1286 CDS_ONLY(SharedClassLoadingMark slm(THREAD, k);)
1287 k = find_or_define_instance_class(class_name, class_loader, k, CHECK_NULL);
1288 }
1289 return k;
1290 } else {
1291 // Use user specified class loader to load class. Call loadClass operation on class_loader.
1292 ResourceMark rm(THREAD);
1293
1294 JavaThread* jt = THREAD;
1295
1296 PerfClassTraceTime vmtimer(ClassLoader::perf_app_classload_time(),
1297 ClassLoader::perf_app_classload_selftime(),
1298 ClassLoader::perf_app_classload_count(),
1299 jt->get_thread_stat()->perf_recursion_counts_addr(),
1300 jt->get_thread_stat()->perf_timers_addr(),
|