Mercurial > hg > graal-jvmci-8
annotate agent/src/share/classes/sun/jvm/hotspot/tools/HeapDumper.java @ 24234:ea6f94ab283b default tip
Added tag jvmci-0.36 for changeset 8128b98d4736
author | Gilles Duboscq <gilles.m.duboscq@oracle.com> |
---|---|
date | Mon, 18 Sep 2017 18:49:45 +0200 |
parents | 89152779163c |
children |
rev | line source |
---|---|
0 | 1 /* |
17524 | 2 * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. |
0 | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
0
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
0
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
0
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
25 package sun.jvm.hotspot.tools; | |
26 | |
27 import sun.jvm.hotspot.utilities.HeapHprofBinWriter; | |
11054
38ea2efa32a7
8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents:
1552
diff
changeset
|
28 import sun.jvm.hotspot.debugger.JVMDebugger; |
0 | 29 import java.io.IOException; |
30 | |
31 /* | |
32 * This tool is used by the JDK jmap utility to dump the heap of the target | |
33 * process/core as a HPROF binary file. It can also be used as a standalone | |
34 * tool if required. | |
35 */ | |
36 public class HeapDumper extends Tool { | |
37 | |
38 private static String DEFAULT_DUMP_FILE = "heap.bin"; | |
39 | |
40 private String dumpFile; | |
41 | |
42 public HeapDumper(String dumpFile) { | |
43 this.dumpFile = dumpFile; | |
44 } | |
45 | |
11054
38ea2efa32a7
8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents:
1552
diff
changeset
|
46 public HeapDumper(String dumpFile, JVMDebugger d) { |
38ea2efa32a7
8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents:
1552
diff
changeset
|
47 super(d); |
38ea2efa32a7
8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents:
1552
diff
changeset
|
48 this.dumpFile = dumpFile; |
38ea2efa32a7
8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents:
1552
diff
changeset
|
49 } |
38ea2efa32a7
8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents:
1552
diff
changeset
|
50 |
0 | 51 protected void printFlagsUsage() { |
52 System.out.println(" <no option>\tto dump heap to " + | |
53 DEFAULT_DUMP_FILE); | |
54 System.out.println(" -f <file>\tto dump heap to <file>"); | |
55 super.printFlagsUsage(); | |
56 } | |
57 | |
58 // use HeapHprofBinWriter to write the heap dump | |
59 public void run() { | |
60 System.out.println("Dumping heap to " + dumpFile + " ..."); | |
61 try { | |
62 new HeapHprofBinWriter().write(dumpFile); | |
63 System.out.println("Heap dump file created"); | |
64 } catch (IOException ioe) { | |
65 System.err.println(ioe.getMessage()); | |
66 } | |
67 } | |
68 | |
69 // JDK jmap utility will always invoke this tool as: | |
70 // HeapDumper -f <file> <args...> | |
71 public static void main(String args[]) { | |
72 String file = DEFAULT_DUMP_FILE; | |
73 if (args.length > 2) { | |
74 if (args[0].equals("-f")) { | |
75 file = args[1]; | |
76 String[] newargs = new String[args.length-2]; | |
77 System.arraycopy(args, 2, newargs, 0, args.length-2); | |
78 args = newargs; | |
79 } | |
80 } | |
81 | |
82 HeapDumper dumper = new HeapDumper(file); | |
12932
7fe6ef09d242
8025638: jmap returns 0 instead of 1 when it fails.
farvidsson
parents:
11054
diff
changeset
|
83 dumper.execute(args); |
0 | 84 } |
85 | |
86 } |