diff --git a/test/hotspot/jtreg/serviceability/jvmti/vthread/ThreadListStackTracesTest/ThreadListStackTracesTest.java b/test/hotspot/jtreg/serviceability/jvmti/vthread/ThreadListStackTracesTest/ThreadListStackTracesTest.java index 98695390ef7..079f65620d8 100644 --- a/test/hotspot/jtreg/serviceability/jvmti/vthread/ThreadListStackTracesTest/ThreadListStackTracesTest.java +++ b/test/hotspot/jtreg/serviceability/jvmti/vthread/ThreadListStackTracesTest/ThreadListStackTracesTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -44,6 +44,13 @@ abstract class TestTask implements Runnable { } } + public void ensureReadyAndWaiting(Thread vt, Thread.State expState, ReentrantLock rlock) { + // wait while the thread is not ready or thread state is unexpected + while (!threadReady || (vt.getState() != expState) || !rlock.hasQueuedThreads()) { + sleep(1); + } + } + public void ensureReady(Thread vt, Thread.State expState) { // wait while the thread is not ready or thread state is unexpected while (!threadReady || (vt.getState() != expState)) { @@ -97,7 +104,7 @@ public class ThreadListStackTracesTest { String name = "ReentrantLockTestTask"; TestTask task = new ReentrantLockTestTask(); Thread vt = Thread.ofVirtual().name(name).start(task); - task.ensureReady(vt, expState); + task.ensureReadyAndWaiting(vt, expState, reentrantLock); checkStates(vt, expState); }