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