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 TestDieDefault 26 * @key gc 27 * @requires vm.gc.Epsilon 28 * @summary Epsilon GC should die on heap exhaustion 29 * @library /test/lib 30 * @run main TestDieDefault 31 */ 32 33 import jdk.test.lib.process.OutputAnalyzer; 34 import jdk.test.lib.process.ProcessTools; 35 36 public class TestDieDefault { 37 38 public static void passWith(String... args) throws Exception { 39 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(args); 40 OutputAnalyzer out = new OutputAnalyzer(pb.start()); 41 out.shouldNotContain("OutOfMemoryError"); 42 out.shouldHaveExitValue(0); 43 } 44 45 public static void failWith(String... args) throws Exception { 46 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(args); 47 OutputAnalyzer out = new OutputAnalyzer(pb.start()); 48 out.shouldContain("OutOfMemoryError"); 49 if (out.getExitValue() == 0) { 50 throw new IllegalStateException("Should have failed with non-zero exit code"); 51 } 52 } 53 54 public static void main(String[] args) throws Exception { 55 passWith("-Xmx128m", 56 "-XX:+UnlockExperimentalVMOptions", 57 "-XX:+UseEpsilonGC", 58 "-Dcount=1", 59 TestDieDefault.Workload.class.getName()); 60 61 failWith("-Xmx128m", 62 "-XX:+UnlockExperimentalVMOptions", 63 "-XX:+UseEpsilonGC", 64 TestDieDefault.Workload.class.getName()); 65 66 failWith("-Xmx128m", 67 "-Xint", 68 "-XX:+UnlockExperimentalVMOptions", 69 "-XX:+UseEpsilonGC", 70 TestDieDefault.Workload.class.getName()); 71 72 failWith("-Xmx128m", 73 "-Xbatch", 74 "-Xcomp", 75 "-XX:+UnlockExperimentalVMOptions", 76 "-XX:+UseEpsilonGC", 77 TestDieDefault.Workload.class.getName()); 78 79 failWith("-Xmx128m", 80 "-Xbatch", 81 "-Xcomp", 82 "-XX:TieredStopAtLevel=1", 83 "-XX:+UnlockExperimentalVMOptions", 84 "-XX:+UseEpsilonGC", 85 TestDieDefault.Workload.class.getName()); 86 87 failWith("-Xmx128m", 88 "-Xbatch", 89 "-Xcomp", 90 "-XX:TieredStopAtLevel=4", 91 "-XX:+UnlockExperimentalVMOptions", 92 "-XX:+UseEpsilonGC", 93 TestDieDefault.Workload.class.getName()); 94 } 95 96 public static class Workload { 97 static int COUNT = Integer.getInteger("count", 1_000_000_000); // ~24 GB allocation 98 99 static volatile Object sink; 100 101 public static void main(String... args) { 102 for (int c = 0; c < COUNT; c++) { 103 sink = new Object(); 104 } 105 } 106 } 107 108 }