author | cjplummer |
Sat, 28 Sep 2019 12:33:34 -0700 | |
changeset 58389 | 31524b016783 |
parent 52810 | a2500cf11ee5 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
58389
31524b016783
8231287: JMap should do a better job of reporting exception it catches
cjplummer
parents:
52810
diff
changeset
|
2 |
* Copyright (c) 2004, 2019, 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 java.io.*; |
|
18481
fa7f6ad24216
8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents:
17118
diff
changeset
|
28 |
import sun.jvm.hotspot.debugger.JVMDebugger; |
1 | 29 |
import sun.jvm.hotspot.utilities.*; |
30 |
||
31 |
public class JMap extends Tool { |
|
32 |
public JMap(int m) { |
|
33 |
mode = m; |
|
34 |
} |
|
35 |
||
36 |
public JMap() { |
|
37 |
this(MODE_PMAP); |
|
38 |
} |
|
39 |
||
18481
fa7f6ad24216
8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents:
17118
diff
changeset
|
40 |
public JMap(JVMDebugger d) { |
fa7f6ad24216
8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents:
17118
diff
changeset
|
41 |
super(d); |
fa7f6ad24216
8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents:
17118
diff
changeset
|
42 |
} |
fa7f6ad24216
8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents:
17118
diff
changeset
|
43 |
|
1 | 44 |
protected boolean needsJavaPrefix() { |
45 |
return false; |
|
46 |
} |
|
47 |
||
48 |
public String getName() { |
|
49 |
return "jmap"; |
|
50 |
} |
|
51 |
||
52 |
protected String getCommandFlags() { |
|
15809
e2516b8c8f35
8008536: Add HotSpot support for printing class loader statistics for JMap
ehelin
parents:
5547
diff
changeset
|
53 |
return "-heap|-heap:format=b|-histo|-clstats|-finalizerinfo"; |
1 | 54 |
} |
55 |
||
56 |
protected void printFlagsUsage() { |
|
57 |
System.out.println(" <no option>\tto print same info as Solaris pmap"); |
|
58 |
System.out.println(" -heap\tto print java heap summary"); |
|
59 |
System.out.println(" -heap:format=b\tto dump java heap in hprof binary format"); |
|
60 |
System.out.println(" -histo\tto print histogram of java object heap"); |
|
15809
e2516b8c8f35
8008536: Add HotSpot support for printing class loader statistics for JMap
ehelin
parents:
5547
diff
changeset
|
61 |
System.out.println(" -clstats\tto print class loader statistics"); |
1 | 62 |
System.out.println(" -finalizerinfo\tto print information on objects awaiting finalization"); |
63 |
super.printFlagsUsage(); |
|
64 |
} |
|
65 |
||
66 |
public static final int MODE_HEAP_SUMMARY = 0; |
|
67 |
public static final int MODE_HISTOGRAM = 1; |
|
15809
e2516b8c8f35
8008536: Add HotSpot support for printing class loader statistics for JMap
ehelin
parents:
5547
diff
changeset
|
68 |
public static final int MODE_CLSTATS = 2; |
1 | 69 |
public static final int MODE_PMAP = 3; |
70 |
public static final int MODE_HEAP_GRAPH_HPROF_BIN = 4; |
|
71 |
public static final int MODE_HEAP_GRAPH_GXL = 5; |
|
72 |
public static final int MODE_FINALIZERINFO = 6; |
|
73 |
||
38264 | 74 |
private static String dumpfile = "heap.bin"; |
75 |
||
1 | 76 |
public void run() { |
77 |
Tool tool = null; |
|
78 |
switch (mode) { |
|
79 |
||
80 |
case MODE_HEAP_SUMMARY: |
|
81 |
tool = new HeapSummary(); |
|
82 |
break; |
|
83 |
||
84 |
case MODE_HISTOGRAM: |
|
85 |
tool = new ObjectHistogram(); |
|
86 |
break; |
|
87 |
||
15809
e2516b8c8f35
8008536: Add HotSpot support for printing class loader statistics for JMap
ehelin
parents:
5547
diff
changeset
|
88 |
case MODE_CLSTATS: |
e2516b8c8f35
8008536: Add HotSpot support for printing class loader statistics for JMap
ehelin
parents:
5547
diff
changeset
|
89 |
tool = new ClassLoaderStats(); |
1 | 90 |
break; |
91 |
||
92 |
case MODE_PMAP: |
|
93 |
tool = new PMap(); |
|
94 |
break; |
|
95 |
||
96 |
case MODE_HEAP_GRAPH_HPROF_BIN: |
|
38264 | 97 |
writeHeapHprofBin(dumpfile); |
1 | 98 |
return; |
99 |
||
100 |
case MODE_HEAP_GRAPH_GXL: |
|
38264 | 101 |
writeHeapGXL(dumpfile); |
1 | 102 |
return; |
103 |
||
104 |
case MODE_FINALIZERINFO: |
|
105 |
tool = new FinalizerInfo(); |
|
106 |
break; |
|
107 |
||
108 |
default: |
|
109 |
usage(); |
|
110 |
break; |
|
111 |
} |
|
112 |
||
113 |
tool.setAgent(getAgent()); |
|
114 |
tool.setDebugeeType(getDebugeeType()); |
|
115 |
tool.run(); |
|
116 |
} |
|
117 |
||
118 |
public static void main(String[] args) { |
|
119 |
int mode = MODE_PMAP; |
|
120 |
if (args.length > 1 ) { |
|
121 |
String modeFlag = args[0]; |
|
122 |
boolean copyArgs = true; |
|
123 |
if (modeFlag.equals("-heap")) { |
|
124 |
mode = MODE_HEAP_SUMMARY; |
|
125 |
} else if (modeFlag.equals("-histo")) { |
|
126 |
mode = MODE_HISTOGRAM; |
|
15809
e2516b8c8f35
8008536: Add HotSpot support for printing class loader statistics for JMap
ehelin
parents:
5547
diff
changeset
|
127 |
} else if (modeFlag.equals("-clstats")) { |
e2516b8c8f35
8008536: Add HotSpot support for printing class loader statistics for JMap
ehelin
parents:
5547
diff
changeset
|
128 |
mode = MODE_CLSTATS; |
1 | 129 |
} else if (modeFlag.equals("-finalizerinfo")) { |
130 |
mode = MODE_FINALIZERINFO; |
|
131 |
} else { |
|
38264 | 132 |
int index = modeFlag.indexOf("-heap:"); |
1 | 133 |
if (index != -1) { |
38264 | 134 |
String[] options = modeFlag.substring(6).split(","); |
135 |
for (String option : options) { |
|
136 |
String[] keyValue = option.split("="); |
|
137 |
if (keyValue[0].equals("format")) { |
|
138 |
if (keyValue[1].equals("b")) { |
|
139 |
mode = MODE_HEAP_GRAPH_HPROF_BIN; |
|
140 |
} else if (keyValue[1].equals("x")) { |
|
141 |
mode = MODE_HEAP_GRAPH_GXL; |
|
142 |
} else { |
|
143 |
System.err.println("unknown heap format:" + keyValue[0]); |
|
21065
b8281f54308b
8025638: jmap returns 0 instead of 1 when it fails.
farvidsson
parents:
18481
diff
changeset
|
144 |
|
38264 | 145 |
// Exit with error status |
146 |
System.exit(1); |
|
147 |
} |
|
148 |
} else if (keyValue[0].equals("file")) { |
|
149 |
if ((keyValue[1] == null) || keyValue[1].equals("")) { |
|
150 |
System.err.println("File name must be set."); |
|
151 |
System.exit(1); |
|
152 |
} |
|
153 |
dumpfile = keyValue[1]; |
|
154 |
} else { |
|
155 |
System.err.println("unknown option:" + keyValue[0]); |
|
156 |
||
157 |
// Exit with error status |
|
158 |
System.exit(1); |
|
159 |
} |
|
1 | 160 |
} |
161 |
} else { |
|
162 |
copyArgs = false; |
|
163 |
} |
|
164 |
} |
|
165 |
||
166 |
if (copyArgs) { |
|
167 |
String[] newArgs = new String[args.length - 1]; |
|
168 |
for (int i = 0; i < newArgs.length; i++) { |
|
169 |
newArgs[i] = args[i + 1]; |
|
170 |
} |
|
171 |
args = newArgs; |
|
172 |
} |
|
173 |
} |
|
174 |
||
175 |
JMap jmap = new JMap(mode); |
|
21065
b8281f54308b
8025638: jmap returns 0 instead of 1 when it fails.
farvidsson
parents:
18481
diff
changeset
|
176 |
jmap.execute(args); |
1 | 177 |
} |
178 |
||
179 |
public boolean writeHeapHprofBin(String fileName) { |
|
180 |
try { |
|
181 |
HeapGraphWriter hgw = new HeapHprofBinWriter(); |
|
182 |
hgw.write(fileName); |
|
183 |
System.out.println("heap written to " + fileName); |
|
184 |
return true; |
|
58389
31524b016783
8231287: JMap should do a better job of reporting exception it catches
cjplummer
parents:
52810
diff
changeset
|
185 |
} catch (IOException exp) { |
31524b016783
8231287: JMap should do a better job of reporting exception it catches
cjplummer
parents:
52810
diff
changeset
|
186 |
throw new RuntimeException(exp); |
1 | 187 |
} |
188 |
} |
|
189 |
||
190 |
public boolean writeHeapHprofBin() { |
|
191 |
return writeHeapHprofBin("heap.bin"); |
|
192 |
} |
|
193 |
||
194 |
private boolean writeHeapGXL(String fileName) { |
|
195 |
try { |
|
196 |
HeapGraphWriter hgw = new HeapGXLWriter(); |
|
197 |
hgw.write(fileName); |
|
198 |
System.out.println("heap written to " + fileName); |
|
199 |
return true; |
|
200 |
} catch (IOException exp) { |
|
58389
31524b016783
8231287: JMap should do a better job of reporting exception it catches
cjplummer
parents:
52810
diff
changeset
|
201 |
throw new RuntimeException(exp); |
1 | 202 |
} |
203 |
} |
|
204 |
||
205 |
public boolean writeHeapGXL() { |
|
206 |
return writeHeapGXL("heap.xml"); |
|
207 |
} |
|
208 |
||
209 |
private int mode; |
|
210 |
} |