Skip to content

Commit c314d6a

Browse files
committed
fix test under VThread factory
1 parent 8947964 commit c314d6a

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

test/jdk/java/foreign/TestBufferStack.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,18 +109,24 @@ public void stress() throws InterruptedException {
109109
Thread[] vThreads = IntStream.range(0, 1024).mapToObj(_ ->
110110
Thread.ofVirtual().start(() -> {
111111
long threadId = Thread.currentThread().threadId();
112-
while (true) {
113-
try (Arena arena = stack.pushFrame(JAVA_LONG.byteSize(), JAVA_LONG.byteAlignment())) {
114-
// Try to assert no two vThreads get allocated the same stack space.
115-
MemorySegment segment = arena.allocate(JAVA_LONG);
116-
JAVA_LONG.varHandle().setVolatile(segment, 0L, threadId);
117-
Assert.assertEquals(threadId, (long) JAVA_LONG.varHandle().getVolatile(segment, 0L));
112+
while (!Thread.interrupted()) {
113+
for (int i = 0; i < 1_000_000; i++) {
114+
try (Arena arena = stack.pushFrame(JAVA_LONG.byteSize(), JAVA_LONG.byteAlignment())) {
115+
// Try to assert no two vThreads get allocated the same stack space.
116+
MemorySegment segment = arena.allocate(JAVA_LONG);
117+
JAVA_LONG.varHandle().setVolatile(segment, 0L, threadId);
118+
Assert.assertEquals(threadId, (long) JAVA_LONG.varHandle().getVolatile(segment, 0L));
119+
}
118120
}
121+
Thread.yield(); // make sure the driver thread gets a chance.
119122
}
120123
})).toArray(Thread[]::new);
121124
Thread.sleep(Duration.of(10, SECONDS));
122125
Arrays.stream(vThreads).forEach(
123-
thread -> Assert.assertTrue(thread.isAlive()));
126+
thread -> {
127+
Assert.assertTrue(thread.isAlive());
128+
thread.interrupt();
129+
});
124130
}
125131

126132
static {

0 commit comments

Comments
 (0)