@@ -1549,11 +1549,11 @@ void JvmtiExport::post_thread_end(JavaThread *thread) {
15491549
15501550 JvmtiEnvThreadStateIterator it (state);
15511551 for (JvmtiEnvThreadState* ets = it.first (); ets != nullptr ; ets = it.next (ets)) {
1552+ JvmtiEnv *env = ets->get_env ();
1553+ if (env->phase () == JVMTI_PHASE_PRIMORDIAL) {
1554+ continue ;
1555+ }
15521556 if (ets->is_enabled (JVMTI_EVENT_THREAD_END)) {
1553- JvmtiEnv *env = ets->get_env ();
1554- if (env->phase () == JVMTI_PHASE_PRIMORDIAL) {
1555- continue ;
1556- }
15571557 EVT_TRACE (JVMTI_EVENT_THREAD_END, (" [%s] Evt Thread End event sent" ,
15581558 JvmtiTrace::safe_get_thread_name (thread) ));
15591559
@@ -1575,25 +1575,20 @@ void JvmtiExport::post_vthread_start(jobject vthread) {
15751575 }
15761576 EVT_TRIG_TRACE (JVMTI_EVENT_VIRTUAL_THREAD_START, (" [%p] Trg Virtual Thread Start event triggered" , vthread));
15771577
1578- JavaThread *cur_thread = JavaThread::current ();
1579- JvmtiThreadState *state = get_jvmti_thread_state (cur_thread);
1580- if (state == nullptr ) {
1581- return ;
1582- }
1583-
1584- if (state->is_enabled (JVMTI_EVENT_VIRTUAL_THREAD_START)) {
1585- JvmtiEnvThreadStateIterator it (state);
1578+ JavaThread *thread = JavaThread::current ();
1579+ assert (!thread->is_hidden_from_external_view (), " carrier threads can't be hidden" );
15861580
1587- for (JvmtiEnvThreadState* ets = it.first (); ets != nullptr ; ets = it.next (ets)) {
1588- JvmtiEnv *env = ets->get_env ();
1581+ if (JvmtiEventController::is_enabled (JVMTI_EVENT_VIRTUAL_THREAD_START)) {
1582+ JvmtiEnvIterator it;
1583+ for (JvmtiEnv* env = it.first (); env != nullptr ; env = it.next (env)) {
15891584 if (env->phase () == JVMTI_PHASE_PRIMORDIAL) {
15901585 continue ;
15911586 }
1592- if (ets ->is_enabled (JVMTI_EVENT_VIRTUAL_THREAD_START)) {
1587+ if (env ->is_enabled (JVMTI_EVENT_VIRTUAL_THREAD_START)) {
15931588 EVT_TRACE (JVMTI_EVENT_VIRTUAL_THREAD_START, (" [%p] Evt Virtual Thread Start event sent" , vthread));
15941589
1595- JvmtiVirtualThreadEventMark jem (cur_thread );
1596- JvmtiJavaThreadEventTransition jet (cur_thread );
1590+ JvmtiVirtualThreadEventMark jem (thread );
1591+ JvmtiJavaThreadEventTransition jet (thread );
15971592 jvmtiEventVirtualThreadStart callback = env->callbacks ()->VirtualThreadStart ;
15981593 if (callback != nullptr ) {
15991594 (*callback)(env->jvmti_external (), jem.jni_env (), jem.jni_thread ());
@@ -1609,8 +1604,10 @@ void JvmtiExport::post_vthread_end(jobject vthread) {
16091604 }
16101605 EVT_TRIG_TRACE (JVMTI_EVENT_VIRTUAL_THREAD_END, (" [%p] Trg Virtual Thread End event triggered" , vthread));
16111606
1612- JavaThread *cur_thread = JavaThread::current ();
1613- JvmtiThreadState *state = get_jvmti_thread_state (cur_thread);
1607+ JavaThread *thread = JavaThread::current ();
1608+ assert (!thread->is_hidden_from_external_view (), " carrier threads can't be hidden" );
1609+
1610+ JvmtiThreadState *state = get_jvmti_thread_state (thread);
16141611 if (state == nullptr ) {
16151612 return ;
16161613 }
@@ -1626,8 +1623,8 @@ void JvmtiExport::post_vthread_end(jobject vthread) {
16261623 if (ets->is_enabled (JVMTI_EVENT_VIRTUAL_THREAD_END)) {
16271624 EVT_TRACE (JVMTI_EVENT_VIRTUAL_THREAD_END, (" [%p] Evt Virtual Thread End event sent" , vthread));
16281625
1629- JvmtiVirtualThreadEventMark jem (cur_thread );
1630- JvmtiJavaThreadEventTransition jet (cur_thread );
1626+ JvmtiVirtualThreadEventMark jem (thread );
1627+ JvmtiJavaThreadEventTransition jet (thread );
16311628 jvmtiEventVirtualThreadEnd callback = env->callbacks ()->VirtualThreadEnd ;
16321629 if (callback != nullptr ) {
16331630 (*callback)(env->jvmti_external (), jem.jni_env (), vthread);
0 commit comments