Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/stress/jni/jnistress007.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
* jnistress007 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/jnistress007.
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.jnistress007
50
* -numTHREADer 10
51
* -threadInterval 20
52
* -numInterrupter 2
53
* -interruptInterval 50
54
* -numGarbage 80
55
* -garbageInterval 5
56
* -numIteration 130
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 jnistress007 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 = 1000;
80
/* Number of garbage generating threads */
81
static int numGarbage = 1;
82
/* Time between garbage allocations in milliseconds */
83
static int garbageInterval = 1000;
84
// The MAX quantity of monitor's call
85
static int jniStringAllocSize = 300;
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
jnistress007 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 jnistress007(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("jnistress007::main(): halt!");
203
204
if (dm.isAlive()) {
205
System.out.println("TIME LIMIT EXCEEDED");
206
dm.halt();
207
if (DEBUG) System.out.println("jnistress007::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("jnistress007::main(): zzzz...");
219
220
if (JNIter007.passed())
221
System.exit(Consts.TEST_FAILED);
222
223
} catch (Throwable e) {
224
Debug.Fail(e);
225
}
226
}
227
228
jnistress007(
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 JNIter007[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 JNIter007(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
JNIter007.clearCount();
262
JNIter007.clearInterruptCount();
263
for (i = 0; i < jniter.length; i++)
264
jniter[i].start();
265
266
while (JNIter007.getCount() < jniter.length) {
267
try {
268
sleep(100);
269
} catch (InterruptedException e) {
270
}
271
}
272
JNIter007.clearCount();
273
// JNIter007.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 && !JNIter007.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("\tInterrupt count=" +
292
JNIter007.getInterruptCount());
293
}
294
JNIter007.clearCount();
295
synchronized (sync[0]) {
296
sync[0].notifyAll();
297
}
298
int n = 0;
299
for (i = 0; i < jniter.length; i++)
300
if (jniter[i].finished()) n++;
301
if (n == jniter.length) break;
302
}
303
for (i = 0; i < irupt.length; i++)
304
irupt[i].halt();
305
for (i = 0; i < garb.length; i++)
306
garb[i].halt();
307
for (i = 0; i < jniter.length; i++)
308
jniter[i].halt();
309
/* Flush any waiters */
310
if (DEBUG) System.out.println("jnistress007::run(): before sync[0]");
311
synchronized (sync[0]) {
312
sync[0].notifyAll();
313
}
314
if (DEBUG) System.out.println("jnistress007::run(): after sync[0]");
315
for (i = 0; i < irupt.length; i++) {
316
try {
317
irupt[i].join();
318
} catch (InterruptedException e) {
319
}
320
}
321
if (DEBUG) System.out.println("jnistress007::run(): X");
322
for (i = 0; i < garb.length; i++) {
323
try {
324
garb[i].join();
325
} catch (InterruptedException e) {
326
}
327
}
328
if (DEBUG) System.out.println("jnistress007::run(): Y");
329
synchronized (sync[0]) {
330
sync[0].notifyAll();
331
}
332
for (i = 0; i < jniter.length; i++) {
333
try {
334
jniter[i].join();
335
} catch (InterruptedException e) {
336
}
337
}
338
if (JNIter007.passed()) {
339
System.out.println("JNI TEST PASSED");
340
} else {
341
System.out.println("JNI TEST FAILED");
342
}
343
if (DEBUG) System.out.println("jnistress007::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
JNIter007[] 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 JNIter007 extends Thread {
368
369
// The native methods for testing JNI monitors calls
370
public native void incCount(String name);
371
372
static {
373
System.loadLibrary("jnistress007");
374
}
375
376
public static int nativeCount, javaCount = 0;
377
378
public JNIter007(Synchronizer[] aSync) {
379
sync = aSync;
380
}
381
382
public void run() {
383
try {
384
int iter = 0;
385
386
/* Synchronize start of work */
387
incCount();
388
synchronized (sync[0]) {
389
try {
390
sync[0].wait();
391
} catch (InterruptedException e) {
392
}
393
}
394
while (!done && !pass) {
395
try {
396
/* Synchronized the JNI stressing */
397
synchronized (sync[2]) {
398
incCount();
399
}
400
synchronized (sync[0]) {
401
try {
402
sync[0].wait();
403
} catch (InterruptedException e) {
404
synchronized (sync[1]) {
405
JNIter007.incInterruptCount();
406
}
407
}
408
}
409
synchronized (sync[0]) {
410
try {
411
if ((javaCount < jnistress007.jniStringAllocSize) &&
412
(nativeCount < jnistress007.jniStringAllocSize)) {
413
javaCount++;
414
incCount(getName());
415
if ((javaCount % 1000) == 0)
416
System.out.println("Count in java " +
417
getName() + " " + javaCount);
418
} else if (javaCount == nativeCount) {
419
done = true;
420
} else {
421
System.out.println("Native: " + nativeCount +
422
"\t" + "Java: " + javaCount);
423
pass = true;
424
}
425
} catch (Exception e) {
426
System.out.println("Error: " + e);
427
}
428
}
429
if (DEBUG)
430
System.out.println("We have " + activeCount() + " threads now.");
431
synchronized (this) {
432
try {
433
wait(1L);
434
} catch (InterruptedException e) {
435
throw new InterruptedException();
436
}
437
}
438
} catch (Exception e) {
439
synchronized (sync[1]) {
440
JNIter007.incInterruptCount();
441
}
442
}
443
iter++;
444
iter = iter % CASECOUNT;
445
}
446
if (DEBUG) System.out.println("JNITer::run(): done=" + done);
447
done = true;
448
if (DEBUG) System.out.println("JNITer::run(): pass=" + JNIter007.pass);
449
if (DEBUG) System.out.println("JNIter::run(): done");
450
} catch (Throwable e) {
451
Debug.Fail(e);
452
}
453
}
454
455
private synchronized static void incCount() {
456
count++;
457
}
458
459
public static int getCount() {
460
return count;
461
}
462
463
public synchronized static void clearCount() {
464
count = 0;
465
}
466
467
private synchronized static void incInterruptCount() {
468
interruptCount++;
469
}
470
471
public static int getInterruptCount() {
472
return interruptCount;
473
}
474
475
public synchronized static void clearInterruptCount() {
476
interruptCount = 0;
477
}
478
479
public void halt() {
480
done = true;
481
}
482
483
public boolean finished() {
484
return done;
485
}
486
487
public static boolean passed() {
488
return pass;
489
}
490
491
Synchronizer[] sync;
492
private static int count = 0;
493
private static int interruptCount = 0;
494
private boolean done = false;
495
private static boolean pass = false;
496
final private static int CASECOUNT = 2;
497
final private static boolean DEBUG = false;
498
}
499
500