8344577: Virtual thread tests are timing out on some macOS systems

Reviewed-by: jpai
This commit is contained in:
Alan Bateman 2024-11-25 15:34:13 +00:00
parent 4110d3925c
commit a032de2904
8 changed files with 56 additions and 20 deletions

View File

@ -42,6 +42,7 @@
import java.time.Instant;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.atomic.AtomicBoolean;
import jdk.test.lib.Platform;
import jdk.test.lib.thread.VThreadRunner; // ensureParallelism requires jdk.management
public class GetStackTraceALotWhenBlocking {
@ -50,7 +51,14 @@ public class GetStackTraceALotWhenBlocking {
// need at least two carriers
VThreadRunner.ensureParallelism(2);
int iterations = args.length > 0 ? Integer.parseInt(args[0]) : 100_000;
int iterations;
int value = Integer.parseInt(args[0]);
if (Platform.isOSX() && Platform.isX64()) {
// reduced iterations on macosx-x64
iterations = Math.max(value / 4, 1);
} else {
iterations = value;
}
var done = new AtomicBoolean();
var lock = new Object();

View File

@ -42,6 +42,7 @@
import java.time.Instant;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.LockSupport;
import jdk.test.lib.Platform;
import jdk.test.lib.thread.VThreadRunner; // ensureParallelism requires jdk.management
import jdk.test.lib.thread.VThreadPinner;
@ -53,7 +54,15 @@ public class GetStackTraceALotWhenPinned {
VThreadRunner.ensureParallelism(2);
}
int iterations = Integer.parseInt(args[0]);
int iterations;
int value = Integer.parseInt(args[0]);
if (Platform.isOSX() && Platform.isX64()) {
// reduced iterations on macosx-x64
iterations = Math.max(value / 4, 1);
} else {
iterations = value;
}
var barrier = new Barrier(2);
// Start a virtual thread that loops doing Thread.yield and parking while pinned.

View File

@ -25,13 +25,13 @@
* @test
* @summary Stress test Thread.getStackTrace on a virtual thread in timed-Object.wait
* @requires vm.debug != true
* @run main/othervm GetStackTraceALotWithTimedWait 100000
* @run main GetStackTraceALotWithTimedWait 100000
*/
/*
* @test
* @requires vm.debug == true
* @run main/othervm GetStackTraceALotWithTimedWait 50000
* @run main GetStackTraceALotWithTimedWait 50000
*/
import java.time.Instant;

View File

@ -26,7 +26,7 @@
* @summary Test virtual threads entering a lot of monitors with contention
* @requires vm.opt.LockingMode != 1
* @library /test/lib
* @run main/othervm LotsOfContendedMonitorEnter
* @run main LotsOfContendedMonitorEnter
*/
/*

View File

@ -25,7 +25,7 @@
* @test id=default
* @summary Test virtual thread entering (and reentering) a lot of monitors with no contention
* @library /test/lib
* @run main/othervm LotsOfUncontendedMonitorEnter
* @run main LotsOfUncontendedMonitorEnter
*/
/*

View File

@ -25,29 +25,35 @@
* @test
* @summary Stress test parking and unparking
* @requires vm.debug != true
* @run main/othervm ParkALot 500000
* @library /test/lib
* @run main/othervm/timeout=300 ParkALot 300000
*/
/*
* @test
* @requires vm.debug == true
* @run main/othervm ParkALot 100000
* @library /test/lib
* @run main/othervm/timeout=300 ParkALot 100000
*/
import java.time.Instant;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.LockSupport;
import jdk.test.lib.Platform;
public class ParkALot {
private static final int ITERATIONS = 1_000_000;
public static void main(String[] args) {
public static void main(String[] args) throws Exception {
int iterations;
if (args.length > 0) {
iterations = Integer.parseInt(args[0]);
int value = Integer.parseInt(args[0]);
if (Platform.isOSX() && Platform.isX64()) {
// reduced iterations on macosx-x64
iterations = Math.max(value / 4, 1);
} else {
iterations = ITERATIONS;
iterations = value;
}
int maxThreads = Math.clamp(Runtime.getRuntime().availableProcessors() / 2, 1, 4);
@ -55,8 +61,18 @@ public class ParkALot {
System.out.format("%s %d thread(s) ...%n", Instant.now(), nthreads);
ThreadFactory factory = Thread.ofPlatform().factory();
try (var executor = Executors.newThreadPerTaskExecutor(factory)) {
var totalIterations = new AtomicInteger();
for (int i = 0; i < nthreads; i++) {
executor.submit(() -> parkALot(iterations));
executor.submit(() -> parkALot(iterations, totalIterations::incrementAndGet));
}
// shutdown, await for all threads to finish with progress output
executor.shutdown();
boolean terminated = false;
while (!terminated) {
terminated = executor.awaitTermination(1, TimeUnit.SECONDS);
System.out.format("%s => %d of %d%n",
Instant.now(), totalIterations.get(), iterations * nthreads);
}
}
System.out.format("%s %d thread(s) done%n", Instant.now(), nthreads);
@ -66,8 +82,10 @@ public class ParkALot {
/**
* Creates a virtual thread that alternates between untimed and timed parking.
* A platform thread spins unparking the virtual thread.
* @param iterations number of iterations
* @param afterIteration the task to run after each iteration
*/
private static void parkALot(int iterations) {
private static void parkALot(int iterations, Runnable afterIteration) {
Thread vthread = Thread.ofVirtual().start(() -> {
int i = 0;
boolean timed = false;
@ -80,6 +98,7 @@ public class ParkALot {
timed = true;
}
i++;
afterIteration.run();
}
});

View File

@ -25,7 +25,7 @@
* @test
* @summary Stress test Thread.sleep
* @requires vm.debug != true & vm.continuations
* @run main/othervm SleepALot 500000
* @run main SleepALot 500000
*/
/*

View File

@ -24,28 +24,28 @@
/*
* @test id=timeout
* @summary Stress test timed-Object.wait
* @run main/othervm TimedWaitALot 200
* @run main TimedWaitALot 200
*/
/*
* @test id=timeout-notify
* @summary Test timed-Object.wait where the waiting thread is awakened with Object.notify
* at around the same time that the timeout expires.
* @run main/othervm TimedWaitALot 200 true false
* @run main TimedWaitALot 150 true false
*/
/*
* @test id=timeout-interrupt
* @summary Test timed-Object.wait where the waiting thread is awakened with Thread.interrupt
* at around the same time that the timeout expires.
* @run main/othervm TimedWaitALot 200 false true
* @run main TimedWaitALot 150 false true
*/
/*
* @test id=timeout-notify-interrupt
* @summary Test timed-Object.wait where the waiting thread is awakened with Object.notify
* and Thread.interrupt at around the same time that the timeout expires.
* @run main/othervm TimedWaitALot 100 true true
* @run main TimedWaitALot 100 true true
*/
import java.time.Instant;