36 #endif |
36 #endif |
37 #include "classfile/vmSymbols.hpp" |
37 #include "classfile/vmSymbols.hpp" |
38 #include "compiler/compileBroker.hpp" |
38 #include "compiler/compileBroker.hpp" |
39 #include "interpreter/bytecodeStream.hpp" |
39 #include "interpreter/bytecodeStream.hpp" |
40 #include "interpreter/interpreter.hpp" |
40 #include "interpreter/interpreter.hpp" |
|
41 #include "jfr/jfrEvents.hpp" |
|
42 #include "jfr/jni/jfrUpcalls.hpp" |
41 #include "memory/filemap.hpp" |
43 #include "memory/filemap.hpp" |
42 #include "memory/gcLocker.hpp" |
44 #include "memory/gcLocker.hpp" |
43 #include "memory/oopFactory.hpp" |
45 #include "memory/oopFactory.hpp" |
44 #include "oops/instanceKlass.hpp" |
46 #include "oops/instanceKlass.hpp" |
45 #include "oops/instanceRefKlass.hpp" |
47 #include "oops/instanceRefKlass.hpp" |
62 #include "runtime/signature.hpp" |
64 #include "runtime/signature.hpp" |
63 #include "services/classLoadingService.hpp" |
65 #include "services/classLoadingService.hpp" |
64 #include "services/threadService.hpp" |
66 #include "services/threadService.hpp" |
65 #include "utilities/macros.hpp" |
67 #include "utilities/macros.hpp" |
66 #include "utilities/ticks.hpp" |
68 #include "utilities/ticks.hpp" |
67 #if INCLUDE_TRACE |
|
68 #include "trace/tracing.hpp" |
|
69 #endif |
|
70 |
69 |
71 Dictionary* SystemDictionary::_dictionary = NULL; |
70 Dictionary* SystemDictionary::_dictionary = NULL; |
72 PlaceholderTable* SystemDictionary::_placeholders = NULL; |
71 PlaceholderTable* SystemDictionary::_placeholders = NULL; |
73 Dictionary* SystemDictionary::_shared_dictionary = NULL; |
72 Dictionary* SystemDictionary::_shared_dictionary = NULL; |
74 LoaderConstraintTable* SystemDictionary::_loader_constraints = NULL; |
73 LoaderConstraintTable* SystemDictionary::_loader_constraints = NULL; |
94 bool SystemDictionary::_has_checkPackageAccess = false; |
93 bool SystemDictionary::_has_checkPackageAccess = false; |
95 |
94 |
96 // lazily initialized klass variables |
95 // lazily initialized klass variables |
97 Klass* volatile SystemDictionary::_abstract_ownable_synchronizer_klass = NULL; |
96 Klass* volatile SystemDictionary::_abstract_ownable_synchronizer_klass = NULL; |
98 |
97 |
|
98 #if INCLUDE_JFR |
|
99 static const Symbol* jfr_event_handler_proxy = NULL; |
|
100 #endif // INCLUDE_JFR |
99 |
101 |
100 // ---------------------------------------------------------------------------- |
102 // ---------------------------------------------------------------------------- |
101 // Java-level SystemLoader |
103 // Java-level SystemLoader |
102 |
104 |
103 oop SystemDictionary::java_system_loader() { |
105 oop SystemDictionary::java_system_loader() { |
596 } |
601 } |
597 } |
602 } |
598 return (nh); |
603 return (nh); |
599 } |
604 } |
600 |
605 |
|
606 // utility function for class load event |
|
607 static void post_class_load_event(EventClassLoad &event, |
|
608 instanceKlassHandle k, |
|
609 Handle initiating_loader) { |
|
610 #if INCLUDE_JFR |
|
611 if (event.should_commit()) { |
|
612 event.set_loadedClass(k()); |
|
613 event.set_definingClassLoader(k->class_loader_data()); |
|
614 oop class_loader = initiating_loader.is_null() ? (oop)NULL : initiating_loader(); |
|
615 event.set_initiatingClassLoader(class_loader != NULL ? |
|
616 ClassLoaderData::class_loader_data_or_null(class_loader) : |
|
617 (ClassLoaderData*)NULL); |
|
618 event.commit(); |
|
619 } |
|
620 #endif |
|
621 } |
601 |
622 |
602 Klass* SystemDictionary::resolve_instance_class_or_null(Symbol* name, |
623 Klass* SystemDictionary::resolve_instance_class_or_null(Symbol* name, |
603 Handle class_loader, |
624 Handle class_loader, |
604 Handle protection_domain, |
625 Handle protection_domain, |
605 TRAPS) { |
626 TRAPS) { |
606 assert(name != NULL && !FieldType::is_array(name) && |
627 assert(name != NULL && !FieldType::is_array(name) && |
607 !FieldType::is_obj(name), "invalid class name"); |
628 !FieldType::is_obj(name), "invalid class name"); |
608 |
629 |
609 Ticks class_load_start_time = Ticks::now(); |
630 EventClassLoad class_load_start_event; |
610 |
631 |
611 // UseNewReflection |
632 // UseNewReflection |
612 // Fix for 4474172; see evaluation for more details |
633 // Fix for 4474172; see evaluation for more details |
613 class_loader = Handle(THREAD, java_lang_ClassLoader::non_reflection_class_loader(class_loader())); |
634 class_loader = Handle(THREAD, java_lang_ClassLoader::non_reflection_class_loader(class_loader())); |
614 ClassLoaderData *loader_data = register_loader(class_loader, CHECK_NULL); |
635 ClassLoaderData *loader_data = register_loader(class_loader, CHECK_NULL); |
855 |
876 |
856 if (HAS_PENDING_EXCEPTION || k.is_null()) { |
877 if (HAS_PENDING_EXCEPTION || k.is_null()) { |
857 return NULL; |
878 return NULL; |
858 } |
879 } |
859 |
880 |
860 post_class_load_event(class_load_start_time, k, class_loader); |
881 post_class_load_event(class_load_start_event, k, class_loader); |
861 |
882 |
862 #ifdef ASSERT |
883 #ifdef ASSERT |
863 { |
884 { |
864 ClassLoaderData* loader_data = k->class_loader_data(); |
885 ClassLoaderData* loader_data = k->class_loader_data(); |
865 MutexLocker mu(SystemDictionary_lock, THREAD); |
886 MutexLocker mu(SystemDictionary_lock, THREAD); |
980 KlassHandle host_klass, |
1001 KlassHandle host_klass, |
981 GrowableArray<Handle>* cp_patches, |
1002 GrowableArray<Handle>* cp_patches, |
982 TRAPS) { |
1003 TRAPS) { |
983 TempNewSymbol parsed_name = NULL; |
1004 TempNewSymbol parsed_name = NULL; |
984 |
1005 |
985 Ticks class_load_start_time = Ticks::now(); |
1006 EventClassLoad class_load_start_event; |
986 |
1007 |
987 ClassLoaderData* loader_data; |
1008 ClassLoaderData* loader_data; |
988 if (host_klass.not_null()) { |
1009 if (host_klass.not_null()) { |
989 // Create a new CLD for anonymous class, that uses the same class loader |
1010 // Create a new CLD for anonymous class, that uses the same class loader |
990 // as the host_klass |
1011 // as the host_klass |
1041 if (JvmtiExport::should_post_class_load()) { |
1062 if (JvmtiExport::should_post_class_load()) { |
1042 assert(THREAD->is_Java_thread(), "thread->is_Java_thread()"); |
1063 assert(THREAD->is_Java_thread(), "thread->is_Java_thread()"); |
1043 JvmtiExport::post_class_load((JavaThread *) THREAD, k()); |
1064 JvmtiExport::post_class_load((JavaThread *) THREAD, k()); |
1044 } |
1065 } |
1045 |
1066 |
1046 post_class_load_event(class_load_start_time, k, class_loader); |
1067 post_class_load_event(class_load_start_event, k, class_loader); |
1047 } |
1068 } |
1048 assert(host_klass.not_null() || cp_patches == NULL, |
1069 assert(host_klass.not_null() || cp_patches == NULL, |
1049 "cp_patches only found with host_klass"); |
1070 "cp_patches only found with host_klass"); |
1050 |
1071 |
1051 return k(); |
1072 return k(); |
1083 // already be present in the SystemDictionary, otherwise we would not |
1104 // already be present in the SystemDictionary, otherwise we would not |
1084 // throw potential ClassFormatErrors. |
1105 // throw potential ClassFormatErrors. |
1085 // |
1106 // |
1086 // Note: "name" is updated. |
1107 // Note: "name" is updated. |
1087 |
1108 |
1088 instanceKlassHandle k = ClassFileParser(st).parseClassFile(class_name, |
1109 ClassFileParser parser(st); |
1089 loader_data, |
1110 instanceKlassHandle k = parser.parseClassFile(class_name, |
1090 protection_domain, |
1111 loader_data, |
1091 parsed_name, |
1112 protection_domain, |
1092 verify, |
1113 parsed_name, |
1093 THREAD); |
1114 verify, |
|
1115 THREAD); |
1094 |
1116 |
1095 const char* pkg = "java/"; |
1117 const char* pkg = "java/"; |
1096 size_t pkglen = strlen(pkg); |
1118 size_t pkglen = strlen(pkg); |
1097 if (!HAS_PENDING_EXCEPTION && |
1119 if (!HAS_PENDING_EXCEPTION && |
1098 !class_loader.is_null() && |
1120 !class_loader.is_null() && |
1123 // Verification prevents us from creating names with dots in them, this |
1145 // Verification prevents us from creating names with dots in them, this |
1124 // asserts that that's the case. |
1146 // asserts that that's the case. |
1125 assert(is_internal_format(parsed_name), |
1147 assert(is_internal_format(parsed_name), |
1126 "external class name format used internally"); |
1148 "external class name format used internally"); |
1127 |
1149 |
|
1150 #if INCLUDE_JFR |
|
1151 { |
|
1152 InstanceKlass* ik = k(); |
|
1153 ON_KLASS_CREATION(ik, parser, THREAD); |
|
1154 k = instanceKlassHandle(ik); |
|
1155 } |
|
1156 #endif |
|
1157 |
1128 // Add class just loaded |
1158 // Add class just loaded |
1129 // If a class loader supports parallel classloading handle parallel define requests |
1159 // If a class loader supports parallel classloading handle parallel define requests |
1130 // find_or_define_instance_class may return a different InstanceKlass |
1160 // find_or_define_instance_class may return a different InstanceKlass |
1131 if (is_parallelCapable(class_loader)) { |
1161 if (is_parallelCapable(class_loader)) { |
1132 k = find_or_define_instance_class(class_name, class_loader, k, THREAD); |
1162 k = find_or_define_instance_class(class_name, class_loader, k, THREAD); |
1305 |
1335 |
1306 // find_or_define_instance_class may return a different InstanceKlass |
1336 // find_or_define_instance_class may return a different InstanceKlass |
1307 if (!k.is_null()) { |
1337 if (!k.is_null()) { |
1308 k = find_or_define_instance_class(class_name, class_loader, k, CHECK_(nh)); |
1338 k = find_or_define_instance_class(class_name, class_loader, k, CHECK_(nh)); |
1309 } |
1339 } |
|
1340 |
|
1341 #if INCLUDE_JFR |
|
1342 if (k.is_null() && (class_name == jfr_event_handler_proxy)) { |
|
1343 assert(jfr_event_handler_proxy != NULL, "invariant"); |
|
1344 // EventHandlerProxy class is generated dynamically in |
|
1345 // EventHandlerProxyCreator::makeEventHandlerProxyClass |
|
1346 // method, so we generate a Java call from here. |
|
1347 // |
|
1348 // EventHandlerProxy class will finally be defined in |
|
1349 // SystemDictionary::resolve_from_stream method, down |
|
1350 // the call stack. Bootstrap classloader is parallel-capable, |
|
1351 // so no concurrency issues are expected. |
|
1352 CLEAR_PENDING_EXCEPTION; |
|
1353 k = JfrUpcalls::load_event_handler_proxy_class(THREAD); |
|
1354 assert(!k.is_null(), "invariant"); |
|
1355 } |
|
1356 #endif |
|
1357 |
1310 return k; |
1358 return k; |
1311 } else { |
1359 } else { |
1312 // Use user specified class loader to load class. Call loadClass operation on class_loader. |
1360 // Use user specified class loader to load class. Call loadClass operation on class_loader. |
1313 ResourceMark rm(THREAD); |
1361 ResourceMark rm(THREAD); |
1314 |
1362 |
1383 // Class is not found or has the wrong name, return NULL |
1431 // Class is not found or has the wrong name, return NULL |
1384 return nh; |
1432 return nh; |
1385 } |
1433 } |
1386 } |
1434 } |
1387 |
1435 |
|
1436 static void post_class_define_event(InstanceKlass* k, const ClassLoaderData* def_cld) { |
|
1437 EventClassDefine event; |
|
1438 if (event.should_commit()) { |
|
1439 event.set_definedClass(k); |
|
1440 event.set_definingClassLoader(def_cld); |
|
1441 event.commit(); |
|
1442 } |
|
1443 } |
|
1444 |
1388 void SystemDictionary::define_instance_class(instanceKlassHandle k, TRAPS) { |
1445 void SystemDictionary::define_instance_class(instanceKlassHandle k, TRAPS) { |
1389 |
1446 |
1390 ClassLoaderData* loader_data = k->class_loader_data(); |
1447 ClassLoaderData* loader_data = k->class_loader_data(); |
1391 Handle class_loader_h(THREAD, loader_data->class_loader()); |
1448 Handle class_loader_h(THREAD, loader_data->class_loader()); |
1392 |
1449 |
1453 assert(THREAD->is_Java_thread(), "thread->is_Java_thread()"); |
1510 assert(THREAD->is_Java_thread(), "thread->is_Java_thread()"); |
1454 JvmtiExport::post_class_load((JavaThread *) THREAD, k()); |
1511 JvmtiExport::post_class_load((JavaThread *) THREAD, k()); |
1455 |
1512 |
1456 } |
1513 } |
1457 |
1514 |
|
1515 post_class_define_event(k(), loader_data); |
1458 } |
1516 } |
1459 |
1517 |
1460 // Support parallel classloading |
1518 // Support parallel classloading |
1461 // All parallel class loaders, including bootstrap classloader |
1519 // All parallel class loaders, including bootstrap classloader |
1462 // lock a placeholder entry for this class/class_loader pair |
1520 // lock a placeholder entry for this class/class_loader pair |
1714 // Note: anonymous classes are not in the SD. |
1772 // Note: anonymous classes are not in the SD. |
1715 bool SystemDictionary::do_unloading(BoolObjectClosure* is_alive, bool clean_alive) { |
1773 bool SystemDictionary::do_unloading(BoolObjectClosure* is_alive, bool clean_alive) { |
1716 // First, mark for unload all ClassLoaderData referencing a dead class loader. |
1774 // First, mark for unload all ClassLoaderData referencing a dead class loader. |
1717 bool unloading_occurred = ClassLoaderDataGraph::do_unloading(is_alive, clean_alive); |
1775 bool unloading_occurred = ClassLoaderDataGraph::do_unloading(is_alive, clean_alive); |
1718 if (unloading_occurred) { |
1776 if (unloading_occurred) { |
|
1777 JFR_ONLY(Jfr::on_unloading_classes();) |
1719 dictionary()->do_unloading(); |
1778 dictionary()->do_unloading(); |
1720 constraints()->purge_loader_constraints(); |
1779 constraints()->purge_loader_constraints(); |
1721 resolution_errors()->purge_resolution_errors(); |
1780 resolution_errors()->purge_resolution_errors(); |
1722 } |
1781 } |
1723 // Oops referenced by the system dictionary may get unreachable independently |
1782 // Oops referenced by the system dictionary may get unreachable independently |
1847 |
1906 |
1848 // Allocate private object used as system class loader lock |
1907 // Allocate private object used as system class loader lock |
1849 _system_loader_lock_obj = oopFactory::new_intArray(0, CHECK); |
1908 _system_loader_lock_obj = oopFactory::new_intArray(0, CHECK); |
1850 // Initialize basic classes |
1909 // Initialize basic classes |
1851 initialize_preloaded_classes(CHECK); |
1910 initialize_preloaded_classes(CHECK); |
|
1911 #if INCLUDE_JFR |
|
1912 jfr_event_handler_proxy = SymbolTable::new_permanent_symbol("jdk/jfr/proxy/internal/EventHandlerProxy", CHECK); |
|
1913 #endif // INCLUDE_JFR |
1852 } |
1914 } |
1853 |
1915 |
1854 // Compact table of directions on the initialization of klasses: |
1916 // Compact table of directions on the initialization of klasses: |
1855 static const short wk_init_info[] = { |
1917 static const short wk_init_info[] = { |
1856 #define WK_KLASS_INIT_INFO(name, symbol, option) \ |
1918 #define WK_KLASS_INIT_INFO(name, symbol, option) \ |
2685 // Verify constraint table |
2747 // Verify constraint table |
2686 guarantee(constraints() != NULL, "Verify of loader constraints failed"); |
2748 guarantee(constraints() != NULL, "Verify of loader constraints failed"); |
2687 constraints()->verify(dictionary(), placeholders()); |
2749 constraints()->verify(dictionary(), placeholders()); |
2688 } |
2750 } |
2689 |
2751 |
2690 // utility function for class load event |
|
2691 void SystemDictionary::post_class_load_event(const Ticks& start_time, |
|
2692 instanceKlassHandle k, |
|
2693 Handle initiating_loader) { |
|
2694 #if INCLUDE_TRACE |
|
2695 EventClassLoad event(UNTIMED); |
|
2696 if (event.should_commit()) { |
|
2697 event.set_starttime(start_time); |
|
2698 event.set_loadedClass(k()); |
|
2699 oop defining_class_loader = k->class_loader(); |
|
2700 event.set_definingClassLoader(defining_class_loader != NULL ? |
|
2701 defining_class_loader->klass() : (Klass*)NULL); |
|
2702 oop class_loader = initiating_loader.is_null() ? (oop)NULL : initiating_loader(); |
|
2703 event.set_initiatingClassLoader(class_loader != NULL ? |
|
2704 class_loader->klass() : (Klass*)NULL); |
|
2705 event.commit(); |
|
2706 } |
|
2707 #endif // INCLUDE_TRACE |
|
2708 } |
|
2709 |
|
2710 #ifndef PRODUCT |
2752 #ifndef PRODUCT |
2711 |
2753 |
2712 // statistics code |
2754 // statistics code |
2713 class ClassStatistics: AllStatic { |
2755 class ClassStatistics: AllStatic { |
2714 private: |
2756 private: |