Mercurial > hg > graal-jvmci-8
annotate agent/src/share/classes/sun/jvm/hotspot/tools/JMap.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 | 7fe6ef09d242 |
children |
rev | line source |
---|---|
0 | 1 /* |
8112
b685ca4f4fb9
8008536: Add HotSpot support for printing class loader statistics for JMap
ehelin
parents:
1552
diff
changeset
|
2 * Copyright (c) 2004, 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 java.io.*; | |
11054
38ea2efa32a7
8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents:
10192
diff
changeset
|
28 import sun.jvm.hotspot.debugger.JVMDebugger; |
0 | 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 | |
11054
38ea2efa32a7
8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents:
10192
diff
changeset
|
40 public JMap(JVMDebugger d) { |
38ea2efa32a7
8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents:
10192
diff
changeset
|
41 super(d); |
38ea2efa32a7
8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents:
10192
diff
changeset
|
42 } |
38ea2efa32a7
8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents:
10192
diff
changeset
|
43 |
0 | 44 protected boolean needsJavaPrefix() { |
45 return false; | |
46 } | |
47 | |
48 public String getName() { | |
49 return "jmap"; | |
50 } | |
51 | |
52 protected String getCommandFlags() { | |
8112
b685ca4f4fb9
8008536: Add HotSpot support for printing class loader statistics for JMap
ehelin
parents:
1552
diff
changeset
|
53 return "-heap|-heap:format=b|-histo|-clstats|-finalizerinfo"; |
0 | 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"); | |
8112
b685ca4f4fb9
8008536: Add HotSpot support for printing class loader statistics for JMap
ehelin
parents:
1552
diff
changeset
|
61 System.out.println(" -clstats\tto print class loader statistics"); |
0 | 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; | |
8112
b685ca4f4fb9
8008536: Add HotSpot support for printing class loader statistics for JMap
ehelin
parents:
1552
diff
changeset
|
68 public static final int MODE_CLSTATS = 2; |
0 | 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 | |
74 public void run() { | |
75 Tool tool = null; | |
76 switch (mode) { | |
77 | |
78 case MODE_HEAP_SUMMARY: | |
79 tool = new HeapSummary(); | |
80 break; | |
81 | |
82 case MODE_HISTOGRAM: | |
83 tool = new ObjectHistogram(); | |
84 break; | |
85 | |
8112
b685ca4f4fb9
8008536: Add HotSpot support for printing class loader statistics for JMap
ehelin
parents:
1552
diff
changeset
|
86 case MODE_CLSTATS: |
b685ca4f4fb9
8008536: Add HotSpot support for printing class loader statistics for JMap
ehelin
parents:
1552
diff
changeset
|
87 tool = new ClassLoaderStats(); |
0 | 88 break; |
89 | |
90 case MODE_PMAP: | |
91 tool = new PMap(); | |
92 break; | |
93 | |
94 case MODE_HEAP_GRAPH_HPROF_BIN: | |
95 writeHeapHprofBin(); | |
96 return; | |
97 | |
98 case MODE_HEAP_GRAPH_GXL: | |
99 writeHeapGXL(); | |
100 return; | |
101 | |
102 case MODE_FINALIZERINFO: | |
103 tool = new FinalizerInfo(); | |
104 break; | |
105 | |
106 default: | |
107 usage(); | |
108 break; | |
109 } | |
110 | |
111 tool.setAgent(getAgent()); | |
112 tool.setDebugeeType(getDebugeeType()); | |
113 tool.run(); | |
114 } | |
115 | |
116 public static void main(String[] args) { | |
117 int mode = MODE_PMAP; | |
118 if (args.length > 1 ) { | |
119 String modeFlag = args[0]; | |
120 boolean copyArgs = true; | |
121 if (modeFlag.equals("-heap")) { | |
122 mode = MODE_HEAP_SUMMARY; | |
123 } else if (modeFlag.equals("-histo")) { | |
124 mode = MODE_HISTOGRAM; | |
8112
b685ca4f4fb9
8008536: Add HotSpot support for printing class loader statistics for JMap
ehelin
parents:
1552
diff
changeset
|
125 } else if (modeFlag.equals("-clstats")) { |
b685ca4f4fb9
8008536: Add HotSpot support for printing class loader statistics for JMap
ehelin
parents:
1552
diff
changeset
|
126 mode = MODE_CLSTATS; |
0 | 127 } else if (modeFlag.equals("-finalizerinfo")) { |
128 mode = MODE_FINALIZERINFO; | |
129 } else { | |
130 int index = modeFlag.indexOf("-heap:format="); | |
131 if (index != -1) { | |
132 String format = modeFlag.substring(1 + modeFlag.indexOf('=')); | |
133 if (format.equals("b")) { | |
134 mode = MODE_HEAP_GRAPH_HPROF_BIN; | |
135 } else if (format.equals("x")) { | |
136 mode = MODE_HEAP_GRAPH_GXL; | |
137 } else { | |
138 System.err.println("unknown heap format:" + format); | |
12932
7fe6ef09d242
8025638: jmap returns 0 instead of 1 when it fails.
farvidsson
parents:
11054
diff
changeset
|
139 |
7fe6ef09d242
8025638: jmap returns 0 instead of 1 when it fails.
farvidsson
parents:
11054
diff
changeset
|
140 // Exit with error status |
7fe6ef09d242
8025638: jmap returns 0 instead of 1 when it fails.
farvidsson
parents:
11054
diff
changeset
|
141 System.exit(1); |
0 | 142 } |
143 } else { | |
144 copyArgs = false; | |
145 } | |
146 } | |
147 | |
148 if (copyArgs) { | |
149 String[] newArgs = new String[args.length - 1]; | |
150 for (int i = 0; i < newArgs.length; i++) { | |
151 newArgs[i] = args[i + 1]; | |
152 } | |
153 args = newArgs; | |
154 } | |
155 } | |
156 | |
157 JMap jmap = new JMap(mode); | |
12932
7fe6ef09d242
8025638: jmap returns 0 instead of 1 when it fails.
farvidsson
parents:
11054
diff
changeset
|
158 jmap.execute(args); |
0 | 159 } |
160 | |
161 public boolean writeHeapHprofBin(String fileName) { | |
162 try { | |
163 HeapGraphWriter hgw = new HeapHprofBinWriter(); | |
164 hgw.write(fileName); | |
165 System.out.println("heap written to " + fileName); | |
166 return true; | |
167 } catch (IOException exp) { | |
168 System.err.println(exp.getMessage()); | |
169 return false; | |
170 } | |
171 } | |
172 | |
173 public boolean writeHeapHprofBin() { | |
174 return writeHeapHprofBin("heap.bin"); | |
175 } | |
176 | |
177 private boolean writeHeapGXL(String fileName) { | |
178 try { | |
179 HeapGraphWriter hgw = new HeapGXLWriter(); | |
180 hgw.write(fileName); | |
181 System.out.println("heap written to " + fileName); | |
182 return true; | |
183 } catch (IOException exp) { | |
184 System.err.println(exp.getMessage()); | |
185 return false; | |
186 } | |
187 } | |
188 | |
189 public boolean writeHeapGXL() { | |
190 return writeHeapGXL("heap.xml"); | |
191 } | |
192 | |
193 private int mode; | |
194 } |