From 48223f7b9c6fbaf4e6751a5b41ea9e9046a48f91 Mon Sep 17 00:00:00 2001 From: Alan Bateman Date: Tue, 19 Nov 2024 16:37:43 +0000 Subject: [PATCH] 8344143: Test jdk/java/lang/Thread/virtual/stress/GetStackTraceALotWhenPinned.java timed out on macosx-x64 Reviewed-by: pchilanomate --- .../stress/GetStackTraceALotWhenBlocking.java | 18 +++++++++++++----- .../stress/GetStackTraceALotWhenPinned.java | 17 +++++++++++------ 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/test/jdk/java/lang/Thread/virtual/stress/GetStackTraceALotWhenBlocking.java b/test/jdk/java/lang/Thread/virtual/stress/GetStackTraceALotWhenBlocking.java index 5e15ea083e4..b68496bc7db 100644 --- a/test/jdk/java/lang/Thread/virtual/stress/GetStackTraceALotWhenBlocking.java +++ b/test/jdk/java/lang/Thread/virtual/stress/GetStackTraceALotWhenBlocking.java @@ -28,7 +28,7 @@ * @requires vm.debug != true * @modules jdk.management * @library /test/lib - * @run main/othervm GetStackTraceALotWhenBlocking 500000 + * @run main/othervm/timeout=300 GetStackTraceALotWhenBlocking 100000 */ /* @@ -68,16 +68,24 @@ public class GetStackTraceALotWhenBlocking { var thread1 = Thread.ofVirtual().start(task); var thread2 = Thread.ofVirtual().start(task); + long lastTime = System.nanoTime(); try { for (int i = 1; i <= iterations; i++) { - if ((i % 10_000) == 0) { - System.out.format("%s => %d of %d%n", Instant.now(), i, iterations); - } - thread1.getStackTrace(); pause(); thread2.getStackTrace(); pause(); + + long currentTime = System.nanoTime(); + if (i == iterations || ((currentTime - lastTime) > 1_000_000_000L)) { + System.out.format("%s => %d of %d%n", Instant.now(), i, iterations); + lastTime = currentTime; + } + + if (Thread.currentThread().isInterrupted()) { + // fail quickly if interrupted by jtreg + throw new RuntimeException("interrupted"); + } } } finally { done.set(true); diff --git a/test/jdk/java/lang/Thread/virtual/stress/GetStackTraceALotWhenPinned.java b/test/jdk/java/lang/Thread/virtual/stress/GetStackTraceALotWhenPinned.java index 260446a1e3d..9d9d3eddce1 100644 --- a/test/jdk/java/lang/Thread/virtual/stress/GetStackTraceALotWhenPinned.java +++ b/test/jdk/java/lang/Thread/virtual/stress/GetStackTraceALotWhenPinned.java @@ -28,7 +28,7 @@ * @requires vm.debug != true * @modules jdk.management * @library /test/lib - * @run main/othervm --enable-native-access=ALL-UNNAMED GetStackTraceALotWhenPinned 500000 + * @run main/othervm/timeout=300 --enable-native-access=ALL-UNNAMED GetStackTraceALotWhenPinned 100000 */ /* @@ -36,7 +36,7 @@ * @requires vm.debug == true * @modules jdk.management * @library /test/lib - * @run main/othervm/timeout=300 --enable-native-access=ALL-UNNAMED GetStackTraceALotWhenPinned 200000 + * @run main/othervm/timeout=300 --enable-native-access=ALL-UNNAMED GetStackTraceALotWhenPinned 50000 */ import java.time.Instant; @@ -78,7 +78,7 @@ public class GetStackTraceALotWhenPinned { } }); - long lastTimestamp = System.currentTimeMillis(); + long lastTime = System.nanoTime(); for (int i = 1; i <= iterations; i++) { // wait for virtual thread to arrive barrier.await(); @@ -86,10 +86,15 @@ public class GetStackTraceALotWhenPinned { thread.getStackTrace(); LockSupport.unpark(thread); - long currentTime = System.currentTimeMillis(); - if (i == iterations || ((currentTime - lastTimestamp) > 500)) { + long currentTime = System.nanoTime(); + if (i == iterations || ((currentTime - lastTime) > 1_000_000_000L)) { System.out.format("%s => %d of %d%n", Instant.now(), i, iterations); - lastTimestamp = currentTime; + lastTime = currentTime; + } + + if (Thread.currentThread().isInterrupted()) { + // fail quickly if interrupted by jtreg + throw new RuntimeException("interrupted"); } } }