Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/stress/jni/jnistress005.java
41155 views
1
/*
2
* Copyright (c) 2007, 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
* jnistress005 is a class that sets up classes that do the work
26
* for the test.
27
*
28
* The Interrupter objects send interrupts to the JNIters.
29
* The GarbageGenerator objects generate garbage.
30
*
31
* sync[0] synchronizes the test cycles.
32
* sync[1] synchronizes access to exception counters.
33
* sync[2] synchronizes the cycle count update. It also insures that
34
* the interrupts do not interfere with the cycle count updates.
35
* This is because cycle count updates are used to define cycles.
36
*/
37
38
39
/*
40
* @test
41
* @key stress
42
*
43
* @summary converted from VM testbase nsk/stress/jni/jnistress005.
44
* VM testbase keywords: [stress, quick, feature_283, nonconcurrent]
45
*
46
* @library /vmTestbase
47
* /test/lib
48
* @run main/othervm/native
49
* nsk.stress.jni.jnistress005
50
* -numTHREADer 20
51
* -threadInterval 200
52
* -numInterrupter 2
53
* -interruptInterval 500
54
* -numGarbage 80
55
* -garbageInterval 5
56
* -numIteration 260
57
*/
58
59
package nsk.stress.jni;
60
61
import nsk.share.Consts;
62
import nsk.share.Debug;
63
import nsk.share.test.StressOptions;
64
65
public class jnistress005 extends Thread {
66
67
/* Maximum number of iterations. Ignored if <= 0L */
68
static long numIteration = 0L;
69
/* Timeout */
70
static long timeOut;
71
/* Number of test class objects */
72
static int numJNIter = 1;
73
/* Time between JNI stressing by the threads under test */
74
/* (in milliseconds) */
75
static int jniInterval = 10000;
76
/* Number of interrupting threads */
77
static int numInterrupter = 1;
78
/* Time between interrupts in milliseconds */
79
static int interruptInterval = 100;
80
/* Number of garbage generating threads */
81
static int numGarbage = 1;
82
/* Time between garbage allocations in milliseconds */
83
static int garbageInterval = 100;
84
// The MAX quantity of creates exceptions
85
static int jniStringAllocSize = 15000;
86
87
private static StressOptions stressOptions;
88
89
public static void main(String[] argv) {
90
try {
91
int i = 0;
92
int nJNISync = 10;
93
jnistress005 dm = null;
94
boolean errArg = false;
95
96
stressOptions = new StressOptions(argv);
97
98
/* Process arguments */
99
while (!errArg && i < argv.length) {
100
/* Number of iterations. Ignored if <= 0. */
101
if (i < argv.length && argv[i].equals("-numIteration")) {
102
++i;
103
if (i < argv.length && Character.isDigit(argv[i].charAt(0))) {
104
try {
105
numIteration = Long.parseLong(argv[i++]);
106
} catch (NumberFormatException e) {
107
errArg = true;
108
}
109
}
110
} else if (i < argv.length && argv[i].equals("-numTHREADer")) {
111
++i;
112
if (i < argv.length && Character.isDigit(argv[i].charAt(0))) {
113
try {
114
numJNIter = Integer.parseInt(argv[i++]);
115
} catch (NumberFormatException e) {
116
errArg = true;
117
}
118
if (numJNIter <= 0) errArg = true;
119
}
120
} else if (i < argv.length && argv[i].equals("-threadInterval")) {
121
++i;
122
if (i < argv.length && Character.isDigit(argv[i].charAt(0))) {
123
try {
124
jniInterval = Integer.parseInt(argv[i++]);
125
} catch (NumberFormatException e) {
126
errArg = true;
127
}
128
}
129
} else if (i < argv.length && argv[i].equals("-numInterrupter")) {
130
++i;
131
if (i < argv.length && Character.isDigit(argv[i].charAt(0))) {
132
try {
133
numInterrupter = Integer.parseInt(argv[i++]);
134
} catch (NumberFormatException e) {
135
errArg = true;
136
}
137
}
138
} else if (i < argv.length && argv[i].equals("-interruptInterval")) {
139
++i;
140
if (i < argv.length && Character.isDigit(argv[i].charAt(0))) {
141
try {
142
interruptInterval = Integer.parseInt(argv[i++]);
143
} catch (NumberFormatException e) {
144
errArg = true;
145
}
146
}
147
} else if (i < argv.length && argv[i].equals("-numGarbage")) {
148
++i;
149
if (i < argv.length && Character.isDigit(argv[i].charAt(0))) {
150
try {
151
numGarbage = Integer.parseInt(argv[i++]);
152
} catch (NumberFormatException e) {
153
errArg = true;
154
}
155
}
156
} else if (i < argv.length && argv[i].equals("-garbageInterval")) {
157
++i;
158
if (i < argv.length && Character.isDigit(argv[i].charAt(0))) {
159
try {
160
garbageInterval = Integer.parseInt(argv[i++]);
161
} catch (NumberFormatException e) {
162
errArg = true;
163
}
164
}
165
} else if (i < argv.length && argv[i].equals("-jniStringAllocSize")) {
166
++i;
167
if (i < argv.length && Character.isDigit(argv[i].charAt(0))) {
168
try {
169
jniStringAllocSize = Integer.parseInt(argv[i++]);
170
} catch (NumberFormatException e) {
171
errArg = true;
172
}
173
}
174
} else if (i < argv.length && argv[i].startsWith("-stress")) {
175
++i;
176
if (i < argv.length && Character.isDigit(argv[i].charAt(0))) {
177
++i;
178
}
179
} else System.out.println("Argument #" + i++ + " is incorrect");
180
}
181
182
numIteration *= stressOptions.getIterationsFactor();
183
numJNIter *= stressOptions.getThreadsFactor();
184
numInterrupter *= stressOptions.getThreadsFactor();
185
numGarbage *= stressOptions.getThreadsFactor();
186
timeOut = stressOptions.getTime() * 1000;
187
188
sync = new Synchronizer[10];
189
for (i = 0; i < nJNISync; i++)
190
sync[i] = new Synchronizer();
191
dm = new jnistress005(numIteration, numJNIter, jniInterval,
192
numInterrupter, interruptInterval, numGarbage, garbageInterval);
193
dm.start();
194
195
try {
196
dm.join(timeOut);
197
} catch (InterruptedException e) {
198
System.out.println("TESTER THREAD WAS INTERRUPTED");
199
System.exit(Consts.TEST_FAILED);
200
}
201
202
if (DEBUG) System.out.println("jnistress005::main(): halt!");
203
204
if (dm.isAlive()) {
205
System.out.println("TIME LIMIT EXCEEDED");
206
dm.halt();
207
if (DEBUG) System.out.println("jnistress005::main(): join!");
208
try {
209
dm.join(10000L);
210
} catch (InterruptedException e) {
211
System.out.println("TESTER THREAD WAS INTERRUPTED");
212
System.exit(Consts.TEST_FAILED);
213
}
214
} else {
215
System.out.println("TESTER THREAD FINISHED");
216
}
217
218
if (DEBUG) System.out.println("jnistress005::main(): zzzz...");
219
220
if (!JNIter005.passed())
221
System.exit(Consts.TEST_FAILED);
222
223
} catch (Throwable e) {
224
Debug.Fail(e);
225
}
226
}
227
228
jnistress005(
229
long iters,
230
int nJNI,
231
int jniInterval,
232
int nInter,
233
int iruptInterval,
234
int nGarb,
235
int garbInterval
236
) {
237
int i = 0;
238
nCycles = iters;
239
/* Should have at least one of nCycles>0 */
240
if (nCycles <= 0) nCycles = Long.MAX_VALUE;
241
jniter = new JNIter005[nJNI];
242
interval = jniInterval;
243
irupt = new Interrupter[nInter];
244
garb = new GarbageGenerator[nGarb];
245
for (i = 0; i < nJNI; i++)
246
jniter[i] = new JNIter005(sync);
247
for (i = 0; i < nInter; i++) {
248
irupt[i] = new Interrupter(jniter, sync);
249
irupt[i].setInterval(iruptInterval);
250
}
251
for (i = 0; i < nGarb; i++) {
252
garb[i] = new GarbageGenerator();
253
garb[i].setInterval(garbInterval);
254
}
255
}
256
257
public void run() {
258
try {
259
int i = 0;
260
long iCycle = 0L;
261
// JNIter005.clearCount();
262
JNIter005.clearInterruptCount();
263
for (i = 0; i < jniter.length; i++)
264
jniter[i].start();
265
266
while (JNIter005.getCount() < jniter.length) {
267
try {
268
sleep(100);
269
} catch (InterruptedException e) {
270
}
271
}
272
// JNIter005.clearCount();
273
// JNIter005.clearInterruptCount();
274
synchronized (sync[0]) {
275
sync[0].notifyAll();
276
}
277
278
for (i = 0; i < garb.length; i++)
279
garb[i].start();
280
for (i = 0; i < irupt.length; i++)
281
irupt[i].start();
282
283
if (DEBUG) System.out.println("Cycles=" + nCycles);
284
for (iCycle = 0; iCycle < nCycles && !done && JNIter005.passed(); iCycle++) {
285
System.out.print("Cycle: " + iCycle);
286
try {
287
sleep(interval);
288
} catch (InterruptedException e) {
289
}
290
synchronized (sync[1]) {
291
System.out.println(
292
" Interrupt count=" + JNIter005.getInterruptCount() +
293
" Native interrupt count=" + JNIter005.CountException);
294
}
295
// JNIter005.clearCount();
296
synchronized (sync[0]) {
297
sync[0].notifyAll();
298
}
299
int n = 0;
300
for (i = 0; i < jniter.length; i++)
301
if (jniter[i].finished()) n++;
302
if (n == jniter.length) break;
303
}
304
if (JNIter005.passed())
305
System.out.println("JNI TEST PASSED");
306
else
307
System.out.println("JNI TEST FAILED");
308
for (i = 0; i < irupt.length; i++)
309
irupt[i].halt();
310
for (i = 0; i < garb.length; i++)
311
garb[i].halt();
312
for (i = 0; i < jniter.length; i++)
313
jniter[i].halt();
314
/* Flush any waiters */
315
if (DEBUG) System.out.println("jnistress005::run(): before sync[0]");
316
synchronized (sync[0]) {
317
sync[0].notifyAll();
318
}
319
if (DEBUG) System.out.println("jnistress005::run(): after sync[0]");
320
for (i = 0; i < irupt.length; i++) {
321
try {
322
irupt[i].join();
323
} catch (InterruptedException e) {
324
}
325
}
326
if (DEBUG) System.out.println("jnistress005::run(): X");
327
for (i = 0; i < garb.length; i++) {
328
try {
329
garb[i].join();
330
} catch (InterruptedException e) {
331
}
332
}
333
if (DEBUG) System.out.println("jnistress005::run(): Y");
334
synchronized (sync[0]) {
335
sync[0].notifyAll();
336
}
337
for (i = 0; i < jniter.length; i++) {
338
try {
339
if (jniter[i].isAlive()) {
340
jniter[i].join();
341
}
342
} catch (InterruptedException e) {
343
}
344
}
345
if (DEBUG) System.out.println("jnistress005::run(): Z");
346
} catch (Throwable e) {
347
Debug.Fail(e);
348
}
349
}
350
351
public void halt() {
352
done = true;
353
}
354
355
public boolean finished() {
356
return done;
357
}
358
359
long nCycles = 0;
360
JNIter005[] jniter;
361
static Synchronizer[] sync;
362
private int interval = 100;
363
Interrupter[] irupt;
364
GarbageGenerator[] garb;
365
private boolean done = false;
366
final private static boolean DEBUG = false;
367
}
368
369
class JNIter005 extends Thread {
370
371
// The native methods for testing JNI exception calls
372
public native void except(Throwable tobj);
373
374
// public native int count();
375
static {
376
System.loadLibrary("jnistress005");
377
}
378
379
Exception nobj = new Exception();
380
static int CountException = 0;
381
static int counts = 0;
382
383
public JNIter005(Synchronizer[] aSync) {
384
sync = aSync;
385
}
386
387
public void run() {
388
try {
389
char[] Sum;
390
int iter = 0;
391
392
/* Synchronize start of work */
393
incCount();
394
synchronized (sync[0]) {
395
try {
396
sync[0].wait();
397
} catch (InterruptedException e) {
398
}
399
}
400
while (!done && pass) {
401
try {
402
/* Synchronized the JNI stressing */
403
synchronized (sync[2]) {
404
incCount();
405
}
406
synchronized (sync[0]) {
407
try {
408
sync[0].wait();
409
} catch (InterruptedException e) {
410
synchronized (sync[1]) {
411
JNIter005.incInterruptCount();
412
}
413
}
414
}
415
synchronized (sync[0]) {
416
if (CountException < jnistress005.jniStringAllocSize) {
417
try {
418
except(nobj);
419
} catch (Exception e) {
420
if ((CountException % 1000) == 0)
421
System.out.println("JAVA: " + e);
422
System.out.println("Here");
423
System.out.println("counts " + counts +
424
" CountException " + CountException);
425
426
++CountException;
427
}
428
} else
429
// if (CountException==counts) halt();
430
if (CountException == jnistress005.jniStringAllocSize) halt();
431
}
432
if (DEBUG)
433
System.out.println("We have " + activeCount() + " threads now.");
434
synchronized (this) {
435
try {
436
wait(1L);
437
} catch (InterruptedException e) {
438
throw new InterruptedException();
439
}
440
}
441
} catch (Exception e) {
442
synchronized (sync[1]) {
443
JNIter005.incInterruptCount();
444
}
445
}
446
iter++;
447
iter = iter % CASECOUNT;
448
}
449
if (DEBUG) System.out.println("JNITer::run(): done=" + done);
450
done = true;
451
if (DEBUG) System.out.println("JNITer::run(): pass=" + JNIter005.pass);
452
if (DEBUG) System.out.println("JNIter005::run(): done");
453
} catch (Throwable e) {
454
Debug.Fail(e);
455
}
456
}
457
458
public synchronized static void incCount() {
459
count++;
460
}
461
462
public static int getCount() {
463
return count;
464
}
465
466
public synchronized static void clearCount() {
467
count = 0;
468
}
469
470
private synchronized static void incInterruptCount() {
471
interruptCount++;
472
}
473
474
public static int getInterruptCount() {
475
return interruptCount;
476
}
477
478
public synchronized static void clearInterruptCount() {
479
interruptCount = 0;
480
}
481
482
public void halt() {
483
done = true;
484
}
485
486
public boolean finished() {
487
return done;
488
}
489
490
public static boolean passed() {
491
return pass;
492
}
493
494
public static void setpass(boolean value) {
495
pass = value;
496
}
497
498
Synchronizer[] sync;
499
private static int count = 0;
500
private static int interruptCount = 0;
501
private boolean done = false;
502
private static boolean pass = true;
503
final private static int CASECOUNT = 2;
504
final private static boolean DEBUG = false;
505
}
506
507