1 /* 2 * Copyright (c) 2017, 2018, Red Hat, Inc. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 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 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /** 25 * @test TestDieWithOnError 26 * @key gc 27 * @requires vm.gc.Epsilon 28 * @summary Epsilon GC should die on heap exhaustion with error handler attached 29 * @library /test/lib 30 * @run main TestDieWithOnError 31 */ 32 33 import jdk.test.lib.process.OutputAnalyzer; 34 import jdk.test.lib.process.ProcessTools; 35 36 public class TestDieWithOnError { 37 38 static String ON_ERR_MSG = "Epsilon error handler message"; 39 40 public static void passWith(String... args) throws Exception { 41 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(args); 42 OutputAnalyzer out = new OutputAnalyzer(pb.start()); 43 out.shouldNotContain("OutOfMemoryError"); 44 out.stdoutShouldNotMatch("^" + ON_ERR_MSG); 45 out.shouldHaveExitValue(0); 46 } 47 48 public static void failWith(String... args) throws Exception { 49 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(args); 50 OutputAnalyzer out = new OutputAnalyzer(pb.start()); 51 out.shouldContain("OutOfMemoryError"); 52 if (out.getExitValue() == 0) { 53 throw new IllegalStateException("Should have failed with non-zero exit code"); 54 } 55 out.stdoutShouldMatch("^" + ON_ERR_MSG); 56 } 57 58 public static void main(String[] args) throws Exception { 59 passWith("-Xmx128m", 60 "-XX:+UnlockExperimentalVMOptions", 61 "-XX:+UseEpsilonGC", 62 "-Dcount=1", 63 "-XX:OnOutOfMemoryError=echo " + ON_ERR_MSG, 64 TestDieWithOnError.Workload.class.getName()); 65 66 failWith("-Xmx128m", 67 "-XX:+UnlockExperimentalVMOptions", 68 "-XX:+UseEpsilonGC", 69 "-XX:OnOutOfMemoryError=echo " + ON_ERR_MSG, 70 TestDieWithOnError.Workload.class.getName()); 71 72 failWith("-Xmx128m", 73 "-Xint", 74 "-XX:+UnlockExperimentalVMOptions", 75 "-XX:+UseEpsilonGC", 76 "-XX:OnOutOfMemoryError=echo " + ON_ERR_MSG, 77 TestDieWithOnError.Workload.class.getName()); 78 79 failWith("-Xmx128m", 80 "-Xbatch", 81 "-Xcomp", 82 "-XX:+UnlockExperimentalVMOptions", 83 "-XX:+UseEpsilonGC", 84 "-XX:OnOutOfMemoryError=echo " + ON_ERR_MSG, 85 TestDieWithOnError.Workload.class.getName()); 86 87 failWith("-Xmx128m", 88 "-Xbatch", 89 "-Xcomp", 90 "-XX:TieredStopAtLevel=1", 91 "-XX:+UnlockExperimentalVMOptions", 92 "-XX:+UseEpsilonGC", 93 "-XX:OnOutOfMemoryError=echo " + ON_ERR_MSG, 94 TestDieWithOnError.Workload.class.getName()); 95 96 failWith("-Xmx128m", 97 "-Xbatch", 98 "-Xcomp", 99 "-XX:-TieredCompilation", 100 "-XX:+UnlockExperimentalVMOptions", 101 "-XX:+UseEpsilonGC", 102 "-XX:OnOutOfMemoryError=echo " + ON_ERR_MSG, 103 TestDieWithOnError.Workload.class.getName()); 104 } 105 106 public static class Workload { 107 static int COUNT = Integer.getInteger("count", 1_000_000_000); // ~24 GB allocation 108 109 static volatile Object sink; 110 111 public static void main(String... args) { 112 for (int c = 0; c < COUNT; c++) { 113 sink = new Object(); 114 } 115 } 116 } 117 118 }