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