hotspot/test/runtime/ErrorHandling/TestOnOutOfMemoryError.java
changeset 46476 8ead62daaa47
parent 40631 ed82623d7831
equal deleted inserted replaced
46474:c872a196b75f 46476:8ead62daaa47
     1 /*
     1 /*
     2  * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    21  * questions.
    21  * questions.
    22  */
    22  */
    23 
    23 
    24 /*
    24 /*
    25  * @test TestOnOutOfMemoryError
    25  * @test TestOnOutOfMemoryError
    26  * @summary Test using -XX:OnOutOfMemoryError=<cmd>
    26  * @summary Test using single and multiple -XX:OnOutOfMemoryError=<cmd>
    27  * @modules java.base/jdk.internal.misc
    27  * @modules java.base/jdk.internal.misc
    28  * @library /test/lib
    28  * @library /test/lib
    29  * @run main TestOnOutOfMemoryError
    29  * @run main TestOnOutOfMemoryError
    30  * @bug 8078470
    30  * @bug 8078470 8177522
    31  */
    31  */
    32 
    32 
    33 import jdk.test.lib.process.ProcessTools;
    33 import jdk.test.lib.process.ProcessTools;
    34 import jdk.test.lib.process.OutputAnalyzer;
    34 import jdk.test.lib.process.OutputAnalyzer;
    35 
    35 
    42             Object[] oa = new Object[Integer.MAX_VALUE];
    42             Object[] oa = new Object[Integer.MAX_VALUE];
    43             return;
    43             return;
    44         }
    44         }
    45 
    45 
    46         // else this is the main test
    46         // else this is the main test
    47         String msg = "Test Succeeded";
    47         String msg1 = "Test1 Succeeded";
    48         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
    48         String msg2 = "Test2 Succeeded";
    49            "-XX:OnOutOfMemoryError=echo " + msg,
    49         ProcessBuilder pb_single = ProcessTools.createJavaProcessBuilder(
       
    50            "-XX:OnOutOfMemoryError=echo " + msg1,
    50            TestOnOutOfMemoryError.class.getName(),
    51            TestOnOutOfMemoryError.class.getName(),
    51            "throwOOME");
    52            "throwOOME");
    52 
    53 
    53         OutputAnalyzer output = new OutputAnalyzer(pb.start());
    54         ProcessBuilder pb_multiple = ProcessTools.createJavaProcessBuilder(
       
    55            "-XX:OnOutOfMemoryError=echo " + msg1,
       
    56            "-XX:OnOutOfMemoryError=echo " + msg2,
       
    57            TestOnOutOfMemoryError.class.getName(),
       
    58            "throwOOME");
       
    59 
       
    60         OutputAnalyzer output_single = new OutputAnalyzer(pb_single.start());
       
    61 
       
    62         OutputAnalyzer output_multiple = new OutputAnalyzer(pb_multiple.start());
    54 
    63 
    55         /* Actual output should look like this:
    64         /* Actual output should look like this:
    56            #
    65            #
    57            # java.lang.OutOfMemoryError: Requested array size exceeds VM limit
    66            # java.lang.OutOfMemoryError: Requested array size exceeds VM limit
    58            # -XX:OnOutOfMemoryError="echo Test Succeeded"
    67            # -XX:OnOutOfMemoryError="echo Test Succeeded"
    62            at OOME.main(OOME.java:3)
    71            at OOME.main(OOME.java:3)
    63 
    72 
    64            So we don't want to match on the "# Executing ..." line, and they
    73            So we don't want to match on the "# Executing ..." line, and they
    65            both get written to stdout.
    74            both get written to stdout.
    66         */
    75         */
    67         output.shouldContain("Requested array size exceeds VM limit");
    76         output_single.shouldContain("Requested array size exceeds VM limit");
    68         output.stdoutShouldMatch("^" + msg); // match start of line only
    77         output_single.stdoutShouldMatch("^" + msg1); // match start of line only
       
    78 
       
    79         output_multiple.shouldContain("Requested array size exceeds VM limit");
       
    80         output_multiple.stdoutShouldMatch("^" + msg1); // match start of line only
       
    81         output_multiple.stdoutShouldMatch("^" + msg2); // match start of line only
       
    82 
    69         System.out.println("PASSED");
    83         System.out.println("PASSED");
    70     }
    84     }
    71 }
    85 }