blob: 41adabc9ff95bc078b7471a18f4cc9eb0df54a04 [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() {
jeffhao5d1ac922011-09-29 17:41:15 -070028 try {
29 stackOverflowTestSub(0.0, 0.0, 0.0);
30 }
31 catch (StackOverflowError soe) {
Brian Carlstrom60d7a652014-03-13 18:10:08 -070032 System.out.println("caught SOE in testSelfRecursion");
jeffhao5d1ac922011-09-29 17:41:15 -070033 }
jeffhao5d1ac922011-09-29 17:41:15 -070034 }
35
Brian Carlstrom60d7a652014-03-13 18:10:08 -070036 private static void stackOverflowTestSub(double pad1, double pad2, double pad3) {
jeffhao5d1ac922011-09-29 17:41:15 -070037 stackOverflowTestSub(pad1, pad2, pad3);
38 }
Brian Carlstrom60d7a652014-03-13 18:10:08 -070039
40 private static void testMutualRecursion() {
41 try {
42 foo(0.0, 0.0, 0.0);
43 }
44 catch (StackOverflowError soe) {
45 System.out.println("caught SOE in testMutualRecursion");
46 }
47 }
48
49 private static void foo(double pad1, double pad2, double pad3) {
50 bar(pad1, pad2, pad3);
51 }
52
53 private static void bar(double pad1, double pad2, double pad3) {
54 baz(pad1, pad2, pad3);
55 }
56
57 private static void baz(double pad1, double pad2, double pad3) {
58 qux(pad1, pad2, pad3);
59 }
60
61 private static void qux(double pad1, double pad2, double pad3) {
62 foo(pad1, pad2, pad3);
63 }
jeffhao5d1ac922011-09-29 17:41:15 -070064}