Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/stress/stack/stack007.java
41159 views
/*1* Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @key stress26*27* @summary converted from VM testbase nsk/stress/stack/stack007.28* VM testbase keywords: [stress, stack, nonconcurrent]29* VM testbase readme:30* DESCRIPTION31* This test provokes multiple stack overflows in the same thread32* by invoking synchronized virtual recursive method for the given33* fixed depth of recursion (though, for a large depth).34* This test makes measures a number of recursive invocations35* before 1st StackOverflowError, and then tries to reproduce36* such StackOverflowError 10000 times -- each time by trying to37* invoke the same recursive method for the given fixed depth38* of invocations (which is 10 times that depth just measured).39* The test is deemed passed, if VM have not crashed.40* COMMENTS41* This test crashes HS versions 1.3 and 1.4 on Win32, Solaris,42* and Linux platforms in all execution modes. However, it passes43* against HS 2.0 on Win32 platform.44* See also the bug:45* 4366625 (P4/S4) multiple stack overflow causes HS crash46*47* @requires vm.opt.DeoptimizeALot != true48* @run main/othervm/timeout=900 nsk.stress.stack.stack00749*/5051package nsk.stress.stack;525354import java.io.PrintStream;5556public class stack007 implements stack007i {57final static int ITERATIONS = 1000;58final static int INCREMENT = 100;5960public static void main(String[] args) {61int exitCode = run(args, System.out);62System.exit(exitCode + 95);63}6465public static int run(String args[], PrintStream out) {66stack007i test = new stack007();67int depth;68for (depth = 100; ; depth += INCREMENT)69try {70test.recurse(depth);71} catch (StackOverflowError soe) {72break;73} catch (OutOfMemoryError oome) {74break;75}76out.println("Max. depth: " + depth);77for (int i = 0; i < ITERATIONS; i++)78try {79test.recurse(10 * depth);80out.println("?");81} catch (StackOverflowError soe) {82// OK.83} catch (OutOfMemoryError oome) {84// Also OK.85}86return 0;87}8889public synchronized void recurse(int depth) {90if (depth > 0)91recurse(depth - 1);92}93}9495interface stack007i {96void recurse(int depth);97}9899100