Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/strace005.java
41155 views
1
/*
2
* Copyright (c) 2003, 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
* @test
26
* @key stress
27
*
28
* @summary converted from VM testbase nsk/stress/strace/strace005.
29
* VM testbase keywords: [stress, strace]
30
* VM testbase readme:
31
* DESCRIPTION
32
* The test checks up java.lang.Thread.getStackTrace() method for many threads,
33
* that recursively invoke pure java and native methods by turns in running
34
* mode ("alive" stack).
35
* The test fails if:
36
* - amount of stack trace elements is more than depth of recursion plus
37
* four elements corresponding to invocations of Thread.run(), Thread.wait(),
38
* Thread.exit(), Thread.yield() and ThreadGroup.remove() methods;
39
* - there is at least one element corresponding to invocation of unexpected
40
* method.
41
* This test is almost the same as nsk.stress.strace.strace001 and
42
* nsk.stress.strace.strace003 except for the recursive methods are
43
* pure java and native one.
44
* COMMENTS
45
* Below assertion is revealed on engineer's build. It is needed to check
46
* on a promoted build.
47
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
48
* waiting for all threads started ...
49
* Unexpected Signal : 11 occurred at PC=0xFDBB7820
50
* Function=[Unknown. Nearest: SUNWprivate_1.1+0x3B7820]
51
* Library=java/vitp/jdk/4593133/solaris-sparc/jre/lib/sparc/client/libjvm.so
52
* Current Java thread:
53
* at nsk.stress.strace.strace005Thread.recursiveMethod2(Native Method)
54
* at nsk.stress.strace.strace005Thread.recursiveMethod1(strace005.java:285)
55
* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
56
* at nsk.stress.strace.strace005Thread.recursiveMethod2(Native Method)
57
* at nsk.stress.strace.strace005Thread.recursiveMethod1(strace005.java:285)
58
* at nsk.stress.strace.strace005Thread.recursiveMethod2(Native Method)
59
* Dynamic libraries:
60
* 0x10000 jdk/4593133/solaris-sparc/bin/java
61
* 0xff350000 /usr/lib/libthread.so.1
62
* 0xff390000 /usr/lib/libdl.so.1
63
* 0xff200000 /usr/lib/libc.so.1
64
* 0xff330000 /usr/platform/SUNW,Ultra-60/lib/libc_psr.so.1
65
* 0xfd800000 java/vitp/jdk/4593133/solaris-sparc/jre/lib/sparc/client/libjvm.so
66
* 0xff2d0000 /usr/lib/libCrun.so.1
67
* 0xff1d0000 /usr/lib/libsocket.so.1
68
* 0xff100000 /usr/lib/libnsl.so.1
69
* 0xff0d0000 /usr/lib/libm.so.1
70
* 0xff0b0000 /usr/lib/libsched.so.1
71
* 0xff300000 /usr/lib/libw.so.1
72
* 0xff090000 /usr/lib/libmp.so.2
73
* 0xff050000 java/vitp/jdk/4593133/solaris-sparc/jre/lib/sparc/native_threads/libhpi.so
74
* 0xfd7d0000 java/vitp/jdk/4593133/solaris-sparc/jre/lib/sparc/libverify.so
75
* 0xfd790000 java/vitp/jdk/4593133/solaris-sparc/jre/lib/sparc/libjava.so
76
* 0xfe7e0000 java/vitp/jdk/4593133/solaris-sparc/jre/lib/sparc/libzip.so
77
* 0xfc6e0000 java/vitp/tests/4593133/src/libstrace005.so
78
* Heap at VM Abort:
79
* Heap
80
* def new generation total 2112K, used 336K [0xf1800000, 0xf1a20000, 0xf1f10000)
81
* eden space 2048K, 16% used [0xf1800000, 0xf1854300, 0xf1a00000)
82
* from space 64K, 0% used [0xf1a00000, 0xf1a00000, 0xf1a10000)
83
* to space 64K, 0% used [0xf1a10000, 0xf1a10000, 0xf1a20000)
84
* tenured generation total 1408K, used 0K [0xf1f10000, 0xf2070000, 0xf5800000)
85
* the space 1408K, 0% used [0xf1f10000, 0xf1f10000, 0xf1f10200, 0xf2070000)
86
* compacting perm gen total 4096K, used 1020K [0xf5800000, 0xf5c00000, 0xf9800000)
87
* the space 4096K, 24% used [0xf5800000, 0xf58ff028, 0xf58ff200, 0xf5c00000)
88
* Local Time = Fri Apr 25 18:09:16 2003
89
* Elapsed Time = 13
90
* #
91
* # HotSpot Virtual Machine Error : 11
92
* # Error ID : src/share/vm/runtime/os.cpp, 753 [ Patched ]
93
* # Please report this error at
94
* # http://java.sun.com/cgi-bin/bugreport.cgi
95
* #
96
* # Java VM: Java HotSpot(TM) Client VM (1.4.1-internal-debug mixed mode)
97
* #
98
* # An error report file has been saved as hs_err_pid16847.log.
99
* # Please refer to the file for further information.
100
* #
101
* Dumping core....
102
* Abort
103
* Finished at: Fri Apr 25 18:09:17 NSK 2003
104
*
105
* @library /vmTestbase
106
* /test/lib
107
* @run main/othervm/native nsk.stress.strace.strace005
108
*/
109
110
package nsk.stress.strace;
111
112
import nsk.share.ArgumentParser;
113
import nsk.share.Failure;
114
import nsk.share.Log;
115
116
import java.io.PrintStream;
117
118
/**
119
* The test checks up <code>java.lang.Thread.getStackTrace()</code> method for many threads,
120
* that recursively invoke pure java and native methods by turns in running mode
121
* ("alive" stack).
122
* <p>
123
* <p>The test creates <code>THRD_COUNT</code> instances of <code>strace005Thread</code>
124
* class, tries to get their stack traces and checks up that returned array contains
125
* correct stack frames. Each stack frame must be corresponded to one of the following
126
* methods defined by the <code>EXPECTED_METHODS</code> array.</p>
127
* <p>These checking are performed <code>REPEAT_COUNT</code> times.</p>
128
*/
129
public class strace005 {
130
131
static final int DEPTH = 500;
132
static final int THRD_COUNT = 100;
133
static final int REPEAT_COUNT = 10;
134
static final String[] EXPECTED_METHODS = {
135
"java.lang.System.arraycopy",
136
"java.lang.Object.wait",
137
"java.lang.Thread.exit",
138
"java.lang.Thread.yield",
139
"java.lang.ThreadGroup.remove",
140
"java.lang.ThreadGroup.threadTerminated",
141
"nsk.stress.strace.strace005Thread.run",
142
"nsk.stress.strace.strace005Thread.recursiveMethod1",
143
"nsk.stress.strace.strace005Thread.recursiveMethod2"
144
};
145
146
147
static volatile boolean isLocked = false;
148
static PrintStream out;
149
static long waitTime = 2;
150
151
static Object waitStart = new Object();
152
153
static strace005Thread[] threads;
154
static StackTraceElement[][] snapshots = new StackTraceElement[THRD_COUNT][];
155
static Log log;
156
157
volatile int achivedCount = 0;
158
159
public static void main(String[] args) {
160
out = System.out;
161
int exitCode = run(args);
162
System.exit(exitCode + 95);
163
}
164
165
public static int run(String[] args) {
166
ArgumentParser argHandler = new ArgumentParser(args);
167
log = new Log(out, argHandler);
168
waitTime = argHandler.getWaitTime() * 60000;
169
170
strace005 test = new strace005();
171
boolean res = true;
172
173
for (int j = 0; j < REPEAT_COUNT; j++) {
174
test.startThreads();
175
176
if (!test.makeSnapshot(j + 1)) res = false;
177
178
display("waiting for threads finished\n");
179
test.finishThreads();
180
}
181
182
if (!res) {
183
complain("***>>>Test failed<<<***");
184
return 2;
185
}
186
187
return 0;
188
}
189
190
void startThreads() {
191
threads = new strace005Thread[THRD_COUNT];
192
achivedCount = 0;
193
194
String tmp_name;
195
for (int i = 0; i < THRD_COUNT; i++) {
196
tmp_name = "strace005Thread" + Integer.toString(i);
197
threads[i] = new strace005Thread(this, tmp_name);
198
// threads[i].setPriority(Thread.MIN_PRIORITY);
199
}
200
201
for (int i = 0; i < THRD_COUNT; i++) {
202
threads[i].start();
203
}
204
205
waitFor("all threads started ...");
206
synchronized (waitStart) {
207
isLocked = true;
208
waitStart.notifyAll();
209
}
210
try {
211
Thread.yield();
212
Thread.sleep(1);
213
} catch (InterruptedException e) {
214
complain("" + e);
215
}
216
}
217
218
void waitFor(String msg) {
219
if (msg.length() > 0)
220
display("waiting for " + msg);
221
222
while (achivedCount < THRD_COUNT) {
223
try {
224
Thread.sleep(1);
225
} catch (InterruptedException e) {
226
complain("" + e);
227
}
228
}
229
achivedCount = 0;
230
}
231
232
boolean makeSnapshot(int repeat_number) {
233
// wait for native resolution completed (all threads have finished recursiveMethod2)
234
boolean isNativeResolved = false;
235
while (!isNativeResolved) {
236
try {
237
isNativeResolved = true;
238
for (int i = 0; i < threads.length; ++i)
239
if (!threads[i].isNativeResolved)
240
isNativeResolved = false;
241
Thread.sleep(20);
242
} catch (InterruptedException e) {
243
throw new Error(e);
244
}
245
}
246
247
for (int i = 0; i < threads.length; i++) {
248
snapshots[i] = threads[i].getStackTrace();
249
}
250
251
return checkTraces(repeat_number);
252
}
253
254
boolean checkTraces(int repeat_number) {
255
StackTraceElement[] elements;
256
257
boolean res = true;
258
display(">>> snapshot " + repeat_number);
259
int expectedCount = DEPTH + 1;
260
261
for (int i = 0; i < threads.length; i++) {
262
elements = snapshots[i];
263
264
if (elements == null || elements.length == 0)
265
continue;
266
267
if (elements.length > 0) {
268
display("\tchecking " + threads[i].getName()
269
+ "(trace elements: " + elements.length + ")");
270
}
271
272
if (elements.length > expectedCount) {
273
complain(threads[i].getName() + ">Contains more then " +
274
+expectedCount + " elements");
275
}
276
277
for (int j = 0; j < elements.length; j++) {
278
if (!checkElement(elements[j])) {
279
complain(threads[i].getName() + ">Unexpected method name: "
280
+ elements[j].getMethodName());
281
complain("\tat " + j + " position");
282
if (elements[j].isNativeMethod()) {
283
complain("\tline number: (native method)");
284
complain("\tclass name: " + elements[j].getClassName());
285
} else {
286
complain("\tline number: " + elements[j].getLineNumber());
287
complain("\tclass name: " + elements[j].getClassName());
288
complain("\tfile name: " + elements[j].getFileName());
289
}
290
res = false;
291
}
292
}
293
}
294
return res;
295
}
296
297
boolean checkElement(StackTraceElement element) {
298
String name = element.getClassName() + "." + element.getMethodName();
299
for (int i = 0; i < EXPECTED_METHODS.length; i++) {
300
if (EXPECTED_METHODS[i].compareTo(name) == 0)
301
return true;
302
}
303
return false;
304
}
305
306
void finishThreads() {
307
try {
308
for (int i = 0; i < threads.length; i++) {
309
if (threads[i].isAlive())
310
threads[i].join(waitTime / THRD_COUNT);
311
}
312
} catch (InterruptedException e) {
313
complain("" + e);
314
}
315
isLocked = false;
316
}
317
318
static void display(String message) {
319
log.display(message);
320
}
321
322
static void complain(String message) {
323
log.complain(message);
324
}
325
326
}
327
328
/**
329
* The test creates many instances of <code>strace005Thread</code> class and tries
330
* to get their stack traces.
331
*/
332
class strace005Thread extends Thread {
333
334
private int currentDepth = 0;
335
public boolean isNativeResolved = false;
336
337
strace005 test;
338
339
static {
340
try {
341
System.loadLibrary("strace005");
342
} catch (UnsatisfiedLinkError e) {
343
System.err.println("Could not load strace005 library");
344
System.err.println("java.library.path:"
345
+ System.getProperty("java.library.path"));
346
throw e;
347
}
348
}
349
350
strace005Thread(strace005 test, String name) {
351
this.test = test;
352
setName(name);
353
}
354
355
public void run() {
356
357
recursiveMethod1();
358
359
}
360
361
void recursiveMethod1() {
362
363
currentDepth++;
364
365
if (currentDepth == 1) {
366
synchronized (test) {
367
test.achivedCount++;
368
}
369
370
int alltime = 0;
371
while (!strace005.isLocked) {
372
synchronized (test) {
373
try {
374
test.wait(1);
375
alltime++;
376
} catch (InterruptedException e) {
377
strace005.complain("" + e);
378
}
379
if (alltime > strace005.waitTime) {
380
throw new Failure("out of wait time");
381
}
382
}
383
}
384
} else if (currentDepth > 1 && !isNativeResolved)
385
isNativeResolved = true;
386
387
if (strace005.DEPTH - currentDepth > 0) {
388
try {
389
Thread.yield();
390
recursiveMethod2();
391
} catch (StackOverflowError e) {
392
// ignore this exception
393
}
394
}
395
396
currentDepth--;
397
}
398
399
native void recursiveMethod2();
400
}
401
402