Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/gc/TestMemoryMXBeansAndPoolsPresence.java
40930 views
1
/*
2
* Copyright (c) 2017, 2019, Oracle and/or its affiliates. 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
package gc;
25
26
import java.util.List;
27
import java.lang.management.*;
28
import static jdk.test.lib.Asserts.*;
29
import java.util.stream.*;
30
31
/* @test TestMemoryMXBeansAndPoolsPresenceG1
32
* @bug 8191564
33
* @summary Tests that GarbageCollectorMXBeans and GC MemoryPools are created.
34
* @library /test/lib
35
* @modules java.base/jdk.internal.misc
36
* java.management
37
* @requires vm.gc.G1
38
* @run main/othervm -XX:+UseG1GC gc.TestMemoryMXBeansAndPoolsPresence G1
39
*/
40
41
/* @test TestMemoryMXBeansAndPoolsPresenceParallel
42
* @bug 8191564
43
* @summary Tests that GarbageCollectorMXBeans and GC MemoryPools are created.
44
* @library /test/lib
45
* @modules java.base/jdk.internal.misc
46
* java.management
47
* @requires vm.gc.Parallel
48
* @run main/othervm -XX:+UseParallelGC gc.TestMemoryMXBeansAndPoolsPresence Parallel
49
*/
50
51
/* @test TestMemoryMXBeansAndPoolsPresenceSerial
52
* @bug 8191564
53
* @summary Tests that GarbageCollectorMXBeans and GC MemoryPools are created.
54
* @library /test/lib
55
* @modules java.base/jdk.internal.misc
56
* java.management
57
* @requires vm.gc.Serial
58
* @run main/othervm -XX:+UseSerialGC gc.TestMemoryMXBeansAndPoolsPresence Serial
59
*/
60
61
class GCBeanDescription {
62
public String name;
63
public String[] poolNames;
64
65
public GCBeanDescription(String name, String[] poolNames) {
66
this.name = name;
67
this.poolNames = poolNames;
68
}
69
}
70
71
public class TestMemoryMXBeansAndPoolsPresence {
72
public static void test(GCBeanDescription... expectedBeans) {
73
List<MemoryPoolMXBean> memoryPools = ManagementFactory.getMemoryPoolMXBeans();
74
75
List<GarbageCollectorMXBean> gcBeans = ManagementFactory.getGarbageCollectorMXBeans();
76
assertEQ(expectedBeans.length, gcBeans.size());
77
78
for (GCBeanDescription desc : expectedBeans) {
79
List<GarbageCollectorMXBean> beans = gcBeans.stream()
80
.filter(b -> b.getName().equals(desc.name))
81
.collect(Collectors.toList());
82
assertEQ(beans.size(), 1);
83
84
GarbageCollectorMXBean bean = beans.get(0);
85
assertEQ(desc.name, bean.getName());
86
87
String[] pools = bean.getMemoryPoolNames();
88
assertEQ(desc.poolNames.length, pools.length);
89
for (int i = 0; i < desc.poolNames.length; i++) {
90
assertEQ(desc.poolNames[i], pools[i]);
91
}
92
}
93
}
94
95
public static void main(String[] args) {
96
switch (args[0]) {
97
case "G1":
98
test(new GCBeanDescription("G1 Young Generation", new String[] {"G1 Eden Space", "G1 Survivor Space", "G1 Old Gen"}),
99
new GCBeanDescription("G1 Old Generation", new String[] {"G1 Eden Space", "G1 Survivor Space", "G1 Old Gen"}));
100
break;
101
case "Parallel":
102
test(new GCBeanDescription("PS Scavenge", new String[] {"PS Eden Space", "PS Survivor Space"}),
103
new GCBeanDescription("PS MarkSweep", new String[] {"PS Eden Space", "PS Survivor Space", "PS Old Gen"}));
104
break;
105
case "Serial":
106
test(new GCBeanDescription("Copy", new String[] {"Eden Space", "Survivor Space"}),
107
new GCBeanDescription("MarkSweepCompact", new String[] {"Eden Space", "Survivor Space", "Tenured Gen"}));
108
break;
109
default:
110
assertTrue(false);
111
break;
112
113
}
114
}
115
}
116
117