Path: blob/master/test/hotspot/jtreg/gc/epsilon/TestDieDefault.java
40942 views
/*1* Copyright (c) 2017, 2018, Red Hat, Inc. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223package gc.epsilon;2425/**26* @test TestDieDefault27* @requires vm.gc.Epsilon28* @summary Epsilon GC should die on heap exhaustion29* @library /test/lib30* @run driver gc.epsilon.TestDieDefault31*/3233import jdk.test.lib.process.OutputAnalyzer;34import jdk.test.lib.process.ProcessTools;3536public class TestDieDefault {3738public static void passWith(String... args) throws Exception {39ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(args);40OutputAnalyzer out = new OutputAnalyzer(pb.start());41out.shouldNotContain("OutOfMemoryError");42out.shouldHaveExitValue(0);43}4445public static void failWith(String... args) throws Exception {46ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(args);47OutputAnalyzer out = new OutputAnalyzer(pb.start());48out.shouldContain("OutOfMemoryError");49if (out.getExitValue() == 0) {50throw new IllegalStateException("Should have failed with non-zero exit code");51}52}5354public static void main(String[] args) throws Exception {55passWith("-Xmx128m",56"-XX:+UnlockExperimentalVMOptions",57"-XX:+UseEpsilonGC",58"-Dcount=1",59TestDieDefault.Workload.class.getName());6061failWith("-Xmx128m",62"-XX:+UnlockExperimentalVMOptions",63"-XX:+UseEpsilonGC",64TestDieDefault.Workload.class.getName());6566failWith("-Xmx128m",67"-Xint",68"-XX:+UnlockExperimentalVMOptions",69"-XX:+UseEpsilonGC",70TestDieDefault.Workload.class.getName());7172failWith("-Xmx128m",73"-Xbatch",74"-Xcomp",75"-XX:+UnlockExperimentalVMOptions",76"-XX:+UseEpsilonGC",77TestDieDefault.Workload.class.getName());7879failWith("-Xmx128m",80"-Xbatch",81"-Xcomp",82"-XX:TieredStopAtLevel=1",83"-XX:+UnlockExperimentalVMOptions",84"-XX:+UseEpsilonGC",85TestDieDefault.Workload.class.getName());8687failWith("-Xmx128m",88"-Xbatch",89"-Xcomp",90"-XX:-TieredCompilation",91"-XX:+UnlockExperimentalVMOptions",92"-XX:+UseEpsilonGC",93TestDieDefault.Workload.class.getName());94}9596public static class Workload {97static int COUNT = Integer.getInteger("count", 1_000_000_000); // ~24 GB allocation9899static volatile Object sink;100101public static void main(String... args) {102for (int c = 0; c < COUNT; c++) {103sink = new Object();104}105}106}107108}109110111