Path: blob/master/test/jdk/com/sun/management/HotSpotDiagnosticMXBean/DumpHeap.java
41153 views
/*1* Copyright (c) 2006, 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*/2223import static jdk.test.lib.Asserts.assertTrue;24import static jdk.test.lib.Asserts.fail;2526import java.io.File;27import java.lang.management.*;28import java.util.List;2930import jdk.test.lib.hprof.HprofParser;31import jdk.test.lib.process.ProcessTools;3233import com.sun.management.HotSpotDiagnosticMXBean;3435/*36* @test37* @bug 645525838* @summary Sanity test for com.sun.management.HotSpotDiagnosticMXBean.dumpHeap method39* @library /test/lib40* @build jdk.test.lib.hprof.*41* @build jdk.test.lib.hprof.model.*42* @build jdk.test.lib.hprof.parser.*43* @build jdk.test.lib.hprof.util.*44* @run main DumpHeap45*/46public class DumpHeap {4748public static void main(String[] args) throws Exception {49List<HotSpotDiagnosticMXBean> list = ManagementFactory.getPlatformMXBeans(HotSpotDiagnosticMXBean.class);50File dump = new File(ProcessTools.getProcessId() + ".hprof");51if (dump.exists()) {52dump.delete();53}54System.out.println("Dumping to file: " + dump.getAbsolutePath());55list.get(0).dumpHeap(dump.getAbsolutePath(), true);5657verifyDumpFile(dump);5859dump.delete();60}6162private static void verifyDumpFile(File dump) {63assertTrue(dump.exists() && dump.isFile(), "Could not create dump file");64try {65HprofParser.parse(dump);66} catch (Exception e) {67e.printStackTrace();68fail("Could not parse dump file");69}70}7172}737475