From d867a2525a5c799dbc7a3358b0c15c37d4af0527 Mon Sep 17 00:00:00 2001 From: Babneet Singh Date: Wed, 2 Aug 2023 19:54:34 -0700 Subject: [PATCH] Fix BoundVThreadTest - Bad Thread Object After GetAllStackTraces, derive the thread object from the stack_info array, which is filled by GetAllStackTraces. Currently, the thread object is retrieved from the threads_ptr array, which is filled by GetAllThreads before the call to GetAllStackTraces. Live platform threads might have been created or destroyed between the call to GetAllThreads and GetAllStackTraces. This makes the threads_ptr array stale after GetAllStackTraces. A bad thread object is accessed from the stale threads_ptr which causes a segfault. Related: https://github.com/eclipse-openj9/openj9/issues/17868 Signed-off-by: Babneet Singh --- .../vthread/BoundVThreadTest/libBoundVThreadTest.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/test/hotspot/jtreg/serviceability/jvmti/vthread/BoundVThreadTest/libBoundVThreadTest.cpp b/test/hotspot/jtreg/serviceability/jvmti/vthread/BoundVThreadTest/libBoundVThreadTest.cpp index 0fa0f065ae8..f62a3c22754 100644 --- a/test/hotspot/jtreg/serviceability/jvmti/vthread/BoundVThreadTest/libBoundVThreadTest.cpp +++ b/test/hotspot/jtreg/serviceability/jvmti/vthread/BoundVThreadTest/libBoundVThreadTest.cpp @@ -21,6 +21,12 @@ * questions. */ +/* + * =========================================================================== + * (c) Copyright IBM Corp. 2023, 2023 All Rights Reserved + * =========================================================================== + */ + #include #include "jvmti.h" #include "jvmti_common.h" @@ -137,8 +143,8 @@ test_unsupported_jvmti_functions(jvmtiEnv *jvmti, JNIEnv *jni, jthread vthread, err = jvmti->GetAllStackTraces(MAX_FRAMES, &stack_info, &thread_cnt); check_jvmti_status(jni, err, "test_unsupported_jvmti_functions: error in JVMTI GetAllStackTraces"); for (int idx = 0; idx < thread_cnt; idx++) { - jthread thread = threads_ptr[idx]; - if (jni->IsVirtualThread(thread)) { + jvmtiStackInfo *info = &stack_info[idx]; + if (jni->IsVirtualThread(info->thread)) { fatal(jni, "GetAllStackTraces should not include virtual threads"); } }