jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 20 | public class Main { |
| 21 | public static void main(String args[]) { |
Brian Carlstrom | 60d7a65 | 2014-03-13 18:10:08 -0700 | [diff] [blame^] | 22 | testSelfRecursion(); |
| 23 | testMutualRecursion(); |
| 24 | System.out.println("SOE test done"); |
| 25 | } |
| 26 | |
| 27 | private static void testSelfRecursion() { |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 28 | try { |
| 29 | stackOverflowTestSub(0.0, 0.0, 0.0); |
| 30 | } |
| 31 | catch (StackOverflowError soe) { |
Brian Carlstrom | 60d7a65 | 2014-03-13 18:10:08 -0700 | [diff] [blame^] | 32 | System.out.println("caught SOE in testSelfRecursion"); |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 33 | } |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 34 | } |
| 35 | |
Brian Carlstrom | 60d7a65 | 2014-03-13 18:10:08 -0700 | [diff] [blame^] | 36 | private static void stackOverflowTestSub(double pad1, double pad2, double pad3) { |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 37 | stackOverflowTestSub(pad1, pad2, pad3); |
| 38 | } |
Brian Carlstrom | 60d7a65 | 2014-03-13 18:10:08 -0700 | [diff] [blame^] | 39 | |
| 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 | } |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 64 | } |