Skip to content
This repository was archived by the owner on Sep 19, 2023. It is now read-only.
/ jdk20u Public archive

Commit 2109cd2

Browse files
committed
8306774: Make runtime/Monitor/GuaranteedAsyncDeflationIntervalTest.java more reliable
Reviewed-by: serb, simonis Backport-of: 9ad6dc881d285cc26c136f0ef19af5bac0a75022
1 parent 5d2c255 commit 2109cd2

File tree

1 file changed

+30
-11
lines changed

1 file changed

+30
-11
lines changed

test/hotspot/jtreg/runtime/Monitor/GuaranteedAsyncDeflationIntervalTest.java

+30-11
Original file line numberDiff line numberDiff line change
@@ -58,21 +58,40 @@ public class GuaranteedAsyncDeflationIntervalTest {
5858

5959
public static class Test {
6060
// Inflate a lot of monitors, so that threshold heuristics definitely fires
61-
public static final int MONITORS = 10_000;
61+
private static final int MONITORS = 10_000;
6262

63-
public static Object[] monitors;
63+
// Use a handful of threads to inflate the monitors, to eat the cost of
64+
// wait(1) calls. This can be larger than available parallelism, since threads
65+
// would be time-waiting.
66+
private static final int THREADS = 16;
67+
68+
private static Thread[] threads;
69+
private static Object[] monitors;
6470

6571
public static void main(String... args) throws Exception {
6672
monitors = new Object[MONITORS];
67-
for (int i = 0; i < MONITORS; i++) {
68-
Object o = new Object();
69-
synchronized (o) {
70-
try {
71-
o.wait(1); // Inflate!
72-
} catch (InterruptedException ie) {
73+
threads = new Thread[THREADS];
74+
75+
for (int t = 0; t < THREADS; t++) {
76+
int monStart = t * MONITORS / THREADS;
77+
int monEnd = (t + 1) * MONITORS / THREADS;
78+
threads[t] = new Thread(() -> {
79+
for (int m = monStart; m < monEnd; m++) {
80+
Object o = new Object();
81+
synchronized (o) {
82+
try {
83+
o.wait(1);
84+
} catch (InterruptedException e) {
85+
}
86+
}
87+
monitors[m] = o;
7388
}
74-
}
75-
monitors[i] = o;
89+
});
90+
threads[t].start();
91+
}
92+
93+
for (Thread t : threads) {
94+
t.join();
7695
}
7796

7897
try {
@@ -170,7 +189,7 @@ public static void testAllEnabled() throws Exception {
170189
"-Xmx100M",
171190
"-XX:+UnlockDiagnosticVMOptions",
172191
"-XX:GuaranteedAsyncDeflationInterval=5000",
173-
"-XX:MonitorUsedDeflationThreshold=10",
192+
"-XX:MonitorUsedDeflationThreshold=1",
174193
"-Xlog:monitorinflation=info",
175194
"GuaranteedAsyncDeflationIntervalTest$Test");
176195

0 commit comments

Comments
 (0)