64 #include "prims/jvm.h" |
64 #include "prims/jvm.h" |
65 #include "prims/jvmtiEnvBase.hpp" |
65 #include "prims/jvmtiEnvBase.hpp" |
66 #include "prims/resolvedMethodTable.hpp" |
66 #include "prims/resolvedMethodTable.hpp" |
67 #include "prims/methodHandles.hpp" |
67 #include "prims/methodHandles.hpp" |
68 #include "runtime/arguments.hpp" |
68 #include "runtime/arguments.hpp" |
|
69 #include "runtime/arguments_ext.hpp" |
69 #include "runtime/biasedLocking.hpp" |
70 #include "runtime/biasedLocking.hpp" |
70 #include "runtime/fieldType.hpp" |
71 #include "runtime/fieldType.hpp" |
71 #include "runtime/handles.inline.hpp" |
72 #include "runtime/handles.inline.hpp" |
72 #include "runtime/java.hpp" |
73 #include "runtime/java.hpp" |
73 #include "runtime/javaCalls.hpp" |
74 #include "runtime/javaCalls.hpp" |
867 if (!HAS_PENDING_EXCEPTION) { |
868 if (!HAS_PENDING_EXCEPTION) { |
868 { // Grabbing the Compile_lock prevents systemDictionary updates |
869 { // Grabbing the Compile_lock prevents systemDictionary updates |
869 // during compilations. |
870 // during compilations. |
870 MutexLocker mu(Compile_lock, THREAD); |
871 MutexLocker mu(Compile_lock, THREAD); |
871 update_dictionary(d_index, d_hash, p_index, p_hash, |
872 update_dictionary(d_index, d_hash, p_index, p_hash, |
872 k, class_loader, THREAD); |
873 k, class_loader, THREAD); |
873 } |
874 } |
874 |
875 |
875 if (JvmtiExport::should_post_class_load()) { |
876 if (JvmtiExport::should_post_class_load()) { |
876 Thread *thread = THREAD; |
877 Thread *thread = THREAD; |
877 assert(thread->is_Java_thread(), "thread->is_Java_thread()"); |
878 assert(thread->is_Java_thread(), "thread->is_Java_thread()"); |
1004 ClassLoaderData* loader_data; |
1005 ClassLoaderData* loader_data; |
1005 if (host_klass != NULL) { |
1006 if (host_klass != NULL) { |
1006 // Create a new CLD for anonymous class, that uses the same class loader |
1007 // Create a new CLD for anonymous class, that uses the same class loader |
1007 // as the host_klass |
1008 // as the host_klass |
1008 guarantee(host_klass->class_loader() == class_loader(), "should be the same"); |
1009 guarantee(host_klass->class_loader() == class_loader(), "should be the same"); |
1009 guarantee(!DumpSharedSpaces, "must not create anonymous classes when dumping"); |
|
1010 loader_data = ClassLoaderData::anonymous_class_loader_data(class_loader(), CHECK_NULL); |
1010 loader_data = ClassLoaderData::anonymous_class_loader_data(class_loader(), CHECK_NULL); |
1011 } else { |
1011 } else { |
1012 loader_data = ClassLoaderData::class_loader_data(class_loader()); |
1012 loader_data = ClassLoaderData::class_loader_data(class_loader()); |
1013 } |
1013 } |
1014 |
1014 |
1073 InstanceKlass* SystemDictionary::resolve_from_stream(Symbol* class_name, |
1073 InstanceKlass* SystemDictionary::resolve_from_stream(Symbol* class_name, |
1074 Handle class_loader, |
1074 Handle class_loader, |
1075 Handle protection_domain, |
1075 Handle protection_domain, |
1076 ClassFileStream* st, |
1076 ClassFileStream* st, |
1077 TRAPS) { |
1077 TRAPS) { |
|
1078 #if INCLUDE_CDS |
|
1079 ResourceMark rm(THREAD); |
|
1080 if (DumpSharedSpaces && !class_loader.is_null() && |
|
1081 !ArgumentsExt::using_AppCDS() && strcmp(class_name->as_C_string(), "Unnamed") != 0) { |
|
1082 // If AppCDS is not enabled, don't define the class at dump time (except for the "Unnamed" |
|
1083 // class, which is used by MethodHandles). |
|
1084 THROW_MSG_NULL(vmSymbols::java_lang_ClassNotFoundException(), class_name->as_C_string()); |
|
1085 } |
|
1086 #endif |
1078 |
1087 |
1079 HandleMark hm(THREAD); |
1088 HandleMark hm(THREAD); |
1080 |
1089 |
1081 // Classloaders that support parallelism, e.g. bootstrap classloader, |
1090 // Classloaders that support parallelism, e.g. bootstrap classloader, |
1082 // or all classloaders with UnsyncloadClass do not acquire lock here |
1091 // or all classloaders with UnsyncloadClass do not acquire lock here |
1099 // already be present in the SystemDictionary, otherwise we would not |
1108 // already be present in the SystemDictionary, otherwise we would not |
1100 // throw potential ClassFormatErrors. |
1109 // throw potential ClassFormatErrors. |
1101 InstanceKlass* k = NULL; |
1110 InstanceKlass* k = NULL; |
1102 |
1111 |
1103 #if INCLUDE_CDS |
1112 #if INCLUDE_CDS |
1104 k = SystemDictionaryShared::lookup_from_stream(class_name, |
1113 if (!DumpSharedSpaces) { |
1105 class_loader, |
1114 k = SystemDictionaryShared::lookup_from_stream(class_name, |
1106 protection_domain, |
1115 class_loader, |
1107 st, |
1116 protection_domain, |
1108 CHECK_NULL); |
1117 st, |
|
1118 CHECK_NULL); |
|
1119 } |
1109 #endif |
1120 #endif |
1110 |
1121 |
1111 if (k == NULL) { |
1122 if (k == NULL) { |
1112 if (st->buffer() == NULL) { |
1123 if (st->buffer() == NULL) { |
1113 return NULL; |
1124 return NULL; |
1212 Handle class_loader, TRAPS) { |
1223 Handle class_loader, TRAPS) { |
1213 assert(!ModuleEntryTable::javabase_moduleEntry()->is_patched(), |
1224 assert(!ModuleEntryTable::javabase_moduleEntry()->is_patched(), |
1214 "Cannot use sharing if java.base is patched"); |
1225 "Cannot use sharing if java.base is patched"); |
1215 ResourceMark rm; |
1226 ResourceMark rm; |
1216 int path_index = ik->shared_classpath_index(); |
1227 int path_index = ik->shared_classpath_index(); |
|
1228 ClassLoaderData* loader_data = class_loader_data(class_loader); |
|
1229 if (path_index < 0) { |
|
1230 // path_index < 0 indicates that the class is intended for a custom loader |
|
1231 // and should not be loaded by boot/platform/app loaders |
|
1232 if (loader_data->is_builtin_class_loader_data()) { |
|
1233 return false; |
|
1234 } else { |
|
1235 return true; |
|
1236 } |
|
1237 } |
1217 SharedClassPathEntry* ent = |
1238 SharedClassPathEntry* ent = |
1218 (SharedClassPathEntry*)FileMapInfo::shared_classpath(path_index); |
1239 (SharedClassPathEntry*)FileMapInfo::shared_classpath(path_index); |
1219 if (!Universe::is_module_initialized()) { |
1240 if (!Universe::is_module_initialized()) { |
1220 assert(ent != NULL && ent->is_jrt(), |
1241 assert(ent != NULL && ent->is_jrt(), |
1221 "Loading non-bootstrap classes before the module system is initialized"); |
1242 "Loading non-bootstrap classes before the module system is initialized"); |
1225 // Get the pkg_entry from the classloader |
1246 // Get the pkg_entry from the classloader |
1226 TempNewSymbol pkg_name = NULL; |
1247 TempNewSymbol pkg_name = NULL; |
1227 PackageEntry* pkg_entry = NULL; |
1248 PackageEntry* pkg_entry = NULL; |
1228 ModuleEntry* mod_entry = NULL; |
1249 ModuleEntry* mod_entry = NULL; |
1229 const char* pkg_string = NULL; |
1250 const char* pkg_string = NULL; |
1230 ClassLoaderData* loader_data = class_loader_data(class_loader); |
|
1231 pkg_name = InstanceKlass::package_from_name(class_name, CHECK_false); |
1251 pkg_name = InstanceKlass::package_from_name(class_name, CHECK_false); |
1232 if (pkg_name != NULL) { |
1252 if (pkg_name != NULL) { |
1233 pkg_string = pkg_name->as_C_string(); |
1253 pkg_string = pkg_name->as_C_string(); |
1234 if (loader_data != NULL) { |
1254 if (loader_data != NULL) { |
1235 pkg_entry = loader_data->packages()->lookup_only(pkg_name); |
1255 pkg_entry = loader_data->packages()->lookup_only(pkg_name); |
1397 ResourceMark rm; |
1417 ResourceMark rm; |
1398 log_info(class, fingerprint)("%s : expected = " PTR64_FORMAT " actual = " PTR64_FORMAT, ik->external_name(), aot_fp, cds_fp); |
1418 log_info(class, fingerprint)("%s : expected = " PTR64_FORMAT " actual = " PTR64_FORMAT, ik->external_name(), aot_fp, cds_fp); |
1399 } |
1419 } |
1400 } |
1420 } |
1401 return ik; |
1421 return ik; |
|
1422 } |
|
1423 |
|
1424 void SystemDictionary::clear_invoke_method_table() { |
|
1425 SymbolPropertyEntry* spe = NULL; |
|
1426 for (int index = 0; index < _invoke_method_table->table_size(); index++) { |
|
1427 SymbolPropertyEntry* p = _invoke_method_table->bucket(index); |
|
1428 while (p != NULL) { |
|
1429 spe = p; |
|
1430 p = p->next(); |
|
1431 _invoke_method_table->free_entry(spe); |
|
1432 } |
|
1433 } |
1402 } |
1434 } |
1403 #endif // INCLUDE_CDS |
1435 #endif // INCLUDE_CDS |
1404 |
1436 |
1405 InstanceKlass* SystemDictionary::load_instance_class(Symbol* class_name, Handle class_loader, TRAPS) { |
1437 InstanceKlass* SystemDictionary::load_instance_class(Symbol* class_name, Handle class_loader, TRAPS) { |
1406 |
1438 |
1444 return NULL; |
1476 return NULL; |
1445 } |
1477 } |
1446 } |
1478 } |
1447 } |
1479 } |
1448 } else { |
1480 } else { |
1449 assert(!DumpSharedSpaces, "Archive dumped after module system initialization"); |
|
1450 // After the module system has been initialized, check if the class' |
1481 // After the module system has been initialized, check if the class' |
1451 // package is in a module defined to the boot loader. |
1482 // package is in a module defined to the boot loader. |
1452 if (pkg_name == NULL || pkg_entry == NULL || pkg_entry->in_unnamed_module()) { |
1483 if (pkg_name == NULL || pkg_entry == NULL || pkg_entry->in_unnamed_module()) { |
1453 // Class is either in the unnamed package, in a named package |
1484 // Class is either in the unnamed package, in a named package |
1454 // within a module not defined to the boot loader or in a |
1485 // within a module not defined to the boot loader or in a |
1963 ClassLoaderDataGraph::methods_do(f); |
1994 ClassLoaderDataGraph::methods_do(f); |
1964 // Walk method handle intrinsics |
1995 // Walk method handle intrinsics |
1965 invoke_method_table()->methods_do(f); |
1996 invoke_method_table()->methods_do(f); |
1966 } |
1997 } |
1967 |
1998 |
|
1999 class RemoveClassesClosure : public CLDClosure { |
|
2000 public: |
|
2001 void do_cld(ClassLoaderData* cld) { |
|
2002 if (cld->is_system_class_loader_data() || cld->is_platform_class_loader_data()) { |
|
2003 cld->dictionary()->remove_classes_in_error_state(); |
|
2004 } |
|
2005 } |
|
2006 }; |
|
2007 |
1968 void SystemDictionary::remove_classes_in_error_state() { |
2008 void SystemDictionary::remove_classes_in_error_state() { |
1969 ClassLoaderData::the_null_class_loader_data()->dictionary()->remove_classes_in_error_state(); |
2009 ClassLoaderData::the_null_class_loader_data()->dictionary()->remove_classes_in_error_state(); |
|
2010 RemoveClassesClosure rcc; |
|
2011 ClassLoaderDataGraph::cld_do(&rcc); |
1970 } |
2012 } |
1971 |
2013 |
1972 // ---------------------------------------------------------------------------- |
2014 // ---------------------------------------------------------------------------- |
1973 // Lazily load klasses |
2015 // Lazily load klasses |
1974 |
2016 |
2905 } else { |
2947 } else { |
2906 return 0; |
2948 return 0; |
2907 } |
2949 } |
2908 } |
2950 } |
2909 |
2951 |
|
2952 class CombineDictionariesClosure : public CLDClosure { |
|
2953 private: |
|
2954 Dictionary* _master_dictionary; |
|
2955 public: |
|
2956 CombineDictionariesClosure(Dictionary* master_dictionary) : |
|
2957 _master_dictionary(master_dictionary) {} |
|
2958 void do_cld(ClassLoaderData* cld) { |
|
2959 ResourceMark rm; |
|
2960 if (cld->is_system_class_loader_data() || cld->is_platform_class_loader_data()) { |
|
2961 for (int i = 0; i < cld->dictionary()->table_size(); ++i) { |
|
2962 Dictionary* curr_dictionary = cld->dictionary(); |
|
2963 DictionaryEntry* p = curr_dictionary->bucket(i); |
|
2964 while (p != NULL) { |
|
2965 Symbol* name = p->instance_klass()->name(); |
|
2966 unsigned int d_hash = _master_dictionary->compute_hash(name); |
|
2967 int d_index = _master_dictionary->hash_to_index(d_hash); |
|
2968 DictionaryEntry* next = p->next(); |
|
2969 if (p->literal()->class_loader_data() != cld) { |
|
2970 // This is an initiating class loader entry; don't use it |
|
2971 log_trace(cds)("Skipping initiating cl entry: %s", name->as_C_string()); |
|
2972 curr_dictionary->free_entry(p); |
|
2973 } else { |
|
2974 log_trace(cds)("Moved to boot dictionary: %s", name->as_C_string()); |
|
2975 curr_dictionary->unlink_entry(p); |
|
2976 p->set_pd_set(NULL); // pd_set is runtime only information and will be reconstructed. |
|
2977 _master_dictionary->add_entry(d_index, p); |
|
2978 } |
|
2979 p = next; |
|
2980 } |
|
2981 *curr_dictionary->bucket_addr(i) = NULL; |
|
2982 } |
|
2983 } |
|
2984 } |
|
2985 }; |
|
2986 |
|
2987 // Combining platform and system loader dictionaries into boot loader dictionaries. |
|
2988 // During run time, we only have one shared dictionary. |
|
2989 void SystemDictionary::combine_shared_dictionaries() { |
|
2990 assert(DumpSharedSpaces, "dump time only"); |
|
2991 Dictionary* master_dictionary = ClassLoaderData::the_null_class_loader_data()->dictionary(); |
|
2992 CombineDictionariesClosure cdc(master_dictionary); |
|
2993 ClassLoaderDataGraph::cld_do(&cdc); |
|
2994 |
|
2995 // These tables are no longer valid or necessary. Keeping them around will |
|
2996 // cause SystemDictionary::verify() to fail. Let's empty them. |
|
2997 _placeholders = new PlaceholderTable(_placeholder_table_size); |
|
2998 _loader_constraints = new LoaderConstraintTable(_loader_constraint_size); |
|
2999 |
|
3000 NOT_PRODUCT(SystemDictionary::verify()); |
|
3001 } |
2910 |
3002 |
2911 // caller needs ResourceMark |
3003 // caller needs ResourceMark |
2912 const char* SystemDictionary::loader_name(const oop loader) { |
3004 const char* SystemDictionary::loader_name(const oop loader) { |
2913 return ((loader) == NULL ? "<bootloader>" : |
3005 return ((loader) == NULL ? "<bootloader>" : |
2914 InstanceKlass::cast((loader)->klass())->name()->as_C_string()); |
3006 InstanceKlass::cast((loader)->klass())->name()->as_C_string()); |