author | mikael |
Tue, 24 Dec 2013 11:48:39 -0800 | |
changeset 22234 | da823d78ad65 |
parent 21065 | b8281f54308b |
permissions | -rw-r--r-- |
1 | 1 |
/* |
22234
da823d78ad65
8029233: Update copyright year to match last edit in jdk8 hotspot repository for 2013
mikael
parents:
21065
diff
changeset
|
2 |
* Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. |
1 | 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 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
25 |
package sun.jvm.hotspot.tools; |
|
26 |
||
27 |
import sun.jvm.hotspot.utilities.HeapHprofBinWriter; |
|
18481
fa7f6ad24216
8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents:
5547
diff
changeset
|
28 |
import sun.jvm.hotspot.debugger.JVMDebugger; |
1 | 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 |
||
18481
fa7f6ad24216
8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents:
5547
diff
changeset
|
46 |
public HeapDumper(String dumpFile, JVMDebugger d) { |
fa7f6ad24216
8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents:
5547
diff
changeset
|
47 |
super(d); |
fa7f6ad24216
8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents:
5547
diff
changeset
|
48 |
this.dumpFile = dumpFile; |
fa7f6ad24216
8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents:
5547
diff
changeset
|
49 |
} |
fa7f6ad24216
8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents:
5547
diff
changeset
|
50 |
|
1 | 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); |
|
21065
b8281f54308b
8025638: jmap returns 0 instead of 1 when it fails.
farvidsson
parents:
18481
diff
changeset
|
83 |
dumper.execute(args); |
1 | 84 |
} |
85 |
||
86 |
} |