2
* Copyright (c) 2000, 2024, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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.
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
28
* @summary converted from VM testbase nsk/stress/stack/stack012.
29
* VM testbase keywords: [stress, stack, nonconcurrent]
32
* This test provokes multiple stack overflows in the multiple
33
* threads -- by invoking final recursive method for the given
34
* fixed depth of recursion (though, for a large depth).
35
* This test measures a number of recursive invocations until
36
* stack overflow, and then tries to provoke similar stack overflows
37
* 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 100 times that depth measured before.
40
* The test is deemed passed, if VM have not crashed, and
41
* if exception other than due to stack overflow was not
44
* This test crashes HS versions 1.3, 1.4 on Win32, and HS versions
45
* 2.0, 1.3, and 1.4 on Solaris. However, it passes against HS 2.0
48
* 4366625 (P4/S4) multiple stack overflow causes HS crash
50
* @requires vm.opt.DeoptimizeALot != true
51
* @run main/othervm/timeout=900 Stack012
54
public class Stack012 extends Thread {
55
final static int THREADS = 10;
56
final static int CYCLES = 10;
58
public static void main(String[] args) {
59
Stack012 test = new Stack012();
61
// Measure maximal recursion depth until stack overflow:
64
for (int depth = 10; ; depth += 10) {
68
} catch (StackOverflowError | OutOfMemoryError err) {
72
System.out.println("Max. depth: " + maxDepth);
75
// Execute multiple threads repeatedly provoking stack overflows:
77
Stack012 threads[] = new Stack012[THREADS];
78
for (int i = 0; i < threads.length; i++) {
79
threads[i] = new Stack012();
80
threads[i].depthToTry = 100 * maxDepth;
83
for (int i = 0; i < threads.length; i++) {
84
if (threads[i].isAlive()) {
87
} catch (InterruptedException exception) {
88
throw new RuntimeException(exception);
93
// Check if unexpected exceptions were not thrown:
95
for (int i = 0; i < threads.length; i++) {
96
if (threads[i].thrown != null) {
97
threads[i].thrown.printStackTrace();
98
throw new RuntimeException("Exception in the thread " + threads[i], threads[i].thrown);
104
Throwable thrown = null;
107
for (int i = 0; i < CYCLES; i++) {
109
this.recurse(depthToTry);
111
"TEST_RFE: no stack overflow thrown" +
112
", need to try deeper recursion?");
114
} catch (StackOverflowError | OutOfMemoryError err) {
116
} catch (Throwable throwable) {
124
final void recurse(int depth) {