Mercurial > hg > truffle
annotate agent/src/share/classes/sun/jvm/hotspot/tools/ClassLoaderStats.java @ 13705:ac5b0f31f7a2
Truffle API-change: FrameDescriptors are now stored in the RootNode in a final field instead of the CallTarget.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Fri, 17 Jan 2014 17:06:08 +0100 |
parents | 7fe6ef09d242 |
children | c888354aaa35 |
rev | line source |
---|---|
0 | 1 /* |
8112
b685ca4f4fb9
8008536: Add HotSpot support for printing class loader statistics for JMap
ehelin
parents:
6725
diff
changeset
|
2 * Copyright (c) 2003, 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:
337
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
337
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:
337
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
25 package sun.jvm.hotspot.tools; | |
26 | |
27 import java.io.*; | |
28 import java.util.*; | |
29 | |
30 import sun.jvm.hotspot.debugger.*; | |
31 import sun.jvm.hotspot.memory.*; | |
32 import sun.jvm.hotspot.oops.*; | |
33 import sun.jvm.hotspot.runtime.*; | |
34 import sun.jvm.hotspot.tools.*; | |
35 import sun.jvm.hotspot.utilities.*; | |
36 | |
37 /** | |
8112
b685ca4f4fb9
8008536: Add HotSpot support for printing class loader statistics for JMap
ehelin
parents:
6725
diff
changeset
|
38 A command line tool to print class loader statistics. |
0 | 39 */ |
40 | |
8112
b685ca4f4fb9
8008536: Add HotSpot support for printing class loader statistics for JMap
ehelin
parents:
6725
diff
changeset
|
41 public class ClassLoaderStats extends Tool { |
0 | 42 boolean verbose = true; |
43 | |
11054
38ea2efa32a7
8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents:
8112
diff
changeset
|
44 public ClassLoaderStats() { |
38ea2efa32a7
8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents:
8112
diff
changeset
|
45 super(); |
38ea2efa32a7
8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents:
8112
diff
changeset
|
46 } |
38ea2efa32a7
8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents:
8112
diff
changeset
|
47 |
38ea2efa32a7
8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents:
8112
diff
changeset
|
48 public ClassLoaderStats(JVMDebugger d) { |
38ea2efa32a7
8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents:
8112
diff
changeset
|
49 super(d); |
38ea2efa32a7
8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents:
8112
diff
changeset
|
50 } |
38ea2efa32a7
8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents:
8112
diff
changeset
|
51 |
0 | 52 public static void main(String[] args) { |
8112
b685ca4f4fb9
8008536: Add HotSpot support for printing class loader statistics for JMap
ehelin
parents:
6725
diff
changeset
|
53 ClassLoaderStats cls = new ClassLoaderStats(); |
12932
7fe6ef09d242
8025638: jmap returns 0 instead of 1 when it fails.
farvidsson
parents:
11054
diff
changeset
|
54 cls.execute(args); |
0 | 55 } |
56 | |
57 private static class ClassData { | |
58 Klass klass; | |
59 long size; | |
60 | |
61 ClassData(Klass klass, long size) { | |
62 this.klass = klass; this.size = size; | |
63 } | |
64 } | |
65 | |
66 private static class LoaderData { | |
67 long numClasses; | |
68 long classSize; | |
69 List classDetail = new ArrayList(); // List<ClassData> | |
70 } | |
71 | |
72 public void run() { | |
73 printClassLoaderStatistics(); | |
74 } | |
75 | |
76 private void printClassLoaderStatistics() { | |
77 final PrintStream out = System.out; | |
78 final PrintStream err = System.err; | |
79 final Map loaderMap = new HashMap(); | |
80 // loader data for bootstrap class loader | |
81 final LoaderData bootstrapLoaderData = new LoaderData(); | |
82 if (verbose) { | |
83 err.print("finding class loader instances .."); | |
84 } | |
85 | |
86 VM vm = VM.getVM(); | |
87 ObjectHeap heap = vm.getObjectHeap(); | |
88 Klass classLoaderKlass = vm.getSystemDictionary().getClassLoaderKlass(); | |
89 try { | |
90 heap.iterateObjectsOfKlass(new DefaultHeapVisitor() { | |
91 public boolean doObj(Oop oop) { | |
92 loaderMap.put(oop, new LoaderData()); | |
93 return false; | |
94 } | |
95 }, classLoaderKlass); | |
96 } catch (Exception se) { | |
97 se.printStackTrace(); | |
98 } | |
99 | |
100 if (verbose) { | |
101 err.println("done."); | |
102 err.print("computing per loader stat .."); | |
103 } | |
104 | |
105 SystemDictionary dict = VM.getVM().getSystemDictionary(); | |
106 dict.classesDo(new SystemDictionary.ClassAndLoaderVisitor() { | |
107 public void visit(Klass k, Oop loader) { | |
108 if (! (k instanceof InstanceKlass)) { | |
109 return; | |
110 } | |
111 LoaderData ld = (loader != null) ? (LoaderData)loaderMap.get(loader) | |
112 : bootstrapLoaderData; | |
113 if (ld != null) { | |
114 ld.numClasses++; | |
115 long size = computeSize((InstanceKlass)k); | |
116 ld.classDetail.add(new ClassData(k, size)); | |
117 ld.classSize += size; | |
118 } | |
119 } | |
120 }); | |
121 | |
122 if (verbose) { | |
123 err.println("done."); | |
124 err.print("please wait.. computing liveness"); | |
125 } | |
126 | |
127 // compute reverse pointer analysis (takes long time for larger app) | |
128 ReversePtrsAnalysis analysis = new ReversePtrsAnalysis(); | |
129 | |
130 if (verbose) { | |
131 analysis.setHeapProgressThunk(new HeapProgressThunk() { | |
132 public void heapIterationFractionUpdate(double fractionOfHeapVisited) { | |
133 err.print('.'); | |
134 } | |
135 // This will be called after the iteration is complete | |
136 public void heapIterationComplete() { | |
137 err.println("done."); | |
138 } | |
139 }); | |
140 } | |
141 | |
142 try { | |
143 analysis.run(); | |
144 } catch (Exception e) { | |
145 // e.printStackTrace(); | |
146 if (verbose) | |
147 err.println("liveness analysis may be inaccurate ..."); | |
148 } | |
149 ReversePtrs liveness = VM.getVM().getRevPtrs(); | |
150 | |
151 out.println("class_loader\tclasses\tbytes\tparent_loader\talive?\ttype"); | |
152 out.println(); | |
153 | |
154 long numClassLoaders = 1L; | |
155 long totalNumClasses = bootstrapLoaderData.numClasses; | |
156 long totalClassSize = bootstrapLoaderData.classSize; | |
157 long numAliveLoaders = 1L; | |
158 long numDeadLoaders = 0L; | |
159 | |
160 // print bootstrap loader details | |
161 out.print("<bootstrap>"); | |
162 out.print('\t'); | |
163 out.print(bootstrapLoaderData.numClasses); | |
164 out.print('\t'); | |
165 out.print(bootstrapLoaderData.classSize); | |
166 out.print('\t'); | |
167 out.print(" null "); | |
168 out.print('\t'); | |
169 // bootstrap loader is always alive | |
170 out.print("live"); | |
171 out.print('\t'); | |
172 out.println("<internal>"); | |
173 | |
174 for (Iterator keyItr = loaderMap.keySet().iterator(); keyItr.hasNext();) { | |
175 Oop loader = (Oop) keyItr.next(); | |
176 LoaderData data = (LoaderData) loaderMap.get(loader); | |
177 numClassLoaders ++; | |
178 totalNumClasses += data.numClasses; | |
179 totalClassSize += data.classSize; | |
180 | |
181 out.print(loader.getHandle()); | |
182 out.print('\t'); | |
183 out.print(data.numClasses); | |
184 out.print('\t'); | |
185 out.print(data.classSize); | |
186 out.print('\t'); | |
187 | |
188 class ParentFinder extends DefaultOopVisitor { | |
189 public void doOop(OopField field, boolean isVMField) { | |
190 if (field.getID().getName().equals("parent")) { | |
191 parent = field.getValue(getObj()); | |
192 } | |
193 } | |
194 private Oop parent = null; | |
195 public Oop getParent() { return parent; } | |
196 } | |
197 | |
198 ParentFinder parentFinder = new ParentFinder(); | |
199 loader.iterate(parentFinder, false); | |
200 Oop parent = parentFinder.getParent(); | |
201 out.print((parent != null)? parent.getHandle().toString() : " null "); | |
202 out.print('\t'); | |
203 boolean alive = (liveness != null) ? (liveness.get(loader) != null) : true; | |
204 out.print(alive? "live" : "dead"); | |
205 if (alive) numAliveLoaders++; else numDeadLoaders++; | |
206 out.print('\t'); | |
207 Klass loaderKlass = loader.getKlass(); | |
208 if (loaderKlass != null) { | |
209 out.print(loaderKlass.getName().asString()); | |
210 out.print('@'); | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4061
diff
changeset
|
211 out.print(loader.getKlass().getAddress()); |
0 | 212 } else { |
213 out.print(" null! "); | |
214 } | |
215 out.println(); | |
216 } | |
217 | |
218 out.println(); | |
219 // summary line | |
220 out.print("total = "); | |
221 out.print(numClassLoaders); | |
222 out.print('\t'); | |
223 out.print(totalNumClasses); | |
224 out.print('\t'); | |
225 out.print(totalClassSize); | |
226 out.print('\t'); | |
227 out.print(" N/A "); | |
228 out.print('\t'); | |
229 out.print("alive="); | |
230 out.print(numAliveLoaders); | |
231 out.print(", dead="); | |
232 out.print(numDeadLoaders); | |
233 out.print('\t'); | |
234 out.print(" N/A "); | |
235 out.println(); | |
236 } | |
237 | |
261
7f601f7c9b48
6731726: jmap -permstat reports only 50-60% of permgen memory usage.
martin
parents:
0
diff
changeset
|
238 private static long objectSize(Oop oop) { |
7f601f7c9b48
6731726: jmap -permstat reports only 50-60% of permgen memory usage.
martin
parents:
0
diff
changeset
|
239 return oop == null ? 0L : oop.getObjectSize(); |
7f601f7c9b48
6731726: jmap -permstat reports only 50-60% of permgen memory usage.
martin
parents:
0
diff
changeset
|
240 } |
7f601f7c9b48
6731726: jmap -permstat reports only 50-60% of permgen memory usage.
martin
parents:
0
diff
changeset
|
241 |
7f601f7c9b48
6731726: jmap -permstat reports only 50-60% of permgen memory usage.
martin
parents:
0
diff
changeset
|
242 // Don't count the shared empty arrays |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4061
diff
changeset
|
243 private static long arraySize(GenericArray arr) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4061
diff
changeset
|
244 return arr.getLength() != 0L ? arr.getSize() : 0L; |
261
7f601f7c9b48
6731726: jmap -permstat reports only 50-60% of permgen memory usage.
martin
parents:
0
diff
changeset
|
245 } |
7f601f7c9b48
6731726: jmap -permstat reports only 50-60% of permgen memory usage.
martin
parents:
0
diff
changeset
|
246 |
0 | 247 private long computeSize(InstanceKlass k) { |
248 long size = 0L; | |
261
7f601f7c9b48
6731726: jmap -permstat reports only 50-60% of permgen memory usage.
martin
parents:
0
diff
changeset
|
249 // the InstanceKlass object itself |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4061
diff
changeset
|
250 size += k.getSize(); |
0 | 251 |
261
7f601f7c9b48
6731726: jmap -permstat reports only 50-60% of permgen memory usage.
martin
parents:
0
diff
changeset
|
252 // Constant pool |
7f601f7c9b48
6731726: jmap -permstat reports only 50-60% of permgen memory usage.
martin
parents:
0
diff
changeset
|
253 ConstantPool cp = k.getConstants(); |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4061
diff
changeset
|
254 size += cp.getSize(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4061
diff
changeset
|
255 if (cp.getCache() != null) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4061
diff
changeset
|
256 size += cp.getCache().getSize(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4061
diff
changeset
|
257 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4061
diff
changeset
|
258 size += arraySize(cp.getTags()); |
261
7f601f7c9b48
6731726: jmap -permstat reports only 50-60% of permgen memory usage.
martin
parents:
0
diff
changeset
|
259 |
7f601f7c9b48
6731726: jmap -permstat reports only 50-60% of permgen memory usage.
martin
parents:
0
diff
changeset
|
260 // Interfaces |
7f601f7c9b48
6731726: jmap -permstat reports only 50-60% of permgen memory usage.
martin
parents:
0
diff
changeset
|
261 size += arraySize(k.getLocalInterfaces()); |
7f601f7c9b48
6731726: jmap -permstat reports only 50-60% of permgen memory usage.
martin
parents:
0
diff
changeset
|
262 size += arraySize(k.getTransitiveInterfaces()); |
7f601f7c9b48
6731726: jmap -permstat reports only 50-60% of permgen memory usage.
martin
parents:
0
diff
changeset
|
263 |
7f601f7c9b48
6731726: jmap -permstat reports only 50-60% of permgen memory usage.
martin
parents:
0
diff
changeset
|
264 // Inner classes |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4061
diff
changeset
|
265 size += arraySize(k.getInnerClasses()); |
0 | 266 |
261
7f601f7c9b48
6731726: jmap -permstat reports only 50-60% of permgen memory usage.
martin
parents:
0
diff
changeset
|
267 // Fields |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4061
diff
changeset
|
268 size += arraySize(k.getFields()); |
261
7f601f7c9b48
6731726: jmap -permstat reports only 50-60% of permgen memory usage.
martin
parents:
0
diff
changeset
|
269 |
7f601f7c9b48
6731726: jmap -permstat reports only 50-60% of permgen memory usage.
martin
parents:
0
diff
changeset
|
270 // Methods |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4061
diff
changeset
|
271 MethodArray methods = k.getMethods(); |
261
7f601f7c9b48
6731726: jmap -permstat reports only 50-60% of permgen memory usage.
martin
parents:
0
diff
changeset
|
272 int nmethods = (int) methods.getLength(); |
7f601f7c9b48
6731726: jmap -permstat reports only 50-60% of permgen memory usage.
martin
parents:
0
diff
changeset
|
273 if (nmethods != 0L) { |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4061
diff
changeset
|
274 size += methods.getSize(); |
261
7f601f7c9b48
6731726: jmap -permstat reports only 50-60% of permgen memory usage.
martin
parents:
0
diff
changeset
|
275 for (int i = 0; i < nmethods; ++i) { |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4061
diff
changeset
|
276 Method m = methods.at(i); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4061
diff
changeset
|
277 size += m.getSize(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
4061
diff
changeset
|
278 size += m.getConstMethod().getSize(); |
261
7f601f7c9b48
6731726: jmap -permstat reports only 50-60% of permgen memory usage.
martin
parents:
0
diff
changeset
|
279 } |
0 | 280 } |
281 | |
282 return size; | |
283 } | |
284 } |