Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/runtime/Metaspace/elastic/TestMetaspaceAllocationMT1.java
41155 views
1
/*
2
* Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved.
3
* Copyright (c) 2020 SAP SE. All rights reserved.
4
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5
*
6
* This code is free software; you can redistribute it and/or modify it
7
* under the terms of the GNU General Public License version 2 only, as
8
* published by the Free Software Foundation.
9
*
10
* This code is distributed in the hope that it will be useful, but WITHOUT
11
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13
* version 2 for more details (a copy is included in the LICENSE file that
14
* accompanied this code).
15
*
16
* You should have received a copy of the GNU General Public License version
17
* 2 along with this work; if not, write to the Free Software Foundation,
18
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19
*
20
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21
* or visit www.oracle.com if you need additional information or have any
22
* questions.
23
*
24
*/
25
26
/*
27
* This is a stress test for allocating from a single MetaspaceArena from
28
* multiple threads, optionally with reserve limit (mimicking the non-expandable CompressedClassSpace)
29
* or commit limit (mimimcking MaxMetaspaceSize).
30
*
31
* The test threads will start to allocate from the Arena, and occasionally deallocate.
32
* The threads run with a safety allocation max; if reached (or, if the underlying arena
33
* hits either commit or reserve limit, if given) they will switch to deallocation and then
34
* kind of float at the allocation ceiling, alternating between allocation and deallocation.
35
*
36
* We test with various flags, to exercise all 3 reclaim policies (none, balanced (default)
37
* and aggessive) as well as one run with allocation guards enabled.
38
*
39
* We also set MetaspaceVerifyInterval very low to trigger many verifications in debug vm.
40
*
41
*/
42
43
/*
44
* @test id=debug-default
45
* @library /test/lib
46
* @modules java.base/jdk.internal.misc
47
* java.management
48
* @build sun.hotspot.WhiteBox
49
* @key randomness
50
* @requires (vm.debug == true)
51
*
52
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
53
*
54
* @run main/othervm/timeout=400
55
* -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
56
* -XX:VerifyMetaspaceInterval=10
57
* TestMetaspaceAllocationMT1
58
*/
59
60
/*
61
* @test id=debug-none
62
* @library /test/lib
63
* @modules java.base/jdk.internal.misc
64
* java.management
65
* @build sun.hotspot.WhiteBox
66
* @key randomness
67
* @requires (vm.debug == true)
68
*
69
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
70
*
71
* @run main/othervm/timeout=400
72
* -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
73
* -XX:VerifyMetaspaceInterval=10
74
* -XX:MetaspaceReclaimPolicy=none
75
* TestMetaspaceAllocationMT1
76
*/
77
78
/*
79
* @test id=debug-aggressive
80
* @library /test/lib
81
* @modules java.base/jdk.internal.misc
82
* java.management
83
* @build sun.hotspot.WhiteBox
84
* @key randomness
85
* @requires (vm.debug == true)
86
*
87
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
88
*
89
* @run main/othervm/timeout=400
90
* -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
91
* -XX:VerifyMetaspaceInterval=10
92
* -XX:MetaspaceReclaimPolicy=aggressive
93
* TestMetaspaceAllocationMT1
94
*/
95
96
/*
97
* @test id=debug-guard
98
* @library /test/lib
99
* @modules java.base/jdk.internal.misc
100
* java.management
101
* @build sun.hotspot.WhiteBox
102
* @key randomness
103
* @requires (vm.debug == true)
104
*
105
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
106
*
107
* @run main/othervm/timeout=400
108
* -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
109
* -XX:VerifyMetaspaceInterval=10
110
* -XX:+MetaspaceGuardAllocations
111
* TestMetaspaceAllocationMT1
112
*/
113
114
/*
115
* @test id=ndebug-default
116
* @library /test/lib
117
* @modules java.base/jdk.internal.misc
118
* java.management
119
* @build sun.hotspot.WhiteBox
120
* @key randomness
121
* @requires (vm.debug == false)
122
*
123
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
124
*
125
* @run main/othervm/timeout=400
126
* -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
127
* TestMetaspaceAllocationMT1
128
*/
129
130
/*
131
* @test id=ndebug-none
132
* @library /test/lib
133
* @modules java.base/jdk.internal.misc
134
* java.management
135
* @build sun.hotspot.WhiteBox
136
* @key randomness
137
* @requires (vm.debug == false)
138
*
139
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
140
*
141
* @run main/othervm/timeout=400
142
* -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
143
* -XX:MetaspaceReclaimPolicy=none
144
* TestMetaspaceAllocationMT1
145
*/
146
147
/*
148
* @test id=ndebug-aggressive
149
* @library /test/lib
150
* @modules java.base/jdk.internal.misc
151
* java.management
152
* @build sun.hotspot.WhiteBox
153
* @key randomness
154
* @requires (vm.debug == false)
155
*
156
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
157
*
158
* @run main/othervm/timeout=400
159
* -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
160
* -XX:MetaspaceReclaimPolicy=aggressive
161
* TestMetaspaceAllocationMT1
162
*/
163
164
public class TestMetaspaceAllocationMT1 {
165
166
public static void main(String[] args) throws Exception {
167
168
final long testAllocationCeiling = 1024 * 1024 * 8; // 8m words = 64M on 64bit
169
final int numThreads = 4;
170
final int seconds = 10;
171
172
for (int i = 0; i < 3; i ++) {
173
174
long commitLimit = (i == 1) ? 1024 * 256 : 0;
175
176
// Note: reserve limit must be a multiple of Metaspace::reserve_alignment_words()
177
// (512K on 64bit, 1M on 32bit)
178
long reserveLimit = (i == 2) ? 1024 * 1024 : 0;
179
180
System.out.println("#### Test: ");
181
System.out.println("#### testAllocationCeiling: " + testAllocationCeiling);
182
System.out.println("#### numThreads: " + numThreads);
183
System.out.println("#### seconds: " + seconds);
184
System.out.println("#### commitLimit: " + commitLimit);
185
System.out.println("#### reserveLimit: " + reserveLimit);
186
System.out.println("#### ReclaimPolicy: " + Settings.settings().reclaimPolicy);
187
System.out.println("#### guards: " + Settings.settings().usesAllocationGuards);
188
189
MetaspaceTestContext context = new MetaspaceTestContext(commitLimit, reserveLimit);
190
MetaspaceTestOneArenaManyThreads test = new MetaspaceTestOneArenaManyThreads(context, testAllocationCeiling, numThreads, seconds);
191
192
try {
193
test.runTest();
194
} catch (RuntimeException e) {
195
System.out.println(e);
196
context.printToTTY();
197
throw e;
198
}
199
200
context.destroy();
201
202
System.out.println("#### Done. ####");
203
System.out.println("###############");
204
205
}
206
207
}
208
209
}
210
211