Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/stress/stack/stack010.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/stack010.28* VM testbase keywords: [stress, stack, nonconcurrent]29* VM testbase readme:30* DESCRIPTION31* This test provokes multiple stack overflows in the multiple32* threads -- by invoking static recursive method for the given33* fixed depth of recursion (though, for a large depth).34* This test measures a number of recursive invocations until35* stack overflow, and then tries to provoke similar stack overflows36* 10 times in each of 10 threads. Each provocation consists of37* invoking that recursive method for the given fixed depth38* of invocations which is 10 times that depth measured before.39* The test is deemed passed, if VM have not crashed, and40* if exception other than due to stack overflow was not41* thrown.42* COMMENTS43* This test crashes HS versions 2.0, 1.3, 1.4 on Win32 and Solaris44* platforms.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.stack01050*/5152package nsk.stress.stack;535455import java.io.PrintStream;5657public class stack010 extends Thread {58final static int THREADS = 10;59final static int CYCLES = 10;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) {67//68// Measure maximal recursion depth until stack overflow:69//70int maxDepth = 0;71for (int depth = 10; ; depth += 10)72try {73recurse(depth);74maxDepth = depth;75} catch (StackOverflowError soe) {76break;77} catch (OutOfMemoryError oome) {78break;79}80out.println("Max. depth: " + maxDepth);8182//83// Execute multiple threads repeatedly provoking stack overflows:84//85stack010 threads[] = new stack010[THREADS];86for (int i = 0; i < threads.length; i++) {87threads[i] = new stack010();88threads[i].depthToTry = 10 * maxDepth;89threads[i].start();90}91for (int i = 0; i < threads.length; i++)92if (threads[i].isAlive())93try {94threads[i].join();95} catch (InterruptedException exception) {96exception.printStackTrace(out);97return 2;98}99100//101// Check if unexpected exceptions were not thrown:102//103int exitCode = 0;104for (int i = 0; i < threads.length; i++)105if (threads[i].thrown != null) {106threads[i].thrown.printStackTrace(out);107exitCode = 2;108}109110if (exitCode != 0)111out.println("# TEST FAILED");112return exitCode;113}114115int depthToTry = 0;116Throwable thrown = null;117118public void run() {119for (int i = 0; i < CYCLES; i++)120try {121recurse(depthToTry);122throw new Exception(123"TEST_RFE: no stack overflow thrown" +124", need to try deeper recursion?");125126} catch (StackOverflowError soe) {127// It's OK: stack overflow was expected.128} catch (OutOfMemoryError oome) {129// Also OK: out of memory may indacate stack overflow.130131} catch (Throwable throwable) {132if (throwable instanceof ThreadDeath)133throw (ThreadDeath) throwable;134// It isn't OK!135thrown = throwable;136break;137}138}139140static void recurse(int depth) {141if (depth > 0)142recurse(depth - 1);143}144}145146147