Path: blob/master/test/hotspot/jtreg/serviceability/dcmd/gc/HeapDumpCompressedTest.java
41153 views
/*1* Copyright (c) 2020 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*/2223import java.io.File;24import java.nio.file.Files;25import java.io.IOException;26import java.util.List;2728import jdk.test.lib.hprof.HprofParser;29import jdk.test.lib.hprof.parser.Reader;30import jdk.test.lib.hprof.model.Snapshot;3132import jdk.test.lib.Asserts;33import jdk.test.lib.dcmd.PidJcmdExecutor;34import jdk.test.lib.process.OutputAnalyzer;3536/*37* @test38* @requires vm.gc.Serial39* @summary Test of diagnostic command GC.heap_dump with gzipped output (Serial GC)40* @library /test/lib41* @modules java.base/jdk.internal.misc42* java.compiler43* java.management44* jdk.internal.jvmstat/sun.jvmstat.monitor45* @run main/othervm -XX:+UseSerialGC HeapDumpCompressedTest46*/4748/*49* @test50* @requires vm.gc.Parallel51* @summary Test of diagnostic command GC.heap_dump with gzipped output (Parallel GC)52* @library /test/lib53* @modules java.base/jdk.internal.misc54* java.compiler55* java.management56* jdk.internal.jvmstat/sun.jvmstat.monitor57* @run main/othervm -XX:+UseParallelGC HeapDumpCompressedTest58*/5960/*61* @test62* @requires vm.gc.G163* @summary Test of diagnostic command GC.heap_dump with gzipped output (G1 GC)64* @library /test/lib65* @modules java.base/jdk.internal.misc66* java.compiler67* java.management68* jdk.internal.jvmstat/sun.jvmstat.monitor69* @run main/othervm -XX:+UseG1GC HeapDumpCompressedTest70*/7172/*73* @test74* @requires vm.gc.Z75* @summary Test of diagnostic command GC.heap_dump with gzipped output (Z GC)76* @library /test/lib77* @modules java.base/jdk.internal.misc78* java.compiler79* java.management80* jdk.internal.jvmstat/sun.jvmstat.monitor81* @run main/othervm -XX:+UseZGC HeapDumpCompressedTest82*/8384/*85* @test86* @requires vm.gc.Shenandoah87* @summary Test of diagnostic command GC.heap_dump with gzipped output (Shenandoah GC)88* @library /test/lib89* @modules java.base/jdk.internal.misc90* java.compiler91* java.management92* jdk.internal.jvmstat/sun.jvmstat.monitor93* @run main/othervm -XX:+UseShenandoahGC HeapDumpCompressedTest94*/9596/*97* @test98* @requires vm.gc.Epsilon99* @summary Test of diagnostic command GC.heap_dump with gzipped output (Epsilon GC)100* @library /test/lib101* @modules java.base/jdk.internal.misc102* java.compiler103* java.management104* jdk.internal.jvmstat/sun.jvmstat.monitor105* @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC HeapDumpCompressedTest106*/107108public class HeapDumpCompressedTest {109public static HeapDumpCompressedTest ref;110111public static void main(String[] args) throws Exception {112PidJcmdExecutor executor = new PidJcmdExecutor();113ref = new HeapDumpCompressedTest();114File dump = new File("jcmd.gc.heap_dump." + System.currentTimeMillis() + ".hprof.gz");115116if (dump.exists()) {117dump.delete();118}119120// Check we detect an invalid compression level.121OutputAnalyzer output = executor.execute("GC.heap_dump -gz=0 " +122dump.getAbsolutePath());123output.shouldContain("Compression level out of range");124125// Check we can create a gzipped dump.126output = executor.execute("GC.heap_dump -gz=1 " + dump.getAbsolutePath());127output.shouldContain("Heap dump file created");128129// Check we detect an already present heap dump.130output = executor.execute("GC.heap_dump -gz=1 " + dump.getAbsolutePath());131output.shouldContain("Unable to create ");132133verifyHeapDump(dump);134dump.delete();135}136137private static void verifyHeapDump(File dump) throws Exception {138139Asserts.assertTrue(dump.exists() && dump.isFile(),140"Could not create dump file " + dump.getAbsolutePath());141142try {143File out = HprofParser.parse(dump);144145Asserts.assertTrue(out != null && out.exists() && out.isFile(),146"Could not find hprof parser output file");147List<String> lines = Files.readAllLines(out.toPath());148Asserts.assertTrue(lines.size() > 0, "hprof parser output file is empty");149for (String line : lines) {150Asserts.assertFalse(line.matches(".*WARNING(?!.*Failed to resolve " +151"object.*constantPoolOop.*).*"));152}153154out.delete();155} catch (Exception e) {156e.printStackTrace();157Asserts.fail("Could not parse dump file " + dump.getAbsolutePath());158}159}160}161162163164