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/stack007. 29 * VM testbase keywords: [stress, stack, nonconcurrent] 30 * VM testbase readme: 31 * DESCRIPTION 32 * This test provokes multiple stack overflows in the same thread 33 * by invoking synchronized virtual recursive method for the given 34 * fixed depth of recursion (though, for a large depth). 35 * This test makes measures a number of recursive invocations 36 * before 1st StackOverflowError, and then tries to reproduce 37 * such StackOverflowError 10000 times -- each time by trying to 38 * invoke the same recursive method for the given fixed depth 39 * of invocations (which is 10 times that depth just measured). 40 * The test is deemed passed, if VM have not crashed. 41 * COMMENTS 42 * This test crashes HS versions 1.3 and 1.4 on Win32, Solaris, 43 * and Linux platforms in all execution modes. However, it passes 44 * against HS 2.0 on Win32 platform. 45 * See also the bug: 46 * 4366625 (P4/S4) multiple stack overflow causes HS crash 47 * 48 * @requires vm.opt.DeoptimizeALot == null | vm.opt.DeoptimizeALot == false 49 * @run main/othervm nsk.stress.stack.stack007 50 */ 51 52 package nsk.stress.stack; 53 54 55 import java.io.PrintStream; 56 57 public class stack007 implements stack007i { 58 final static int ITERATIONS = 1000; 59 final static int INCREMENT = 100; 60 61 public static void main(String[] args) { 62 int exitCode = run(args, System.out); 63 System.exit(exitCode + 95); 64 } 65 66 public static int run(String args[], PrintStream out) { 67 stack007i test = new stack007(); 68 int depth; 69 for (depth = 100; ; depth += INCREMENT) 70 try { 71 test.recurse(depth); 72 } catch (StackOverflowError soe) { 73 break; 74 } catch (OutOfMemoryError oome) { 75 break; 76 } 77 out.println("Max. depth: " + depth); 78 for (int i = 0; i < ITERATIONS; i++) 79 try { 80 test.recurse(10 * depth); 81 out.println("?"); 82 } catch (StackOverflowError soe) { 83 // OK. 84 } catch (OutOfMemoryError oome) { 85 // Also OK. 86 } 87 return 0; 88 } 89 90 public synchronized void recurse(int depth) { 91 if (depth > 0) 92 recurse(depth - 1); 93 } 94 } 95 96 interface stack007i { 97 void recurse(int depth); 98 }