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"
970 assert(cl->is_modules_image() || HeapShared::is_a_test_class_in_unnamed_module(ik),
971 "only these classes can be loaded before the module system is initialized");
972 assert(class_loader.is_null(), "sanity");
973 return true;
974 }
975
976 if (pkg_entry == nullptr) {
977 // We might have looked up pkg_entry before the module system was initialized.
978 // Need to reload it now.
979 TempNewSymbol pkg_name = ClassLoader::package_from_class_name(class_name);
980 if (pkg_name != nullptr) {
981 pkg_entry = class_loader_data(class_loader)->packages()->lookup_only(pkg_name);
982 }
983 }
984
985 ModuleEntry* mod_entry = (pkg_entry == nullptr) ? nullptr : pkg_entry->module();
986 bool should_be_in_named_module = (mod_entry != nullptr && mod_entry->is_named());
987 bool was_archived_from_named_module = !cl->has_unnamed_module();
988 bool visible;
989
990 if (was_archived_from_named_module) {
991 if (should_be_in_named_module) {
992 // Is the module loaded from the same location as during dump time?
993 visible = mod_entry->shared_path_index() == scp_index;
994 if (visible) {
995 assert(!mod_entry->is_patched(), "cannot load archived classes for patched module");
996 }
997 } else {
998 // During dump time, this class was in a named module, but at run time, this class should be
999 // in an unnamed module.
1000 visible = false;
1001 }
1002 } else {
1003 if (should_be_in_named_module) {
1004 // During dump time, this class was in an unnamed, but at run time, this class should be
1005 // in a named module.
1006 visible = false;
1007 } else {
1008 visible = true;
1009 }
1010 }
1121 {
1122 HandleMark hm(THREAD);
1123 Handle lockObject = get_loader_lock_or_null(class_loader);
1124 ObjectLocker ol(lockObject, THREAD);
1125 // prohibited package check assumes all classes loaded from archive call
1126 // restore_unshareable_info which calls ik->set_package()
1127 ik->restore_unshareable_info(loader_data, protection_domain, pkg_entry, CHECK_NULL);
1128 }
1129
1130 load_shared_class_misc(ik, loader_data);
1131 return ik;
1132 }
1133
1134 void SystemDictionary::load_shared_class_misc(InstanceKlass* ik, ClassLoaderData* loader_data) {
1135 ik->print_class_load_logging(loader_data, nullptr, nullptr);
1136
1137 // For boot loader, ensure that GetSystemPackage knows that a class in this
1138 // package was loaded.
1139 if (loader_data->is_the_null_class_loader_data()) {
1140 s2 path_index = ik->shared_classpath_index();
1141 ik->set_classpath_index(path_index);
1142 }
1143
1144 // notify a class loaded from shared object
1145 ClassLoadingService::notify_class_loaded(ik, true /* shared class */);
1146
1147 if (CDSConfig::is_dumping_final_static_archive()) {
1148 SystemDictionaryShared::init_dumptime_info_from_preimage(ik);
1149 }
1150 }
1151
1152 #endif // INCLUDE_CDS
1153
1154 InstanceKlass* SystemDictionary::load_instance_class_impl(Symbol* class_name, Handle class_loader, TRAPS) {
1155
1156 if (class_loader.is_null()) {
1157 ResourceMark rm(THREAD);
1158 PackageEntry* pkg_entry = nullptr;
1159 bool search_only_bootloader_append = false;
1160
1161 // Find the package in the boot loader's package entry table.
1204 // If there is no bootclasspath append entry, no need to continue
1205 // searching.
1206 return nullptr;
1207 }
1208 search_only_bootloader_append = true;
1209 }
1210 }
1211
1212 // Prior to bootstrapping's module initialization, never load a class outside
1213 // of the boot loader's module path
1214 assert(Universe::is_module_initialized() ||
1215 !search_only_bootloader_append,
1216 "Attempt to load a class outside of boot loader's module path");
1217
1218 // Search for classes in the CDS archive.
1219 InstanceKlass* k = nullptr;
1220
1221 #if INCLUDE_CDS
1222 if (CDSConfig::is_using_archive())
1223 {
1224 PerfTraceTime vmtimer(ClassLoader::perf_shared_classload_time());
1225 InstanceKlass* ik = SystemDictionaryShared::find_builtin_class(class_name);
1226 if (ik != nullptr && ik->defined_by_boot_loader() && !ik->shared_loading_failed()) {
1227 SharedClassLoadingMark slm(THREAD, ik);
1228 k = load_shared_class(ik, class_loader, Handle(), nullptr, pkg_entry, CHECK_NULL);
1229 }
1230 }
1231 #endif
1232
1233 if (k == nullptr) {
1234 // Use VM class loader
1235 PerfTraceTime vmtimer(ClassLoader::perf_sys_classload_time());
1236 k = ClassLoader::load_class(class_name, pkg_entry, search_only_bootloader_append, CHECK_NULL);
1237 }
1238
1239 // find_or_define_instance_class may return a different InstanceKlass
1240 if (k != nullptr) {
1241 CDS_ONLY(SharedClassLoadingMark slm(THREAD, k);)
1242 k = find_or_define_instance_class(class_name, class_loader, k, CHECK_NULL);
1243 }
1244 return k;
1245 } else {
1246 // Use user specified class loader to load class. Call loadClass operation on class_loader.
1247 ResourceMark rm(THREAD);
1248
1249 JavaThread* jt = THREAD;
1250
1251 PerfClassTraceTime vmtimer(ClassLoader::perf_app_classload_time(),
1252 ClassLoader::perf_app_classload_selftime(),
1253 ClassLoader::perf_app_classload_count(),
1254 jt->get_thread_stat()->perf_recursion_counts_addr(),
1255 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"
971 assert(cl->is_modules_image() || HeapShared::is_a_test_class_in_unnamed_module(ik),
972 "only these classes can be loaded before the module system is initialized");
973 assert(class_loader.is_null(), "sanity");
974 return true;
975 }
976
977 if (pkg_entry == nullptr) {
978 // We might have looked up pkg_entry before the module system was initialized.
979 // Need to reload it now.
980 TempNewSymbol pkg_name = ClassLoader::package_from_class_name(class_name);
981 if (pkg_name != nullptr) {
982 pkg_entry = class_loader_data(class_loader)->packages()->lookup_only(pkg_name);
983 }
984 }
985
986 ModuleEntry* mod_entry = (pkg_entry == nullptr) ? nullptr : pkg_entry->module();
987 bool should_be_in_named_module = (mod_entry != nullptr && mod_entry->is_named());
988 bool was_archived_from_named_module = !cl->has_unnamed_module();
989 bool visible;
990
991 if (mod_entry != nullptr && mod_entry->location() == nullptr && mod_entry->is_named()) {
992 // Archived module for dynamic proxies. It's always visible.
993 assert(Modules::is_dynamic_proxy_module(mod_entry), "must be");
994 visible = true;
995 } else 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 if (path_index >= 0) { // FIXME ... for lambda form classes
1147 ik->set_classpath_index(path_index);
1148
1149 if (CDSConfig::is_dumping_final_static_archive()) {
1150 AOTClassLocationConfig::dumptime_update_max_used_index(path_index);
1151 }
1152 }
1153 }
1154
1155 // notify a class loaded from shared object
1156 ClassLoadingService::notify_class_loaded(ik, true /* shared class */);
1157
1158 if (CDSConfig::is_dumping_final_static_archive()) {
1159 SystemDictionaryShared::init_dumptime_info_from_preimage(ik);
1160 }
1161 }
1162
1163 #endif // INCLUDE_CDS
1164
1165 InstanceKlass* SystemDictionary::load_instance_class_impl(Symbol* class_name, Handle class_loader, TRAPS) {
1166
1167 if (class_loader.is_null()) {
1168 ResourceMark rm(THREAD);
1169 PackageEntry* pkg_entry = nullptr;
1170 bool search_only_bootloader_append = false;
1171
1172 // Find the package in the boot loader's package entry table.
1215 // If there is no bootclasspath append entry, no need to continue
1216 // searching.
1217 return nullptr;
1218 }
1219 search_only_bootloader_append = true;
1220 }
1221 }
1222
1223 // Prior to bootstrapping's module initialization, never load a class outside
1224 // of the boot loader's module path
1225 assert(Universe::is_module_initialized() ||
1226 !search_only_bootloader_append,
1227 "Attempt to load a class outside of boot loader's module path");
1228
1229 // Search for classes in the CDS archive.
1230 InstanceKlass* k = nullptr;
1231
1232 #if INCLUDE_CDS
1233 if (CDSConfig::is_using_archive())
1234 {
1235 PerfTraceElapsedTime vmtimer(ClassLoader::perf_shared_classload_time());
1236 InstanceKlass* ik = SystemDictionaryShared::find_builtin_class(class_name);
1237 if (ik != nullptr && ik->defined_by_boot_loader() && !ik->shared_loading_failed()) {
1238 SharedClassLoadingMark slm(THREAD, ik);
1239 k = load_shared_class(ik, class_loader, Handle(), nullptr, pkg_entry, CHECK_NULL);
1240 }
1241 }
1242 #endif
1243
1244 if (k == nullptr) {
1245 // Use VM class loader
1246 PerfTraceElapsedTime vmtimer(ClassLoader::perf_sys_classload_time());
1247 k = ClassLoader::load_class(class_name, pkg_entry, search_only_bootloader_append, CHECK_NULL);
1248 }
1249
1250 // find_or_define_instance_class may return a different InstanceKlass
1251 if (k != nullptr) {
1252 CDS_ONLY(SharedClassLoadingMark slm(THREAD, k);)
1253 k = find_or_define_instance_class(class_name, class_loader, k, CHECK_NULL);
1254 }
1255 return k;
1256 } else {
1257 // Use user specified class loader to load class. Call loadClass operation on class_loader.
1258 ResourceMark rm(THREAD);
1259
1260 JavaThread* jt = THREAD;
1261
1262 PerfClassTraceTime vmtimer(ClassLoader::perf_app_classload_time(),
1263 ClassLoader::perf_app_classload_selftime(),
1264 ClassLoader::perf_app_classload_count(),
1265 jt->get_thread_stat()->perf_recursion_counts_addr(),
1266 jt->get_thread_stat()->perf_timers_addr(),
|