Path: blob/master/test/hotspot/jtreg/gc/epsilon/TestDieWithOnError.java
40943 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("-Xmx128m",60"-XX:+UnlockExperimentalVMOptions",61"-XX:+UseEpsilonGC",62"-Dcount=1",63"-XX:OnOutOfMemoryError=echo " + ON_ERR_MSG,64TestDieWithOnError.Workload.class.getName());6566failWith("-Xmx128m",67"-XX:+UnlockExperimentalVMOptions",68"-XX:+UseEpsilonGC",69"-XX:OnOutOfMemoryError=echo " + ON_ERR_MSG,70TestDieWithOnError.Workload.class.getName());7172failWith("-Xmx128m",73"-Xint",74"-XX:+UnlockExperimentalVMOptions",75"-XX:+UseEpsilonGC",76"-XX:OnOutOfMemoryError=echo " + ON_ERR_MSG,77TestDieWithOnError.Workload.class.getName());7879failWith("-Xmx128m",80"-Xbatch",81"-Xcomp",82"-XX:+UnlockExperimentalVMOptions",83"-XX:+UseEpsilonGC",84"-XX:OnOutOfMemoryError=echo " + ON_ERR_MSG,85TestDieWithOnError.Workload.class.getName());8687failWith("-Xmx128m",88"-Xbatch",89"-Xcomp",90"-XX:TieredStopAtLevel=1",91"-XX:+UnlockExperimentalVMOptions",92"-XX:+UseEpsilonGC",93"-XX:OnOutOfMemoryError=echo " + ON_ERR_MSG,94TestDieWithOnError.Workload.class.getName());9596failWith("-Xmx128m",97"-Xbatch",98"-Xcomp",99"-XX:-TieredCompilation",100"-XX:+UnlockExperimentalVMOptions",101"-XX:+UseEpsilonGC",102"-XX:OnOutOfMemoryError=echo " + ON_ERR_MSG,103TestDieWithOnError.Workload.class.getName());104}105106public static class Workload {107static int COUNT = Integer.getInteger("count", 1_000_000_000); // ~24 GB allocation108109static volatile Object sink;110111public static void main(String... args) {112for (int c = 0; c < COUNT; c++) {113sink = new Object();114}115}116}117118}119120121