diff --git a/test/jdk/java/lang/Thread/virtual/stress/GetStackTraceALotWhenBlocking.java b/test/jdk/java/lang/Thread/virtual/stress/GetStackTraceALotWhenBlocking.java index 5e15ea083e492..b68496bc7db6f 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 static void main(String[] args) throws Exception { 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 260446a1e3de5..9d9d3eddce108 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 static void main(String[] args) throws Exception { } }); - 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 static void main(String[] args) throws Exception { 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"); } } }