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