Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/stress/stack/stack002.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/stack002.28* VM testbase keywords: [stress, quick, stack, nonconcurrent]29* VM testbase readme:30* DESCRIPTION31* Provoke StackOverflowError by infinite recursion in Java method,32* intercept the exception and continue to invoke that method until33* the test exceeds timeout, or until Java VM crashes.34* COMMENTS35* I believe that the test causes HS crashes due to the following bug:36* 4330318 (P2/S2) NSK test fails as An irrecoverable stack overflow37* See also bugs (lots of bugs!):38* Evaluated:39* 4217960 [native stack overflow bug] reflection test causes crash40* Accepted:41* 4285716 native stack overflow causes crash on Solaris42* 4281578 Second stack overflow crashes HotSpot VM43* Closed (duplicate):44* 4027933 Native stack overflows not detected or handled correctly45* 4134353 (hpi) sysThreadCheckStack is a no-op on win3246* 4185411 Various crashes when using recursive reflection.47* 4167055 infinite recursion in FindClass48* 4222359 Infinite recursion crashes jvm49* Closed (will not fix):50* 4231968 StackOverflowError in a native method causes Segmentation Fault51* 4254634 println() while catching StackOverflowError causes hotspot VM crash52* 4302288 the second stack overflow causes Classic VM to exit on win3253*54* @requires vm.opt.DeoptimizeALot != true55* @run main/othervm/timeout=900 nsk.stress.stack.stack00256*/5758package nsk.stress.stack;596061import java.io.PrintStream;6263public class stack002 {64static final long timeout = 10000; // 10 seconds6566public static void main(String[] args) {67int exitCode = run(args, System.out);68System.exit(exitCode + 95);69}7071public static int run(String args[], PrintStream out) {72Tester tester = new Tester(out);73Timer timer = new Timer(tester);74timer.start();75tester.start();76while (timer.isAlive())77try {78timer.join();79} catch (InterruptedException e) {80e.printStackTrace(out);81return 2;82}83// if (tester.isAlive())84// return 2;85out.println("Maximal depth: " + tester.maxdepth);86return 0;87}8889private static class Tester extends Thread {90int maxdepth;91PrintStream out;9293public Tester(PrintStream out) {94this.out = out;95maxdepth = 0;96}9798public void run() {99recurse(0);100}101102void recurse(int depth) {103maxdepth = depth;104try {105recurse(depth + 1);106// } catch (StackOverflowError e) {107//108// OutOfMemoryError is also eligible to indicate stack overflow:109//110} catch (Error error) {111if (!(error instanceof StackOverflowError) &&112!(error instanceof OutOfMemoryError))113throw error;114115/***116*** Originally, I supposed that VM crashes because of unexpected117*** native stack overflow (println() invokes native method).118*** However, I found that HS 1.3 and HS 2.0 crash even on119*** invocation of Java (not native) method.120***121out.println("StackOverflowError, depth=" + depth);122***/123recurse(depth + 1);124}125}126}127128private static class Timer extends Thread {129private Tester tester;130131public Timer(Tester tester) {132this.tester = tester;133}134135public void run() {136long started;137started = System.currentTimeMillis();138while (System.currentTimeMillis() - started < timeout)139; /***140*** The test hangs on JDK 1.2.2 Classic VM if sleep() is invoked.141***142try {143this.sleep(1000);144} catch (InterruptedException e) {145e.printStackTrace(tester.out);146return;147};148***/149tester.stop();150}151}152}153154155