Skip to content

Commit f1ddff4

Browse files
committed
Stabilize TestSharedCloseJvmti by avoiding latch park
Update TestSharedCloseJvmti to remove CountDownLatch.await() from the JVMTI re-entrant callback path and replace it with a spin wait on a volatile flag. The previous test parked the Trigger thread while executing re-entrantly from a JVMTI MethodExit callback during a scoped access. On OpenJ9, shared scope close relies on async polling (javaCheckAsyncMessages) for close-scope acknowledgement. Parking the thread in this path can prevent polling and cause intermittent hangs. The test intent is to exercise additional stack frames during scoped access, not thread parking inside JVMTI callbacks. Using a spin loop keeps the thread runnable and preserves the stack-shape stress scenario while avoiding the hang. Scoped close/exception handling differs across JVMs. The RI uses a per-thread handshake and deopt-based approach, while OpenJ9 uses a flag-and-polling model. This change keeps the test portable across both. Remove the unused TARGET_LATCH and add a volatile CLOSED flag for cross-thread visibility. Related: eclipse-openj9/openj9#22934 Signed-off-by: Babneet Singh <sbabneet@ca.ibm.com>
1 parent e1f4c54 commit f1ddff4

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

test/jdk/java/foreign/sharedclosejvmti/TestSharedCloseJvmti.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@
2121
* questions.
2222
*/
2323

24+
/*
25+
* ===========================================================================
26+
* (c) Copyright IBM Corp. 2026, 2026 All Rights Reserved
27+
* ===========================================================================
28+
*/
29+
2430
/*
2531
* @test
2632
* @bug 8370344
@@ -71,9 +77,9 @@ public static class EventDuringScopedAccessRunner {
7177
static final int ADDED_FRAMES = 10;
7278

7379
static final CountDownLatch MAIN_LATCH = new CountDownLatch(1);
74-
static final CountDownLatch TARGET_LATCH = new CountDownLatch(1);
7580

7681
static volatile int SINK;
82+
static volatile boolean CLOSED = false;
7783

7884
public static void main(String[] args) throws Throwable {
7985
try (Arena arena = Arena.ofShared()) {
@@ -89,7 +95,7 @@ public static void main(String[] args) throws Throwable {
8995
MAIN_LATCH.await();
9096
}
9197
// Notify trigger thread that arena was closed
92-
TARGET_LATCH.countDown();
98+
CLOSED = true;
9399
}
94100

95101
static boolean reentrant = false;
@@ -121,11 +127,8 @@ private static void addFrames(int depth) {
121127
if (depth >= ADDED_FRAMES) {
122128
// notify main thread to close the arena
123129
MAIN_LATCH.countDown();
124-
try {
125-
// wait here until main thread has closed arena
126-
TARGET_LATCH.await();
127-
} catch (InterruptedException ex) {
128-
throw new RuntimeException("Unexpected interruption");
130+
while (!CLOSED) {
131+
Thread.onSpinWait();
129132
}
130133
return;
131134
}

0 commit comments

Comments
 (0)