blob: 0961226e64c0206ccc4ebcf2121a3bcdaf790aaa [file] [log] [blame]
jeffhao5d1ac922011-09-29 17:41:15 -07001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17/**
18 * generate a stack overflow condition and catch it
19 */
20public class Main {
21 public static void main(String args[]) {
Brian Carlstrom60d7a652014-03-13 18:10:08 -070022 testSelfRecursion();
23 testMutualRecursion();
24 System.out.println("SOE test done");
25 }
26
27 private static void testSelfRecursion() {
Andreas Gampe7ea6f792014-07-14 16:21:44 -070028// try {
29// stackOverflowTestSub0();
30// }
31// catch (StackOverflowError soe) {
32// System.out.println("caught SOE0 in testSelfRecursion");
33// }
jeffhao5d1ac922011-09-29 17:41:15 -070034 try {
Andreas Gampe7ea6f792014-07-14 16:21:44 -070035 stackOverflowTestSub3(0.0, 1.0, 2.0);
jeffhao5d1ac922011-09-29 17:41:15 -070036 }
37 catch (StackOverflowError soe) {
Andreas Gampe7ea6f792014-07-14 16:21:44 -070038 System.out.println("caught SOE3 in testSelfRecursion");
39 }
40 try {
41 stackOverflowTestSub10(0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0);
42 }
43 catch (StackOverflowError soe) {
44 System.out.println("caught SOE10 in testSelfRecursion");
jeffhao5d1ac922011-09-29 17:41:15 -070045 }
jeffhao5d1ac922011-09-29 17:41:15 -070046 }
47
Andreas Gampe7ea6f792014-07-14 16:21:44 -070048 private static void stackOverflowTestSub0() {
49 stackOverflowTestSub0();
50 }
51
52 private static void stackOverflowTestSub3(double pad1, double pad2, double pad3) {
53 stackOverflowTestSub3(pad1, pad2, pad3);
54 }
55
56 private static void stackOverflowTestSub10(double pad1, double pad2, double pad3, double pad4,
57 double pad5, double pad6, double pad7, double pad8,
58 double pad9, double pad10) {
59 stackOverflowTestSub10(pad1, pad2, pad3, pad4, pad5, pad6, pad7, pad8, pad9, pad10);
jeffhao5d1ac922011-09-29 17:41:15 -070060 }
Brian Carlstrom60d7a652014-03-13 18:10:08 -070061
62 private static void testMutualRecursion() {
63 try {
64 foo(0.0, 0.0, 0.0);
65 }
66 catch (StackOverflowError soe) {
67 System.out.println("caught SOE in testMutualRecursion");
68 }
69 }
70
71 private static void foo(double pad1, double pad2, double pad3) {
72 bar(pad1, pad2, pad3);
73 }
74
75 private static void bar(double pad1, double pad2, double pad3) {
76 baz(pad1, pad2, pad3);
77 }
78
79 private static void baz(double pad1, double pad2, double pad3) {
80 qux(pad1, pad2, pad3);
81 }
82
83 private static void qux(double pad1, double pad2, double pad3) {
84 foo(pad1, pad2, pad3);
85 }
jeffhao5d1ac922011-09-29 17:41:15 -070086}