Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/gc/shenandoah/mxbeans/TestChurnNotifications.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 TestChurnNotifications
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 -Dprecise=true
33
* TestChurnNotifications
34
*
35
* @run main/othervm -Xmx128m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
36
* -XX:+UseShenandoahGC -XX:ShenandoahGCMode=passive
37
* -XX:-ShenandoahDegeneratedGC -Dprecise=true
38
* TestChurnNotifications
39
*/
40
41
/*
42
* @test TestChurnNotifications
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
* -Dprecise=false
49
* TestChurnNotifications
50
*/
51
52
/*
53
* @test TestChurnNotifications
54
* @summary Check that MX notifications are reported for all cycles
55
* @requires vm.gc.Shenandoah
56
*
57
* @run main/othervm -Xmx128m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
58
* -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=adaptive
59
* -Dprecise=false
60
* TestChurnNotifications
61
*/
62
63
/*
64
* @test TestChurnNotifications
65
* @summary Check that MX notifications are reported for all cycles
66
* @requires vm.gc.Shenandoah
67
*
68
* @run main/othervm -Xmx128m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
69
* -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=static
70
* -Dprecise=false
71
* TestChurnNotifications
72
*/
73
74
/*
75
* @test TestChurnNotifications
76
* @summary Check that MX notifications are reported for all cycles
77
* @requires vm.gc.Shenandoah
78
*
79
* @run main/othervm -Xmx128m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
80
* -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=compact
81
* -Dprecise=false
82
* TestChurnNotifications
83
*/
84
85
/*
86
* @test TestChurnNotifications
87
* @summary Check that MX notifications are reported for all cycles
88
* @requires vm.gc.Shenandoah
89
*
90
* @run main/othervm -Xmx128m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
91
* -XX:+UseShenandoahGC -XX:ShenandoahGCMode=iu -XX:ShenandoahGCHeuristics=aggressive
92
* -Dprecise=false
93
* TestChurnNotifications
94
*
95
* @run main/othervm -Xmx128m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
96
* -XX:+UseShenandoahGC -XX:ShenandoahGCMode=iu
97
* -Dprecise=false
98
* TestChurnNotifications
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 com.sun.management.GarbageCollectionNotificationInfo;
108
109
public class TestChurnNotifications {
110
111
static final long HEAP_MB = 128; // adjust for test configuration above
112
static final long TARGET_MB = Long.getLong("target", 2_000); // 2 Gb allocation
113
114
// Should we track the churn precisely?
115
// Precise tracking is only reliable when GC is fully stop-the-world. Otherwise,
116
// we cannot tell, looking at heap used before/after, what was the GC churn.
117
static final boolean PRECISE = Boolean.getBoolean("precise");
118
119
static final long M = 1024 * 1024;
120
121
static volatile Object sink;
122
123
public static void main(String[] args) throws Exception {
124
final AtomicLong churnBytes = 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
Map<String, MemoryUsage> mapBefore = info.getGcInfo().getMemoryUsageBeforeGc();
132
Map<String, MemoryUsage> mapAfter = info.getGcInfo().getMemoryUsageAfterGc();
133
134
MemoryUsage before = mapBefore.get("Shenandoah");
135
MemoryUsage after = mapAfter.get("Shenandoah");
136
137
if ((before != null) && (after != null)) {
138
long diff = before.getUsed() - after.getUsed();
139
if (diff > 0) {
140
churnBytes.addAndGet(diff);
141
}
142
}
143
}
144
}
145
};
146
147
for (GarbageCollectorMXBean bean : ManagementFactory.getGarbageCollectorMXBeans()) {
148
((NotificationEmitter) bean).addNotificationListener(listener, null, null);
149
}
150
151
final int size = 100_000;
152
long count = TARGET_MB * 1024 * 1024 / (16 + 4 * size);
153
154
long mem = count * (16 + 4 * size);
155
156
for (int c = 0; c < count; c++) {
157
sink = new int[size];
158
}
159
160
System.gc();
161
162
// Wait until notifications start arriving, and then wait some more
163
// to catch the ones arriving late.
164
while (churnBytes.get() == 0) {
165
Thread.sleep(1000);
166
}
167
Thread.sleep(5000);
168
169
long actual = churnBytes.get();
170
171
long minExpected = PRECISE ? (mem - HEAP_MB * 1024 * 1024) : 1;
172
long maxExpected = mem + HEAP_MB * 1024 * 1024;
173
174
String msg = "Expected = [" + minExpected / M + "; " + maxExpected / M + "] (" + mem / M + "), actual = " + actual / M;
175
if (minExpected <= actual && actual <= maxExpected) {
176
System.out.println(msg);
177
} else {
178
throw new IllegalStateException(msg);
179
}
180
}
181
}
182
183