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() { |
Andreas Gampe | 7ea6f79 | 2014-07-14 16:21:44 -0700 | [diff] [blame] | 28 | // try { |
| 29 | // stackOverflowTestSub0(); |
| 30 | // } |
| 31 | // catch (StackOverflowError soe) { |
| 32 | // System.out.println("caught SOE0 in testSelfRecursion"); |
| 33 | // } |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 34 | try { |
Andreas Gampe | 7ea6f79 | 2014-07-14 16:21:44 -0700 | [diff] [blame] | 35 | stackOverflowTestSub3(0.0, 1.0, 2.0); |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 36 | } |
| 37 | catch (StackOverflowError soe) { |
Andreas Gampe | 7ea6f79 | 2014-07-14 16:21:44 -0700 | [diff] [blame] | 38 | 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"); |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 45 | } |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 46 | } |
| 47 | |
Andreas Gampe | 7ea6f79 | 2014-07-14 16:21:44 -0700 | [diff] [blame] | 48 | 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); |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 60 | } |
Brian Carlstrom | 60d7a65 | 2014-03-13 18:10:08 -0700 | [diff] [blame] | 61 | |
| 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 | } |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 86 | } |