Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/stress/strace/strace003.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
/*
26
* @test
27
* @key stress
28
*
29
* @summary converted from VM testbase nsk/stress/strace/strace003.
30
* VM testbase keywords: [stress, strace]
31
* VM testbase readme:
32
* DESCRIPTION
33
* The test checks up java.lang.Thread.getStackTrace() method for many threads,
34
* that recursively invoke a native method in running 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 except for
42
* the recursive method is a native one.
43
* COMMENTS
44
* Below assertion is revealed on engineer's build. It is needed to check
45
* on a promoted build.
46
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
47
* Started at: Fri Apr 25 15:47:13 NSK 2003
48
* waiting for all threads started ...
49
* >>> snapshot 1
50
* checking strace003Thread0(trace elements: 2)
51
* checking strace003Thread1(trace elements: 2)
52
* checking strace003Thread2(trace elements: 3)
53
* checking strace003Thread3(trace elements: 2)
54
* checking strace003Thread4(trace elements: 2)
55
* checking strace003Thread5(trace elements: 2)
56
* checking strace003Thread6(trace elements: 3)
57
* checking strace003Thread7(trace elements: 2)
58
* # To suppress the following error report, specify this argument
59
* # after -XX: or in .hotspotrc: SuppressErrorAt=/jniHandles.hpp:157
60
* #
61
* # HotSpot Virtual Machine Error, assertion failure
62
* # Please report this error at
63
* # http://java.sun.com/cgi-bin/bugreport.cgi
64
* #
65
* # Java VM: Java HotSpot(TM) Client VM (1.4.1-internal-debug mixed mode)
66
* #
67
* # assert(result != ((oop)::badJNIHandleVal), "Pointing to zapped jni handle area")
68
* #
69
* # Error ID: src/share/vm/runtime/jniHandles.hpp, 157 [ Patched ]
70
* #
71
* # Problematic Thread: prio=5 tid=0x001b99e8 nid=0xbf runnable
72
* #
73
* Heap at VM Abort:
74
* Heap
75
* def new generation total 2112K, used 300K [0xf1800000, 0xf1a20000, 0xf1f10000)
76
* eden space 2048K, 14% used [0xf1800000, 0xf184b358, 0xf1a00000)
77
* from space 64K, 0% used [0xf1a00000, 0xf1a00000, 0xf1a10000)
78
* to space 64K, 0% used [0xf1a10000, 0xf1a10000, 0xf1a20000)
79
* tenured generation total 1408K, used 0K [0xf1f10000, 0xf2070000, 0xf5800000)
80
* the space 1408K, 0% used [0xf1f10000, 0xf1f10000, 0xf1f10200, 0xf2070000)
81
* compacting perm gen total 4096K, used 1024K [0xf5800000, 0xf5c00000, 0xf9800000)
82
* the space 4096K, 25% used [0xf5800000, 0xf5900240, 0xf5900400, 0xf5c00000)
83
* Dumping core....
84
* Abort
85
* Finished at: Fri Apr 25 15:48:10 NSK 2003
86
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
87
*
88
* @library /vmTestbase
89
* /test/lib
90
* @run main/othervm/native nsk.stress.strace.strace003
91
*/
92
93
package nsk.stress.strace;
94
95
import nsk.share.ArgumentParser;
96
import nsk.share.Log;
97
98
import java.io.PrintStream;
99
100
/**
101
* The test check up <code>java.lang.Thread.getStackTrace()</code> method for many threads,
102
* that recursively invoke a native method in running mode ("alive" stack).
103
* <p>
104
* <p>The test creates <code>THRD_COUNT</code> instances of <code>strace003Thread</code>
105
* class, tries to get their stack traces and checks up that returned array contains
106
* correct stack frames. Each stack frame must be corresponded to one of the following
107
* methods defined by the <code>EXPECTED_METHODS</code> array.</p>
108
* <p>These checking are performed <code>REPEAT_COUNT</code> times.</p>
109
*/
110
public class strace003 {
111
112
static final int DEPTH = 100;
113
static final int THRD_COUNT = 100;
114
static final int REPEAT_COUNT = 10;
115
static final String[] EXPECTED_METHODS = {
116
"java.lang.System.arraycopy",
117
"java.lang.Object.wait",
118
"java.lang.Thread.exit",
119
"java.lang.Thread.yield",
120
"java.lang.ThreadGroup.remove",
121
"java.lang.ThreadGroup.threadTerminated",
122
"nsk.stress.strace.strace003Thread.run",
123
"nsk.stress.strace.strace003Thread.recursiveMethod"
124
};
125
126
127
static volatile boolean isLocked = false;
128
static PrintStream out;
129
static long waitTime = 2;
130
131
static Object waitStart = new Object();
132
133
static strace003Thread[] threads;
134
static StackTraceElement[][] snapshots = new StackTraceElement[THRD_COUNT][];
135
static Log log;
136
137
volatile int achivedCount = 0;
138
139
public static void main(String[] args) {
140
out = System.out;
141
int exitCode = run(args);
142
System.exit(exitCode + 95);
143
}
144
145
public static int run(String[] args) {
146
ArgumentParser argHandler = new ArgumentParser(args);
147
log = new Log(out, argHandler);
148
waitTime = argHandler.getWaitTime() * 60000;
149
150
strace003 test = new strace003();
151
boolean res = true;
152
153
for (int j = 0; j < REPEAT_COUNT; j++) {
154
test.startThreads();
155
156
if (!test.makeSnapshot(j + 1)) res = false;
157
158
display("waiting for threads finished\n");
159
test.finishThreads();
160
}
161
162
if (!res) {
163
complain("***>>>Test failed<<<***");
164
return 2;
165
}
166
167
return 0;
168
}
169
170
void startThreads() {
171
threads = new strace003Thread[THRD_COUNT];
172
achivedCount = 0;
173
174
String tmp_name;
175
for (int i = 0; i < THRD_COUNT; i++) {
176
tmp_name = "strace003Thread" + Integer.toString(i);
177
threads[i] = new strace003Thread(this, tmp_name);
178
}
179
180
for (int i = 0; i < THRD_COUNT; i++) {
181
threads[i].start();
182
}
183
184
waitFor("all threads started ...");
185
synchronized (waitStart) {
186
isLocked = true;
187
waitStart.notifyAll();
188
}
189
try {
190
Thread.yield();
191
Thread.sleep(1);
192
} catch (InterruptedException e) {
193
complain("" + e);
194
}
195
}
196
197
void waitFor(String msg) {
198
if (msg.length() > 0)
199
display("waiting for " + msg);
200
201
while (achivedCount < THRD_COUNT) {
202
try {
203
Thread.sleep(1);
204
} catch (InterruptedException e) {
205
complain("" + e);
206
}
207
}
208
achivedCount = 0;
209
}
210
211
boolean makeSnapshot(int repeat_number) {
212
213
for (int i = 0; i < threads.length; i++) {
214
snapshots[i] = threads[i].getStackTrace();
215
}
216
217
return checkTraces(repeat_number);
218
}
219
220
boolean checkTraces(int repeat_number) {
221
StackTraceElement[] elements;
222
223
boolean res = true;
224
display(">>> snapshot " + repeat_number);
225
int expectedCount = DEPTH + 1;
226
227
for (int i = 0; i < threads.length; i++) {
228
elements = snapshots[i];
229
230
if (elements == null)
231
continue;
232
233
if (elements.length == 0)
234
continue;
235
236
if (elements.length > 0) {
237
display("\tchecking " + threads[i].getName()
238
+ "(trace elements: " + elements.length + ")");
239
}
240
241
if (elements.length > expectedCount) {
242
complain(threads[i].getName() + ">Contains more then " +
243
+expectedCount + " elements");
244
}
245
246
for (int j = 0; j < elements.length; j++) {
247
if (!checkElement(elements[j])) {
248
complain(threads[i].getName() + ">Unexpected method name: "
249
+ elements[j].getMethodName());
250
complain("\tat " + j + " position");
251
if (elements[j].isNativeMethod()) {
252
complain("\tline number: (native method)");
253
complain("\tclass name: " + elements[j].getClassName());
254
} else {
255
complain("\tline number: " + elements[j].getLineNumber());
256
complain("\tclass name: " + elements[j].getClassName());
257
complain("\tfile name: " + elements[j].getFileName());
258
}
259
res = false;
260
}
261
}
262
}
263
return res;
264
}
265
266
boolean checkElement(StackTraceElement element) {
267
String name = element.getClassName() + "." + element.getMethodName();
268
for (int i = 0; i < EXPECTED_METHODS.length; i++) {
269
if (EXPECTED_METHODS[i].compareTo(name) == 0)
270
return true;
271
}
272
return false;
273
}
274
275
void finishThreads() {
276
try {
277
for (int i = 0; i < threads.length; i++) {
278
if (threads[i].isAlive())
279
threads[i].join(waitTime / THRD_COUNT);
280
}
281
} catch (InterruptedException e) {
282
complain("" + e);
283
}
284
isLocked = false;
285
}
286
287
static void display(String message) {
288
log.display(message);
289
}
290
291
static void complain(String message) {
292
log.complain(message);
293
}
294
295
}
296
297
class strace003Thread extends Thread {
298
299
private int currentDepth = 0;
300
301
strace003 test;
302
303
static {
304
try {
305
System.loadLibrary("strace003");
306
} catch (UnsatisfiedLinkError e) {
307
System.err.println("Could not load strace003 library");
308
System.err.println("java.library.path:"
309
+ System.getProperty("java.library.path"));
310
throw e;
311
}
312
}
313
314
strace003Thread(strace003 test, String name) {
315
this.test = test;
316
setName(name);
317
}
318
319
public void run() {
320
321
recursiveMethod();
322
323
}
324
325
native void recursiveMethod();
326
}
327
328