Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/tools/HeapDumper.java
41161 views
1
/*
2
* Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
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
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*
23
*/
24
25
package sun.jvm.hotspot.tools;
26
27
import sun.jvm.hotspot.utilities.HeapHprofBinWriter;
28
import sun.jvm.hotspot.debugger.JVMDebugger;
29
30
import java.io.IOException;
31
32
/*
33
* This tool is used by the JDK jmap utility to dump the heap of the target
34
* process/core as a HPROF binary file. It can also be used as a standalone
35
* tool if required.
36
*/
37
public class HeapDumper extends Tool {
38
39
private static String DEFAULT_DUMP_FILE = "heap.bin";
40
41
private String dumpFile;
42
43
public HeapDumper() {
44
this.dumpFile = DEFAULT_DUMP_FILE;
45
}
46
47
public HeapDumper(String dumpFile) {
48
this.dumpFile = dumpFile;
49
}
50
51
public HeapDumper(String dumpFile, JVMDebugger d) {
52
super(d);
53
this.dumpFile = dumpFile;
54
}
55
56
@Override
57
public String getName() {
58
return "heapDumper";
59
}
60
61
protected void printFlagsUsage() {
62
System.out.println(" <no option>\tto dump heap to " +
63
DEFAULT_DUMP_FILE);
64
System.out.println(" -f <file>\tto dump heap to <file>");
65
super.printFlagsUsage();
66
}
67
68
// use HeapHprofBinWriter to write the heap dump
69
public void run() {
70
System.out.println("Dumping heap to " + dumpFile + " ...");
71
try {
72
new HeapHprofBinWriter().write(dumpFile);
73
System.out.println("Heap dump file created");
74
} catch (IOException ioe) {
75
System.err.println(ioe.getMessage());
76
}
77
}
78
79
// JDK jmap utility will always invoke this tool as:
80
// HeapDumper -f <file> <args...>
81
public static void main(String args[]) {
82
HeapDumper dumper = new HeapDumper();
83
dumper.runWithArgs(args);
84
}
85
86
public void runWithArgs(String... args) {
87
if (args.length > 2) {
88
if (args[0].equals("-f")) {
89
this.dumpFile = args[1];
90
String[] newargs = new String[args.length-2];
91
System.arraycopy(args, 2, newargs, 0, args.length-2);
92
args = newargs;
93
}
94
}
95
96
execute(args);
97
}
98
99
}
100
101