Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/stress/stack/stack013.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/stack013.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 virtual 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, and 1.4 on both Win3244* and Solaris 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.stack01350*/5152package nsk.stress.stack;535455import java.io.PrintStream;5657public class stack013 extends stack013i {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) {67stack013i test = new stack013();68//69// Measure maximal recursion depth until stack overflow:70//71int maxDepth = 0;72for (int depth = 10; ; depth += 10)73try {74test.recurse(depth);75maxDepth = depth;76} catch (StackOverflowError soe) {77break;78} catch (OutOfMemoryError oome) {79break;80}81out.println("Max. depth: " + maxDepth);8283//84// Execute multiple threads repeatedly provoking stack overflows:85//86stack013i threads[] = new stack013i[THREADS];87for (int i = 0; i < threads.length; i++) {88threads[i] = new stack013();89threads[i].depthToTry = 10 * maxDepth;90threads[i].cycles = CYCLES;91threads[i].start();92}93for (int i = 0; i < threads.length; i++)94if (threads[i].isAlive())95try {96threads[i].join();97} catch (InterruptedException exception) {98exception.printStackTrace(out);99return 2;100}101102//103// Check if unexpected exceptions were thrown:104//105int exitCode = 0;106for (int i = 0; i < threads.length; i++)107if (threads[i].thrown != null) {108threads[i].thrown.printStackTrace(out);109exitCode = 2;110}111112if (exitCode != 0)113out.println("# TEST FAILED");114return exitCode;115}116117void recurse(int depth) {118if (depth > 0)119recurse(depth - 1);120}121}122123abstract class stack013i extends Thread {124//125// Pure virtual method:126//127abstract void recurse(int depth);128129Throwable thrown = null;130int depthToTry;131int cycles;132133public void run() {134//135// Provoke multiple stack overflows:136//137for (int i = 0; i < cycles; i++)138try {139recurse(depthToTry);140throw new Exception(141"TEST_RFE: no stack overflow thrown" +142", need to try deeper recursion?");143144} catch (StackOverflowError error) {145// It's OK: stack overflow was expected.146} catch (OutOfMemoryError oome) {147// Also OK: out of memory is eligible here.148149} catch (Throwable throwable) {150if (throwable instanceof ThreadDeath)151throw (ThreadDeath) throwable;152// It isn't OK!153thrown = throwable;154break;155}156}157}158159160