Path: blob/master/test/hotspot/jtreg/gc/epsilon/TestDieWithHeapDump.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 TestDieWithHeapDump27* @requires vm.gc.Epsilon28* @summary Epsilon GC should die on heap exhaustion with error handler attached29* @library /test/lib30* @run driver gc.epsilon.TestDieWithHeapDump31*/3233import java.io.*;34import jdk.test.lib.process.OutputAnalyzer;35import jdk.test.lib.process.ProcessTools;3637public class TestDieWithHeapDump {3839public static void passWith(String... args) throws Exception {40ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(args);41OutputAnalyzer out = new OutputAnalyzer(pb.start());42out.shouldNotContain("OutOfMemoryError");43out.shouldHaveExitValue(0);44}4546public static void failWith(String... args) throws Exception {47ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(args);48Process p = pb.start();49OutputAnalyzer out = new OutputAnalyzer(p);50out.shouldContain("OutOfMemoryError");51if (out.getExitValue() == 0) {52throw new IllegalStateException("Should have failed with non-zero exit code");53}54String heapDump = "java_pid" + p.pid() + ".hprof";55if (!new File(heapDump).exists()) {56throw new IllegalStateException("Should have produced the heap dump at: " + heapDump);57}58}5960public static void main(String[] args) throws Exception {61passWith("-Xmx128m",62"-XX:+UnlockExperimentalVMOptions",63"-XX:+UseEpsilonGC",64"-Dcount=1",65"-XX:+HeapDumpOnOutOfMemoryError",66TestDieWithHeapDump.Workload.class.getName());6768failWith("-Xmx128m",69"-XX:+UnlockExperimentalVMOptions",70"-XX:+UseEpsilonGC",71"-XX:+HeapDumpOnOutOfMemoryError",72TestDieWithHeapDump.Workload.class.getName());7374failWith("-Xmx128m",75"-Xint",76"-XX:+UnlockExperimentalVMOptions",77"-XX:+UseEpsilonGC",78"-XX:+HeapDumpOnOutOfMemoryError",79TestDieWithHeapDump.Workload.class.getName());8081failWith("-Xmx128m",82"-Xbatch",83"-Xcomp",84"-XX:+UnlockExperimentalVMOptions",85"-XX:+UseEpsilonGC",86"-XX:+HeapDumpOnOutOfMemoryError",87TestDieWithHeapDump.Workload.class.getName());8889failWith("-Xmx128m",90"-Xbatch",91"-Xcomp",92"-XX:TieredStopAtLevel=1",93"-XX:+UnlockExperimentalVMOptions",94"-XX:+UseEpsilonGC",95"-XX:+HeapDumpOnOutOfMemoryError",96TestDieWithHeapDump.Workload.class.getName());9798failWith("-Xmx128m",99"-Xbatch",100"-Xcomp",101"-XX:-TieredCompilation",102"-XX:+UnlockExperimentalVMOptions",103"-XX:+UseEpsilonGC",104"-XX:+HeapDumpOnOutOfMemoryError",105TestDieWithHeapDump.Workload.class.getName());106}107108public static class Workload {109static int COUNT = Integer.getInteger("count", 1_000_000_000); // ~24 GB allocation110111static volatile Object sink;112113public static void main(String... args) {114for (int c = 0; c < COUNT; c++) {115sink = new Object();116}117}118}119120}121122123