1 /* 2 * Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 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. 8 * 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). 14 * 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. 18 * 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 21 * questions. 22 */ 23 24 /* 25 * @test 26 * @key stress 27 * 28 * @summary converted from VM testbase nsk/stress/stack/stack001. 29 * VM testbase keywords: [stress, quick, stack, nonconcurrent] 30 * VM testbase readme: 31 * DESCRIPTION 32 * Provoke StackOverflowError by infinite recursion in Java method, 33 * intercept the exception try to make one more invocation. 34 * COMMENTS 35 * Kestrel for Solaris_JDK_1.3-b10 crashes while trying to execute 36 * this test with Client HS VM. 37 * See lots of bugs concerning similar failuires: 38 * Evaluated: 39 * 4217960 [native stack overflow bug] reflection test causes crash 40 * Accepted: 41 * 4285716 native stack overflow causes crash on Solaris 42 * 4281578 Second stack overflow crashes HotSpot VM 43 * Closed (duplicate): 44 * 4027933 Native stack overflows not detected or handled correctly 45 * 4134353 (hpi) sysThreadCheckStack is a no-op on win32 46 * 4185411 Various crashes when using recursive reflection. 47 * 4167055 infinite recursion in FindClass 48 * 4222359 Infinite recursion crashes jvm 49 * Closed (will not fix): 50 * 4231968 StackOverflowError in a native method causes Segmentation Fault 51 * 4254634 println() while catching StackOverflowError causes hotspot VM crash 52 * 4302288 the second stack overflow causes Classic VM to exit on win32 53 * 54 * @run main/othervm nsk.stress.stack.stack001 55 */ 56 57 package nsk.stress.stack; 58 59 60 import java.io.PrintStream; 61 62 public class stack001 { 63 public static void main(String[] args) { 64 int exitCode = run(args, System.out); 65 System.exit(exitCode + 95); 66 } 67 68 public static int run(String args[], PrintStream out) { 69 stack001 test = new stack001(); 70 test.recurse(0); 71 out.println("Maximal depth: " + test.maxdepth); 72 return 0; 73 } 74 75 private int maxdepth; 76 77 private void recurse(int depth) { 78 maxdepth = depth; 79 try { 80 recurse(depth + 1); 81 } catch (Error error) { 82 if (!(error instanceof StackOverflowError) && 83 !(error instanceof OutOfMemoryError)) 84 throw error; 85 86 if (maxdepth == depth) 87 recurse(depth + 1); 88 } 89 } 90 }