Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/stress/stack/stack002.java
41159 views
1
/*
2
* Copyright (c) 2000, 2018, 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/stack002.
29
* VM testbase keywords: [stress, quick, stack, nonconcurrent]
30
* VM testbase readme:
31
* DESCRIPTION
32
* Provoke StackOverflowError by infinite recursion in Java method,
33
* intercept the exception and continue to invoke that method until
34
* the test exceeds timeout, or until Java VM crashes.
35
* COMMENTS
36
* I believe that the test causes HS crashes due to the following bug:
37
* 4330318 (P2/S2) NSK test fails as An irrecoverable stack overflow
38
* See also bugs (lots of bugs!):
39
* Evaluated:
40
* 4217960 [native stack overflow bug] reflection test causes crash
41
* Accepted:
42
* 4285716 native stack overflow causes crash on Solaris
43
* 4281578 Second stack overflow crashes HotSpot VM
44
* Closed (duplicate):
45
* 4027933 Native stack overflows not detected or handled correctly
46
* 4134353 (hpi) sysThreadCheckStack is a no-op on win32
47
* 4185411 Various crashes when using recursive reflection.
48
* 4167055 infinite recursion in FindClass
49
* 4222359 Infinite recursion crashes jvm
50
* Closed (will not fix):
51
* 4231968 StackOverflowError in a native method causes Segmentation Fault
52
* 4254634 println() while catching StackOverflowError causes hotspot VM crash
53
* 4302288 the second stack overflow causes Classic VM to exit on win32
54
*
55
* @requires vm.opt.DeoptimizeALot != true
56
* @run main/othervm/timeout=900 nsk.stress.stack.stack002
57
*/
58
59
package nsk.stress.stack;
60
61
62
import java.io.PrintStream;
63
64
public class stack002 {
65
static final long timeout = 10000; // 10 seconds
66
67
public static void main(String[] args) {
68
int exitCode = run(args, System.out);
69
System.exit(exitCode + 95);
70
}
71
72
public static int run(String args[], PrintStream out) {
73
Tester tester = new Tester(out);
74
Timer timer = new Timer(tester);
75
timer.start();
76
tester.start();
77
while (timer.isAlive())
78
try {
79
timer.join();
80
} catch (InterruptedException e) {
81
e.printStackTrace(out);
82
return 2;
83
}
84
// if (tester.isAlive())
85
// return 2;
86
out.println("Maximal depth: " + tester.maxdepth);
87
return 0;
88
}
89
90
private static class Tester extends Thread {
91
int maxdepth;
92
PrintStream out;
93
94
public Tester(PrintStream out) {
95
this.out = out;
96
maxdepth = 0;
97
}
98
99
public void run() {
100
recurse(0);
101
}
102
103
void recurse(int depth) {
104
maxdepth = depth;
105
try {
106
recurse(depth + 1);
107
// } catch (StackOverflowError e) {
108
//
109
// OutOfMemoryError is also eligible to indicate stack overflow:
110
//
111
} catch (Error error) {
112
if (!(error instanceof StackOverflowError) &&
113
!(error instanceof OutOfMemoryError))
114
throw error;
115
116
/***
117
*** Originally, I supposed that VM crashes because of unexpected
118
*** native stack overflow (println() invokes native method).
119
*** However, I found that HS 1.3 and HS 2.0 crash even on
120
*** invocation of Java (not native) method.
121
***
122
out.println("StackOverflowError, depth=" + depth);
123
***/
124
recurse(depth + 1);
125
}
126
}
127
}
128
129
private static class Timer extends Thread {
130
private Tester tester;
131
132
public Timer(Tester tester) {
133
this.tester = tester;
134
}
135
136
public void run() {
137
long started;
138
started = System.currentTimeMillis();
139
while (System.currentTimeMillis() - started < timeout)
140
; /***
141
*** The test hangs on JDK 1.2.2 Classic VM if sleep() is invoked.
142
***
143
try {
144
this.sleep(1000);
145
} catch (InterruptedException e) {
146
e.printStackTrace(tester.out);
147
return;
148
};
149
***/
150
tester.stop();
151
}
152
}
153
}
154
155