Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/stress/stack/stack005.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/stack005.28* VM testbase keywords: [stress, quick, stack, nonconcurrent]29* VM testbase readme:30* DESCRIPTION31* This test provokes multiple stack overflows in the same thread32* by invoking final recursive method for the given fixed depth of33* 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 100 times -- each time by trying to37* invoke the same recursive method for the given fixed depth38* of invocations (which is twice that depth just measured).39* The test is deemed passed, if VM have not crashed.40* COMMENTS41* This test crashes all HS versions (2.0, 1.3, 1.4) on all42* platforms (Win32, Solaris, Linux) in all execution modes43* (-Xint, -Xmixed, -Xcomp) in 100% of executions in which44* I had tryied it.45* See the bug:46* 4366625 (P4/S4) multiple stack overflow causes HS crash47*48* @requires vm.opt.DeoptimizeALot != true49* @run main/othervm/timeout=900 nsk.stress.stack.stack00550*/5152package nsk.stress.stack;535455import java.io.PrintStream;5657public class stack005 {58public static void main(String[] args) {59int exitCode = run(args, System.out);60System.exit(exitCode + 95);61}6263public static int run(String args[], PrintStream out) {64stack005 test = new stack005();65int depth;66for (depth = 100; ; depth += 100)67try {68test.recurse(depth);69} catch (StackOverflowError soe) {70break;71} catch (OutOfMemoryError oome) {72break;73}74out.println("Max. depth: " + depth);75for (int i = 0; i < 100; i++)76try {77test.recurse(2 * depth);78out.println("?");79} catch (StackOverflowError soe) {80// OK.81} catch (OutOfMemoryError oome) {82// Also OK.83}84return 0;85}8687final void recurse(int depth) {88if (depth > 0)89recurse(depth - 1);90}91}929394