hotspot/test/runtime/ErrorHandling/TestExitOnOutOfMemoryError.java
author dsamersoff
Sun, 01 May 2016 12:47:00 +0300
changeset 38152 80e5da81fb2c
parent 34670 5ab871b40190
child 40631 ed82623d7831
permissions -rw-r--r--
8154258: [TESTBUG] Various serviceability tests fail compilation Summary: Replace sun.misc.Unsafe with jdk.internal.misc.Unsafe Reviewed-by: chegar, kvn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
34670
5ab871b40190 8138745: Implement ExitOnOutOfMemory and CrashOnOutOfMemory in HotSpot
kevinw
parents:
diff changeset
     1
/*
5ab871b40190 8138745: Implement ExitOnOutOfMemory and CrashOnOutOfMemory in HotSpot
kevinw
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
5ab871b40190 8138745: Implement ExitOnOutOfMemory and CrashOnOutOfMemory in HotSpot
kevinw
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5ab871b40190 8138745: Implement ExitOnOutOfMemory and CrashOnOutOfMemory in HotSpot
kevinw
parents:
diff changeset
     4
 *
5ab871b40190 8138745: Implement ExitOnOutOfMemory and CrashOnOutOfMemory in HotSpot
kevinw
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
5ab871b40190 8138745: Implement ExitOnOutOfMemory and CrashOnOutOfMemory in HotSpot
kevinw
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5ab871b40190 8138745: Implement ExitOnOutOfMemory and CrashOnOutOfMemory in HotSpot
kevinw
parents:
diff changeset
     7
 * published by the Free Software Foundation.
5ab871b40190 8138745: Implement ExitOnOutOfMemory and CrashOnOutOfMemory in HotSpot
kevinw
parents:
diff changeset
     8
 *
5ab871b40190 8138745: Implement ExitOnOutOfMemory and CrashOnOutOfMemory in HotSpot
kevinw
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
5ab871b40190 8138745: Implement ExitOnOutOfMemory and CrashOnOutOfMemory in HotSpot
kevinw
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5ab871b40190 8138745: Implement ExitOnOutOfMemory and CrashOnOutOfMemory in HotSpot
kevinw
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
5ab871b40190 8138745: Implement ExitOnOutOfMemory and CrashOnOutOfMemory in HotSpot
kevinw
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
5ab871b40190 8138745: Implement ExitOnOutOfMemory and CrashOnOutOfMemory in HotSpot
kevinw
parents:
diff changeset
    13
 * accompanied this code).
5ab871b40190 8138745: Implement ExitOnOutOfMemory and CrashOnOutOfMemory in HotSpot
kevinw
parents:
diff changeset
    14
 *
5ab871b40190 8138745: Implement ExitOnOutOfMemory and CrashOnOutOfMemory in HotSpot
kevinw
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
5ab871b40190 8138745: Implement ExitOnOutOfMemory and CrashOnOutOfMemory in HotSpot
kevinw
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
5ab871b40190 8138745: Implement ExitOnOutOfMemory and CrashOnOutOfMemory in HotSpot
kevinw
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5ab871b40190 8138745: Implement ExitOnOutOfMemory and CrashOnOutOfMemory in HotSpot
kevinw
parents:
diff changeset
    18
 *
5ab871b40190 8138745: Implement ExitOnOutOfMemory and CrashOnOutOfMemory in HotSpot
kevinw
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
5ab871b40190 8138745: Implement ExitOnOutOfMemory and CrashOnOutOfMemory in HotSpot
kevinw
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
5ab871b40190 8138745: Implement ExitOnOutOfMemory and CrashOnOutOfMemory in HotSpot
kevinw
parents:
diff changeset
    21
 * questions.
5ab871b40190 8138745: Implement ExitOnOutOfMemory and CrashOnOutOfMemory in HotSpot
kevinw
parents:
diff changeset
    22
 */
5ab871b40190 8138745: Implement ExitOnOutOfMemory and CrashOnOutOfMemory in HotSpot
kevinw
parents:
diff changeset
    23
5ab871b40190 8138745: Implement ExitOnOutOfMemory and CrashOnOutOfMemory in HotSpot
kevinw
parents:
diff changeset
    24
/*
5ab871b40190 8138745: Implement ExitOnOutOfMemory and CrashOnOutOfMemory in HotSpot
kevinw
parents:
diff changeset
    25
 * @test TestExitOnOutOfMemoryError
5ab871b40190 8138745: Implement ExitOnOutOfMemory and CrashOnOutOfMemory in HotSpot
kevinw
parents:
diff changeset
    26
 * @summary Test using -XX:ExitOnOutOfMemoryError
38152
80e5da81fb2c 8154258: [TESTBUG] Various serviceability tests fail compilation
dsamersoff
parents: 34670
diff changeset
    27
 * @modules java.base/jdk.internal.misc
34670
5ab871b40190 8138745: Implement ExitOnOutOfMemory and CrashOnOutOfMemory in HotSpot
kevinw
parents:
diff changeset
    28
 * @library /testlibrary
5ab871b40190 8138745: Implement ExitOnOutOfMemory and CrashOnOutOfMemory in HotSpot
kevinw
parents:
diff changeset
    29
 * @build jdk.test.lib.*
5ab871b40190 8138745: Implement ExitOnOutOfMemory and CrashOnOutOfMemory in HotSpot
kevinw
parents:
diff changeset
    30
 * @run driver TestExitOnOutOfMemoryError
5ab871b40190 8138745: Implement ExitOnOutOfMemory and CrashOnOutOfMemory in HotSpot
kevinw
parents:
diff changeset
    31
 * @bug 8138745
5ab871b40190 8138745: Implement ExitOnOutOfMemory and CrashOnOutOfMemory in HotSpot
kevinw
parents:
diff changeset
    32
 */
5ab871b40190 8138745: Implement ExitOnOutOfMemory and CrashOnOutOfMemory in HotSpot
kevinw
parents:
diff changeset
    33
5ab871b40190 8138745: Implement ExitOnOutOfMemory and CrashOnOutOfMemory in HotSpot
kevinw
parents:
diff changeset
    34
import jdk.test.lib.ProcessTools;
5ab871b40190 8138745: Implement ExitOnOutOfMemory and CrashOnOutOfMemory in HotSpot
kevinw
parents:
diff changeset
    35
import jdk.test.lib.OutputAnalyzer;
5ab871b40190 8138745: Implement ExitOnOutOfMemory and CrashOnOutOfMemory in HotSpot
kevinw
parents:
diff changeset
    36
5ab871b40190 8138745: Implement ExitOnOutOfMemory and CrashOnOutOfMemory in HotSpot
kevinw
parents:
diff changeset
    37
public class TestExitOnOutOfMemoryError {
5ab871b40190 8138745: Implement ExitOnOutOfMemory and CrashOnOutOfMemory in HotSpot
kevinw
parents:
diff changeset
    38
5ab871b40190 8138745: Implement ExitOnOutOfMemory and CrashOnOutOfMemory in HotSpot
kevinw
parents:
diff changeset
    39
    public static void main(String[] args) throws Exception {
5ab871b40190 8138745: Implement ExitOnOutOfMemory and CrashOnOutOfMemory in HotSpot
kevinw
parents:
diff changeset
    40
        if (args.length == 1) {
5ab871b40190 8138745: Implement ExitOnOutOfMemory and CrashOnOutOfMemory in HotSpot
kevinw
parents:
diff changeset
    41
            // This should guarantee to throw:
5ab871b40190 8138745: Implement ExitOnOutOfMemory and CrashOnOutOfMemory in HotSpot
kevinw
parents:
diff changeset
    42
            // java.lang.OutOfMemoryError: Requested array size exceeds VM limit
5ab871b40190 8138745: Implement ExitOnOutOfMemory and CrashOnOutOfMemory in HotSpot
kevinw
parents:
diff changeset
    43
            try {
5ab871b40190 8138745: Implement ExitOnOutOfMemory and CrashOnOutOfMemory in HotSpot
kevinw
parents:
diff changeset
    44
                Object[] oa = new Object[Integer.MAX_VALUE];
5ab871b40190 8138745: Implement ExitOnOutOfMemory and CrashOnOutOfMemory in HotSpot
kevinw
parents:
diff changeset
    45
                throw new Error("OOME not triggered");
5ab871b40190 8138745: Implement ExitOnOutOfMemory and CrashOnOutOfMemory in HotSpot
kevinw
parents:
diff changeset
    46
            } catch (OutOfMemoryError err) {
5ab871b40190 8138745: Implement ExitOnOutOfMemory and CrashOnOutOfMemory in HotSpot
kevinw
parents:
diff changeset
    47
                throw new Error("OOME didn't terminate JVM!");
5ab871b40190 8138745: Implement ExitOnOutOfMemory and CrashOnOutOfMemory in HotSpot
kevinw
parents:
diff changeset
    48
            }
5ab871b40190 8138745: Implement ExitOnOutOfMemory and CrashOnOutOfMemory in HotSpot
kevinw
parents:
diff changeset
    49
        }
5ab871b40190 8138745: Implement ExitOnOutOfMemory and CrashOnOutOfMemory in HotSpot
kevinw
parents:
diff changeset
    50
5ab871b40190 8138745: Implement ExitOnOutOfMemory and CrashOnOutOfMemory in HotSpot
kevinw
parents:
diff changeset
    51
        // else this is the main test
5ab871b40190 8138745: Implement ExitOnOutOfMemory and CrashOnOutOfMemory in HotSpot
kevinw
parents:
diff changeset
    52
        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+ExitOnOutOfMemoryError",
5ab871b40190 8138745: Implement ExitOnOutOfMemory and CrashOnOutOfMemory in HotSpot
kevinw
parents:
diff changeset
    53
                "-Xmx64m", TestExitOnOutOfMemoryError.class.getName(), "throwOOME");
5ab871b40190 8138745: Implement ExitOnOutOfMemory and CrashOnOutOfMemory in HotSpot
kevinw
parents:
diff changeset
    54
        OutputAnalyzer output = new OutputAnalyzer(pb.start());
5ab871b40190 8138745: Implement ExitOnOutOfMemory and CrashOnOutOfMemory in HotSpot
kevinw
parents:
diff changeset
    55
5ab871b40190 8138745: Implement ExitOnOutOfMemory and CrashOnOutOfMemory in HotSpot
kevinw
parents:
diff changeset
    56
        /*
5ab871b40190 8138745: Implement ExitOnOutOfMemory and CrashOnOutOfMemory in HotSpot
kevinw
parents:
diff changeset
    57
         * Actual output should look like this:
5ab871b40190 8138745: Implement ExitOnOutOfMemory and CrashOnOutOfMemory in HotSpot
kevinw
parents:
diff changeset
    58
         * Terminating due to java.lang.OutOfMemoryError: Requested array size exceeds VM limit
5ab871b40190 8138745: Implement ExitOnOutOfMemory and CrashOnOutOfMemory in HotSpot
kevinw
parents:
diff changeset
    59
         */
5ab871b40190 8138745: Implement ExitOnOutOfMemory and CrashOnOutOfMemory in HotSpot
kevinw
parents:
diff changeset
    60
        output.shouldHaveExitValue(3);
5ab871b40190 8138745: Implement ExitOnOutOfMemory and CrashOnOutOfMemory in HotSpot
kevinw
parents:
diff changeset
    61
        output.stdoutShouldNotBeEmpty();
5ab871b40190 8138745: Implement ExitOnOutOfMemory and CrashOnOutOfMemory in HotSpot
kevinw
parents:
diff changeset
    62
        output.shouldContain("Terminating due to java.lang.OutOfMemoryError: Requested array size exceeds VM limit");
5ab871b40190 8138745: Implement ExitOnOutOfMemory and CrashOnOutOfMemory in HotSpot
kevinw
parents:
diff changeset
    63
        System.out.println("PASSED");
5ab871b40190 8138745: Implement ExitOnOutOfMemory and CrashOnOutOfMemory in HotSpot
kevinw
parents:
diff changeset
    64
    }
5ab871b40190 8138745: Implement ExitOnOutOfMemory and CrashOnOutOfMemory in HotSpot
kevinw
parents:
diff changeset
    65
}