test/compiler/7116216/StackOverflow.java

changeset 3372
dca455dea3a7
child 3407
35acf8f0a2e4
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/compiler/7116216/StackOverflow.java	Tue Dec 20 12:33:05 2011 +0100
     1.3 @@ -0,0 +1,64 @@
     1.4 +/*
     1.5 + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 + * or visit www.oracle.com if you need additional information or have any
    1.24 + * questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +/**
    1.29 + * @test
    1.30 + * @bug 7116216
    1.31 + * @summary The vm crashes when GC happens during throwing a StackOverflow exception
    1.32 + *
    1.33 + * @run main/othervm -Xcomp -Xbatch StackOverflow
    1.34 + */
    1.35 +
    1.36 +class StackOverflow {
    1.37 +    static String stackOverflow_largeFrame_liveOopForGC;
    1.38 +
    1.39 +    public static int stackOverflow_largeFrame(int call_count, String liveOopForGC) {
    1.40 +        try {
    1.41 +            int return_count = stackOverflow_largeFrame(++call_count, liveOopForGC);
    1.42 +            if (return_count == 0) {
    1.43 +                try {
    1.44 +                    LargeFrame.method_with_many_locals(liveOopForGC, 2,3,4,5,6,7,liveOopForGC);
    1.45 +                } catch (StackOverflowError e2) {
    1.46 +                    // access liveOopForGC to make it a live variable
    1.47 +                    stackOverflow_largeFrame_liveOopForGC = liveOopForGC;
    1.48 +                }
    1.49 +            }
    1.50 +            return return_count - 1;
    1.51 +        } catch (StackOverflowError e) {
    1.52 +            // Return a value that is large enough such that no unrecoverable
    1.53 +            // stack overflow will occur afterwards, but that is small enough
    1.54 +            // such that calling LargeFrame.method_with_many_locals() will
    1.55 +            // cause a StackOverflowError.
    1.56 +            // Don't use a call here because we're out of stack space anyway!
    1.57 +            int tmp = call_count / 2;
    1.58 +            return (tmp < 100 ? tmp : 100);
    1.59 +        }
    1.60 +    }
    1.61 +    public static void main(String args[]) {
    1.62 +        LargeFrame.method_with_many_locals(new Object(), 2,3,4,5,6,7,new Object());
    1.63 +
    1.64 +        stackOverflow_largeFrame(0, "this is a live oop to test GC");
    1.65 +        System.out.println("finished ok!");
    1.66 +    }
    1.67 +}

mercurial