Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/stress/stack/stack001.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/stack001.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 try to make one more invocation.33* COMMENTS34* Kestrel for Solaris_JDK_1.3-b10 crashes while trying to execute35* this test with Client HS VM.36* See lots of bugs concerning similar failures:37* Evaluated:38* 4217960 [native stack overflow bug] reflection test causes crash39* Accepted:40* 4285716 native stack overflow causes crash on Solaris41* 4281578 Second stack overflow crashes HotSpot VM42* Closed (duplicate):43* 4027933 Native stack overflows not detected or handled correctly44* 4134353 (hpi) sysThreadCheckStack is a no-op on win3245* 4185411 Various crashes when using recursive reflection.46* 4167055 infinite recursion in FindClass47* 4222359 Infinite recursion crashes jvm48* Closed (will not fix):49* 4231968 StackOverflowError in a native method causes Segmentation Fault50* 4254634 println() while catching StackOverflowError causes hotspot VM crash51* 4302288 the second stack overflow causes Classic VM to exit on win3252*53* @requires vm.opt.DeoptimizeALot != true54* @run main/othervm/timeout=900 nsk.stress.stack.stack00155*/5657package nsk.stress.stack;585960import java.io.PrintStream;6162public class stack001 {63public static void main(String[] args) {64int exitCode = run(args, System.out);65System.exit(exitCode + 95);66}6768public static int run(String args[], PrintStream out) {69stack001 test = new stack001();70test.recurse(0);71out.println("Maximal depth: " + test.maxdepth);72return 0;73}7475private int maxdepth;7677private void recurse(int depth) {78maxdepth = depth;79try {80recurse(depth + 1);81} catch (Error error) {82if (!(error instanceof StackOverflowError) &&83!(error instanceof OutOfMemoryError))84throw error;8586if (maxdepth == depth)87recurse(depth + 1);88}89}90}919293