< prev index next >

src/hotspot/share/prims/jvmtiExport.cpp

Print this page

1661 
1662         JvmtiVirtualThreadEventMark jem(thread);
1663         JvmtiJavaThreadEventTransition jet(thread);
1664         jvmtiExtensionEvent callback = env->ext_callbacks()->VirtualThreadMount;
1665         if (callback != nullptr) {
1666           (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread());
1667         }
1668       }
1669     }
1670   }
1671 }
1672 
1673 void JvmtiExport::post_vthread_unmount(jobject vthread) {
1674   if (JvmtiEnv::get_phase() < JVMTI_PHASE_PRIMORDIAL) {
1675     return;
1676   }
1677   JavaThread *thread = JavaThread::current();
1678   HandleMark hm(thread);
1679   EVT_TRIG_TRACE(EXT_EVENT_VIRTUAL_THREAD_UNMOUNT, ("[%p] Trg Virtual Thread Unmount event triggered", vthread));
1680 
1681   JvmtiThreadState *state = get_jvmti_thread_state(thread);
1682   if (state == nullptr) {

1683     return;
1684   }
1685 
1686   if (state->is_enabled((jvmtiEvent)EXT_EVENT_VIRTUAL_THREAD_UNMOUNT)) {
1687     JvmtiEnvThreadStateIterator it(state);
1688 
1689     for (JvmtiEnvThreadState* ets = it.first(); ets != nullptr; ets = it.next(ets)) {
1690       JvmtiEnv *env = ets->get_env();
1691       if (env->phase() == JVMTI_PHASE_PRIMORDIAL) {
1692         continue;
1693       }
1694       if (ets->is_enabled((jvmtiEvent)EXT_EVENT_VIRTUAL_THREAD_UNMOUNT)) {
1695         EVT_TRACE(EXT_EVENT_VIRTUAL_THREAD_UNMOUNT, ("[%p] Evt Virtual Thread Unmount event sent", vthread));
1696 
1697         JvmtiVirtualThreadEventMark jem(thread);
1698         JvmtiJavaThreadEventTransition jet(thread);
1699         jvmtiExtensionEvent callback = env->ext_callbacks()->VirtualThreadUnmount;
1700         if (callback != nullptr) {
1701           (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread());
1702         }
1703       }
1704     }
1705   }
1706 }
1707 
1708 void JvmtiExport::continuation_yield_cleanup(JavaThread* thread, jint continuation_frame_count) {
1709   if (JvmtiEnv::get_phase() < JVMTI_PHASE_PRIMORDIAL) {
1710     return;
1711   }
1712 
1713   assert(thread == JavaThread::current(), "must be");
1714   JvmtiThreadState *state = get_jvmti_thread_state(thread);
1715   if (state == nullptr) {
1716     return;
1717   }
1718   state->invalidate_cur_stack_depth();
1719 
1720   // Clear frame_pop requests in frames popped by yield
1721   if (can_post_frame_pop()) {

2845                      ("[%s] monitor waited event triggered",
2846                       JvmtiTrace::safe_get_thread_name(thread)));
2847   JvmtiEnvThreadStateIterator it(state);
2848   for (JvmtiEnvThreadState* ets = it.first(); ets != nullptr; ets = it.next(ets)) {
2849     if (ets->is_enabled(JVMTI_EVENT_MONITOR_WAITED)) {
2850       EVT_TRACE(JVMTI_EVENT_MONITOR_WAITED,
2851                    ("[%s] monitor waited event sent",
2852                     JvmtiTrace::safe_get_thread_name(thread)));
2853       JvmtiMonitorEventMark  jem(thread, h());
2854       JvmtiEnv *env = ets->get_env();
2855       JvmtiThreadEventTransition jet(thread);
2856       jvmtiEventMonitorWaited callback = env->callbacks()->MonitorWaited;
2857       if (callback != nullptr) {
2858         (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(),
2859                     jem.jni_object(), timed_out);
2860       }
2861     }
2862   }
2863 }
2864 
























2865 void JvmtiExport::post_vm_object_alloc(JavaThread *thread, oop object) {
2866   if (object == nullptr) {
2867     return;
2868   }
2869   if (thread->is_in_any_VTMS_transition()) {
2870     return; // no events should be posted if thread is in any VTMS transition
2871   }
2872   HandleMark hm(thread);
2873   Handle h(thread, object);
2874 
2875   EVT_TRIG_TRACE(JVMTI_EVENT_VM_OBJECT_ALLOC, ("[%s] Trg vm object alloc triggered",
2876                       JvmtiTrace::safe_get_thread_name(thread)));
2877   JvmtiEnvIterator it;
2878   for (JvmtiEnv* env = it.first(); env != nullptr; env = it.next(env)) {
2879     if (env->is_enabled(JVMTI_EVENT_VM_OBJECT_ALLOC)) {
2880       EVT_TRACE(JVMTI_EVENT_VM_OBJECT_ALLOC, ("[%s] Evt vmobject alloc sent %s",
2881                                          JvmtiTrace::safe_get_thread_name(thread),
2882                                          object==nullptr? "null" : object->klass()->external_name()));
2883 
2884       JvmtiObjectAllocEventMark jem(thread, h());

1661 
1662         JvmtiVirtualThreadEventMark jem(thread);
1663         JvmtiJavaThreadEventTransition jet(thread);
1664         jvmtiExtensionEvent callback = env->ext_callbacks()->VirtualThreadMount;
1665         if (callback != nullptr) {
1666           (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread());
1667         }
1668       }
1669     }
1670   }
1671 }
1672 
1673 void JvmtiExport::post_vthread_unmount(jobject vthread) {
1674   if (JvmtiEnv::get_phase() < JVMTI_PHASE_PRIMORDIAL) {
1675     return;
1676   }
1677   JavaThread *thread = JavaThread::current();
1678   HandleMark hm(thread);
1679   EVT_TRIG_TRACE(EXT_EVENT_VIRTUAL_THREAD_UNMOUNT, ("[%p] Trg Virtual Thread Unmount event triggered", vthread));
1680 
1681   // On preemption JVMTI state rebinding has already happened so get it always direclty from the oop.
1682   JvmtiThreadState *state = java_lang_Thread::jvmti_thread_state(JNIHandles::resolve(vthread));
1683   if (state == NULL) {
1684     return;
1685   }
1686 
1687   if (state->is_enabled((jvmtiEvent)EXT_EVENT_VIRTUAL_THREAD_UNMOUNT)) {
1688     JvmtiEnvThreadStateIterator it(state);
1689 
1690     for (JvmtiEnvThreadState* ets = it.first(); ets != nullptr; ets = it.next(ets)) {
1691       JvmtiEnv *env = ets->get_env();
1692       if (env->phase() == JVMTI_PHASE_PRIMORDIAL) {
1693         continue;
1694       }
1695       if (ets->is_enabled((jvmtiEvent)EXT_EVENT_VIRTUAL_THREAD_UNMOUNT)) {
1696         EVT_TRACE(EXT_EVENT_VIRTUAL_THREAD_UNMOUNT, ("[%p] Evt Virtual Thread Unmount event sent", vthread));
1697 
1698         JvmtiVirtualThreadEventMark jem(thread);
1699         JvmtiJavaThreadEventTransition jet(thread);
1700         jvmtiExtensionEvent callback = env->ext_callbacks()->VirtualThreadUnmount;
1701         if (callback != nullptr) {
1702           (*callback)(env->jvmti_external(), jem.jni_env(), vthread);
1703         }
1704       }
1705     }
1706   }
1707 }
1708 
1709 void JvmtiExport::continuation_yield_cleanup(JavaThread* thread, jint continuation_frame_count) {
1710   if (JvmtiEnv::get_phase() < JVMTI_PHASE_PRIMORDIAL) {
1711     return;
1712   }
1713 
1714   assert(thread == JavaThread::current(), "must be");
1715   JvmtiThreadState *state = get_jvmti_thread_state(thread);
1716   if (state == nullptr) {
1717     return;
1718   }
1719   state->invalidate_cur_stack_depth();
1720 
1721   // Clear frame_pop requests in frames popped by yield
1722   if (can_post_frame_pop()) {

2846                      ("[%s] monitor waited event triggered",
2847                       JvmtiTrace::safe_get_thread_name(thread)));
2848   JvmtiEnvThreadStateIterator it(state);
2849   for (JvmtiEnvThreadState* ets = it.first(); ets != nullptr; ets = it.next(ets)) {
2850     if (ets->is_enabled(JVMTI_EVENT_MONITOR_WAITED)) {
2851       EVT_TRACE(JVMTI_EVENT_MONITOR_WAITED,
2852                    ("[%s] monitor waited event sent",
2853                     JvmtiTrace::safe_get_thread_name(thread)));
2854       JvmtiMonitorEventMark  jem(thread, h());
2855       JvmtiEnv *env = ets->get_env();
2856       JvmtiThreadEventTransition jet(thread);
2857       jvmtiEventMonitorWaited callback = env->callbacks()->MonitorWaited;
2858       if (callback != nullptr) {
2859         (*callback)(env->jvmti_external(), jem.jni_env(), jem.jni_thread(),
2860                     jem.jni_object(), timed_out);
2861       }
2862     }
2863   }
2864 }
2865 
2866 void JvmtiExport::vthread_post_monitor_waited(JavaThread *current, ObjectMonitor *obj_mntr, jboolean timed_out) {
2867   Handle vthread(current, current->vthread());
2868 
2869   // Finish the VTMS transition temporarily to post the event.
2870   current->rebind_to_jvmti_thread_state_of(vthread());
2871   {
2872     MutexLocker mu(JvmtiThreadState_lock);
2873     JvmtiThreadState* state = current->jvmti_thread_state();
2874     if (state != NULL && state->is_pending_interp_only_mode()) {
2875       JvmtiEventController::enter_interp_only_mode(state);
2876     }
2877   }
2878   assert(current->is_in_VTMS_transition(), "sanity check");
2879   assert(!current->is_in_tmp_VTMS_transition(), "sanity check");
2880   JvmtiVTMSTransitionDisabler::finish_VTMS_transition((jthread)vthread.raw_value(), /* is_mount */ true);
2881 
2882   // Post event.
2883   JvmtiExport::post_monitor_waited(current, obj_mntr, timed_out);
2884 
2885   // Go back to VTMS transition state.
2886   JvmtiVTMSTransitionDisabler::start_VTMS_transition((jthread)vthread.raw_value(), /* is_mount */ true);
2887   current->rebind_to_jvmti_thread_state_of(current->threadObj());
2888 }
2889 
2890 void JvmtiExport::post_vm_object_alloc(JavaThread *thread, oop object) {
2891   if (object == nullptr) {
2892     return;
2893   }
2894   if (thread->is_in_any_VTMS_transition()) {
2895     return; // no events should be posted if thread is in any VTMS transition
2896   }
2897   HandleMark hm(thread);
2898   Handle h(thread, object);
2899 
2900   EVT_TRIG_TRACE(JVMTI_EVENT_VM_OBJECT_ALLOC, ("[%s] Trg vm object alloc triggered",
2901                       JvmtiTrace::safe_get_thread_name(thread)));
2902   JvmtiEnvIterator it;
2903   for (JvmtiEnv* env = it.first(); env != nullptr; env = it.next(env)) {
2904     if (env->is_enabled(JVMTI_EVENT_VM_OBJECT_ALLOC)) {
2905       EVT_TRACE(JVMTI_EVENT_VM_OBJECT_ALLOC, ("[%s] Evt vmobject alloc sent %s",
2906                                          JvmtiTrace::safe_get_thread_name(thread),
2907                                          object==nullptr? "null" : object->klass()->external_name()));
2908 
2909       JvmtiObjectAllocEventMark jem(thread, h());
< prev index next >