@@ -58,21 +58,40 @@ public class GuaranteedAsyncDeflationIntervalTest {
58
58
59
59
public static class Test {
60
60
// 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 ;
62
62
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 ;
64
70
65
71
public static void main (String ... args ) throws Exception {
66
72
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 ;
73
88
}
74
- }
75
- monitors [i ] = o ;
89
+ });
90
+ threads [t ].start ();
91
+ }
92
+
93
+ for (Thread t : threads ) {
94
+ t .join ();
76
95
}
77
96
78
97
try {
@@ -170,7 +189,7 @@ public static void testAllEnabled() throws Exception {
170
189
"-Xmx100M" ,
171
190
"-XX:+UnlockDiagnosticVMOptions" ,
172
191
"-XX:GuaranteedAsyncDeflationInterval=5000" ,
173
- "-XX:MonitorUsedDeflationThreshold=10 " ,
192
+ "-XX:MonitorUsedDeflationThreshold=1 " ,
174
193
"-Xlog:monitorinflation=info" ,
175
194
"GuaranteedAsyncDeflationIntervalTest$Test" );
176
195
0 commit comments