Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/stress/stack/stack012.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/stack012.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 final 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 1.3, 1.4 on Win32, and HS versions44* 2.0, 1.3, and 1.4 on Solaris. However, it passes against HS 2.045* on Win32.46* See the bug:47* 4366625 (P4/S4) multiple stack overflow causes HS crash48*49* @requires vm.opt.DeoptimizeALot != true50* @run main/othervm/timeout=900 nsk.stress.stack.stack01251*/5253package nsk.stress.stack;545556import java.io.PrintStream;5758public class stack012 extends Thread {59final static int THREADS = 10;60final static int CYCLES = 10;6162public static void main(String[] args) {63int exitCode = run(args, System.out);64System.exit(exitCode + 95);65}6667public static int run(String args[], PrintStream out) {68stack012 test = new stack012();69//70// Measure maximal recursion depth until stack overflow:71//72int maxDepth = 0;73for (int depth = 10; ; depth += 10)74try {75test.recurse(depth);76maxDepth = depth;77} catch (StackOverflowError soe) {78break;79} catch (OutOfMemoryError oome) {80break;81}82out.println("Max. depth: " + maxDepth);8384//85// Execute multiple threads repeatedly provoking stack overflows:86//87stack012 threads[] = new stack012[THREADS];88for (int i = 0; i < threads.length; i++) {89threads[i] = new stack012();90threads[i].depthToTry = 10 * maxDepth;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 not 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}116117int depthToTry = 0;118Throwable thrown = null;119120public void run() {121for (int i = 0; i < CYCLES; i++)122try {123this.recurse(depthToTry);124throw new Exception(125"TEST_RFE: no stack overflow thrown" +126", need to try deeper recursion?");127128} catch (StackOverflowError error) {129// It's OK: stack overflow was expected.130} catch (OutOfMemoryError oome) {131// Also OK: invocation may result in out of memory.132133} catch (Throwable throwable) {134if (throwable instanceof ThreadDeath)135throw (ThreadDeath) throwable;136// It isn't OK!137thrown = throwable;138break;139}140}141142final void recurse(int depth) {143if (depth > 0)144recurse(depth - 1);145}146}147148149