Skip to content

Commit

Permalink
Adjust ThreadListStackTracesTest for checkReentrantLock
Browse files Browse the repository at this point in the history
Adjust ThreadListStackTracesTest for checkReentrantLock
to be ready when the virtual thread state is WAITING after
the reentrant lock parks the virtual thread. When the
virtual thread is mounted, the virtual thread state, which
is obtained from the carrier thread, can transition
between WAITING and RUNNABLE before the reentrant lock
parks the virtual thread.

Issue: eclipse-openj9/openj9#18089
Signed-off-by: Amarpreet Singh <[email protected]>
  • Loading branch information
singh264 committed Nov 16, 2023
1 parent 4b666c7 commit c2578b0
Showing 1 changed file with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ static void sleep(long millis) {
}

public void ensureReady(Thread vt, Thread.State expState) {
// sleep for 1 second to allow the thread to reach the expected state
sleep(1000);
// wait while the thread is not ready or thread state is unexpected
while (!threadReady || (vt.getState() != expState)) {
sleep(1);
Expand Down Expand Up @@ -86,6 +88,14 @@ public class ThreadListStackTracesTest {
static void log(String msg) { System.out.println(msg); }
static void failed(String msg) { throw new RuntimeException(msg); }

static void sleep(long millis) {
try {
Thread.sleep(millis);
} catch (InterruptedException e) {
throw new RuntimeException("Interruption in ThreadListStackTracesTest.sleep: \n\t" + e);
}
}

public static void main(String[] args) throws InterruptedException {
checkReentrantLock();
checkSynchronized();
Expand All @@ -97,6 +107,10 @@ private static void checkReentrantLock() throws InterruptedException {
String name = "ReentrantLockTestTask";
TestTask task = new ReentrantLockTestTask();
Thread vt = Thread.ofVirtual().name(name).start(task);
// wait until vt is waiting to acquire the lock
while (!reentrantLock.hasQueuedThread(vt)) {
sleep(1);
}
task.ensureReady(vt, expState);
checkStates(vt, expState);
}
Expand Down

0 comments on commit c2578b0

Please sign in to comment.