Path: blob/master/test/hotspot/jtreg/runtime/ErrorHandling/TestGZippedHeapDumpOnOutOfMemoryError.java
40942 views
/*1* Copyright (c) 2021 SAP SE. 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*/2223/*24* @test25* @summary Test verifies that -XX:HeapDumpGzipLevel=0 works26* @library /test/lib27* @run driver/timeout=240 TestGZippedHeapDumpOnOutOfMemoryError run 028*/2930/*31* @test32* @summary Test verifies that -XX:HeapDumpGzipLevel=1 works33* @library /test/lib34* @run driver/timeout=240 TestGZippedHeapDumpOnOutOfMemoryError run 135*/3637import jdk.test.lib.Asserts;38import jdk.test.lib.hprof.HprofParser;39import jdk.test.lib.process.ProcessTools;40import jdk.test.lib.process.OutputAnalyzer;4142import java.io.File;4344public class TestGZippedHeapDumpOnOutOfMemoryError {4546static volatile Object[] oa;4748public static void main(String[] args) throws Exception {49if (args.length == 2) {50test(Integer.parseInt(args[1]));51return;52}5354try {55oa = new Object[Integer.MAX_VALUE];56throw new Error("OOME not triggered");57} catch (OutOfMemoryError err) {58// Ignore59}60}6162static void test(int level) throws Exception {63ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(64"-XX:+HeapDumpOnOutOfMemoryError",65"-XX:HeapDumpGzipLevel=" + level,66"-Xmx128M",67TestGZippedHeapDumpOnOutOfMemoryError.class.getName());6869Process proc = pb.start();70String heapdumpFilename = "java_pid" + proc.pid() + ".hprof" + (level > 0 ? ".gz" : "");71OutputAnalyzer output = new OutputAnalyzer(proc);72output.stdoutShouldNotBeEmpty();73output.shouldContain("Dumping heap to " + heapdumpFilename);74File dump = new File(heapdumpFilename);75Asserts.assertTrue(dump.exists() && dump.isFile(),76"Could not find dump file " + dump.getAbsolutePath());7778HprofParser.parse(new File(heapdumpFilename));79System.out.println("PASSED");80}8182}838485