Path: blob/master/test/hotspot/jtreg/runtime/ErrorHandling/TestHeapDumpPath.java
40942 views
/*1* Copyright (c) 2018, Oracle and/or its affiliates. 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* @test TestHeapDumpPath25* @summary Test verifies that -XX:HeapDumpPath= supports directory as a parameter.26* @library /test/lib27* @run driver TestHeapDumpPath28*/2930import jdk.test.lib.Asserts;31import jdk.test.lib.hprof.HprofParser;32import jdk.test.lib.process.ProcessTools;33import jdk.test.lib.process.OutputAnalyzer;3435import java.io.File;3637public class TestHeapDumpPath {3839public static void main(String[] args) throws Exception {40if (args.length == 1) {41try {42Object[] oa = new Object[Integer.MAX_VALUE];43throw new Error("OOME not triggered");44} catch (OutOfMemoryError err) {45return;46}47}4849testHeapDumpPath();50}51static void testHeapDumpPath() throws Exception {52String heapdumpPath = "dumps";53File dumpDirectory = new File(heapdumpPath);54dumpDirectory.mkdir();55ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+HeapDumpOnOutOfMemoryError",56"-Xmx64m", "-XX:HeapDumpPath=" + heapdumpPath, TestHeapDumpPath.class.getName(), "OOME");5758OutputAnalyzer output = new OutputAnalyzer(pb.start());59output.stdoutShouldNotBeEmpty();60output.shouldContain("Dumping heap");6162Asserts.assertFalse(dumpDirectory.listFiles().length == 0,63"There is no dump files found in " + dumpDirectory );6465Asserts.assertTrue(dumpDirectory.listFiles().length == 1,66"There are unexpected files in " + dumpDirectory67+ ": " + String.join(",", dumpDirectory.list()) +".");6869File dump = dumpDirectory.listFiles()[0];70Asserts.assertTrue(dump.exists() && dump.isFile(),71"Could not find dump file " + dump.getAbsolutePath());7273HprofParser.parse(dump);74System.out.println("PASSED");75}7677}787980