Skip to content

Commit 04ad59d

Browse files
author
Serguei Spitsyn
committed
8316397: StackTrace/Suspended/GetStackTraceSuspendedStressTest.java failed with: SingleStep event is NOT expected
Reviewed-by: dholmes, pchilanomate
1 parent 034c0d4 commit 04ad59d

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/hotspot/share/prims/jvmtiExport.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,10 +418,16 @@ JvmtiExport::get_jvmti_interface(JavaVM *jvm, void **penv, jint version) {
418418
}
419419

420420
JvmtiThreadState*
421-
JvmtiExport::get_jvmti_thread_state(JavaThread *thread) {
421+
JvmtiExport::get_jvmti_thread_state(JavaThread *thread, bool allow_suspend) {
422422
assert(thread == JavaThread::current(), "must be current thread");
423423
if (thread->is_vthread_mounted() && thread->jvmti_thread_state() == nullptr) {
424424
JvmtiEventController::thread_started(thread);
425+
if (allow_suspend && thread->is_suspended()) {
426+
// Suspend here if thread_started got a suspend request during its execution.
427+
// Within thread_started we could block on a VM mutex and pick up a suspend
428+
// request from debug agent which we need to honor before proceeding.
429+
ThreadBlockInVM tbivm(thread, true /* allow suspend */);
430+
}
425431
}
426432
return thread->jvmti_thread_state();
427433
}
@@ -2636,7 +2642,7 @@ void JvmtiExport::post_dynamic_code_generated_while_holding_locks(const char* na
26362642
// jvmti thread state.
26372643
// The collector and/or state might be null if JvmtiDynamicCodeEventCollector
26382644
// has been initialized while JVMTI_EVENT_DYNAMIC_CODE_GENERATED was disabled.
2639-
JvmtiThreadState *state = get_jvmti_thread_state(thread);
2645+
JvmtiThreadState *state = get_jvmti_thread_state(thread, false /* allow_suspend */);
26402646
if (state != nullptr) {
26412647
JvmtiDynamicCodeEventCollector *collector = state->get_dynamic_code_event_collector();
26422648
if (collector != nullptr) {

src/hotspot/share/prims/jvmtiExport.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,11 @@ class JvmtiExport : public AllStatic {
309309
// If the jvmti_thread_state is absent and any thread filtered event
310310
// is enabled globally then it is created.
311311
// Otherwise, the thread->jvmti_thread_state() is returned.
312-
static JvmtiThreadState* get_jvmti_thread_state(JavaThread *thread);
312+
// The 'allow_suspend' parameter is passed as 'true' by default which work for almost all call sites.
313+
// It means that a suspend point need to be organized by this function for virtual threads if the call
314+
// to jvmtiEventController::thread_started hits a safepoint and gets a new suspend request.
315+
// The 'allow_suspend' parameter must be passed as 'false' if thread is holding a VM lock.
316+
static JvmtiThreadState* get_jvmti_thread_state(JavaThread *thread, bool allow_suspend = true);
313317

314318
// single stepping management methods
315319
static void at_single_stepping_point(JavaThread *thread, Method* method, address location) NOT_JVMTI_RETURN;

0 commit comments

Comments
 (0)