annotate agent/src/share/classes/sun/jvm/hotspot/tools/ClassLoaderStats.java @ 11054:38ea2efa32a7

8010278: SA: provide mechanism for using an alternative SA debugger back-end. Reviewed-by: sla, dsamersoff
author kevinw
date Wed, 26 Jun 2013 00:01:20 +0100
parents b685ca4f4fb9
children 7fe6ef09d242
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 package sun.jvm.hotspot.tools;
a61af66fc99e Initial load
duke
parents:
diff changeset
26
a61af66fc99e Initial load
duke
parents:
diff changeset
27 import java.io.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
28 import java.util.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
29
a61af66fc99e Initial load
duke
parents:
diff changeset
30 import sun.jvm.hotspot.debugger.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
31 import sun.jvm.hotspot.memory.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
32 import sun.jvm.hotspot.oops.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
33 import sun.jvm.hotspot.runtime.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
34 import sun.jvm.hotspot.tools.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
35 import sun.jvm.hotspot.utilities.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
36
a61af66fc99e Initial load
duke
parents:
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
39 */
a61af66fc99e Initial load
duke
parents:
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
42 boolean verbose = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
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();
b685ca4f4fb9 8008536: Add HotSpot support for printing class loader statistics for JMap
ehelin
parents: 6725
diff changeset
54 cls.start(args);
b685ca4f4fb9 8008536: Add HotSpot support for printing class loader statistics for JMap
ehelin
parents: 6725
diff changeset
55 cls.stop();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
56 }
a61af66fc99e Initial load
duke
parents:
diff changeset
57
a61af66fc99e Initial load
duke
parents:
diff changeset
58 private static class ClassData {
a61af66fc99e Initial load
duke
parents:
diff changeset
59 Klass klass;
a61af66fc99e Initial load
duke
parents:
diff changeset
60 long size;
a61af66fc99e Initial load
duke
parents:
diff changeset
61
a61af66fc99e Initial load
duke
parents:
diff changeset
62 ClassData(Klass klass, long size) {
a61af66fc99e Initial load
duke
parents:
diff changeset
63 this.klass = klass; this.size = size;
a61af66fc99e Initial load
duke
parents:
diff changeset
64 }
a61af66fc99e Initial load
duke
parents:
diff changeset
65 }
a61af66fc99e Initial load
duke
parents:
diff changeset
66
a61af66fc99e Initial load
duke
parents:
diff changeset
67 private static class LoaderData {
a61af66fc99e Initial load
duke
parents:
diff changeset
68 long numClasses;
a61af66fc99e Initial load
duke
parents:
diff changeset
69 long classSize;
a61af66fc99e Initial load
duke
parents:
diff changeset
70 List classDetail = new ArrayList(); // List<ClassData>
a61af66fc99e Initial load
duke
parents:
diff changeset
71 }
a61af66fc99e Initial load
duke
parents:
diff changeset
72
a61af66fc99e Initial load
duke
parents:
diff changeset
73 public void run() {
a61af66fc99e Initial load
duke
parents:
diff changeset
74 printClassLoaderStatistics();
a61af66fc99e Initial load
duke
parents:
diff changeset
75 }
a61af66fc99e Initial load
duke
parents:
diff changeset
76
a61af66fc99e Initial load
duke
parents:
diff changeset
77 private void printClassLoaderStatistics() {
a61af66fc99e Initial load
duke
parents:
diff changeset
78 final PrintStream out = System.out;
a61af66fc99e Initial load
duke
parents:
diff changeset
79 final PrintStream err = System.err;
a61af66fc99e Initial load
duke
parents:
diff changeset
80 final Map loaderMap = new HashMap();
a61af66fc99e Initial load
duke
parents:
diff changeset
81 // loader data for bootstrap class loader
a61af66fc99e Initial load
duke
parents:
diff changeset
82 final LoaderData bootstrapLoaderData = new LoaderData();
a61af66fc99e Initial load
duke
parents:
diff changeset
83 if (verbose) {
a61af66fc99e Initial load
duke
parents:
diff changeset
84 err.print("finding class loader instances ..");
a61af66fc99e Initial load
duke
parents:
diff changeset
85 }
a61af66fc99e Initial load
duke
parents:
diff changeset
86
a61af66fc99e Initial load
duke
parents:
diff changeset
87 VM vm = VM.getVM();
a61af66fc99e Initial load
duke
parents:
diff changeset
88 ObjectHeap heap = vm.getObjectHeap();
a61af66fc99e Initial load
duke
parents:
diff changeset
89 Klass classLoaderKlass = vm.getSystemDictionary().getClassLoaderKlass();
a61af66fc99e Initial load
duke
parents:
diff changeset
90 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
91 heap.iterateObjectsOfKlass(new DefaultHeapVisitor() {
a61af66fc99e Initial load
duke
parents:
diff changeset
92 public boolean doObj(Oop oop) {
a61af66fc99e Initial load
duke
parents:
diff changeset
93 loaderMap.put(oop, new LoaderData());
a61af66fc99e Initial load
duke
parents:
diff changeset
94 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
95 }
a61af66fc99e Initial load
duke
parents:
diff changeset
96 }, classLoaderKlass);
a61af66fc99e Initial load
duke
parents:
diff changeset
97 } catch (Exception se) {
a61af66fc99e Initial load
duke
parents:
diff changeset
98 se.printStackTrace();
a61af66fc99e Initial load
duke
parents:
diff changeset
99 }
a61af66fc99e Initial load
duke
parents:
diff changeset
100
a61af66fc99e Initial load
duke
parents:
diff changeset
101 if (verbose) {
a61af66fc99e Initial load
duke
parents:
diff changeset
102 err.println("done.");
a61af66fc99e Initial load
duke
parents:
diff changeset
103 err.print("computing per loader stat ..");
a61af66fc99e Initial load
duke
parents:
diff changeset
104 }
a61af66fc99e Initial load
duke
parents:
diff changeset
105
a61af66fc99e Initial load
duke
parents:
diff changeset
106 SystemDictionary dict = VM.getVM().getSystemDictionary();
a61af66fc99e Initial load
duke
parents:
diff changeset
107 dict.classesDo(new SystemDictionary.ClassAndLoaderVisitor() {
a61af66fc99e Initial load
duke
parents:
diff changeset
108 public void visit(Klass k, Oop loader) {
a61af66fc99e Initial load
duke
parents:
diff changeset
109 if (! (k instanceof InstanceKlass)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
110 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
111 }
a61af66fc99e Initial load
duke
parents:
diff changeset
112 LoaderData ld = (loader != null) ? (LoaderData)loaderMap.get(loader)
a61af66fc99e Initial load
duke
parents:
diff changeset
113 : bootstrapLoaderData;
a61af66fc99e Initial load
duke
parents:
diff changeset
114 if (ld != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
115 ld.numClasses++;
a61af66fc99e Initial load
duke
parents:
diff changeset
116 long size = computeSize((InstanceKlass)k);
a61af66fc99e Initial load
duke
parents:
diff changeset
117 ld.classDetail.add(new ClassData(k, size));
a61af66fc99e Initial load
duke
parents:
diff changeset
118 ld.classSize += size;
a61af66fc99e Initial load
duke
parents:
diff changeset
119 }
a61af66fc99e Initial load
duke
parents:
diff changeset
120 }
a61af66fc99e Initial load
duke
parents:
diff changeset
121 });
a61af66fc99e Initial load
duke
parents:
diff changeset
122
a61af66fc99e Initial load
duke
parents:
diff changeset
123 if (verbose) {
a61af66fc99e Initial load
duke
parents:
diff changeset
124 err.println("done.");
a61af66fc99e Initial load
duke
parents:
diff changeset
125 err.print("please wait.. computing liveness");
a61af66fc99e Initial load
duke
parents:
diff changeset
126 }
a61af66fc99e Initial load
duke
parents:
diff changeset
127
a61af66fc99e Initial load
duke
parents:
diff changeset
128 // compute reverse pointer analysis (takes long time for larger app)
a61af66fc99e Initial load
duke
parents:
diff changeset
129 ReversePtrsAnalysis analysis = new ReversePtrsAnalysis();
a61af66fc99e Initial load
duke
parents:
diff changeset
130
a61af66fc99e Initial load
duke
parents:
diff changeset
131 if (verbose) {
a61af66fc99e Initial load
duke
parents:
diff changeset
132 analysis.setHeapProgressThunk(new HeapProgressThunk() {
a61af66fc99e Initial load
duke
parents:
diff changeset
133 public void heapIterationFractionUpdate(double fractionOfHeapVisited) {
a61af66fc99e Initial load
duke
parents:
diff changeset
134 err.print('.');
a61af66fc99e Initial load
duke
parents:
diff changeset
135 }
a61af66fc99e Initial load
duke
parents:
diff changeset
136 // This will be called after the iteration is complete
a61af66fc99e Initial load
duke
parents:
diff changeset
137 public void heapIterationComplete() {
a61af66fc99e Initial load
duke
parents:
diff changeset
138 err.println("done.");
a61af66fc99e Initial load
duke
parents:
diff changeset
139 }
a61af66fc99e Initial load
duke
parents:
diff changeset
140 });
a61af66fc99e Initial load
duke
parents:
diff changeset
141 }
a61af66fc99e Initial load
duke
parents:
diff changeset
142
a61af66fc99e Initial load
duke
parents:
diff changeset
143 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
144 analysis.run();
a61af66fc99e Initial load
duke
parents:
diff changeset
145 } catch (Exception e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
146 // e.printStackTrace();
a61af66fc99e Initial load
duke
parents:
diff changeset
147 if (verbose)
a61af66fc99e Initial load
duke
parents:
diff changeset
148 err.println("liveness analysis may be inaccurate ...");
a61af66fc99e Initial load
duke
parents:
diff changeset
149 }
a61af66fc99e Initial load
duke
parents:
diff changeset
150 ReversePtrs liveness = VM.getVM().getRevPtrs();
a61af66fc99e Initial load
duke
parents:
diff changeset
151
a61af66fc99e Initial load
duke
parents:
diff changeset
152 out.println("class_loader\tclasses\tbytes\tparent_loader\talive?\ttype");
a61af66fc99e Initial load
duke
parents:
diff changeset
153 out.println();
a61af66fc99e Initial load
duke
parents:
diff changeset
154
a61af66fc99e Initial load
duke
parents:
diff changeset
155 long numClassLoaders = 1L;
a61af66fc99e Initial load
duke
parents:
diff changeset
156 long totalNumClasses = bootstrapLoaderData.numClasses;
a61af66fc99e Initial load
duke
parents:
diff changeset
157 long totalClassSize = bootstrapLoaderData.classSize;
a61af66fc99e Initial load
duke
parents:
diff changeset
158 long numAliveLoaders = 1L;
a61af66fc99e Initial load
duke
parents:
diff changeset
159 long numDeadLoaders = 0L;
a61af66fc99e Initial load
duke
parents:
diff changeset
160
a61af66fc99e Initial load
duke
parents:
diff changeset
161 // print bootstrap loader details
a61af66fc99e Initial load
duke
parents:
diff changeset
162 out.print("<bootstrap>");
a61af66fc99e Initial load
duke
parents:
diff changeset
163 out.print('\t');
a61af66fc99e Initial load
duke
parents:
diff changeset
164 out.print(bootstrapLoaderData.numClasses);
a61af66fc99e Initial load
duke
parents:
diff changeset
165 out.print('\t');
a61af66fc99e Initial load
duke
parents:
diff changeset
166 out.print(bootstrapLoaderData.classSize);
a61af66fc99e Initial load
duke
parents:
diff changeset
167 out.print('\t');
a61af66fc99e Initial load
duke
parents:
diff changeset
168 out.print(" null ");
a61af66fc99e Initial load
duke
parents:
diff changeset
169 out.print('\t');
a61af66fc99e Initial load
duke
parents:
diff changeset
170 // bootstrap loader is always alive
a61af66fc99e Initial load
duke
parents:
diff changeset
171 out.print("live");
a61af66fc99e Initial load
duke
parents:
diff changeset
172 out.print('\t');
a61af66fc99e Initial load
duke
parents:
diff changeset
173 out.println("<internal>");
a61af66fc99e Initial load
duke
parents:
diff changeset
174
a61af66fc99e Initial load
duke
parents:
diff changeset
175 for (Iterator keyItr = loaderMap.keySet().iterator(); keyItr.hasNext();) {
a61af66fc99e Initial load
duke
parents:
diff changeset
176 Oop loader = (Oop) keyItr.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
177 LoaderData data = (LoaderData) loaderMap.get(loader);
a61af66fc99e Initial load
duke
parents:
diff changeset
178 numClassLoaders ++;
a61af66fc99e Initial load
duke
parents:
diff changeset
179 totalNumClasses += data.numClasses;
a61af66fc99e Initial load
duke
parents:
diff changeset
180 totalClassSize += data.classSize;
a61af66fc99e Initial load
duke
parents:
diff changeset
181
a61af66fc99e Initial load
duke
parents:
diff changeset
182 out.print(loader.getHandle());
a61af66fc99e Initial load
duke
parents:
diff changeset
183 out.print('\t');
a61af66fc99e Initial load
duke
parents:
diff changeset
184 out.print(data.numClasses);
a61af66fc99e Initial load
duke
parents:
diff changeset
185 out.print('\t');
a61af66fc99e Initial load
duke
parents:
diff changeset
186 out.print(data.classSize);
a61af66fc99e Initial load
duke
parents:
diff changeset
187 out.print('\t');
a61af66fc99e Initial load
duke
parents:
diff changeset
188
a61af66fc99e Initial load
duke
parents:
diff changeset
189 class ParentFinder extends DefaultOopVisitor {
a61af66fc99e Initial load
duke
parents:
diff changeset
190 public void doOop(OopField field, boolean isVMField) {
a61af66fc99e Initial load
duke
parents:
diff changeset
191 if (field.getID().getName().equals("parent")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
192 parent = field.getValue(getObj());
a61af66fc99e Initial load
duke
parents:
diff changeset
193 }
a61af66fc99e Initial load
duke
parents:
diff changeset
194 }
a61af66fc99e Initial load
duke
parents:
diff changeset
195 private Oop parent = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
196 public Oop getParent() { return parent; }
a61af66fc99e Initial load
duke
parents:
diff changeset
197 }
a61af66fc99e Initial load
duke
parents:
diff changeset
198
a61af66fc99e Initial load
duke
parents:
diff changeset
199 ParentFinder parentFinder = new ParentFinder();
a61af66fc99e Initial load
duke
parents:
diff changeset
200 loader.iterate(parentFinder, false);
a61af66fc99e Initial load
duke
parents:
diff changeset
201 Oop parent = parentFinder.getParent();
a61af66fc99e Initial load
duke
parents:
diff changeset
202 out.print((parent != null)? parent.getHandle().toString() : " null ");
a61af66fc99e Initial load
duke
parents:
diff changeset
203 out.print('\t');
a61af66fc99e Initial load
duke
parents:
diff changeset
204 boolean alive = (liveness != null) ? (liveness.get(loader) != null) : true;
a61af66fc99e Initial load
duke
parents:
diff changeset
205 out.print(alive? "live" : "dead");
a61af66fc99e Initial load
duke
parents:
diff changeset
206 if (alive) numAliveLoaders++; else numDeadLoaders++;
a61af66fc99e Initial load
duke
parents:
diff changeset
207 out.print('\t');
a61af66fc99e Initial load
duke
parents:
diff changeset
208 Klass loaderKlass = loader.getKlass();
a61af66fc99e Initial load
duke
parents:
diff changeset
209 if (loaderKlass != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
210 out.print(loaderKlass.getName().asString());
a61af66fc99e Initial load
duke
parents:
diff changeset
211 out.print('@');
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 4061
diff changeset
212 out.print(loader.getKlass().getAddress());
0
a61af66fc99e Initial load
duke
parents:
diff changeset
213 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
214 out.print(" null! ");
a61af66fc99e Initial load
duke
parents:
diff changeset
215 }
a61af66fc99e Initial load
duke
parents:
diff changeset
216 out.println();
a61af66fc99e Initial load
duke
parents:
diff changeset
217 }
a61af66fc99e Initial load
duke
parents:
diff changeset
218
a61af66fc99e Initial load
duke
parents:
diff changeset
219 out.println();
a61af66fc99e Initial load
duke
parents:
diff changeset
220 // summary line
a61af66fc99e Initial load
duke
parents:
diff changeset
221 out.print("total = ");
a61af66fc99e Initial load
duke
parents:
diff changeset
222 out.print(numClassLoaders);
a61af66fc99e Initial load
duke
parents:
diff changeset
223 out.print('\t');
a61af66fc99e Initial load
duke
parents:
diff changeset
224 out.print(totalNumClasses);
a61af66fc99e Initial load
duke
parents:
diff changeset
225 out.print('\t');
a61af66fc99e Initial load
duke
parents:
diff changeset
226 out.print(totalClassSize);
a61af66fc99e Initial load
duke
parents:
diff changeset
227 out.print('\t');
a61af66fc99e Initial load
duke
parents:
diff changeset
228 out.print(" N/A ");
a61af66fc99e Initial load
duke
parents:
diff changeset
229 out.print('\t');
a61af66fc99e Initial load
duke
parents:
diff changeset
230 out.print("alive=");
a61af66fc99e Initial load
duke
parents:
diff changeset
231 out.print(numAliveLoaders);
a61af66fc99e Initial load
duke
parents:
diff changeset
232 out.print(", dead=");
a61af66fc99e Initial load
duke
parents:
diff changeset
233 out.print(numDeadLoaders);
a61af66fc99e Initial load
duke
parents:
diff changeset
234 out.print('\t');
a61af66fc99e Initial load
duke
parents:
diff changeset
235 out.print(" N/A ");
a61af66fc99e Initial load
duke
parents:
diff changeset
236 out.println();
a61af66fc99e Initial load
duke
parents:
diff changeset
237 }
a61af66fc99e Initial load
duke
parents:
diff changeset
238
261
7f601f7c9b48 6731726: jmap -permstat reports only 50-60% of permgen memory usage.
martin
parents: 0
diff changeset
239 private static long objectSize(Oop oop) {
7f601f7c9b48 6731726: jmap -permstat reports only 50-60% of permgen memory usage.
martin
parents: 0
diff changeset
240 return oop == null ? 0L : oop.getObjectSize();
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
7f601f7c9b48 6731726: jmap -permstat reports only 50-60% of permgen memory usage.
martin
parents: 0
diff changeset
243 // Don't count the shared empty arrays
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 4061
diff changeset
244 private static long arraySize(GenericArray arr) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 4061
diff changeset
245 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
246 }
7f601f7c9b48 6731726: jmap -permstat reports only 50-60% of permgen memory usage.
martin
parents: 0
diff changeset
247
0
a61af66fc99e Initial load
duke
parents:
diff changeset
248 private long computeSize(InstanceKlass k) {
a61af66fc99e Initial load
duke
parents:
diff changeset
249 long size = 0L;
261
7f601f7c9b48 6731726: jmap -permstat reports only 50-60% of permgen memory usage.
martin
parents: 0
diff changeset
250 // the InstanceKlass object itself
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 4061
diff changeset
251 size += k.getSize();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
252
261
7f601f7c9b48 6731726: jmap -permstat reports only 50-60% of permgen memory usage.
martin
parents: 0
diff changeset
253 // Constant pool
7f601f7c9b48 6731726: jmap -permstat reports only 50-60% of permgen memory usage.
martin
parents: 0
diff changeset
254 ConstantPool cp = k.getConstants();
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 4061
diff changeset
255 size += cp.getSize();
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 4061
diff changeset
256 if (cp.getCache() != null) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 4061
diff changeset
257 size += cp.getCache().getSize();
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 4061
diff changeset
258 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 4061
diff changeset
259 size += arraySize(cp.getTags());
261
7f601f7c9b48 6731726: jmap -permstat reports only 50-60% of permgen memory usage.
martin
parents: 0
diff changeset
260
7f601f7c9b48 6731726: jmap -permstat reports only 50-60% of permgen memory usage.
martin
parents: 0
diff changeset
261 // Interfaces
7f601f7c9b48 6731726: jmap -permstat reports only 50-60% of permgen memory usage.
martin
parents: 0
diff changeset
262 size += arraySize(k.getLocalInterfaces());
7f601f7c9b48 6731726: jmap -permstat reports only 50-60% of permgen memory usage.
martin
parents: 0
diff changeset
263 size += arraySize(k.getTransitiveInterfaces());
7f601f7c9b48 6731726: jmap -permstat reports only 50-60% of permgen memory usage.
martin
parents: 0
diff changeset
264
7f601f7c9b48 6731726: jmap -permstat reports only 50-60% of permgen memory usage.
martin
parents: 0
diff changeset
265 // Inner classes
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 4061
diff changeset
266 size += arraySize(k.getInnerClasses());
0
a61af66fc99e Initial load
duke
parents:
diff changeset
267
261
7f601f7c9b48 6731726: jmap -permstat reports only 50-60% of permgen memory usage.
martin
parents: 0
diff changeset
268 // Fields
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 4061
diff changeset
269 size += arraySize(k.getFields());
261
7f601f7c9b48 6731726: jmap -permstat reports only 50-60% of permgen memory usage.
martin
parents: 0
diff changeset
270
7f601f7c9b48 6731726: jmap -permstat reports only 50-60% of permgen memory usage.
martin
parents: 0
diff changeset
271 // Methods
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 4061
diff changeset
272 MethodArray methods = k.getMethods();
261
7f601f7c9b48 6731726: jmap -permstat reports only 50-60% of permgen memory usage.
martin
parents: 0
diff changeset
273 int nmethods = (int) methods.getLength();
7f601f7c9b48 6731726: jmap -permstat reports only 50-60% of permgen memory usage.
martin
parents: 0
diff changeset
274 if (nmethods != 0L) {
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 4061
diff changeset
275 size += methods.getSize();
261
7f601f7c9b48 6731726: jmap -permstat reports only 50-60% of permgen memory usage.
martin
parents: 0
diff changeset
276 for (int i = 0; i < nmethods; ++i) {
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 4061
diff changeset
277 Method m = methods.at(i);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 4061
diff changeset
278 size += m.getSize();
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 4061
diff changeset
279 size += m.getConstMethod().getSize();
261
7f601f7c9b48 6731726: jmap -permstat reports only 50-60% of permgen memory usage.
martin
parents: 0
diff changeset
280 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
281 }
a61af66fc99e Initial load
duke
parents:
diff changeset
282
a61af66fc99e Initial load
duke
parents:
diff changeset
283 return size;
a61af66fc99e Initial load
duke
parents:
diff changeset
284 }
a61af66fc99e Initial load
duke
parents:
diff changeset
285 }