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" |
41 #include "memory/filemap.hpp" |
42 #include "memory/filemap.hpp" |
42 #include "memory/gcLocker.hpp" |
43 #include "memory/gcLocker.hpp" |
43 #include "memory/oopFactory.hpp" |
44 #include "memory/oopFactory.hpp" |
44 #include "oops/instanceKlass.hpp" |
45 #include "oops/instanceKlass.hpp" |
45 #include "oops/instanceRefKlass.hpp" |
46 #include "oops/instanceRefKlass.hpp" |
62 #include "runtime/signature.hpp" |
63 #include "runtime/signature.hpp" |
63 #include "services/classLoadingService.hpp" |
64 #include "services/classLoadingService.hpp" |
64 #include "services/threadService.hpp" |
65 #include "services/threadService.hpp" |
65 #include "utilities/macros.hpp" |
66 #include "utilities/macros.hpp" |
66 #include "utilities/ticks.hpp" |
67 #include "utilities/ticks.hpp" |
67 #if INCLUDE_TRACE |
|
68 #include "trace/tracing.hpp" |
|
69 #endif |
|
70 |
68 |
71 Dictionary* SystemDictionary::_dictionary = NULL; |
69 Dictionary* SystemDictionary::_dictionary = NULL; |
72 PlaceholderTable* SystemDictionary::_placeholders = NULL; |
70 PlaceholderTable* SystemDictionary::_placeholders = NULL; |
73 Dictionary* SystemDictionary::_shared_dictionary = NULL; |
71 Dictionary* SystemDictionary::_shared_dictionary = NULL; |
74 LoaderConstraintTable* SystemDictionary::_loader_constraints = NULL; |
72 LoaderConstraintTable* SystemDictionary::_loader_constraints = NULL; |
596 } |
594 } |
597 } |
595 } |
598 return (nh); |
596 return (nh); |
599 } |
597 } |
600 |
598 |
|
599 // utility function for class load event |
|
600 static void post_class_load_event(EventClassLoad &event, |
|
601 instanceKlassHandle k, |
|
602 Handle initiating_loader) { |
|
603 #if INCLUDE_JFR |
|
604 if (event.should_commit()) { |
|
605 event.set_loadedClass(k()); |
|
606 event.set_definingClassLoader(k->class_loader_data()); |
|
607 oop class_loader = initiating_loader.is_null() ? (oop)NULL : initiating_loader(); |
|
608 event.set_initiatingClassLoader(class_loader != NULL ? |
|
609 ClassLoaderData::class_loader_data_or_null(class_loader) : |
|
610 (ClassLoaderData*)NULL); |
|
611 event.commit(); |
|
612 } |
|
613 #endif // INCLUDE_JFR |
|
614 } |
601 |
615 |
602 Klass* SystemDictionary::resolve_instance_class_or_null(Symbol* name, |
616 Klass* SystemDictionary::resolve_instance_class_or_null(Symbol* name, |
603 Handle class_loader, |
617 Handle class_loader, |
604 Handle protection_domain, |
618 Handle protection_domain, |
605 TRAPS) { |
619 TRAPS) { |
606 assert(name != NULL && !FieldType::is_array(name) && |
620 assert(name != NULL && !FieldType::is_array(name) && |
607 !FieldType::is_obj(name), "invalid class name"); |
621 !FieldType::is_obj(name), "invalid class name"); |
608 |
622 |
609 Ticks class_load_start_time = Ticks::now(); |
623 EventClassLoad class_load_start_event; |
610 |
624 |
611 // UseNewReflection |
625 // UseNewReflection |
612 // Fix for 4474172; see evaluation for more details |
626 // Fix for 4474172; see evaluation for more details |
613 class_loader = Handle(THREAD, java_lang_ClassLoader::non_reflection_class_loader(class_loader())); |
627 class_loader = Handle(THREAD, java_lang_ClassLoader::non_reflection_class_loader(class_loader())); |
614 ClassLoaderData *loader_data = register_loader(class_loader, CHECK_NULL); |
628 ClassLoaderData *loader_data = register_loader(class_loader, CHECK_NULL); |
855 |
869 |
856 if (HAS_PENDING_EXCEPTION || k.is_null()) { |
870 if (HAS_PENDING_EXCEPTION || k.is_null()) { |
857 return NULL; |
871 return NULL; |
858 } |
872 } |
859 |
873 |
860 post_class_load_event(class_load_start_time, k, class_loader); |
874 post_class_load_event(class_load_start_event, k, class_loader); |
861 |
875 |
862 #ifdef ASSERT |
876 #ifdef ASSERT |
863 { |
877 { |
864 ClassLoaderData* loader_data = k->class_loader_data(); |
878 ClassLoaderData* loader_data = k->class_loader_data(); |
865 MutexLocker mu(SystemDictionary_lock, THREAD); |
879 MutexLocker mu(SystemDictionary_lock, THREAD); |
980 KlassHandle host_klass, |
994 KlassHandle host_klass, |
981 GrowableArray<Handle>* cp_patches, |
995 GrowableArray<Handle>* cp_patches, |
982 TRAPS) { |
996 TRAPS) { |
983 TempNewSymbol parsed_name = NULL; |
997 TempNewSymbol parsed_name = NULL; |
984 |
998 |
985 Ticks class_load_start_time = Ticks::now(); |
999 EventClassLoad class_load_start_event; |
986 |
1000 |
987 ClassLoaderData* loader_data; |
1001 ClassLoaderData* loader_data; |
988 if (host_klass.not_null()) { |
1002 if (host_klass.not_null()) { |
989 // Create a new CLD for anonymous class, that uses the same class loader |
1003 // Create a new CLD for anonymous class, that uses the same class loader |
990 // as the host_klass |
1004 // as the host_klass |
1041 if (JvmtiExport::should_post_class_load()) { |
1055 if (JvmtiExport::should_post_class_load()) { |
1042 assert(THREAD->is_Java_thread(), "thread->is_Java_thread()"); |
1056 assert(THREAD->is_Java_thread(), "thread->is_Java_thread()"); |
1043 JvmtiExport::post_class_load((JavaThread *) THREAD, k()); |
1057 JvmtiExport::post_class_load((JavaThread *) THREAD, k()); |
1044 } |
1058 } |
1045 |
1059 |
1046 post_class_load_event(class_load_start_time, k, class_loader); |
1060 post_class_load_event(class_load_start_event, k, class_loader); |
1047 } |
1061 } |
1048 assert(host_klass.not_null() || cp_patches == NULL, |
1062 assert(host_klass.not_null() || cp_patches == NULL, |
1049 "cp_patches only found with host_klass"); |
1063 "cp_patches only found with host_klass"); |
1050 |
1064 |
1051 return k(); |
1065 return k(); |
1083 // already be present in the SystemDictionary, otherwise we would not |
1097 // already be present in the SystemDictionary, otherwise we would not |
1084 // throw potential ClassFormatErrors. |
1098 // throw potential ClassFormatErrors. |
1085 // |
1099 // |
1086 // Note: "name" is updated. |
1100 // Note: "name" is updated. |
1087 |
1101 |
1088 instanceKlassHandle k = ClassFileParser(st).parseClassFile(class_name, |
1102 ClassFileParser parser(st); |
1089 loader_data, |
1103 instanceKlassHandle k = parser.parseClassFile(class_name, |
1090 protection_domain, |
1104 loader_data, |
1091 parsed_name, |
1105 protection_domain, |
1092 verify, |
1106 parsed_name, |
1093 THREAD); |
1107 verify, |
|
1108 THREAD); |
1094 |
1109 |
1095 const char* pkg = "java/"; |
1110 const char* pkg = "java/"; |
1096 size_t pkglen = strlen(pkg); |
1111 size_t pkglen = strlen(pkg); |
1097 if (!HAS_PENDING_EXCEPTION && |
1112 if (!HAS_PENDING_EXCEPTION && |
1098 !class_loader.is_null() && |
1113 !class_loader.is_null() && |
1122 assert(class_name == NULL || class_name == parsed_name, "name mismatch"); |
1137 assert(class_name == NULL || class_name == parsed_name, "name mismatch"); |
1123 // Verification prevents us from creating names with dots in them, this |
1138 // Verification prevents us from creating names with dots in them, this |
1124 // asserts that that's the case. |
1139 // asserts that that's the case. |
1125 assert(is_internal_format(parsed_name), |
1140 assert(is_internal_format(parsed_name), |
1126 "external class name format used internally"); |
1141 "external class name format used internally"); |
|
1142 |
|
1143 #if INCLUDE_JFR |
|
1144 { |
|
1145 InstanceKlass* ik = k(); |
|
1146 ON_KLASS_CREATION(ik, parser, THREAD); |
|
1147 k = instanceKlassHandle(ik); |
|
1148 } |
|
1149 #endif |
1127 |
1150 |
1128 // Add class just loaded |
1151 // Add class just loaded |
1129 // If a class loader supports parallel classloading handle parallel define requests |
1152 // If a class loader supports parallel classloading handle parallel define requests |
1130 // find_or_define_instance_class may return a different InstanceKlass |
1153 // find_or_define_instance_class may return a different InstanceKlass |
1131 if (is_parallelCapable(class_loader)) { |
1154 if (is_parallelCapable(class_loader)) { |
1383 // Class is not found or has the wrong name, return NULL |
1406 // Class is not found or has the wrong name, return NULL |
1384 return nh; |
1407 return nh; |
1385 } |
1408 } |
1386 } |
1409 } |
1387 |
1410 |
|
1411 static void post_class_define_event(InstanceKlass* k, const ClassLoaderData* def_cld) { |
|
1412 EventClassDefine event; |
|
1413 if (event.should_commit()) { |
|
1414 event.set_definedClass(k); |
|
1415 event.set_definingClassLoader(def_cld); |
|
1416 event.commit(); |
|
1417 } |
|
1418 } |
|
1419 |
1388 void SystemDictionary::define_instance_class(instanceKlassHandle k, TRAPS) { |
1420 void SystemDictionary::define_instance_class(instanceKlassHandle k, TRAPS) { |
1389 |
1421 |
1390 ClassLoaderData* loader_data = k->class_loader_data(); |
1422 ClassLoaderData* loader_data = k->class_loader_data(); |
1391 Handle class_loader_h(THREAD, loader_data->class_loader()); |
1423 Handle class_loader_h(THREAD, loader_data->class_loader()); |
1392 |
1424 |
1453 assert(THREAD->is_Java_thread(), "thread->is_Java_thread()"); |
1485 assert(THREAD->is_Java_thread(), "thread->is_Java_thread()"); |
1454 JvmtiExport::post_class_load((JavaThread *) THREAD, k()); |
1486 JvmtiExport::post_class_load((JavaThread *) THREAD, k()); |
1455 |
1487 |
1456 } |
1488 } |
1457 |
1489 |
|
1490 post_class_define_event(k(), loader_data); |
1458 } |
1491 } |
1459 |
1492 |
1460 // Support parallel classloading |
1493 // Support parallel classloading |
1461 // All parallel class loaders, including bootstrap classloader |
1494 // All parallel class loaders, including bootstrap classloader |
1462 // lock a placeholder entry for this class/class_loader pair |
1495 // lock a placeholder entry for this class/class_loader pair |
2685 // Verify constraint table |
2718 // Verify constraint table |
2686 guarantee(constraints() != NULL, "Verify of loader constraints failed"); |
2719 guarantee(constraints() != NULL, "Verify of loader constraints failed"); |
2687 constraints()->verify(dictionary(), placeholders()); |
2720 constraints()->verify(dictionary(), placeholders()); |
2688 } |
2721 } |
2689 |
2722 |
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 |
2723 #ifndef PRODUCT |
2711 |
2724 |
2712 // statistics code |
2725 // statistics code |
2713 class ClassStatistics: AllStatic { |
2726 class ClassStatistics: AllStatic { |
2714 private: |
2727 private: |