test/runtime/ErrorHandling/TestOnOutOfMemoryError.java

Mon, 06 Nov 2017 16:51:47 +0800

author
aoqi
date
Mon, 06 Nov 2017 16:51:47 +0800
changeset 7997
6cbff0651f1a
parent 7793
915ca3e9d15e
permissions
-rw-r--r--

[Code Reorganization] remove trailing whitespace to pass jcheck test

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

mercurial