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 }
1124 {
1125 HandleMark hm(THREAD);
1126 Handle lockObject = get_loader_lock_or_null(class_loader);
1127 ObjectLocker ol(lockObject, THREAD);
1128 // prohibited package check assumes all classes loaded from archive call
1129 // restore_unshareable_info which calls ik->set_package()
1130 ik->restore_unshareable_info(loader_data, protection_domain, pkg_entry, CHECK_NULL);
1131 }
1132
1133 load_shared_class_misc(ik, loader_data);
1134 return ik;
1135 }
1136
1137 void SystemDictionary::load_shared_class_misc(InstanceKlass* ik, ClassLoaderData* loader_data) {
1138 ik->print_class_load_logging(loader_data, nullptr, nullptr);
1139
1140 // For boot loader, ensure that GetSystemPackage knows that a class in this
1141 // package was loaded.
1142 if (loader_data->is_the_null_class_loader_data()) {
1143 s2 path_index = ik->shared_classpath_index();
1144 ik->set_classpath_index(path_index);
1145 }
1146
1147 // notify a class loaded from shared object
1148 ClassLoadingService::notify_class_loaded(ik, true /* shared class */);
1149
1150 if (CDSConfig::is_dumping_final_static_archive()) {
1151 SystemDictionaryShared::init_dumptime_info_from_preimage(ik);
1152 }
1153 }
1154
1155 #endif // INCLUDE_CDS
1156
1157 InstanceKlass* SystemDictionary::load_instance_class_impl(Symbol* class_name, Handle class_loader, TRAPS) {
1158
1159 if (class_loader.is_null()) {
1160 ResourceMark rm(THREAD);
1161 PackageEntry* pkg_entry = nullptr;
1162 bool search_only_bootloader_append = false;
1163
1164 // Find the package in the boot loader's package entry table.
1207 // If there is no bootclasspath append entry, no need to continue
1208 // searching.
1209 return nullptr;
1210 }
1211 search_only_bootloader_append = true;
1212 }
1213 }
1214
1215 // Prior to bootstrapping's module initialization, never load a class outside
1216 // of the boot loader's module path
1217 assert(Universe::is_module_initialized() ||
1218 !search_only_bootloader_append,
1219 "Attempt to load a class outside of boot loader's module path");
1220
1221 // Search for classes in the CDS archive.
1222 InstanceKlass* k = nullptr;
1223
1224 #if INCLUDE_CDS
1225 if (CDSConfig::is_using_archive())
1226 {
1227 PerfTraceTime vmtimer(ClassLoader::perf_shared_classload_time());
1228 InstanceKlass* ik = SystemDictionaryShared::find_builtin_class(class_name);
1229 if (ik != nullptr && ik->is_shared_boot_class() && !ik->shared_loading_failed()) {
1230 SharedClassLoadingMark slm(THREAD, ik);
1231 k = load_shared_class(ik, class_loader, Handle(), nullptr, pkg_entry, CHECK_NULL);
1232 }
1233 }
1234 #endif
1235
1236 if (k == nullptr) {
1237 // Use VM class loader
1238 PerfTraceTime vmtimer(ClassLoader::perf_sys_classload_time());
1239 k = ClassLoader::load_class(class_name, pkg_entry, search_only_bootloader_append, CHECK_NULL);
1240 }
1241
1242 // find_or_define_instance_class may return a different InstanceKlass
1243 if (k != nullptr) {
1244 CDS_ONLY(SharedClassLoadingMark slm(THREAD, k);)
1245 k = find_or_define_instance_class(class_name, class_loader, k, CHECK_NULL);
1246 }
1247 return k;
1248 } else {
1249 // Use user specified class loader to load class. Call loadClass operation on class_loader.
1250 ResourceMark rm(THREAD);
1251
1252 JavaThread* jt = THREAD;
1253
1254 PerfClassTraceTime vmtimer(ClassLoader::perf_app_classload_time(),
1255 ClassLoader::perf_app_classload_selftime(),
1256 ClassLoader::perf_app_classload_count(),
1257 jt->get_thread_stat()->perf_recursion_counts_addr(),
1258 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 }
1129 {
1130 HandleMark hm(THREAD);
1131 Handle lockObject = get_loader_lock_or_null(class_loader);
1132 ObjectLocker ol(lockObject, THREAD);
1133 // prohibited package check assumes all classes loaded from archive call
1134 // restore_unshareable_info which calls ik->set_package()
1135 ik->restore_unshareable_info(loader_data, protection_domain, pkg_entry, CHECK_NULL);
1136 }
1137
1138 load_shared_class_misc(ik, loader_data);
1139 return ik;
1140 }
1141
1142 void SystemDictionary::load_shared_class_misc(InstanceKlass* ik, ClassLoaderData* loader_data) {
1143 ik->print_class_load_logging(loader_data, nullptr, nullptr);
1144
1145 // For boot loader, ensure that GetSystemPackage knows that a class in this
1146 // package was loaded.
1147 if (loader_data->is_the_null_class_loader_data()) {
1148 s2 path_index = ik->shared_classpath_index();
1149 if (path_index >= 0) { // FIXME ... for lambda form classes
1150 ik->set_classpath_index(path_index);
1151
1152 if (CDSConfig::is_dumping_final_static_archive()) {
1153 AOTClassLocationConfig::dumptime_update_max_used_index(path_index);
1154 }
1155 }
1156 }
1157
1158 // notify a class loaded from shared object
1159 ClassLoadingService::notify_class_loaded(ik, true /* shared class */);
1160
1161 if (CDSConfig::is_dumping_final_static_archive()) {
1162 SystemDictionaryShared::init_dumptime_info_from_preimage(ik);
1163 }
1164 }
1165
1166 #endif // INCLUDE_CDS
1167
1168 InstanceKlass* SystemDictionary::load_instance_class_impl(Symbol* class_name, Handle class_loader, TRAPS) {
1169
1170 if (class_loader.is_null()) {
1171 ResourceMark rm(THREAD);
1172 PackageEntry* pkg_entry = nullptr;
1173 bool search_only_bootloader_append = false;
1174
1175 // Find the package in the boot loader's package entry table.
1218 // If there is no bootclasspath append entry, no need to continue
1219 // searching.
1220 return nullptr;
1221 }
1222 search_only_bootloader_append = true;
1223 }
1224 }
1225
1226 // Prior to bootstrapping's module initialization, never load a class outside
1227 // of the boot loader's module path
1228 assert(Universe::is_module_initialized() ||
1229 !search_only_bootloader_append,
1230 "Attempt to load a class outside of boot loader's module path");
1231
1232 // Search for classes in the CDS archive.
1233 InstanceKlass* k = nullptr;
1234
1235 #if INCLUDE_CDS
1236 if (CDSConfig::is_using_archive())
1237 {
1238 PerfTraceElapsedTime vmtimer(ClassLoader::perf_shared_classload_time());
1239 InstanceKlass* ik = SystemDictionaryShared::find_builtin_class(class_name);
1240 if (ik != nullptr && ik->is_shared_boot_class() && !ik->shared_loading_failed()) {
1241 SharedClassLoadingMark slm(THREAD, ik);
1242 k = load_shared_class(ik, class_loader, Handle(), nullptr, pkg_entry, CHECK_NULL);
1243 }
1244 }
1245 #endif
1246
1247 if (k == nullptr) {
1248 // Use VM class loader
1249 PerfTraceElapsedTime vmtimer(ClassLoader::perf_sys_classload_time());
1250 k = ClassLoader::load_class(class_name, pkg_entry, search_only_bootloader_append, CHECK_NULL);
1251 }
1252
1253 // find_or_define_instance_class may return a different InstanceKlass
1254 if (k != nullptr) {
1255 CDS_ONLY(SharedClassLoadingMark slm(THREAD, k);)
1256 k = find_or_define_instance_class(class_name, class_loader, k, CHECK_NULL);
1257 }
1258 return k;
1259 } else {
1260 // Use user specified class loader to load class. Call loadClass operation on class_loader.
1261 ResourceMark rm(THREAD);
1262
1263 JavaThread* jt = THREAD;
1264
1265 PerfClassTraceTime vmtimer(ClassLoader::perf_app_classload_time(),
1266 ClassLoader::perf_app_classload_selftime(),
1267 ClassLoader::perf_app_classload_count(),
1268 jt->get_thread_stat()->perf_recursion_counts_addr(),
1269 jt->get_thread_stat()->perf_timers_addr(),
|