hotspot/test/runtime/ErrorHandling/TestOnOutOfMemoryError.java
author vkempik
Thu, 18 May 2017 08:14:33 -0400
changeset 46476 8ead62daaa47
parent 40631 ed82623d7831
permissions -rw-r--r--
8177522: -XX:OnOutOfMemoryError does not work if supplied twice on windows Summary: use cmd /c on windows to execute onError commands Reviewed-by: dholmes, hseigel
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
30745
8ebe80838174 8078470: [Linux] Replace syscall use in os::fork_and_exec with glibc fork() and execve()
dholmes
parents:
diff changeset
     1
/*
46476
8ead62daaa47 8177522: -XX:OnOutOfMemoryError does not work if supplied twice on windows
vkempik
parents: 40631
diff changeset
     2
 * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
30745
8ebe80838174 8078470: [Linux] Replace syscall use in os::fork_and_exec with glibc fork() and execve()
dholmes
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8ebe80838174 8078470: [Linux] Replace syscall use in os::fork_and_exec with glibc fork() and execve()
dholmes
parents:
diff changeset
     4
 *
8ebe80838174 8078470: [Linux] Replace syscall use in os::fork_and_exec with glibc fork() and execve()
dholmes
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
8ebe80838174 8078470: [Linux] Replace syscall use in os::fork_and_exec with glibc fork() and execve()
dholmes
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
8ebe80838174 8078470: [Linux] Replace syscall use in os::fork_and_exec with glibc fork() and execve()
dholmes
parents:
diff changeset
     7
 * published by the Free Software Foundation.
8ebe80838174 8078470: [Linux] Replace syscall use in os::fork_and_exec with glibc fork() and execve()
dholmes
parents:
diff changeset
     8
 *
8ebe80838174 8078470: [Linux] Replace syscall use in os::fork_and_exec with glibc fork() and execve()
dholmes
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
8ebe80838174 8078470: [Linux] Replace syscall use in os::fork_and_exec with glibc fork() and execve()
dholmes
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
8ebe80838174 8078470: [Linux] Replace syscall use in os::fork_and_exec with glibc fork() and execve()
dholmes
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
8ebe80838174 8078470: [Linux] Replace syscall use in os::fork_and_exec with glibc fork() and execve()
dholmes
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
8ebe80838174 8078470: [Linux] Replace syscall use in os::fork_and_exec with glibc fork() and execve()
dholmes
parents:
diff changeset
    13
 * accompanied this code).
8ebe80838174 8078470: [Linux] Replace syscall use in os::fork_and_exec with glibc fork() and execve()
dholmes
parents:
diff changeset
    14
 *
8ebe80838174 8078470: [Linux] Replace syscall use in os::fork_and_exec with glibc fork() and execve()
dholmes
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
8ebe80838174 8078470: [Linux] Replace syscall use in os::fork_and_exec with glibc fork() and execve()
dholmes
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
8ebe80838174 8078470: [Linux] Replace syscall use in os::fork_and_exec with glibc fork() and execve()
dholmes
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
8ebe80838174 8078470: [Linux] Replace syscall use in os::fork_and_exec with glibc fork() and execve()
dholmes
parents:
diff changeset
    18
 *
8ebe80838174 8078470: [Linux] Replace syscall use in os::fork_and_exec with glibc fork() and execve()
dholmes
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
8ebe80838174 8078470: [Linux] Replace syscall use in os::fork_and_exec with glibc fork() and execve()
dholmes
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
8ebe80838174 8078470: [Linux] Replace syscall use in os::fork_and_exec with glibc fork() and execve()
dholmes
parents:
diff changeset
    21
 * questions.
8ebe80838174 8078470: [Linux] Replace syscall use in os::fork_and_exec with glibc fork() and execve()
dholmes
parents:
diff changeset
    22
 */
8ebe80838174 8078470: [Linux] Replace syscall use in os::fork_and_exec with glibc fork() and execve()
dholmes
parents:
diff changeset
    23
8ebe80838174 8078470: [Linux] Replace syscall use in os::fork_and_exec with glibc fork() and execve()
dholmes
parents:
diff changeset
    24
/*
8ebe80838174 8078470: [Linux] Replace syscall use in os::fork_and_exec with glibc fork() and execve()
dholmes
parents:
diff changeset
    25
 * @test TestOnOutOfMemoryError
46476
8ead62daaa47 8177522: -XX:OnOutOfMemoryError does not work if supplied twice on windows
vkempik
parents: 40631
diff changeset
    26
 * @summary Test using single and multiple -XX:OnOutOfMemoryError=<cmd>
38152
80e5da81fb2c 8154258: [TESTBUG] Various serviceability tests fail compilation
dsamersoff
parents: 30745
diff changeset
    27
 * @modules java.base/jdk.internal.misc
40631
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 38152
diff changeset
    28
 * @library /test/lib
30745
8ebe80838174 8078470: [Linux] Replace syscall use in os::fork_and_exec with glibc fork() and execve()
dholmes
parents:
diff changeset
    29
 * @run main TestOnOutOfMemoryError
46476
8ead62daaa47 8177522: -XX:OnOutOfMemoryError does not work if supplied twice on windows
vkempik
parents: 40631
diff changeset
    30
 * @bug 8078470 8177522
30745
8ebe80838174 8078470: [Linux] Replace syscall use in os::fork_and_exec with glibc fork() and execve()
dholmes
parents:
diff changeset
    31
 */
8ebe80838174 8078470: [Linux] Replace syscall use in os::fork_and_exec with glibc fork() and execve()
dholmes
parents:
diff changeset
    32
40631
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 38152
diff changeset
    33
import jdk.test.lib.process.ProcessTools;
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 38152
diff changeset
    34
import jdk.test.lib.process.OutputAnalyzer;
30745
8ebe80838174 8078470: [Linux] Replace syscall use in os::fork_and_exec with glibc fork() and execve()
dholmes
parents:
diff changeset
    35
8ebe80838174 8078470: [Linux] Replace syscall use in os::fork_and_exec with glibc fork() and execve()
dholmes
parents:
diff changeset
    36
public class TestOnOutOfMemoryError {
8ebe80838174 8078470: [Linux] Replace syscall use in os::fork_and_exec with glibc fork() and execve()
dholmes
parents:
diff changeset
    37
8ebe80838174 8078470: [Linux] Replace syscall use in os::fork_and_exec with glibc fork() and execve()
dholmes
parents:
diff changeset
    38
    public static void main(String[] args) throws Exception {
8ebe80838174 8078470: [Linux] Replace syscall use in os::fork_and_exec with glibc fork() and execve()
dholmes
parents:
diff changeset
    39
        if (args.length == 1) {
8ebe80838174 8078470: [Linux] Replace syscall use in os::fork_and_exec with glibc fork() and execve()
dholmes
parents:
diff changeset
    40
            // This should guarantee to throw:
8ebe80838174 8078470: [Linux] Replace syscall use in os::fork_and_exec with glibc fork() and execve()
dholmes
parents:
diff changeset
    41
            //  java.lang.OutOfMemoryError: Requested array size exceeds VM limit
8ebe80838174 8078470: [Linux] Replace syscall use in os::fork_and_exec with glibc fork() and execve()
dholmes
parents:
diff changeset
    42
            Object[] oa = new Object[Integer.MAX_VALUE];
8ebe80838174 8078470: [Linux] Replace syscall use in os::fork_and_exec with glibc fork() and execve()
dholmes
parents:
diff changeset
    43
            return;
8ebe80838174 8078470: [Linux] Replace syscall use in os::fork_and_exec with glibc fork() and execve()
dholmes
parents:
diff changeset
    44
        }
8ebe80838174 8078470: [Linux] Replace syscall use in os::fork_and_exec with glibc fork() and execve()
dholmes
parents:
diff changeset
    45
8ebe80838174 8078470: [Linux] Replace syscall use in os::fork_and_exec with glibc fork() and execve()
dholmes
parents:
diff changeset
    46
        // else this is the main test
46476
8ead62daaa47 8177522: -XX:OnOutOfMemoryError does not work if supplied twice on windows
vkempik
parents: 40631
diff changeset
    47
        String msg1 = "Test1 Succeeded";
8ead62daaa47 8177522: -XX:OnOutOfMemoryError does not work if supplied twice on windows
vkempik
parents: 40631
diff changeset
    48
        String msg2 = "Test2 Succeeded";
8ead62daaa47 8177522: -XX:OnOutOfMemoryError does not work if supplied twice on windows
vkempik
parents: 40631
diff changeset
    49
        ProcessBuilder pb_single = ProcessTools.createJavaProcessBuilder(
8ead62daaa47 8177522: -XX:OnOutOfMemoryError does not work if supplied twice on windows
vkempik
parents: 40631
diff changeset
    50
           "-XX:OnOutOfMemoryError=echo " + msg1,
30745
8ebe80838174 8078470: [Linux] Replace syscall use in os::fork_and_exec with glibc fork() and execve()
dholmes
parents:
diff changeset
    51
           TestOnOutOfMemoryError.class.getName(),
8ebe80838174 8078470: [Linux] Replace syscall use in os::fork_and_exec with glibc fork() and execve()
dholmes
parents:
diff changeset
    52
           "throwOOME");
8ebe80838174 8078470: [Linux] Replace syscall use in os::fork_and_exec with glibc fork() and execve()
dholmes
parents:
diff changeset
    53
46476
8ead62daaa47 8177522: -XX:OnOutOfMemoryError does not work if supplied twice on windows
vkempik
parents: 40631
diff changeset
    54
        ProcessBuilder pb_multiple = ProcessTools.createJavaProcessBuilder(
8ead62daaa47 8177522: -XX:OnOutOfMemoryError does not work if supplied twice on windows
vkempik
parents: 40631
diff changeset
    55
           "-XX:OnOutOfMemoryError=echo " + msg1,
8ead62daaa47 8177522: -XX:OnOutOfMemoryError does not work if supplied twice on windows
vkempik
parents: 40631
diff changeset
    56
           "-XX:OnOutOfMemoryError=echo " + msg2,
8ead62daaa47 8177522: -XX:OnOutOfMemoryError does not work if supplied twice on windows
vkempik
parents: 40631
diff changeset
    57
           TestOnOutOfMemoryError.class.getName(),
8ead62daaa47 8177522: -XX:OnOutOfMemoryError does not work if supplied twice on windows
vkempik
parents: 40631
diff changeset
    58
           "throwOOME");
8ead62daaa47 8177522: -XX:OnOutOfMemoryError does not work if supplied twice on windows
vkempik
parents: 40631
diff changeset
    59
8ead62daaa47 8177522: -XX:OnOutOfMemoryError does not work if supplied twice on windows
vkempik
parents: 40631
diff changeset
    60
        OutputAnalyzer output_single = new OutputAnalyzer(pb_single.start());
8ead62daaa47 8177522: -XX:OnOutOfMemoryError does not work if supplied twice on windows
vkempik
parents: 40631
diff changeset
    61
8ead62daaa47 8177522: -XX:OnOutOfMemoryError does not work if supplied twice on windows
vkempik
parents: 40631
diff changeset
    62
        OutputAnalyzer output_multiple = new OutputAnalyzer(pb_multiple.start());
30745
8ebe80838174 8078470: [Linux] Replace syscall use in os::fork_and_exec with glibc fork() and execve()
dholmes
parents:
diff changeset
    63
8ebe80838174 8078470: [Linux] Replace syscall use in os::fork_and_exec with glibc fork() and execve()
dholmes
parents:
diff changeset
    64
        /* Actual output should look like this:
8ebe80838174 8078470: [Linux] Replace syscall use in os::fork_and_exec with glibc fork() and execve()
dholmes
parents:
diff changeset
    65
           #
8ebe80838174 8078470: [Linux] Replace syscall use in os::fork_and_exec with glibc fork() and execve()
dholmes
parents:
diff changeset
    66
           # java.lang.OutOfMemoryError: Requested array size exceeds VM limit
8ebe80838174 8078470: [Linux] Replace syscall use in os::fork_and_exec with glibc fork() and execve()
dholmes
parents:
diff changeset
    67
           # -XX:OnOutOfMemoryError="echo Test Succeeded"
8ebe80838174 8078470: [Linux] Replace syscall use in os::fork_and_exec with glibc fork() and execve()
dholmes
parents:
diff changeset
    68
           #   Executing /bin/sh -c "echo Test Succeeded"...
8ebe80838174 8078470: [Linux] Replace syscall use in os::fork_and_exec with glibc fork() and execve()
dholmes
parents:
diff changeset
    69
           Test Succeeded
8ebe80838174 8078470: [Linux] Replace syscall use in os::fork_and_exec with glibc fork() and execve()
dholmes
parents:
diff changeset
    70
           Exception in thread "main" java.lang.OutOfMemoryError: Requested array size exceeds VM limit
8ebe80838174 8078470: [Linux] Replace syscall use in os::fork_and_exec with glibc fork() and execve()
dholmes
parents:
diff changeset
    71
           at OOME.main(OOME.java:3)
8ebe80838174 8078470: [Linux] Replace syscall use in os::fork_and_exec with glibc fork() and execve()
dholmes
parents:
diff changeset
    72
8ebe80838174 8078470: [Linux] Replace syscall use in os::fork_and_exec with glibc fork() and execve()
dholmes
parents:
diff changeset
    73
           So we don't want to match on the "# Executing ..." line, and they
8ebe80838174 8078470: [Linux] Replace syscall use in os::fork_and_exec with glibc fork() and execve()
dholmes
parents:
diff changeset
    74
           both get written to stdout.
8ebe80838174 8078470: [Linux] Replace syscall use in os::fork_and_exec with glibc fork() and execve()
dholmes
parents:
diff changeset
    75
        */
46476
8ead62daaa47 8177522: -XX:OnOutOfMemoryError does not work if supplied twice on windows
vkempik
parents: 40631
diff changeset
    76
        output_single.shouldContain("Requested array size exceeds VM limit");
8ead62daaa47 8177522: -XX:OnOutOfMemoryError does not work if supplied twice on windows
vkempik
parents: 40631
diff changeset
    77
        output_single.stdoutShouldMatch("^" + msg1); // match start of line only
8ead62daaa47 8177522: -XX:OnOutOfMemoryError does not work if supplied twice on windows
vkempik
parents: 40631
diff changeset
    78
8ead62daaa47 8177522: -XX:OnOutOfMemoryError does not work if supplied twice on windows
vkempik
parents: 40631
diff changeset
    79
        output_multiple.shouldContain("Requested array size exceeds VM limit");
8ead62daaa47 8177522: -XX:OnOutOfMemoryError does not work if supplied twice on windows
vkempik
parents: 40631
diff changeset
    80
        output_multiple.stdoutShouldMatch("^" + msg1); // match start of line only
8ead62daaa47 8177522: -XX:OnOutOfMemoryError does not work if supplied twice on windows
vkempik
parents: 40631
diff changeset
    81
        output_multiple.stdoutShouldMatch("^" + msg2); // match start of line only
8ead62daaa47 8177522: -XX:OnOutOfMemoryError does not work if supplied twice on windows
vkempik
parents: 40631
diff changeset
    82
30745
8ebe80838174 8078470: [Linux] Replace syscall use in os::fork_and_exec with glibc fork() and execve()
dholmes
parents:
diff changeset
    83
        System.out.println("PASSED");
8ebe80838174 8078470: [Linux] Replace syscall use in os::fork_and_exec with glibc fork() and execve()
dholmes
parents:
diff changeset
    84
    }
8ebe80838174 8078470: [Linux] Replace syscall use in os::fork_and_exec with glibc fork() and execve()
dholmes
parents:
diff changeset
    85
}