Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/stress/stack/stack014.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/stack014.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 synchronized virtual recursive method33* for the given fixed depth of recursion (though, for a large34* depth). Note however, that different threads are not actual35* synchronized, because different instances having the recursive36* method are used.37* This test measures a number of recursive invocations until38* stack overflow, and then tries to provoke similar stack overflows39* 10 times in each of 10 threads. Each provocation consists of40* invoking that recursive method for the given fixed depth41* of invocations which is 10 times that depth measured before.42* The test is deemed passed, if VM have not crashed, and43* if exception other than due to stack overflow was not44* thrown.45* COMMENTS46* This test crashes HS versions 2.0, 1.3, and 1.4 on Solaris.47* However, it passes against all these HS versions on Win32.48* See the bug:49* 4366625 (P4/S4) multiple stack overflow causes HS crash50*51* @requires vm.opt.DeoptimizeALot != true52* @run main/othervm/timeout=900 nsk.stress.stack.stack01453*/5455package nsk.stress.stack;565758import java.io.PrintStream;5960public class stack014 extends stack014i {61final static int THREADS = 10;62final static int CYCLES = 10;6364public static void main(String[] args) {65int exitCode = run(args, System.out);66System.exit(exitCode + 95);67}6869public static int run(String args[], PrintStream out) {70stack014i test = new stack014();71//72// Measure maximal recursion depth until stack overflow:73//74int maxDepth = 0;75for (int depth = 10; ; depth += 10)76try {77test.recurse(depth);78maxDepth = depth;79} catch (StackOverflowError soe) {80break;81} catch (OutOfMemoryError oome) {82break;83}84out.println("Max. depth: " + maxDepth);8586//87// Execute multiple threads repeatedly provoking stack overflows:88//89stack014i threads[] = new stack014i[THREADS];90for (int i = 0; i < threads.length; i++) {91threads[i] = new stack014();92threads[i].depthToTry = 10 * maxDepth;93threads[i].cycles = CYCLES;94threads[i].start();95}96for (int i = 0; i < threads.length; i++)97if (threads[i].isAlive())98try {99threads[i].join();100} catch (InterruptedException exception) {101exception.printStackTrace(out);102return 2;103}104105//106// Check if unexpected exceptions were thrown:107//108int exitCode = 0;109for (int i = 0; i < threads.length; i++)110if (threads[i].thrown != null) {111threads[i].thrown.printStackTrace(out);112exitCode = 2;113}114115if (exitCode != 0)116out.println("# TEST FAILED");117return exitCode;118}119120synchronized void recurse(int depth) {121if (depth > 0)122recurse(depth - 1);123}124}125126abstract class stack014i extends Thread {127//128// Pure virtual method:129//130abstract void recurse(int depth);131132Throwable thrown = null;133int depthToTry;134int cycles;135136public void run() {137//138// Provoke multiple stack overflows:139//140for (int i = 0; i < cycles; i++)141try {142recurse(depthToTry);143throw new Exception(144"TEST_RFE: no stack overflow thrown" +145", need to try deeper recursion?");146147} catch (StackOverflowError error) {148// It's OK: stack overflow was expected.149} catch (OutOfMemoryError oome) {150// Also OK: if there is no memory for stack expansion.151152} catch (Throwable throwable) {153if (throwable instanceof ThreadDeath)154throw (ThreadDeath) throwable;155// It isn't OK!156thrown = throwable;157break;158}159}160}161162163