Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/stress/stack/stack016.java
41159 views
1
/*
2
* Copyright (c) 2000, 2021, 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/stack/stack016.
29
* VM testbase keywords: [stress, diehard, stack, nonconcurrent]
30
* VM testbase readme:
31
* DESCRIPTION
32
* The test provokes second stack overflow from within the
33
* stack overflow handler -- repeatedly multiple times, and
34
* in multiple threads.
35
* This test measures a number of recursive invocations until
36
* stack overflow, and then tries to provoke similar stack overflows
37
* in 10 times in each of 10 threads. Each provocation consists of
38
* invoking that recursive method for the given fixed depth
39
* of invocations which is 10 times that depth measured before,
40
* and then trying to invoke that recursive method once again
41
* from within the catch clause just caught StackOverflowError.
42
* The test is deemed passed, if VM have not crashed, and
43
* if exception other than due to stack overflow was not
44
* thrown.
45
* COMMENTS
46
* This test crashes HS versions 2.0, 1.3, and 1.4 on both
47
* Solaris and Win32 platforms.
48
* See the bug:
49
* 4366625 (P4/S4) multiple stack overflow causes HS crash
50
*
51
* @requires (vm.opt.DeoptimizeALot != true & vm.compMode != "Xcomp")
52
* @library /vmTestbase
53
* @build nsk.share.Terminator
54
* @run main/othervm/timeout=900 -Xint -Xss448K nsk.stress.stack.stack016 -eager
55
* @run main/othervm/timeout=900 -Xcomp -Xss448K nsk.stress.stack.stack016 -eager
56
* @run main/othervm/timeout=900 -Xcomp -XX:-TieredCompilation -Xss448K nsk.stress.stack.stack016 -eager
57
*/
58
59
package nsk.stress.stack;
60
61
62
import nsk.share.Terminator;
63
64
import java.io.PrintStream;
65
66
public class stack016 extends Thread {
67
private final static int THREADS = 10;
68
private final static int CYCLES = 10;
69
private final static int STEP = 10;
70
private final static int RESERVE = 10;
71
private final static int PROBES = STEP * RESERVE;
72
73
public static void main(String[] args) {
74
int exitCode = run(args, System.out);
75
System.exit(exitCode + 95);
76
}
77
78
public static int run(String args[], PrintStream out) {
79
verbose = false;
80
boolean eager = false;
81
for (int i = 0; i < args.length; i++)
82
if (args[i].toLowerCase().equals("-verbose"))
83
verbose = true;
84
else if (args[i].toLowerCase().equals("-eager"))
85
eager = true;
86
if (!eager)
87
Terminator.appoint(Terminator.parseAppointment(args));
88
stack016.out = out;
89
stack016 test = new stack016();
90
return test.doRun();
91
}
92
93
private static boolean verbose;
94
private static PrintStream out;
95
96
private void display(Object message) {
97
if (!verbose)
98
return;
99
synchronized (out) {
100
out.println(message.toString());
101
}
102
}
103
104
private int doRun() {
105
//
106
// Measure recursive depth before stack overflow:
107
//
108
int maxDepth = 0;
109
for (depthToTry = 0; ; depthToTry += STEP) {
110
try {
111
trickyRecurse(depthToTry);
112
maxDepth = depthToTry;
113
} catch (StackOverflowError | OutOfMemoryError ex) {
114
break;
115
}
116
}
117
out.println("Maximal recursion depth: " + maxDepth);
118
119
//
120
// Run the tested threads:
121
//
122
stack016 threads[] = new stack016[THREADS];
123
for (int i = 0; i < threads.length; i++) {
124
threads[i] = new stack016();
125
threads[i].setName("Thread: " + (i + 1) + "/" + THREADS);
126
threads[i].depthToTry = RESERVE * maxDepth;
127
threads[i].start();
128
}
129
for (int i = 0; i < threads.length; i++) {
130
if (threads[i].isAlive()) {
131
try {
132
threads[i].join();
133
} catch (InterruptedException exception) {
134
exception.printStackTrace(out);
135
return 2;
136
}
137
}
138
}
139
140
//
141
// Check if unexpected exceptions were thrown:
142
//
143
int exitCode = 0;
144
for (int i = 0; i < threads.length; i++) {
145
if (threads[i].thrown != null) {
146
threads[i].thrown.printStackTrace(out);
147
exitCode = 2;
148
}
149
}
150
if (exitCode != 0)
151
out.println("# TEST FAILED");
152
return exitCode;
153
}
154
155
private int stackTop = 0;
156
private int depthToTry = 0;
157
private Throwable thrown = null;
158
159
private void trickyRecurse(int depth) {
160
stackTop = depthToTry - depth;
161
if (depth > 0) {
162
try {
163
trickyRecurse(depth - 1);
164
} catch (Error error) {
165
if (!(error instanceof StackOverflowError) &&
166
!(error instanceof OutOfMemoryError))
167
throw error;
168
169
//
170
// Provoke more stack overflow,
171
// if current stack is deep enough:
172
//
173
if (depthToTry - depth < stackTop - PROBES)
174
throw error;
175
recurse(depthToTry);
176
177
throw new Error("TEST_RFE: try deeper recursion!");
178
}
179
}
180
}
181
182
private static void recurse(int depth) {
183
if (depth > 0)
184
recurse(depth - 1);
185
}
186
187
public void run() {
188
String threadName = Thread.currentThread().getName();
189
for (int i = 1; i <= CYCLES; i++) {
190
try {
191
display(threadName + ", iteration: " + i + "/" + CYCLES +
192
", depthToTry: " + depthToTry);
193
trickyRecurse(depthToTry);
194
throw new Error(
195
"TEST_BUG: trickyRecursion() must throw an error anyway!");
196
197
} catch (StackOverflowError error) {
198
// It's OK: stack overflow was expected.
199
} catch (OutOfMemoryError oome) {
200
// Also OK, if there is no memory for stack expansion.
201
202
} catch (Throwable throwable) {
203
if (throwable instanceof ThreadDeath)
204
throw (ThreadDeath) throwable;
205
thrown = throwable;
206
break;
207
}
208
}
209
}
210
}
211
212