8313654: Test WaitNotifySuspendedVThreadTest.java timed out

Reviewed-by: sspitsyn
This commit is contained in:
Leonid Mesnik 2023-08-10 15:18:57 +00:00
parent e7c83ea948
commit 9b53251131
2 changed files with 16 additions and 21 deletions

View File

@ -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();
}

View File

@ -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);
}