Path: blob/master/test/hotspot/jtreg/gc/epsilon/TestDieWithOnError.java
66644 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 TestDieWithOnError27* @requires vm.gc.Epsilon28* @summary Epsilon GC should die on heap exhaustion with error handler attached29* @library /test/lib30* @run driver gc.epsilon.TestDieWithOnError31*/3233import jdk.test.lib.process.OutputAnalyzer;34import jdk.test.lib.process.ProcessTools;3536public class TestDieWithOnError {3738static String ON_ERR_MSG = "Epsilon error handler message";3940public static void passWith(String... args) throws Exception {41ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(args);42OutputAnalyzer out = new OutputAnalyzer(pb.start());43out.shouldNotContain("OutOfMemoryError");44out.stdoutShouldNotMatch("^" + ON_ERR_MSG);45out.shouldHaveExitValue(0);46}4748public static void failWith(String... args) throws Exception {49ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(args);50OutputAnalyzer out = new OutputAnalyzer(pb.start());51out.shouldContain("OutOfMemoryError");52if (out.getExitValue() == 0) {53throw new IllegalStateException("Should have failed with non-zero exit code");54}55out.stdoutShouldMatch("^" + ON_ERR_MSG);56}5758public static void main(String[] args) throws Exception {59passWith("-Xmx64m",60"-XX:+UnlockExperimentalVMOptions",61"-XX:+UseEpsilonGC",62"-Dcount=1",63"-XX:OnOutOfMemoryError=echo " + ON_ERR_MSG,64TestDieWithOnError.Workload.class.getName());6566failWith("-Xmx64m",67"-XX:+UnlockExperimentalVMOptions",68"-XX:+UseEpsilonGC",69"-XX:OnOutOfMemoryError=echo " + ON_ERR_MSG,70TestDieWithOnError.Workload.class.getName());7172failWith("-Xmx64m",73"-Xint",74"-XX:+UnlockExperimentalVMOptions",75"-XX:+UseEpsilonGC",76"-XX:OnOutOfMemoryError=echo " + ON_ERR_MSG,77TestDieWithOnError.Workload.class.getName());7879failWith("-Xmx64m",80"-Xbatch",81"-Xcomp",82"-XX:TieredStopAtLevel=1",83"-XX:+UnlockExperimentalVMOptions",84"-XX:+UseEpsilonGC",85"-XX:OnOutOfMemoryError=echo " + ON_ERR_MSG,86TestDieWithOnError.Workload.class.getName());8788failWith("-Xmx64m",89"-Xbatch",90"-Xcomp",91"-XX:-TieredCompilation",92"-XX:+UnlockExperimentalVMOptions",93"-XX:+UseEpsilonGC",94"-XX:OnOutOfMemoryError=echo " + ON_ERR_MSG,95TestDieWithOnError.Workload.class.getName());96}9798public static class Workload {99static int COUNT = Integer.getInteger("count", 1_000_000_000); // ~24 GB allocation100101static volatile Object sink;102103public static void main(String... args) {104for (int c = 0; c < COUNT; c++) {105sink = new Object();106}107}108}109110}111112113