1120
1121 static inline Klass* oop_to_klass(oop obj) {
1122 Klass* k = obj->klass();
1123
1124 // if the object is a java.lang.Class then return the java mirror
1125 if (k == vmClasses::Class_klass()) {
1126 if (!java_lang_Class::is_primitive(obj)) {
1127 k = java_lang_Class::as_Klass(obj);
1128 assert(k != nullptr, "class for non-primitive mirror must exist");
1129 }
1130 }
1131 return k;
1132 }
1133
1134 class JvmtiObjectAllocEventMark : public JvmtiClassEventMark {
1135 private:
1136 jobject _jobj;
1137 jlong _size;
1138 public:
1139 JvmtiObjectAllocEventMark(JavaThread *thread, oop obj) : JvmtiClassEventMark(thread, oop_to_klass(obj)) {
1140 _jobj = (jobject)to_jobject(obj);
1141 _size = obj->size() * wordSize;
1142 };
1143 jobject jni_jobject() { return _jobj; }
1144 jlong size() { return _size; }
1145 };
1146
1147 class JvmtiCompiledMethodLoadEventMark : public JvmtiMethodEventMark {
1148 private:
1149 jint _code_size;
1150 const void *_code_data;
1151 jint _map_length;
1152 jvmtiAddrLocationMap *_map;
1153 const void *_compile_info;
1154 public:
1155 JvmtiCompiledMethodLoadEventMark(JavaThread *thread, nmethod *nm, void* compile_info_ptr = nullptr)
1156 : JvmtiMethodEventMark(thread,methodHandle(thread, nm->method())) {
1157 _code_data = nm->code_begin();
1158 _code_size = nm->code_size();
1159 _compile_info = compile_info_ptr; // Set void pointer of compiledMethodLoad Event. Default value is null.
1160 JvmtiCodeBlobEvents::build_jvmti_addr_location_map(nm, &_map, &_map_length);
1265 thread->osthread()->set_state(old_os_state);
1266 }
1267 }
1268 }
1269
1270 //////////////////////////////////////////////////////////////////////////////
1271
1272 bool JvmtiExport::_can_get_source_debug_extension = false;
1273 bool JvmtiExport::_can_maintain_original_method_order = false;
1274 bool JvmtiExport::_can_post_interpreter_events = false;
1275 bool JvmtiExport::_can_post_on_exceptions = false;
1276 bool JvmtiExport::_can_post_breakpoint = false;
1277 bool JvmtiExport::_can_post_field_access = false;
1278 bool JvmtiExport::_can_post_field_modification = false;
1279 bool JvmtiExport::_can_post_method_entry = false;
1280 bool JvmtiExport::_can_post_method_exit = false;
1281 bool JvmtiExport::_can_post_frame_pop = false;
1282 bool JvmtiExport::_can_pop_frame = false;
1283 bool JvmtiExport::_can_force_early_return = false;
1284 bool JvmtiExport::_can_support_virtual_threads = false;
1285 bool JvmtiExport::_can_get_owned_monitor_info = false;
1286
1287 bool JvmtiExport::_early_vmstart_recorded = false;
1288
1289 bool JvmtiExport::_should_post_single_step = false;
1290 bool JvmtiExport::_should_post_field_access = false;
1291 bool JvmtiExport::_should_post_field_modification = false;
1292 bool JvmtiExport::_should_post_class_load = false;
1293 bool JvmtiExport::_should_post_class_prepare = false;
1294 bool JvmtiExport::_should_post_class_unload = false;
1295 bool JvmtiExport::_should_post_thread_life = false;
1296 bool JvmtiExport::_should_clean_up_heap_objects = false;
1297 bool JvmtiExport::_should_post_native_method_bind = false;
1298 bool JvmtiExport::_should_post_dynamic_code_generated = false;
1299 bool JvmtiExport::_should_post_data_dump = false;
1300 bool JvmtiExport::_should_post_compiled_method_load = false;
1301 bool JvmtiExport::_should_post_compiled_method_unload = false;
1302 bool JvmtiExport::_should_post_monitor_contended_enter = false;
1303 bool JvmtiExport::_should_post_monitor_contended_entered = false;
1304 bool JvmtiExport::_should_post_monitor_wait = false;
2950 void JvmtiExport::vthread_post_monitor_waited(JavaThread *current, ObjectMonitor *obj_mntr, jboolean timed_out) {
2951 Handle vthread(current, current->vthread());
2952
2953 // Finish the VTMS transition temporarily to post the event.
2954 MountUnmountDisabler::end_transition(current, vthread(), true /*is_mount*/, false /*is_thread_start*/);
2955
2956 // Post event.
2957 JvmtiExport::post_monitor_waited(current, obj_mntr, timed_out);
2958
2959 // Go back to VTMS transition state.
2960 MountUnmountDisabler::start_transition(current, vthread(), false /*is_mount*/, false /*is_thread_start*/);
2961 }
2962
2963 void JvmtiExport::post_vm_object_alloc(JavaThread *thread, oop object) {
2964 if (object == nullptr) {
2965 return;
2966 }
2967 if (thread->should_hide_jvmti_events()) {
2968 return;
2969 }
2970 HandleMark hm(thread);
2971 Handle h(thread, object);
2972
2973 EVT_TRIG_TRACE(JVMTI_EVENT_VM_OBJECT_ALLOC, ("[%s] Trg vm object alloc triggered",
2974 JvmtiTrace::safe_get_thread_name(thread)));
2975 JvmtiEnvIterator it;
2976 for (JvmtiEnv* env = it.first(); env != nullptr; env = it.next(env)) {
2977 if (env->is_enabled(JVMTI_EVENT_VM_OBJECT_ALLOC)) {
2978 EVT_TRACE(JVMTI_EVENT_VM_OBJECT_ALLOC, ("[%s] Evt vmobject alloc sent %s",
2979 JvmtiTrace::safe_get_thread_name(thread),
2980 object==nullptr? "null" : object->klass()->external_name()));
2981
2982 JvmtiObjectAllocEventMark jem(thread, h());
2983 JVMTI_JAVA_THREAD_EVENT_CALLBACK_BLOCK(thread)
2984 jvmtiEventVMObjectAlloc callback = env->callbacks()->VMObjectAlloc;
2985 if (callback != nullptr) {
2986 (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(),
2987 jem.jni_jobject(), jem.jni_class(), jem.size());
2988 }
2989 }
2990 }
2991 }
2992
2993 void JvmtiExport::post_sampled_object_alloc(JavaThread *thread, oop object) {
2994 HandleMark hm(thread);
2995 Handle h(thread, object);
2996
2997 JvmtiThreadState *state = get_jvmti_thread_state(thread);
2998 if (state == nullptr) {
2999 return;
3000 }
3001 if (object == nullptr) {
3002 return;
3003 }
3004 if (thread->should_hide_jvmti_events()) {
3005 return;
3006 }
3007
3008 EVT_TRIG_TRACE(JVMTI_EVENT_SAMPLED_OBJECT_ALLOC,
3009 ("[%s] Trg sampled object alloc triggered",
3010 JvmtiTrace::safe_get_thread_name(thread)));
3011 JvmtiEnvThreadStateIterator it(state);
3012 for (JvmtiEnvThreadState* ets = it.first(); ets != nullptr; ets = it.next(ets)) {
3013 if (ets->is_enabled(JVMTI_EVENT_SAMPLED_OBJECT_ALLOC)) {
3014 EVT_TRACE(JVMTI_EVENT_SAMPLED_OBJECT_ALLOC,
3015 ("[%s] Evt sampled object alloc sent %s",
3016 JvmtiTrace::safe_get_thread_name(thread),
3017 object == nullptr ? "null" : object->klass()->external_name()));
3018
3019 JvmtiEnv *env = ets->get_env();
3020 JvmtiObjectAllocEventMark jem(thread, h());
3021 JVMTI_JAVA_THREAD_EVENT_CALLBACK_BLOCK(thread)
3022 jvmtiEventSampledObjectAlloc callback = env->callbacks()->SampledObjectAlloc;
3023 if (callback != nullptr) {
3024 (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(),
3025 jem.jni_jobject(), jem.jni_class(), jem.size());
3026 }
3027 }
3028 }
3029 }
3030
3031 ////////////////////////////////////////////////////////////////////////////////////////////////
3032
3033 void JvmtiExport::cleanup_thread(JavaThread* thread) {
3034 assert(JavaThread::current() == thread, "thread is not current");
3035 MutexLocker mu(thread, JvmtiThreadState_lock);
3036
3037 if (thread->jvmti_thread_state() != nullptr) {
3038 // This has to happen after the thread state is removed, which is
3039 // why it is not in post_thread_end_event like its complement
|
1120
1121 static inline Klass* oop_to_klass(oop obj) {
1122 Klass* k = obj->klass();
1123
1124 // if the object is a java.lang.Class then return the java mirror
1125 if (k == vmClasses::Class_klass()) {
1126 if (!java_lang_Class::is_primitive(obj)) {
1127 k = java_lang_Class::as_Klass(obj);
1128 assert(k != nullptr, "class for non-primitive mirror must exist");
1129 }
1130 }
1131 return k;
1132 }
1133
1134 class JvmtiObjectAllocEventMark : public JvmtiClassEventMark {
1135 private:
1136 jobject _jobj;
1137 jlong _size;
1138 public:
1139 JvmtiObjectAllocEventMark(JavaThread *thread, oop obj) : JvmtiClassEventMark(thread, oop_to_klass(obj)) {
1140 _jobj = obj->is_inline() ? nullptr : (jobject)to_jobject(obj); // nullptr for non-identity objects
1141 _size = obj->size() * wordSize;
1142 };
1143 jobject jni_jobject() { return _jobj; }
1144 jlong size() { return _size; }
1145 };
1146
1147 class JvmtiCompiledMethodLoadEventMark : public JvmtiMethodEventMark {
1148 private:
1149 jint _code_size;
1150 const void *_code_data;
1151 jint _map_length;
1152 jvmtiAddrLocationMap *_map;
1153 const void *_compile_info;
1154 public:
1155 JvmtiCompiledMethodLoadEventMark(JavaThread *thread, nmethod *nm, void* compile_info_ptr = nullptr)
1156 : JvmtiMethodEventMark(thread,methodHandle(thread, nm->method())) {
1157 _code_data = nm->code_begin();
1158 _code_size = nm->code_size();
1159 _compile_info = compile_info_ptr; // Set void pointer of compiledMethodLoad Event. Default value is null.
1160 JvmtiCodeBlobEvents::build_jvmti_addr_location_map(nm, &_map, &_map_length);
1265 thread->osthread()->set_state(old_os_state);
1266 }
1267 }
1268 }
1269
1270 //////////////////////////////////////////////////////////////////////////////
1271
1272 bool JvmtiExport::_can_get_source_debug_extension = false;
1273 bool JvmtiExport::_can_maintain_original_method_order = false;
1274 bool JvmtiExport::_can_post_interpreter_events = false;
1275 bool JvmtiExport::_can_post_on_exceptions = false;
1276 bool JvmtiExport::_can_post_breakpoint = false;
1277 bool JvmtiExport::_can_post_field_access = false;
1278 bool JvmtiExport::_can_post_field_modification = false;
1279 bool JvmtiExport::_can_post_method_entry = false;
1280 bool JvmtiExport::_can_post_method_exit = false;
1281 bool JvmtiExport::_can_post_frame_pop = false;
1282 bool JvmtiExport::_can_pop_frame = false;
1283 bool JvmtiExport::_can_force_early_return = false;
1284 bool JvmtiExport::_can_support_virtual_threads = false;
1285 bool JvmtiExport::_can_support_value_objects = false;
1286 bool JvmtiExport::_can_get_owned_monitor_info = false;
1287
1288 bool JvmtiExport::_early_vmstart_recorded = false;
1289
1290 bool JvmtiExport::_should_post_single_step = false;
1291 bool JvmtiExport::_should_post_field_access = false;
1292 bool JvmtiExport::_should_post_field_modification = false;
1293 bool JvmtiExport::_should_post_class_load = false;
1294 bool JvmtiExport::_should_post_class_prepare = false;
1295 bool JvmtiExport::_should_post_class_unload = false;
1296 bool JvmtiExport::_should_post_thread_life = false;
1297 bool JvmtiExport::_should_clean_up_heap_objects = false;
1298 bool JvmtiExport::_should_post_native_method_bind = false;
1299 bool JvmtiExport::_should_post_dynamic_code_generated = false;
1300 bool JvmtiExport::_should_post_data_dump = false;
1301 bool JvmtiExport::_should_post_compiled_method_load = false;
1302 bool JvmtiExport::_should_post_compiled_method_unload = false;
1303 bool JvmtiExport::_should_post_monitor_contended_enter = false;
1304 bool JvmtiExport::_should_post_monitor_contended_entered = false;
1305 bool JvmtiExport::_should_post_monitor_wait = false;
2951 void JvmtiExport::vthread_post_monitor_waited(JavaThread *current, ObjectMonitor *obj_mntr, jboolean timed_out) {
2952 Handle vthread(current, current->vthread());
2953
2954 // Finish the VTMS transition temporarily to post the event.
2955 MountUnmountDisabler::end_transition(current, vthread(), true /*is_mount*/, false /*is_thread_start*/);
2956
2957 // Post event.
2958 JvmtiExport::post_monitor_waited(current, obj_mntr, timed_out);
2959
2960 // Go back to VTMS transition state.
2961 MountUnmountDisabler::start_transition(current, vthread(), false /*is_mount*/, false /*is_thread_start*/);
2962 }
2963
2964 void JvmtiExport::post_vm_object_alloc(JavaThread *thread, oop object) {
2965 if (object == nullptr) {
2966 return;
2967 }
2968 if (thread->should_hide_jvmti_events()) {
2969 return;
2970 }
2971 const bool is_inline = object->is_inline();
2972 if (is_inline && !JvmtiExport::can_support_value_objects()) {
2973 return;
2974 }
2975 HandleMark hm(thread);
2976 Handle h(thread, object);
2977
2978 EVT_TRIG_TRACE(JVMTI_EVENT_VM_OBJECT_ALLOC, ("[%s] Trg vm object alloc triggered",
2979 JvmtiTrace::safe_get_thread_name(thread)));
2980 JvmtiEnvIterator it;
2981 for (JvmtiEnv* env = it.first(); env != nullptr; env = it.next(env)) {
2982 if (env->is_enabled(JVMTI_EVENT_VM_OBJECT_ALLOC) &&
2983 (!is_inline || env->get_capabilities()->can_support_value_objects != 0)) {
2984 EVT_TRACE(JVMTI_EVENT_VM_OBJECT_ALLOC, ("[%s] Evt vmobject alloc sent %s",
2985 JvmtiTrace::safe_get_thread_name(thread),
2986 object->klass()->external_name()));
2987
2988 JvmtiObjectAllocEventMark jem(thread, h());
2989 JVMTI_JAVA_THREAD_EVENT_CALLBACK_BLOCK(thread)
2990 jvmtiEventVMObjectAlloc callback = env->callbacks()->VMObjectAlloc;
2991 if (callback != nullptr) {
2992 (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(),
2993 jem.jni_jobject(), jem.jni_class(), jem.size());
2994 }
2995 }
2996 }
2997 }
2998
2999 void JvmtiExport::post_sampled_object_alloc(JavaThread *thread, oop object) {
3000 HandleMark hm(thread);
3001 Handle h(thread, object);
3002
3003 JvmtiThreadState *state = get_jvmti_thread_state(thread);
3004 if (state == nullptr) {
3005 return;
3006 }
3007 if (object == nullptr) {
3008 return;
3009 }
3010 if (thread->should_hide_jvmti_events()) {
3011 return;
3012 }
3013 const bool is_inline = object->is_inline();
3014 if (is_inline && !JvmtiExport::can_support_value_objects()) {
3015 return;
3016 }
3017
3018 EVT_TRIG_TRACE(JVMTI_EVENT_SAMPLED_OBJECT_ALLOC,
3019 ("[%s] Trg sampled object alloc triggered",
3020 JvmtiTrace::safe_get_thread_name(thread)));
3021 JvmtiEnvThreadStateIterator it(state);
3022 for (JvmtiEnvThreadState* ets = it.first(); ets != nullptr; ets = it.next(ets)) {
3023 JvmtiEnv *env = ets->get_env();
3024 if (ets->is_enabled(JVMTI_EVENT_SAMPLED_OBJECT_ALLOC) &&
3025 (!is_inline || env->get_capabilities()->can_support_value_objects != 0)) {
3026 EVT_TRACE(JVMTI_EVENT_SAMPLED_OBJECT_ALLOC,
3027 ("[%s] Evt sampled object alloc sent %s",
3028 JvmtiTrace::safe_get_thread_name(thread),
3029 object->klass()->external_name()));
3030
3031 JvmtiObjectAllocEventMark jem(thread, h());
3032 JVMTI_JAVA_THREAD_EVENT_CALLBACK_BLOCK(thread)
3033 jvmtiEventSampledObjectAlloc callback = env->callbacks()->SampledObjectAlloc;
3034 if (callback != nullptr) {
3035 (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(),
3036 jem.jni_jobject(), jem.jni_class(), jem.size());
3037 }
3038 }
3039 }
3040 }
3041
3042 ////////////////////////////////////////////////////////////////////////////////////////////////
3043
3044 void JvmtiExport::cleanup_thread(JavaThread* thread) {
3045 assert(JavaThread::current() == thread, "thread is not current");
3046 MutexLocker mu(thread, JvmtiThreadState_lock);
3047
3048 if (thread->jvmti_thread_state() != nullptr) {
3049 // This has to happen after the thread state is removed, which is
3050 // why it is not in post_thread_end_event like its complement
|