1.1 --- a/src/share/vm/classfile/systemDictionary.cpp Wed Oct 14 16:43:13 2020 +0800 1.2 +++ b/src/share/vm/classfile/systemDictionary.cpp Wed Oct 14 17:44:48 2020 +0800 1.3 @@ -38,6 +38,8 @@ 1.4 #include "compiler/compileBroker.hpp" 1.5 #include "interpreter/bytecodeStream.hpp" 1.6 #include "interpreter/interpreter.hpp" 1.7 +#include "jfr/jfrEvents.hpp" 1.8 +#include "jfr/jni/jfrUpcalls.hpp" 1.9 #include "memory/filemap.hpp" 1.10 #include "memory/gcLocker.hpp" 1.11 #include "memory/oopFactory.hpp" 1.12 @@ -64,9 +66,6 @@ 1.13 #include "services/threadService.hpp" 1.14 #include "utilities/macros.hpp" 1.15 #include "utilities/ticks.hpp" 1.16 -#if INCLUDE_TRACE 1.17 -#include "trace/tracing.hpp" 1.18 -#endif 1.19 1.20 Dictionary* SystemDictionary::_dictionary = NULL; 1.21 PlaceholderTable* SystemDictionary::_placeholders = NULL; 1.22 @@ -96,6 +95,9 @@ 1.23 // lazily initialized klass variables 1.24 Klass* volatile SystemDictionary::_abstract_ownable_synchronizer_klass = NULL; 1.25 1.26 +#if INCLUDE_JFR 1.27 +static const Symbol* jfr_event_handler_proxy = NULL; 1.28 +#endif // INCLUDE_JFR 1.29 1.30 // ---------------------------------------------------------------------------- 1.31 // Java-level SystemLoader 1.32 @@ -141,6 +143,9 @@ 1.33 } 1.34 1.35 #endif 1.36 +#if INCLUDE_JFR 1.37 +#include "jfr/jfr.hpp" 1.38 +#endif 1.39 1.40 // ---------------------------------------------------------------------------- 1.41 // Parallel class loading check 1.42 @@ -598,6 +603,22 @@ 1.43 return (nh); 1.44 } 1.45 1.46 +// utility function for class load event 1.47 +static void post_class_load_event(EventClassLoad &event, 1.48 + instanceKlassHandle k, 1.49 + Handle initiating_loader) { 1.50 +#if INCLUDE_JFR 1.51 + if (event.should_commit()) { 1.52 + event.set_loadedClass(k()); 1.53 + event.set_definingClassLoader(k->class_loader_data()); 1.54 + oop class_loader = initiating_loader.is_null() ? (oop)NULL : initiating_loader(); 1.55 + event.set_initiatingClassLoader(class_loader != NULL ? 1.56 + ClassLoaderData::class_loader_data_or_null(class_loader) : 1.57 + (ClassLoaderData*)NULL); 1.58 + event.commit(); 1.59 + } 1.60 +#endif 1.61 +} 1.62 1.63 Klass* SystemDictionary::resolve_instance_class_or_null(Symbol* name, 1.64 Handle class_loader, 1.65 @@ -606,7 +627,7 @@ 1.66 assert(name != NULL && !FieldType::is_array(name) && 1.67 !FieldType::is_obj(name), "invalid class name"); 1.68 1.69 - Ticks class_load_start_time = Ticks::now(); 1.70 + EventClassLoad class_load_start_event; 1.71 1.72 // UseNewReflection 1.73 // Fix for 4474172; see evaluation for more details 1.74 @@ -857,7 +878,7 @@ 1.75 return NULL; 1.76 } 1.77 1.78 - post_class_load_event(class_load_start_time, k, class_loader); 1.79 + post_class_load_event(class_load_start_event, k, class_loader); 1.80 1.81 #ifdef ASSERT 1.82 { 1.83 @@ -982,7 +1003,7 @@ 1.84 TRAPS) { 1.85 TempNewSymbol parsed_name = NULL; 1.86 1.87 - Ticks class_load_start_time = Ticks::now(); 1.88 + EventClassLoad class_load_start_event; 1.89 1.90 ClassLoaderData* loader_data; 1.91 if (host_klass.not_null()) { 1.92 @@ -1043,7 +1064,7 @@ 1.93 JvmtiExport::post_class_load((JavaThread *) THREAD, k()); 1.94 } 1.95 1.96 - post_class_load_event(class_load_start_time, k, class_loader); 1.97 + post_class_load_event(class_load_start_event, k, class_loader); 1.98 } 1.99 assert(host_klass.not_null() || cp_patches == NULL, 1.100 "cp_patches only found with host_klass"); 1.101 @@ -1085,12 +1106,13 @@ 1.102 // 1.103 // Note: "name" is updated. 1.104 1.105 - instanceKlassHandle k = ClassFileParser(st).parseClassFile(class_name, 1.106 - loader_data, 1.107 - protection_domain, 1.108 - parsed_name, 1.109 - verify, 1.110 - THREAD); 1.111 + ClassFileParser parser(st); 1.112 + instanceKlassHandle k = parser.parseClassFile(class_name, 1.113 + loader_data, 1.114 + protection_domain, 1.115 + parsed_name, 1.116 + verify, 1.117 + THREAD); 1.118 1.119 const char* pkg = "java/"; 1.120 size_t pkglen = strlen(pkg); 1.121 @@ -1125,6 +1147,14 @@ 1.122 assert(is_internal_format(parsed_name), 1.123 "external class name format used internally"); 1.124 1.125 +#if INCLUDE_JFR 1.126 + { 1.127 + InstanceKlass* ik = k(); 1.128 + ON_KLASS_CREATION(ik, parser, THREAD); 1.129 + k = instanceKlassHandle(ik); 1.130 + } 1.131 +#endif 1.132 + 1.133 // Add class just loaded 1.134 // If a class loader supports parallel classloading handle parallel define requests 1.135 // find_or_define_instance_class may return a different InstanceKlass 1.136 @@ -1307,6 +1337,24 @@ 1.137 if (!k.is_null()) { 1.138 k = find_or_define_instance_class(class_name, class_loader, k, CHECK_(nh)); 1.139 } 1.140 + 1.141 +#if INCLUDE_JFR 1.142 + if (k.is_null() && (class_name == jfr_event_handler_proxy)) { 1.143 + assert(jfr_event_handler_proxy != NULL, "invariant"); 1.144 + // EventHandlerProxy class is generated dynamically in 1.145 + // EventHandlerProxyCreator::makeEventHandlerProxyClass 1.146 + // method, so we generate a Java call from here. 1.147 + // 1.148 + // EventHandlerProxy class will finally be defined in 1.149 + // SystemDictionary::resolve_from_stream method, down 1.150 + // the call stack. Bootstrap classloader is parallel-capable, 1.151 + // so no concurrency issues are expected. 1.152 + CLEAR_PENDING_EXCEPTION; 1.153 + k = JfrUpcalls::load_event_handler_proxy_class(THREAD); 1.154 + assert(!k.is_null(), "invariant"); 1.155 + } 1.156 +#endif 1.157 + 1.158 return k; 1.159 } else { 1.160 // Use user specified class loader to load class. Call loadClass operation on class_loader. 1.161 @@ -1385,6 +1433,15 @@ 1.162 } 1.163 } 1.164 1.165 +static void post_class_define_event(InstanceKlass* k, const ClassLoaderData* def_cld) { 1.166 + EventClassDefine event; 1.167 + if (event.should_commit()) { 1.168 + event.set_definedClass(k); 1.169 + event.set_definingClassLoader(def_cld); 1.170 + event.commit(); 1.171 + } 1.172 +} 1.173 + 1.174 void SystemDictionary::define_instance_class(instanceKlassHandle k, TRAPS) { 1.175 1.176 ClassLoaderData* loader_data = k->class_loader_data(); 1.177 @@ -1455,6 +1512,7 @@ 1.178 1.179 } 1.180 1.181 + post_class_define_event(k(), loader_data); 1.182 } 1.183 1.184 // Support parallel classloading 1.185 @@ -1716,6 +1774,7 @@ 1.186 // First, mark for unload all ClassLoaderData referencing a dead class loader. 1.187 bool unloading_occurred = ClassLoaderDataGraph::do_unloading(is_alive, clean_alive); 1.188 if (unloading_occurred) { 1.189 + JFR_ONLY(Jfr::on_unloading_classes();) 1.190 dictionary()->do_unloading(); 1.191 constraints()->purge_loader_constraints(); 1.192 resolution_errors()->purge_resolution_errors(); 1.193 @@ -1849,6 +1908,9 @@ 1.194 _system_loader_lock_obj = oopFactory::new_intArray(0, CHECK); 1.195 // Initialize basic classes 1.196 initialize_preloaded_classes(CHECK); 1.197 +#if INCLUDE_JFR 1.198 + jfr_event_handler_proxy = SymbolTable::new_permanent_symbol("jdk/jfr/proxy/internal/EventHandlerProxy", CHECK); 1.199 +#endif // INCLUDE_JFR 1.200 } 1.201 1.202 // Compact table of directions on the initialization of klasses: 1.203 @@ -2687,26 +2749,6 @@ 1.204 constraints()->verify(dictionary(), placeholders()); 1.205 } 1.206 1.207 -// utility function for class load event 1.208 -void SystemDictionary::post_class_load_event(const Ticks& start_time, 1.209 - instanceKlassHandle k, 1.210 - Handle initiating_loader) { 1.211 -#if INCLUDE_TRACE 1.212 - EventClassLoad event(UNTIMED); 1.213 - if (event.should_commit()) { 1.214 - event.set_starttime(start_time); 1.215 - event.set_loadedClass(k()); 1.216 - oop defining_class_loader = k->class_loader(); 1.217 - event.set_definingClassLoader(defining_class_loader != NULL ? 1.218 - defining_class_loader->klass() : (Klass*)NULL); 1.219 - oop class_loader = initiating_loader.is_null() ? (oop)NULL : initiating_loader(); 1.220 - event.set_initiatingClassLoader(class_loader != NULL ? 1.221 - class_loader->klass() : (Klass*)NULL); 1.222 - event.commit(); 1.223 - } 1.224 -#endif // INCLUDE_TRACE 1.225 -} 1.226 - 1.227 #ifndef PRODUCT 1.228 1.229 // statistics code