Skip to content

Commit f877767

Browse files
Serguei Spitsynpull[bot]
authored andcommitted
8316233: VirtualThreadStart events should not be thread-filtered
Reviewed-by: lmesnik, amenkov, cjplummer
1 parent d5a015a commit f877767

File tree

3 files changed

+22
-25
lines changed

3 files changed

+22
-25
lines changed

src/hotspot/share/prims/jvmti.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13041,7 +13041,7 @@ myInit() {
1304113041
</event>
1304213042

1304313043
<event label="Virtual Thread Start"
13044-
id="VirtualThreadStart" const="JVMTI_EVENT_VIRTUAL_THREAD_START" filtered="thread" num="87" phase="start" since="21">
13044+
id="VirtualThreadStart" const="JVMTI_EVENT_VIRTUAL_THREAD_START" num="87" phase="start" since="21">
1304513045
<description>
1304613046
A virtual thread start event is generated before its initial method executes.
1304713047
<p/>

src/hotspot/share/prims/jvmtiEventController.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,16 +99,16 @@ static const jlong VTHREAD_MOUNT_BIT = (((jlong)1) << (EXT_EVENT_VIRTUAL_THREAD
9999
static const jlong VTHREAD_UNMOUNT_BIT = (((jlong)1) << (EXT_EVENT_VIRTUAL_THREAD_UNMOUNT - TOTAL_MIN_EVENT_TYPE_VAL));
100100

101101

102-
static const jlong VTHREAD_BITS = VTHREAD_START_BIT | VTHREAD_END_BIT | VTHREAD_MOUNT_BIT | VTHREAD_UNMOUNT_BIT;
102+
static const jlong VTHREAD_FILTERED_EVENT_BITS = VTHREAD_END_BIT | VTHREAD_MOUNT_BIT | VTHREAD_UNMOUNT_BIT;
103103
static const jlong MONITOR_BITS = MONITOR_CONTENDED_ENTER_BIT | MONITOR_CONTENDED_ENTERED_BIT |
104104
MONITOR_WAIT_BIT | MONITOR_WAITED_BIT;
105105
static const jlong EXCEPTION_BITS = EXCEPTION_THROW_BIT | EXCEPTION_CATCH_BIT;
106106
static const jlong INTERP_EVENT_BITS = SINGLE_STEP_BIT | METHOD_ENTRY_BIT | METHOD_EXIT_BIT |
107107
FRAME_POP_BIT | FIELD_ACCESS_BIT | FIELD_MODIFICATION_BIT;
108-
static const jlong THREAD_FILTERED_EVENT_BITS = INTERP_EVENT_BITS | EXCEPTION_BITS | MONITOR_BITS | VTHREAD_BITS |
108+
static const jlong THREAD_FILTERED_EVENT_BITS = INTERP_EVENT_BITS | EXCEPTION_BITS | MONITOR_BITS | VTHREAD_FILTERED_EVENT_BITS |
109109
BREAKPOINT_BIT | CLASS_LOAD_BIT | CLASS_PREPARE_BIT | THREAD_END_BIT |
110110
SAMPLED_OBJECT_ALLOC_BIT;
111-
static const jlong NEED_THREAD_LIFE_EVENTS = THREAD_FILTERED_EVENT_BITS | THREAD_START_BIT;
111+
static const jlong NEED_THREAD_LIFE_EVENTS = THREAD_FILTERED_EVENT_BITS | THREAD_START_BIT | VTHREAD_START_BIT;
112112
static const jlong EARLY_EVENT_BITS = CLASS_FILE_LOAD_HOOK_BIT | CLASS_LOAD_BIT | CLASS_PREPARE_BIT |
113113
VM_START_BIT | VM_INIT_BIT | VM_DEATH_BIT | NATIVE_METHOD_BIND_BIT |
114114
THREAD_START_BIT | THREAD_END_BIT |

src/hotspot/share/prims/jvmtiExport.cpp

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)