test/runtime/ErrorHandling/TestExitOnOutOfMemoryError.java

Thu, 07 Jan 2016 02:36:48 -0800

author
kevinw
date
Thu, 07 Jan 2016 02:36:48 -0800
changeset 8209
8641949eb21f
child 9617
6384d7f8a123
permissions
-rw-r--r--

8138745: Implement ExitOnOutOfMemory and CrashOnOutOfMemory in HotSpot
Reviewed-by: dholmes
Contributed-by: cheleswer.sahu@oracle.com

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

mercurial