Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/gc/shenandoah/mxbeans/TestPauseNotifications.java
41153 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 TestPauseNotifications
27
* @summary Check that MX notifications are reported for all cycles
28
* @requires vm.gc.Shenandoah
29
*
30
* @run main/othervm -Xmx128m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
31
* -XX:+UseShenandoahGC -XX:ShenandoahGCMode=passive
32
* -XX:+ShenandoahDegeneratedGC
33
* TestPauseNotifications
34
*
35
* @run main/othervm -Xmx128m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
36
* -XX:+UseShenandoahGC -XX:ShenandoahGCMode=passive
37
* -XX:-ShenandoahDegeneratedGC
38
* TestPauseNotifications
39
*/
40
41
/*
42
* @test TestPauseNotifications
43
* @summary Check that MX notifications are reported for all cycles
44
* @requires vm.gc.Shenandoah
45
*
46
* @run main/othervm -Xmx128m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
47
* -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive
48
* TestPauseNotifications
49
*/
50
51
/*
52
* @test TestPauseNotifications
53
* @summary Check that MX notifications are reported for all cycles
54
* @requires vm.gc.Shenandoah
55
*
56
* @run main/othervm -Xmx128m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
57
* -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=adaptive
58
* TestPauseNotifications
59
*/
60
61
/*
62
* @test TestPauseNotifications
63
* @summary Check that MX notifications are reported for all cycles
64
* @requires vm.gc.Shenandoah
65
*
66
* @run main/othervm -Xmx128m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
67
* -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=static
68
* TestPauseNotifications
69
*/
70
71
/*
72
* @test TestPauseNotifications
73
* @summary Check that MX notifications are reported for all cycles
74
* @requires vm.gc.Shenandoah
75
*
76
* @run main/othervm -Xmx128m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
77
* -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=compact
78
* TestPauseNotifications
79
*/
80
81
/*
82
* @test TestPauseNotifications
83
* @summary Check that MX notifications are reported for all cycles
84
* @requires vm.gc.Shenandoah
85
*
86
* @run main/othervm -Xmx128m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
87
* -XX:+UseShenandoahGC -XX:ShenandoahGCMode=iu -XX:ShenandoahGCHeuristics=aggressive
88
* TestPauseNotifications
89
*
90
* @run main/othervm -Xmx128m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
91
* -XX:+UseShenandoahGC -XX:ShenandoahGCMode=iu
92
* TestPauseNotifications
93
*/
94
95
import java.util.*;
96
import java.util.concurrent.atomic.*;
97
import javax.management.*;
98
import java.lang.management.*;
99
import javax.management.openmbean.*;
100
101
import com.sun.management.GarbageCollectionNotificationInfo;
102
103
public class TestPauseNotifications {
104
105
static final long HEAP_MB = 128; // adjust for test configuration above
106
static final long TARGET_MB = Long.getLong("target", 2_000); // 2 Gb allocation
107
108
static volatile Object sink;
109
110
public static void main(String[] args) throws Exception {
111
final AtomicLong pausesDuration = new AtomicLong();
112
final AtomicLong cyclesDuration = new AtomicLong();
113
114
NotificationListener listener = new NotificationListener() {
115
@Override
116
public void handleNotification(Notification n, Object o) {
117
if (n.getType().equals(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION)) {
118
GarbageCollectionNotificationInfo info = GarbageCollectionNotificationInfo.from((CompositeData) n.getUserData());
119
120
System.out.println(info.getGcInfo().toString());
121
System.out.println(info.getGcName());
122
System.out.println();
123
124
long d = info.getGcInfo().getDuration();
125
126
String name = info.getGcName();
127
if (name.contains("Shenandoah")) {
128
if (name.equals("Shenandoah Pauses")) {
129
pausesDuration.addAndGet(d);
130
} else if (name.equals("Shenandoah Cycles")) {
131
cyclesDuration.addAndGet(d);
132
} else {
133
throw new IllegalStateException("Unknown name: " + name);
134
}
135
}
136
}
137
}
138
};
139
140
for (GarbageCollectorMXBean bean : ManagementFactory.getGarbageCollectorMXBeans()) {
141
((NotificationEmitter) bean).addNotificationListener(listener, null, null);
142
}
143
144
final int size = 100_000;
145
long count = TARGET_MB * 1024 * 1024 / (16 + 4 * size);
146
147
for (int c = 0; c < count; c++) {
148
sink = new int[size];
149
}
150
151
// Wait until notifications start arriving, and then wait some more
152
// to catch the ones arriving late.
153
while (pausesDuration.get() == 0) {
154
Thread.sleep(1000);
155
}
156
Thread.sleep(5000);
157
158
long pausesActual = pausesDuration.get();
159
long cyclesActual = cyclesDuration.get();
160
161
long minExpected = 1;
162
long maxExpected = Long.MAX_VALUE;
163
164
{
165
String msg = "Pauses expected = [" + minExpected + "; " + maxExpected + "], actual = " + pausesActual;
166
if (minExpected <= pausesActual && pausesActual <= maxExpected) {
167
System.out.println(msg);
168
} else {
169
throw new IllegalStateException(msg);
170
}
171
}
172
173
{
174
String msg = "Cycles expected = [" + minExpected + "; " + maxExpected + "], actual = " + cyclesActual;
175
if (minExpected <= cyclesActual && cyclesActual <= maxExpected) {
176
System.out.println(msg);
177
} else {
178
throw new IllegalStateException(msg);
179
}
180
}
181
182
{
183
String msg = "Cycle duration (" + cyclesActual + "), pause duration (" + pausesActual + ")";
184
if (pausesActual <= cyclesActual) {
185
System.out.println(msg);
186
} else {
187
throw new IllegalStateException(msg);
188
}
189
}
190
}
191
}
192
193