From 9b53251131c67b1abb69b59eb66a1a133acc41d9 Mon Sep 17 00:00:00 2001 From: Leonid Mesnik Date: Thu, 10 Aug 2023 15:18:57 +0000 Subject: [PATCH] 8313654: Test WaitNotifySuspendedVThreadTest.java timed out Reviewed-by: sspitsyn --- .../WaitNotifySuspendedVThreadTest.java | 18 ++---------------- .../libWaitNotifySuspendedVThread.cpp | 19 ++++++++++++++----- 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/test/hotspot/jtreg/serviceability/jvmti/vthread/WaitNotifySuspendedVThreadTest/WaitNotifySuspendedVThreadTest.java b/test/hotspot/jtreg/serviceability/jvmti/vthread/WaitNotifySuspendedVThreadTest/WaitNotifySuspendedVThreadTest.java index 341890ba4a0..a7b4b6ff43c 100644 --- a/test/hotspot/jtreg/serviceability/jvmti/vthread/WaitNotifySuspendedVThreadTest/WaitNotifySuspendedVThreadTest.java +++ b/test/hotspot/jtreg/serviceability/jvmti/vthread/WaitNotifySuspendedVThreadTest/WaitNotifySuspendedVThreadTest.java @@ -24,20 +24,8 @@ /* * @test * - * @summary Test verifies set/get TLS data and verifies it's consistency. - * Test set TLS with thread name which it belongs to and verify this information when getting test. - * -- cbThreadStart - * -- by AgentThread - * - * Test doesn't verify that TLS is not NULL because for some threads TLS is not initialized initially. - * TODO: - * -- verify that TLS is not NULL (not possible to do with jvmti, ThreadStart might be called too late) - * -- add more events where TLS is set *first time*, it is needed to test lazily jvmtThreadState init - * -- set/get TLS from other JavaThreads (not from agent and current thread) - * -- set/get for suspened (blocked?) threads - * -- split test to "sanity" and "stress" version - * -- update properties to run jvmti stress tests non-concurrently? - * + * @summary Test verifies that JVMTI raw monitor wait/notify works for + * suspended virtual thread. * * @requires vm.continuations * @library /test/lib @@ -64,8 +52,6 @@ public class WaitNotifySuspendedVThreadTest { WaitNotifySuspendedVThreadTask.setBreakpoint(); WaitNotifySuspendedVThreadTask task = new WaitNotifySuspendedVThreadTask(); Thread t = Thread.ofVirtual().start(task); - - Thread.sleep(1000); WaitNotifySuspendedVThreadTask.notifyRawMonitors(t); t.join(); } diff --git a/test/hotspot/jtreg/serviceability/jvmti/vthread/WaitNotifySuspendedVThreadTest/libWaitNotifySuspendedVThread.cpp b/test/hotspot/jtreg/serviceability/jvmti/vthread/WaitNotifySuspendedVThreadTest/libWaitNotifySuspendedVThread.cpp index 41bd2177646..e6ad883944a 100644 --- a/test/hotspot/jtreg/serviceability/jvmti/vthread/WaitNotifySuspendedVThreadTest/libWaitNotifySuspendedVThread.cpp +++ b/test/hotspot/jtreg/serviceability/jvmti/vthread/WaitNotifySuspendedVThreadTest/libWaitNotifySuspendedVThread.cpp @@ -30,6 +30,8 @@ jrawMonitorID monitor_completed; jvmtiEnv *jvmti_env; +// Accessed using 'monitor' monitor. +bool is_breakpoint_reached = JNI_FALSE; static void set_breakpoint(JNIEnv *jni, jclass klass, const char *mname) { @@ -42,8 +44,6 @@ set_breakpoint(JNIEnv *jni, jclass klass, const char *mname) { } err = jvmti_env->SetBreakpoint(method, location); check_jvmti_status(jni, err, "set_or_clear_breakpoint: error in JVMTI SetBreakpoint"); - - } extern "C" { @@ -60,17 +60,26 @@ Java_WaitNotifySuspendedVThreadTask_setBreakpoint(JNIEnv *jni, jclass klass) { check_jvmti_status(jni, err, "enableEvents: error in JVMTI SetEventNotificationMode: enable BREAKPOINT"); LOG("setBreakpoint: finished\n"); - } JNIEXPORT void JNICALL Java_WaitNotifySuspendedVThreadTask_notifyRawMonitors(JNIEnv *jni, jclass klass, jthread thread) { + + // Wait until virtual thread reach breakpoint and lock 'montior' monitor + bool is_breakpoint_reached_local = JNI_FALSE; + while (!is_breakpoint_reached_local) { + RawMonitorLocker rml(jvmti_env, jni, monitor); + is_breakpoint_reached_local = is_breakpoint_reached; + } + LOG("Main thread: suspending virtual and carrier threads\n"); check_jvmti_status(jni, jvmti_env->SuspendThread(thread), "SuspendThread thread"); jthread cthread = get_carrier_thread(jvmti_env, jni, thread); check_jvmti_status(jni, jvmti_env->SuspendThread(cthread), "SuspendThread thread"); + RawMonitorLocker completed(jvmti_env, jni, monitor_completed); + { RawMonitorLocker rml(jvmti_env, jni, monitor); @@ -78,8 +87,6 @@ Java_WaitNotifySuspendedVThreadTask_notifyRawMonitors(JNIEnv *jni, jclass klass, rml.notify_all(); } - RawMonitorLocker completed(jvmti_env, jni, monitor_completed); - LOG("Main thread: resuming virtual thread\n"); check_jvmti_status(jni, jvmti_env->ResumeThread(thread), "ResumeThread thread"); @@ -104,6 +111,7 @@ Breakpoint(jvmtiEnv *jvmti, JNIEnv* jni, jthread thread, fatal(jni, "Error in breakpoint"); return; } + char* tname = get_thread_name(jvmti, jni, thread); const char* virt = jni->IsVirtualThread(thread) ? "virtual" : "carrier"; @@ -111,6 +119,7 @@ Breakpoint(jvmtiEnv *jvmti, JNIEnv* jni, jthread thread, RawMonitorLocker rml(jvmti, jni, monitor); LOG("Breakpoint: before monitor.wait(): %s in %s thread\n", mname, virt); + is_breakpoint_reached = JNI_TRUE; rml.wait(); LOG("Breakpoint: after monitor.wait(): %s in %s thread\n", mname, virt); }