< prev index next >

src/hotspot/share/jfr/instrumentation/jfrEventClassTransformer.cpp

Print this page

1455   assert(signature != nullptr, "invariant");
1456   return nullptr != ik->find_local_method(name, signature, Klass::OverpassLookupMode::skip, Klass::StaticLookupMode::find,
1457                                           Klass::PrivateLookupMode::find);
1458 }
1459 
1460 // If for a subklass, on initial class load, an implementation exist for any of the final methods declared in Event,
1461 // then constraints are considered breached.
1462 static bool invalid_preconditions_for_subklass_on_initial_load(const InstanceKlass* ik) {
1463   assert(ik != nullptr, "invariant");
1464   return has_local_method_implementation(ik, begin, void_method_sig) ||
1465          has_local_method_implementation(ik, end, void_method_sig) ||
1466          has_local_method_implementation(ik, commit, void_method_sig) ||
1467          has_local_method_implementation(ik, isEnabled, boolean_method_sig) ||
1468          has_local_method_implementation(ik, shouldCommit, boolean_method_sig);
1469 }
1470 
1471 static ClassFileStream* schema_extend_event_subklass_bytes(const InstanceKlass* ik, const ClassFileParser& parser, bool& is_instrumented, TRAPS) {
1472   assert(JdkJfrEvent::is_a(ik), "invariant");
1473   assert(!is_instrumented, "invariant");
1474   DEBUG_ONLY(JfrJavaSupport::check_java_thread_in_vm(THREAD));

1475   if (invalid_preconditions_for_subklass_on_initial_load(ik)) {
1476     // Remove the tag denoting this as a jdk.jfr.Event subklass. No instrumentation, hence no events can be written.
1477     // The class is allowed to load as-is, but it is classified as outside of the jfr system.
1478     JdkJfrEvent::remove(ik);
1479     return nullptr;
1480   }
1481   jint size_of_new_bytes = 0;
1482   const u1* new_bytes = schema_extend_event_subklass_bytes(ik, parser, size_of_new_bytes, THREAD);
1483   if (new_bytes == nullptr) {
1484     return nullptr;
1485   }
1486   assert(new_bytes != nullptr, "invariant");
1487   assert(size_of_new_bytes > 0, "invariant");
1488   const bool force_instrumentation = should_force_instrumentation();
1489   if (Jfr::is_recording() || force_instrumentation) {
1490     jint size_of_instrumented_bytes = 0;
1491     unsigned char* instrumented_bytes = nullptr;
1492     const jclass super = static_cast<jclass>(JfrJavaSupport::local_jni_handle(ik->super()->java_mirror(), THREAD));
1493     const jboolean boot_class_loader = ik->class_loader_data()->is_boot_class_loader_data();
1494     JfrUpcalls::new_bytes_eager_instrumentation(JfrTraceId::load_raw(ik),

1455   assert(signature != nullptr, "invariant");
1456   return nullptr != ik->find_local_method(name, signature, Klass::OverpassLookupMode::skip, Klass::StaticLookupMode::find,
1457                                           Klass::PrivateLookupMode::find);
1458 }
1459 
1460 // If for a subklass, on initial class load, an implementation exist for any of the final methods declared in Event,
1461 // then constraints are considered breached.
1462 static bool invalid_preconditions_for_subklass_on_initial_load(const InstanceKlass* ik) {
1463   assert(ik != nullptr, "invariant");
1464   return has_local_method_implementation(ik, begin, void_method_sig) ||
1465          has_local_method_implementation(ik, end, void_method_sig) ||
1466          has_local_method_implementation(ik, commit, void_method_sig) ||
1467          has_local_method_implementation(ik, isEnabled, boolean_method_sig) ||
1468          has_local_method_implementation(ik, shouldCommit, boolean_method_sig);
1469 }
1470 
1471 static ClassFileStream* schema_extend_event_subklass_bytes(const InstanceKlass* ik, const ClassFileParser& parser, bool& is_instrumented, TRAPS) {
1472   assert(JdkJfrEvent::is_a(ik), "invariant");
1473   assert(!is_instrumented, "invariant");
1474   DEBUG_ONLY(JfrJavaSupport::check_java_thread_in_vm(THREAD));
1475   initialize_symbols();
1476   if (invalid_preconditions_for_subklass_on_initial_load(ik)) {
1477     // Remove the tag denoting this as a jdk.jfr.Event subklass. No instrumentation, hence no events can be written.
1478     // The class is allowed to load as-is, but it is classified as outside of the jfr system.
1479     JdkJfrEvent::remove(ik);
1480     return nullptr;
1481   }
1482   jint size_of_new_bytes = 0;
1483   const u1* new_bytes = schema_extend_event_subklass_bytes(ik, parser, size_of_new_bytes, THREAD);
1484   if (new_bytes == nullptr) {
1485     return nullptr;
1486   }
1487   assert(new_bytes != nullptr, "invariant");
1488   assert(size_of_new_bytes > 0, "invariant");
1489   const bool force_instrumentation = should_force_instrumentation();
1490   if (Jfr::is_recording() || force_instrumentation) {
1491     jint size_of_instrumented_bytes = 0;
1492     unsigned char* instrumented_bytes = nullptr;
1493     const jclass super = static_cast<jclass>(JfrJavaSupport::local_jni_handle(ik->super()->java_mirror(), THREAD));
1494     const jboolean boot_class_loader = ik->class_loader_data()->is_boot_class_loader_data();
1495     JfrUpcalls::new_bytes_eager_instrumentation(JfrTraceId::load_raw(ik),
< prev index next >