Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/jdk17u
Path: blob/master/test/hotspot/jtreg/gc/shenandoah/mxbeans/TestPauseNotifications.java
64507 views
1
/*
2
* Copyright (c) 2018, Red Hat, Inc. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*
23
*/
24
25
/*
26
* @test id=passive
27
* @summary Check that MX notifications are reported for all cycles
28
* @library /test/lib /
29
* @requires vm.gc.Shenandoah
30
*
31
* @run main/othervm -Xmx128m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
32
* -XX:+UseShenandoahGC -XX:ShenandoahGCMode=passive
33
* -XX:+ShenandoahDegeneratedGC
34
* TestPauseNotifications
35
*
36
* @run main/othervm -Xmx128m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
37
* -XX:+UseShenandoahGC -XX:ShenandoahGCMode=passive
38
* -XX:-ShenandoahDegeneratedGC
39
* TestPauseNotifications
40
*/
41
42
/*
43
* @test id=aggressive
44
* @summary Check that MX notifications are reported for all cycles
45
* @library /test/lib /
46
* @requires vm.gc.Shenandoah
47
*
48
* @run main/othervm -Xmx128m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
49
* -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive
50
* TestPauseNotifications
51
*/
52
53
/*
54
* @test id=adaptive
55
* @summary Check that MX notifications are reported for all cycles
56
* @library /test/lib /
57
* @requires vm.gc.Shenandoah
58
*
59
* @run main/othervm -Xmx128m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
60
* -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=adaptive
61
* TestPauseNotifications
62
*/
63
64
/*
65
* @test id=static
66
* @summary Check that MX notifications are reported for all cycles
67
* @library /test/lib /
68
* @requires vm.gc.Shenandoah
69
*
70
* @run main/othervm -Xmx128m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
71
* -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=static
72
* TestPauseNotifications
73
*/
74
75
/*
76
* @test id=compact
77
* @summary Check that MX notifications are reported for all cycles
78
* @library /test/lib /
79
* @requires vm.gc.Shenandoah
80
*
81
* @run main/othervm -Xmx128m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
82
* -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=compact
83
* TestPauseNotifications
84
*/
85
86
/*
87
* @test id=iu
88
* @summary Check that MX notifications are reported for all cycles
89
* @library /test/lib /
90
* @requires vm.gc.Shenandoah
91
*
92
* @run main/othervm -Xmx128m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
93
* -XX:+UseShenandoahGC -XX:ShenandoahGCMode=iu -XX:ShenandoahGCHeuristics=aggressive
94
* TestPauseNotifications
95
*
96
* @run main/othervm -Xmx128m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
97
* -XX:+UseShenandoahGC -XX:ShenandoahGCMode=iu
98
* TestPauseNotifications
99
*/
100
101
import java.util.*;
102
import java.util.concurrent.atomic.*;
103
import javax.management.*;
104
import java.lang.management.*;
105
import javax.management.openmbean.*;
106
107
import jdk.test.lib.Utils;
108
109
import com.sun.management.GarbageCollectionNotificationInfo;
110
111
public class TestPauseNotifications {
112
113
static final long HEAP_MB = 128; // adjust for test configuration above
114
static final long TARGET_MB = Long.getLong("target", 2_000); // 2 Gb allocation
115
116
static volatile Object sink;
117
118
public static void main(String[] args) throws Exception {
119
final long startTime = System.currentTimeMillis();
120
121
final AtomicLong pausesDuration = new AtomicLong();
122
final AtomicLong cyclesDuration = new AtomicLong();
123
final AtomicLong pausesCount = new AtomicLong();
124
final AtomicLong cyclesCount = new AtomicLong();
125
126
NotificationListener listener = new NotificationListener() {
127
@Override
128
public void handleNotification(Notification n, Object o) {
129
if (n.getType().equals(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION)) {
130
GarbageCollectionNotificationInfo info = GarbageCollectionNotificationInfo.from((CompositeData) n.getUserData());
131
132
System.out.println("Received: " + info.getGcName());
133
134
long d = info.getGcInfo().getDuration();
135
136
String name = info.getGcName();
137
if (name.contains("Shenandoah")) {
138
if (name.equals("Shenandoah Pauses")) {
139
pausesCount.incrementAndGet();
140
pausesDuration.addAndGet(d);
141
} else if (name.equals("Shenandoah Cycles")) {
142
cyclesCount.incrementAndGet();
143
cyclesDuration.addAndGet(d);
144
} else {
145
throw new IllegalStateException("Unknown name: " + name);
146
}
147
}
148
}
149
}
150
};
151
152
for (GarbageCollectorMXBean bean : ManagementFactory.getGarbageCollectorMXBeans()) {
153
((NotificationEmitter) bean).addNotificationListener(listener, null, null);
154
}
155
156
final int size = 100_000;
157
long count = TARGET_MB * 1024 * 1024 / (16 + 4 * size);
158
159
for (int c = 0; c < count; c++) {
160
sink = new int[size];
161
}
162
163
// Look at test timeout to figure out how long we can wait without breaking into timeout.
164
// Default to 1/4 of the remaining time in 1s steps.
165
final long STEP_MS = 1000;
166
long spentTime = System.currentTimeMillis() - startTime;
167
long maxTries = (Utils.adjustTimeout(Utils.DEFAULT_TEST_TIMEOUT) - spentTime) / STEP_MS / 4;
168
169
long actualPauses = 0;
170
long actualCycles = 0;
171
172
// Wait until enough notifications are accrued to match minimum boundary.
173
long minExpected = 10;
174
175
long tries = 0;
176
while (tries++ < maxTries) {
177
actualPauses = pausesCount.get();
178
actualCycles = cyclesCount.get();
179
if (minExpected <= actualPauses && minExpected <= actualCycles) {
180
// Wait a little bit to catch the lingering notifications.
181
Thread.sleep(5000);
182
actualPauses = pausesCount.get();
183
actualCycles = cyclesCount.get();
184
break;
185
}
186
Thread.sleep(STEP_MS);
187
}
188
189
{
190
String msg = "Pauses expected = [" + minExpected + "; +inf], actual = " + actualPauses;
191
if (minExpected <= actualPauses) {
192
System.out.println(msg);
193
} else {
194
throw new IllegalStateException(msg);
195
}
196
}
197
198
{
199
String msg = "Cycles expected = [" + minExpected + "; +inf], actual = " + actualCycles;
200
if (minExpected <= actualCycles) {
201
System.out.println(msg);
202
} else {
203
throw new IllegalStateException(msg);
204
}
205
}
206
207
{
208
long actualPauseDuration = pausesDuration.get();
209
long actualCycleDuration = cyclesDuration.get();
210
211
String msg = "Pauses duration (" + actualPauseDuration + ") is expected to be not larger than cycles duration (" + actualCycleDuration + ")";
212
213
if (actualPauseDuration <= actualCycleDuration) {
214
System.out.println(msg);
215
} else {
216
throw new IllegalStateException(msg);
217
}
218
}
219
}
220
}
221
222