Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/gc/gctests/gctest01/gctest01.java
41155 views
1
/*
2
* Copyright (c) 2002, 2021, 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
/*
26
* @test
27
* @key randomness
28
*
29
* @summary converted from VM Testbase gc/gctests/gctest01.
30
* VM Testbase keywords: [gc]
31
*
32
* @library /vmTestbase
33
* /test/lib
34
* @run main/othervm gc.gctests.gctest01.gctest01 100 10
35
*/
36
37
package gc.gctests.gctest01;
38
39
import nsk.share.test.*;
40
import nsk.share.log.*;
41
import nsk.share.gc.*;
42
import nsk.share.TestBug;
43
44
//import RusageStruct;
45
46
/* -- stress testing
47
create 20 memory evil threads requesting to allocate
48
the object of sizes from 8 to ( 2 ^ 19).
49
The live time of objects is very short.
50
Memory evil thread exits the first time memory allocation fails.
51
*/
52
53
class ThreadTracker {
54
static int threadCount = 0;
55
56
static synchronized int getThreadCount() {
57
return threadCount;
58
}
59
60
static synchronized void setThreadCount(int count) {
61
threadCount = count;
62
}
63
64
static synchronized void incr() {
65
threadCount++;
66
}
67
68
static synchronized void decr() {
69
threadCount--;
70
}
71
}
72
73
class PopulationException extends Exception {
74
}
75
76
class Person {
77
String name;
78
int ssid;
79
int age;
80
int buf[];
81
int bufsz;
82
static int populationLimit;
83
static int currentPopulation;
84
85
public Person(String n, int ssid, int age, int bufsz) throws PopulationException {
86
this.incr();
87
if (this.getPopulation() > this.getPopulationLimit()) {
88
throw new PopulationException();
89
}
90
name = n;
91
this.ssid = ssid;
92
this.age = age;
93
if ( bufsz > 0 ) {
94
this.bufsz = bufsz;
95
this.buf = new int[bufsz];
96
}
97
}
98
99
static synchronized void incr() {
100
currentPopulation++;
101
}
102
103
static synchronized int getPopulation() {
104
return currentPopulation;
105
}
106
107
static synchronized void setPopulation(int census) {
108
currentPopulation = census;
109
}
110
111
static synchronized void setPopulationLimit(int limit) {
112
populationLimit = limit;
113
}
114
115
static synchronized int getPopulationLimit() {
116
return populationLimit;
117
}
118
}
119
120
121
122
// create 20 memory evil threads requesting to allocate
123
// the object of sizes from 8 to ( 2 ^ 19).
124
// The live time of objects is very short.
125
public class gctest01 extends TestBase {
126
private String[] args;
127
128
public gctest01(String[] args) {
129
setArgs(args);
130
}
131
132
class memevil extends Thread {
133
int sum;
134
int bufsz = 64;
135
136
public memevil(int bufsz) {
137
ThreadTracker.incr();
138
sum = 0;
139
this.bufsz = bufsz;
140
141
}
142
143
/* Person object is live short, it will be garbage after
144
control returns
145
*/
146
private boolean doit() {
147
try {
148
Person p = new Person("Duke", 100, 100, bufsz);
149
} catch (OutOfMemoryError e ) {
150
log.info(getName() + ": Out of Memory");
151
return false; //should free up some memory
152
} catch (PopulationException e) {
153
//we've reached the limit, so stop
154
return false;
155
}
156
return true;
157
}
158
159
public void run() {
160
while ( doit() ) {
161
if ( LocalRandom.random() > 0.6668) {
162
try {
163
sleep(10); // to be nice
164
}
165
catch (InterruptedException e) {}
166
}
167
}
168
//must be done, decrement the thread count
169
ThreadTracker.decr();
170
}
171
}
172
173
class escaper extends Thread {
174
public void run() {
175
while ( ThreadTracker.getThreadCount() > 0 ) {
176
int buf[] = new int[32];
177
try
178
{
179
Thread.currentThread().sleep(1000);
180
} catch (InterruptedException e) {
181
}
182
// log.info("Is the sun rising?");
183
}
184
}
185
}
186
187
188
public void run() {
189
int bufsz = 8;
190
int i = 3;
191
int peopleLimit = 1000;
192
String usage = "usage: gctest01 [NumberOfObjects [Iterations] ] ]";
193
int loops;
194
int LOOPCOUNT = 10;
195
196
if (args.length > 0) {
197
try {
198
peopleLimit = Integer.valueOf(args[0]).intValue();
199
} catch (NumberFormatException e) {
200
log.info(usage);
201
throw new TestBug("Bad input to gctest01." +
202
" Expected integer, got: ->" + args[0] + "<-", e);
203
}
204
}
205
206
if (args.length > 1 ) {
207
try {
208
LOOPCOUNT = Integer.valueOf(args[1]).intValue();
209
} catch (NumberFormatException e) {
210
log.error(usage);
211
throw new TestBug("Bad input to gctest01." +
212
" Expected int, got: ->" + args[1] + "<-", e);
213
}
214
215
}
216
217
double before = 0.0;
218
double after;
219
220
Person.setPopulationLimit(peopleLimit);
221
222
for (loops = 0; loops < LOOPCOUNT; loops++) {
223
Person.setPopulation(0);
224
escaper you = new escaper();
225
you.setName("Escaper");
226
you.start();
227
i = 3;
228
bufsz = 8;
229
while ( i < 20 )
230
{
231
memevil me = new memevil(bufsz);
232
me.setName("Memevil" + bufsz);
233
bufsz = 2*bufsz;
234
me.start();
235
i++;
236
Thread.currentThread().yield();
237
}
238
try
239
{
240
you.join();
241
}
242
catch (InterruptedException e)
243
{
244
e.printStackTrace();
245
}
246
} // end of loops
247
log.info("Test passed.");
248
249
}
250
251
public void setArgs(String[] args) {
252
this.args = args;
253
}
254
255
public static void main(String args[]) {
256
GC.runTest(new gctest01(args), args);
257
}
258
}
259
260