Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/stress/stack/stack019.java
41159 views
/*1* Copyright (c) 2000, 2020, 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/stack019.28* VM testbase keywords: [stress, diehard, stack, nonconcurrent]29* VM testbase readme:30* DESCRIPTION31* The test invokes infinitely recursive method from within stack32* overflow handler -- repeatedly multiple times in a single thread.33* The test is deemed passed, if VM have not crashed, and if exception34* other than due to stack overflow was not thrown.35* COMMENTS36* This test crashes HS versions 2.0, 1.3, and 1.4 on both37* Solaris and Win32 platforms.38* See the bug:39* 4366625 (P4/S4) multiple stack overflow causes HS crash40* The stack size is too small to run on systems with > 4K page size.41* Making it bigger could cause timeouts on other platform.42*43* @requires (vm.opt.DeoptimizeALot != true & vm.compMode != "Xcomp" & vm.pageSize == 4096)44* @requires os.family != "windows"45* @library /vmTestbase46* @build nsk.share.Terminator47* @run main/othervm/timeout=900 -Xss200K nsk.stress.stack.stack019 -eager48*/4950package nsk.stress.stack;515253import nsk.share.Terminator;5455import java.io.PrintStream;5657public class stack019 {58private final static int CYCLES = 50;59private final static int PROBES = 50;6061public static void main(String[] args) {62int exitCode = run(args, System.out);63System.exit(exitCode + 95);64}6566public static int run(String args[], PrintStream out) {67boolean verbose = false, eager = false;68for (int i = 0; i < args.length; i++)69if (args[i].toLowerCase().equals("-verbose"))70verbose = true;71else if (args[i].toLowerCase().equals("-eager"))72eager = true;73if (!eager)74Terminator.appoint(Terminator.parseAppointment(args));75//76// Measure recursive depth before stack overflow:77//78try {79recurse(0);80} catch (StackOverflowError soe) {81} catch (OutOfMemoryError oome) {82}83out.println("Maximal recursion depth: " + maxDepth);84depthToTry = maxDepth;8586//87// Run the tested threads:88//89for (int i = 0; i < CYCLES; i++) {90try {91out.println("Iteration: " + i + "/" + CYCLES);92trickyRecurse(0);93out.println("# TEST_BUG: stack overflow was expected!");94return 2;9596} catch (StackOverflowError error) {97} catch (OutOfMemoryError oome) {98// It's OK: stack overflow was expected.99100} catch (Throwable throwable) {101if (throwable instanceof ThreadDeath)102throw (ThreadDeath) throwable;103throwable.printStackTrace(out);104return 2;105}106}107return 0;108}109110private static int maxDepth;111private static int depthToTry;112113private static void recurse(int depth) {114maxDepth = depth;115recurse(depth + 1);116}117118private static void trickyRecurse(int depth) {119try {120maxDepth = depth;121trickyRecurse(depth + 1);122} catch (Error error) {123if (!(error instanceof StackOverflowError) &&124!(error instanceof OutOfMemoryError))125throw error;126127//128// Stack problem caught: provoke it again,129// if current stack is enough deep:130//131if (depth < depthToTry - PROBES)132throw error;133recurse(depth + 1);134}135}136}137138139