Skip to content

Commit 9b53251

Browse files
committed
8313654: Test WaitNotifySuspendedVThreadTest.java timed out
Reviewed-by: sspitsyn
1 parent e7c83ea commit 9b53251

File tree

2 files changed

+16
-21
lines changed

2 files changed

+16
-21
lines changed

test/hotspot/jtreg/serviceability/jvmti/vthread/WaitNotifySuspendedVThreadTest/WaitNotifySuspendedVThreadTest.java

+2-16
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,8 @@
2424
/*
2525
* @test
2626
*
27-
* @summary Test verifies set/get TLS data and verifies it's consistency.
28-
* Test set TLS with thread name which it belongs to and verify this information when getting test.
29-
* -- cbThreadStart
30-
* -- by AgentThread
31-
*
32-
* Test doesn't verify that TLS is not NULL because for some threads TLS is not initialized initially.
33-
* TODO:
34-
* -- verify that TLS is not NULL (not possible to do with jvmti, ThreadStart might be called too late)
35-
* -- add more events where TLS is set *first time*, it is needed to test lazily jvmtThreadState init
36-
* -- set/get TLS from other JavaThreads (not from agent and current thread)
37-
* -- set/get for suspened (blocked?) threads
38-
* -- split test to "sanity" and "stress" version
39-
* -- update properties to run jvmti stress tests non-concurrently?
40-
*
27+
* @summary Test verifies that JVMTI raw monitor wait/notify works for
28+
* suspended virtual thread.
4129
*
4230
* @requires vm.continuations
4331
* @library /test/lib
@@ -64,8 +52,6 @@ public static void main(String argv[]) throws InterruptedException {
6452
WaitNotifySuspendedVThreadTask.setBreakpoint();
6553
WaitNotifySuspendedVThreadTask task = new WaitNotifySuspendedVThreadTask();
6654
Thread t = Thread.ofVirtual().start(task);
67-
68-
Thread.sleep(1000);
6955
WaitNotifySuspendedVThreadTask.notifyRawMonitors(t);
7056
t.join();
7157
}

test/hotspot/jtreg/serviceability/jvmti/vthread/WaitNotifySuspendedVThreadTest/libWaitNotifySuspendedVThread.cpp

+14-5
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ jrawMonitorID monitor_completed;
3030

3131
jvmtiEnv *jvmti_env;
3232

33+
// Accessed using 'monitor' monitor.
34+
bool is_breakpoint_reached = JNI_FALSE;
3335

3436
static void
3537
set_breakpoint(JNIEnv *jni, jclass klass, const char *mname) {
@@ -42,8 +44,6 @@ set_breakpoint(JNIEnv *jni, jclass klass, const char *mname) {
4244
}
4345
err = jvmti_env->SetBreakpoint(method, location);
4446
check_jvmti_status(jni, err, "set_or_clear_breakpoint: error in JVMTI SetBreakpoint");
45-
46-
4747
}
4848

4949
extern "C" {
@@ -60,26 +60,33 @@ Java_WaitNotifySuspendedVThreadTask_setBreakpoint(JNIEnv *jni, jclass klass) {
6060
check_jvmti_status(jni, err, "enableEvents: error in JVMTI SetEventNotificationMode: enable BREAKPOINT");
6161

6262
LOG("setBreakpoint: finished\n");
63-
6463
}
6564

6665
JNIEXPORT void JNICALL
6766
Java_WaitNotifySuspendedVThreadTask_notifyRawMonitors(JNIEnv *jni, jclass klass, jthread thread) {
67+
68+
// Wait until virtual thread reach breakpoint and lock 'montior' monitor
69+
bool is_breakpoint_reached_local = JNI_FALSE;
70+
while (!is_breakpoint_reached_local) {
71+
RawMonitorLocker rml(jvmti_env, jni, monitor);
72+
is_breakpoint_reached_local = is_breakpoint_reached;
73+
}
74+
6875
LOG("Main thread: suspending virtual and carrier threads\n");
6976

7077
check_jvmti_status(jni, jvmti_env->SuspendThread(thread), "SuspendThread thread");
7178
jthread cthread = get_carrier_thread(jvmti_env, jni, thread);
7279
check_jvmti_status(jni, jvmti_env->SuspendThread(cthread), "SuspendThread thread");
7380

81+
RawMonitorLocker completed(jvmti_env, jni, monitor_completed);
82+
7483
{
7584
RawMonitorLocker rml(jvmti_env, jni, monitor);
7685

7786
LOG("Main thread: calling monitor.notifyAll()\n");
7887
rml.notify_all();
7988
}
8089

81-
RawMonitorLocker completed(jvmti_env, jni, monitor_completed);
82-
8390
LOG("Main thread: resuming virtual thread\n");
8491
check_jvmti_status(jni, jvmti_env->ResumeThread(thread), "ResumeThread thread");
8592

@@ -104,13 +111,15 @@ Breakpoint(jvmtiEnv *jvmti, JNIEnv* jni, jthread thread,
104111
fatal(jni, "Error in breakpoint");
105112
return;
106113
}
114+
107115
char* tname = get_thread_name(jvmti, jni, thread);
108116
const char* virt = jni->IsVirtualThread(thread) ? "virtual" : "carrier";
109117

110118
{
111119
RawMonitorLocker rml(jvmti, jni, monitor);
112120

113121
LOG("Breakpoint: before monitor.wait(): %s in %s thread\n", mname, virt);
122+
is_breakpoint_reached = JNI_TRUE;
114123
rml.wait();
115124
LOG("Breakpoint: after monitor.wait(): %s in %s thread\n", mname, virt);
116125
}

0 commit comments

Comments
 (0)