Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/gc/memory/LargePagesTest/LargePagesTest.java
41155 views
1
/*
2
* Copyright (c) 2013, 2020, 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
/*
25
* @test
26
* @key stress randomness
27
*
28
* @summary converted from VM Testbase gc/memory/LargePagesTest.
29
* VM Testbase keywords: [gc, stress, stressopt]
30
*
31
* @library /vmTestbase
32
* /test/lib
33
* @run main/othervm gc.memory.LargePagesTest.LargePagesTest noThreads=5 duration=60
34
*/
35
36
package gc.memory.LargePagesTest;
37
38
import java.io.PrintStream;
39
import nsk.share.test.LocalRandom;
40
41
/*
42
* Allocators purpose is to create pressure on the garbage collector
43
* for a certain amount of time.
44
* Note: this test moved from the "jr", the original name is func.vm.largepages.LargePagesTest
45
*/
46
47
48
/**
49
* @run main/othervm/timeout=150
50
* -XX:+UseLargePages
51
* -Xmx64m
52
* -Xms16m
53
* LargePagesTest
54
* noThreads=5 duration=60
55
* @summary heap shrink/grow test
56
*/
57
final public class LargePagesTest extends Thread {
58
59
private static int cnt;
60
private static final int SMALL_OBJECT_ALLOCATER = 1;
61
private static final int LARGE_OBJECT_ALLOCATER = 2;
62
private static final int ANY_OBJECT_ALLOCATER = 3;
63
private static final int ANY_NO_MULTIARRAYS_ALLOCATER = 4;
64
private int myType;
65
66
/** Dummy thingies to update. */
67
public LargePagesTest.Dummy[] d0;
68
/** Dummy thingies to update. */
69
public LargePagesTest.Dummy[] d1;
70
/** Dummy thingies to update. */
71
public LargePagesTest.Dummy[][] d2;
72
/** Dummy thingies to update. */
73
public LargePagesTest.Dummy[][] d3;
74
/** Dummy thingies to update. */
75
public LargePagesTest.Dummy[][][] d4;
76
/** Dummy thingies to update. */
77
public LargePagesTest.Dummy d5;
78
79
/** Time to run execute(). */
80
private long duration;
81
82
/** Boolean of progress should be printed. */
83
private boolean verbose;
84
85
private static int noThreads = 5;
86
87
/** Iterations. */
88
public long iterations = 0L;
89
90
/** Result. */
91
public boolean result = false;
92
93
private PrintStream out;
94
95
/**
96
* Creates DurAllocator.
97
* @param name Parameter
98
* @param duration Parameter
99
* @param out Parameter
100
* @param verbose Parameter
101
*/
102
LargePagesTest(String name, long duration, PrintStream out, boolean verbose) {
103
104
super(name);
105
this.duration = duration;
106
this.out = out;
107
this.verbose = verbose;
108
}
109
110
/**
111
* Print status.
112
*/
113
void describe() {
114
out.println("DurAllocator run: ");
115
out.println(" test duration: " + duration / 1000 + " seconds");
116
out.println(" number of threads: " + noThreads + " threads");
117
}
118
119
/**
120
* Allocates memory in a loop.
121
*/
122
public void run() {
123
124
long startTime = System.currentTimeMillis();
125
126
while (System.currentTimeMillis() - startTime < duration) {
127
try {
128
allocate();
129
} catch (Throwable t) {
130
out.println(getName() + " FAILED: " + t.getClass().getName() + " in iteration " + iterations + ": " + t.getMessage());
131
return;
132
}
133
iterations++;
134
if (verbose && iterations % 1000 == 0) {
135
out.print(".");
136
}
137
if (verbose && iterations % 60000 == 0) {
138
out.println(".");
139
}
140
}
141
if (verbose) {
142
out.println("");
143
}
144
145
146
long endTime = System.currentTimeMillis();
147
long runTime = endTime - startTime;
148
if (duration > runTime) {
149
out.println(getName() + " FAILED: Execution time < requested execution time.");
150
out.println(" execution time is " + runTime);
151
out.println(" requested time is " + duration);
152
} else if (iterations <= 0) {
153
out.println(getName() + " FAILED: No executions finished");
154
} else {
155
result = true;
156
}
157
}
158
159
private void allocate() {
160
for (int j = 0; j < 1000; j++) {
161
int i = 0;
162
163
switch (myType) {
164
case SMALL_OBJECT_ALLOCATER:
165
i = 5;
166
break;
167
case LARGE_OBJECT_ALLOCATER:
168
i = 1;
169
break;
170
case ANY_OBJECT_ALLOCATER:
171
i = LocalRandom.nextInt(100);
172
break;
173
case ANY_NO_MULTIARRAYS_ALLOCATER:
174
i = LocalRandom.nextInt(100);
175
if ((i >= 2) && (i <= 4)) {
176
i = 5;
177
}
178
break;
179
default:
180
break;
181
}
182
183
switch (i) {
184
case 0:
185
d0 = new LargePagesTest.Dummy[10];
186
break;
187
case 1:
188
d1 = new LargePagesTest.Dummy[1000];
189
break;
190
case 2:
191
d2 = new LargePagesTest.Dummy[10][10];
192
break;
193
case 3:
194
d3 = new LargePagesTest.Dummy[100][100];
195
break;
196
case 4:
197
d4 = new LargePagesTest.Dummy[10][10][10];
198
break;
199
default:
200
d5 = new LargePagesTest.Dummy();
201
break;
202
}
203
}
204
}
205
206
/**
207
* A Dummy class.
208
*/
209
private class Dummy {
210
/**
211
* Creates a dummy.
212
*/
213
Dummy() {
214
cnt++;
215
}
216
}
217
218
/**
219
* @param args Input arguments
220
*/
221
public static void main(String[] args) {
222
223
long duration = 30 * 60 * 1000;
224
PrintStream out = System.out;
225
boolean verbose = true;
226
227
for (int i = 0; i < args.length; i++) {
228
String noThreadsArgName = "noThreads=";
229
String executionTimeArgName = "duration=";
230
String verboseArgName = "verbose=";
231
if (args[i].indexOf(noThreadsArgName) != -1) {
232
noThreads = Integer.parseInt(args[i].substring(noThreadsArgName.length(), args[i].length()));
233
} else if (args[i].indexOf(executionTimeArgName) != -1) {
234
duration = 1000 * Long.parseLong(args[i].substring(executionTimeArgName.length(), args[i].length()));
235
} else if (args[i].indexOf(verboseArgName) != -1) {
236
verbose = Boolean.parseBoolean(args[i].substring(verboseArgName.length(), args[i].length()));
237
} else {
238
System.out.println("ERROR: Unknown argument string: " + args[i]);
239
System.exit(-1);
240
}
241
}
242
243
// Please don't...
244
if (noThreads <= 0) {
245
noThreads = 1;
246
}
247
248
LargePagesTest[] runners = new LargePagesTest[noThreads];
249
250
for (int i = 0; i < noThreads; i++) {
251
runners[i] = new LargePagesTest("DurAllocator " + i, duration, out, verbose);
252
}
253
254
runners[0].describe();
255
256
for (int i = 0; i < noThreads; i++) {
257
runners[i].start();
258
}
259
260
for (int i = 0; i < noThreads; i++) {
261
try {
262
runners[i].join(duration + 10 * 60 * 1000);
263
} catch (InterruptedException e) {
264
out.println(runners[i].getName() + " FAILED: " + e.getClass().getName() + " " + e.getMessage());
265
System.exit(-1);
266
}
267
}
268
269
for (int i = 0; i < noThreads; i++) {
270
if (!runners[i].result) {
271
out.println(runners[i].getName() + " FAILED: status=" + runners[i].result);
272
System.exit(-1);
273
}
274
}
275
276
if (verbose) {
277
out.println();
278
}
279
280
out.print("DurAllocator PASSED with (");
281
for (int i = 0; i < noThreads; i++) {
282
out.print("" + runners[i].iterations + (i + 1 < noThreads ? "+" : ""));
283
}
284
out.println(") iterations.");
285
// System.exit(90); // use to return 90 as indication of success
286
}
287
288
}
289
290