Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/metaspace/gc/MemoryUsageTest.java
41155 views
1
/*
2
* Copyright (c) 2013, 2018, 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 metaspace.gc;
25
26
/**
27
* Test observers the progress on used/committed memory.
28
* MemoryPoolMXBean is used for that purpose.
29
*
30
* Depending on command line option the test checks either Metaspace or
31
* Compressed Class Space area.
32
*
33
* This test checks two things:
34
* 1) Loading/Unloading classes doesn't cause memory increase
35
* 2) Loading classes causes permanent increase of memory.
36
*/
37
public class MemoryUsageTest extends MetaspaceBaseGC {
38
39
private String pool_name;
40
41
public static void main(String[] args) {
42
new MemoryUsageTest().run(args);
43
}
44
45
46
47
/**
48
* Loads new classes by bunches and invokes GC after each bunch.
49
* Expected behavior: used/committed should stop growing after 5 iterations.
50
*/
51
public void checkForNotGrowing() {
52
53
long p_used = 0;
54
long p_committed = 0;
55
56
System.out.println("%%%% Loading classes without storing refs, invoking gc manually");
57
final int numberOfIteration = 10;
58
for (int i = 0; i < numberOfIteration; i++) {
59
loadNewClasses(500, false);
60
gc();
61
printMemoryUsage("% " + i + " ");
62
if (i == numberOfIteration / 2) {
63
// used/committed in the middle of the step.
64
p_used = getUsed();
65
p_committed = getCommitted();
66
}
67
68
}
69
long used = getUsed();
70
long committed = getCommitted();
71
72
// loading classes without keeping references to them
73
// should not affect used/commited metaspace
74
// but OK, let's allow some noise such as +/-8K
75
if (Math.abs((int) (used - p_used)) > 1024*8) {
76
throw new Fault("Used amount should be stable: " +
77
p_used + " --> " + used);
78
}
79
if (Math.abs((int) (committed - p_committed)) > 1024*8) {
80
throw new Fault("Committed amount should be stable: " +
81
p_committed + " --> " + committed);
82
}
83
84
}
85
86
/**
87
* Loads new classes by bunches and invokes GC after each bunch.
88
* Expected behavior: used/committed should keep growing
89
*/
90
public void checkForGrowing() {
91
long used = 0;
92
long committed = 0;
93
long p_used = 0 ;
94
long p_committed = 0;
95
96
// loading new classes, starting to keep references.
97
// both used and commited metaspace should grow up.
98
System.out.println("%%%% Loading classes, refs are stored, gc is invoking manually");
99
for (int i = 0; i < 10; i++) {
100
try {
101
loadNewClasses(1000, true);
102
} catch (OutOfMemoryError oom) {
103
String message = oom.getMessage().toLowerCase();
104
if (message.contains("metaspace") || message.contains("compressed class space")) {
105
System.out.println("% oom is ok: " + oom);
106
return;
107
} else {
108
System.err.println("% unexpected OOM" + oom);
109
throw new Fault(oom);
110
}
111
}
112
113
gc();
114
printMemoryUsage("% " + i + " ");
115
p_used = used;
116
p_committed = committed;
117
used = getUsed();
118
committed = getCommitted();
119
if (i > 0 && used <= p_used) {
120
throw new Fault("Used amount reduced unexpectedly " +
121
p_used + " --> " + used);
122
}
123
if (i > 0 && committed < p_committed) {
124
throw new Fault("Used amount reduced unexpectedly " +
125
p_committed + " --> " + committed);
126
}
127
}
128
}
129
130
/**
131
* Looks up for memory pool name.
132
* @param args command line options
133
*/
134
@Override
135
protected void parseArgs(String[] args) {
136
if (args.length != 1) {
137
printUsage();
138
throw new Fault("MemoryPool is not specified");
139
}
140
141
String a = args[0];
142
if (a.equalsIgnoreCase("-pool:compressed")) {
143
pool_name = "Compressed Class Space";
144
} else if (a.equalsIgnoreCase("-pool:metaspace")) {
145
pool_name = "Metaspace";
146
} else {
147
printUsage();
148
throw new Fault("Unrecongnized argument: " + a);
149
}
150
}
151
152
private void printUsage() {
153
System.err.println("Usage: ");
154
System.err.println("java [-Xms..] [-XX:MetaspaceSize=..] [-XX:MaxMetaspaceSize=..] \\");
155
System.err.println(" " + MemoryUsageTest.class.getCanonicalName() + " -pool:<metaspace|compressed>");
156
}
157
158
/**
159
* @return name of the MemoryPoolMXBean under test
160
*/
161
@Override
162
protected String getPoolName() {
163
return pool_name;
164
}
165
166
@Override
167
protected void doCheck() {
168
checkForNotGrowing();
169
checkForGrowing();
170
}
171
172
}
173
174