Skip to content

Commit a032de2

Browse files
author
Alan Bateman
committed
8344577: Virtual thread tests are timing out on some macOS systems
Reviewed-by: jpai
1 parent 4110d39 commit a032de2

File tree

8 files changed

+56
-20
lines changed

8 files changed

+56
-20
lines changed

test/jdk/java/lang/Thread/virtual/stress/GetStackTraceALotWhenBlocking.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import java.time.Instant;
4343
import java.util.concurrent.ThreadLocalRandom;
4444
import java.util.concurrent.atomic.AtomicBoolean;
45+
import jdk.test.lib.Platform;
4546
import jdk.test.lib.thread.VThreadRunner; // ensureParallelism requires jdk.management
4647

4748
public class GetStackTraceALotWhenBlocking {
@@ -50,7 +51,14 @@ public static void main(String[] args) throws Exception {
5051
// need at least two carriers
5152
VThreadRunner.ensureParallelism(2);
5253

53-
int iterations = args.length > 0 ? Integer.parseInt(args[0]) : 100_000;
54+
int iterations;
55+
int value = Integer.parseInt(args[0]);
56+
if (Platform.isOSX() && Platform.isX64()) {
57+
// reduced iterations on macosx-x64
58+
iterations = Math.max(value / 4, 1);
59+
} else {
60+
iterations = value;
61+
}
5462

5563
var done = new AtomicBoolean();
5664
var lock = new Object();

test/jdk/java/lang/Thread/virtual/stress/GetStackTraceALotWhenPinned.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import java.time.Instant;
4343
import java.util.concurrent.atomic.AtomicInteger;
4444
import java.util.concurrent.locks.LockSupport;
45+
import jdk.test.lib.Platform;
4546
import jdk.test.lib.thread.VThreadRunner; // ensureParallelism requires jdk.management
4647
import jdk.test.lib.thread.VThreadPinner;
4748

@@ -53,7 +54,15 @@ public static void main(String[] args) throws Exception {
5354
VThreadRunner.ensureParallelism(2);
5455
}
5556

56-
int iterations = Integer.parseInt(args[0]);
57+
int iterations;
58+
int value = Integer.parseInt(args[0]);
59+
if (Platform.isOSX() && Platform.isX64()) {
60+
// reduced iterations on macosx-x64
61+
iterations = Math.max(value / 4, 1);
62+
} else {
63+
iterations = value;
64+
}
65+
5766
var barrier = new Barrier(2);
5867

5968
// Start a virtual thread that loops doing Thread.yield and parking while pinned.

test/jdk/java/lang/Thread/virtual/stress/GetStackTraceALotWithTimedWait.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@
2525
* @test
2626
* @summary Stress test Thread.getStackTrace on a virtual thread in timed-Object.wait
2727
* @requires vm.debug != true
28-
* @run main/othervm GetStackTraceALotWithTimedWait 100000
28+
* @run main GetStackTraceALotWithTimedWait 100000
2929
*/
3030

3131
/*
3232
* @test
3333
* @requires vm.debug == true
34-
* @run main/othervm GetStackTraceALotWithTimedWait 50000
34+
* @run main GetStackTraceALotWithTimedWait 50000
3535
*/
3636

3737
import java.time.Instant;

test/jdk/java/lang/Thread/virtual/stress/LotsOfContendedMonitorEnter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
* @summary Test virtual threads entering a lot of monitors with contention
2727
* @requires vm.opt.LockingMode != 1
2828
* @library /test/lib
29-
* @run main/othervm LotsOfContendedMonitorEnter
29+
* @run main LotsOfContendedMonitorEnter
3030
*/
3131

3232
/*

test/jdk/java/lang/Thread/virtual/stress/LotsOfUncontendedMonitorEnter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
* @test id=default
2626
* @summary Test virtual thread entering (and reentering) a lot of monitors with no contention
2727
* @library /test/lib
28-
* @run main/othervm LotsOfUncontendedMonitorEnter
28+
* @run main LotsOfUncontendedMonitorEnter
2929
*/
3030

3131
/*

test/jdk/java/lang/Thread/virtual/stress/ParkALot.java

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,38 +25,54 @@
2525
* @test
2626
* @summary Stress test parking and unparking
2727
* @requires vm.debug != true
28-
* @run main/othervm ParkALot 500000
28+
* @library /test/lib
29+
* @run main/othervm/timeout=300 ParkALot 300000
2930
*/
3031

3132
/*
3233
* @test
3334
* @requires vm.debug == true
34-
* @run main/othervm ParkALot 100000
35+
* @library /test/lib
36+
* @run main/othervm/timeout=300 ParkALot 100000
3537
*/
3638

3739
import java.time.Instant;
3840
import java.util.concurrent.Executors;
3941
import java.util.concurrent.ThreadFactory;
42+
import java.util.concurrent.TimeUnit;
43+
import java.util.concurrent.atomic.AtomicInteger;
4044
import java.util.concurrent.locks.LockSupport;
45+
import jdk.test.lib.Platform;
4146

4247
public class ParkALot {
43-
private static final int ITERATIONS = 1_000_000;
4448

45-
public static void main(String[] args) {
49+
public static void main(String[] args) throws Exception {
4650
int iterations;
47-
if (args.length > 0) {
48-
iterations = Integer.parseInt(args[0]);
51+
int value = Integer.parseInt(args[0]);
52+
if (Platform.isOSX() && Platform.isX64()) {
53+
// reduced iterations on macosx-x64
54+
iterations = Math.max(value / 4, 1);
4955
} else {
50-
iterations = ITERATIONS;
56+
iterations = value;
5157
}
5258

5359
int maxThreads = Math.clamp(Runtime.getRuntime().availableProcessors() / 2, 1, 4);
5460
for (int nthreads = 1; nthreads <= maxThreads; nthreads++) {
5561
System.out.format("%s %d thread(s) ...%n", Instant.now(), nthreads);
5662
ThreadFactory factory = Thread.ofPlatform().factory();
5763
try (var executor = Executors.newThreadPerTaskExecutor(factory)) {
64+
var totalIterations = new AtomicInteger();
5865
for (int i = 0; i < nthreads; i++) {
59-
executor.submit(() -> parkALot(iterations));
66+
executor.submit(() -> parkALot(iterations, totalIterations::incrementAndGet));
67+
}
68+
69+
// shutdown, await for all threads to finish with progress output
70+
executor.shutdown();
71+
boolean terminated = false;
72+
while (!terminated) {
73+
terminated = executor.awaitTermination(1, TimeUnit.SECONDS);
74+
System.out.format("%s => %d of %d%n",
75+
Instant.now(), totalIterations.get(), iterations * nthreads);
6076
}
6177
}
6278
System.out.format("%s %d thread(s) done%n", Instant.now(), nthreads);
@@ -66,8 +82,10 @@ public static void main(String[] args) {
6682
/**
6783
* Creates a virtual thread that alternates between untimed and timed parking.
6884
* A platform thread spins unparking the virtual thread.
85+
* @param iterations number of iterations
86+
* @param afterIteration the task to run after each iteration
6987
*/
70-
private static void parkALot(int iterations) {
88+
private static void parkALot(int iterations, Runnable afterIteration) {
7189
Thread vthread = Thread.ofVirtual().start(() -> {
7290
int i = 0;
7391
boolean timed = false;
@@ -80,6 +98,7 @@ private static void parkALot(int iterations) {
8098
timed = true;
8199
}
82100
i++;
101+
afterIteration.run();
83102
}
84103
});
85104

test/jdk/java/lang/Thread/virtual/stress/SleepALot.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
* @test
2626
* @summary Stress test Thread.sleep
2727
* @requires vm.debug != true & vm.continuations
28-
* @run main/othervm SleepALot 500000
28+
* @run main SleepALot 500000
2929
*/
3030

3131
/*

test/jdk/java/lang/Thread/virtual/stress/TimedWaitALot.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,28 +24,28 @@
2424
/*
2525
* @test id=timeout
2626
* @summary Stress test timed-Object.wait
27-
* @run main/othervm TimedWaitALot 200
27+
* @run main TimedWaitALot 200
2828
*/
2929

3030
/*
3131
* @test id=timeout-notify
3232
* @summary Test timed-Object.wait where the waiting thread is awakened with Object.notify
3333
* at around the same time that the timeout expires.
34-
* @run main/othervm TimedWaitALot 200 true false
34+
* @run main TimedWaitALot 150 true false
3535
*/
3636

3737
/*
3838
* @test id=timeout-interrupt
3939
* @summary Test timed-Object.wait where the waiting thread is awakened with Thread.interrupt
4040
* at around the same time that the timeout expires.
41-
* @run main/othervm TimedWaitALot 200 false true
41+
* @run main TimedWaitALot 150 false true
4242
*/
4343

4444
/*
4545
* @test id=timeout-notify-interrupt
4646
* @summary Test timed-Object.wait where the waiting thread is awakened with Object.notify
4747
* and Thread.interrupt at around the same time that the timeout expires.
48-
* @run main/othervm TimedWaitALot 100 true true
48+
* @run main TimedWaitALot 100 true true
4949
*/
5050

5151
import java.time.Instant;

0 commit comments

Comments
 (0)