annotate agent/src/share/classes/sun/jvm/hotspot/tools/ClassLoaderStats.java @ 14909:4ca6dc0799b6

Backout jdk9 merge
author Gilles Duboscq <duboscq@ssw.jku.at>
date Tue, 01 Apr 2014 13:57:07 +0200
parents c888354aaa35
children
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();
12932
7fe6ef09d242 8025638: jmap returns 0 instead of 1 when it fails.
farvidsson
parents: 11054
diff changeset
54 cls.execute(args);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
55 }
a61af66fc99e Initial load
duke
parents:
diff changeset
56
a61af66fc99e Initial load
duke
parents:
diff changeset
57 private static class ClassData {
a61af66fc99e Initial load
duke
parents:
diff changeset
58 Klass klass;
a61af66fc99e Initial load
duke
parents:
diff changeset
59 long size;
a61af66fc99e Initial load
duke
parents:
diff changeset
60
a61af66fc99e Initial load
duke
parents:
diff changeset
61 ClassData(Klass klass, long size) {
a61af66fc99e Initial load
duke
parents:
diff changeset
62 this.klass = klass; this.size = size;
a61af66fc99e Initial load
duke
parents:
diff changeset
63 }
a61af66fc99e Initial load
duke
parents:
diff changeset
64 }
a61af66fc99e Initial load
duke
parents:
diff changeset
65
a61af66fc99e Initial load
duke
parents:
diff changeset
66 private static class LoaderData {
a61af66fc99e Initial load
duke
parents:
diff changeset
67 long numClasses;
a61af66fc99e Initial load
duke
parents:
diff changeset
68 long classSize;
a61af66fc99e Initial load
duke
parents:
diff changeset
69 List classDetail = new ArrayList(); // List<ClassData>
a61af66fc99e Initial load
duke
parents:
diff changeset
70 }
a61af66fc99e Initial load
duke
parents:
diff changeset
71
a61af66fc99e Initial load
duke
parents:
diff changeset
72 public void run() {
a61af66fc99e Initial load
duke
parents:
diff changeset
73 printClassLoaderStatistics();
a61af66fc99e Initial load
duke
parents:
diff changeset
74 }
a61af66fc99e Initial load
duke
parents:
diff changeset
75
a61af66fc99e Initial load
duke
parents:
diff changeset
76 private void printClassLoaderStatistics() {
a61af66fc99e Initial load
duke
parents:
diff changeset
77 final PrintStream out = System.out;
a61af66fc99e Initial load
duke
parents:
diff changeset
78 final PrintStream err = System.err;
a61af66fc99e Initial load
duke
parents:
diff changeset
79 final Map loaderMap = new HashMap();
a61af66fc99e Initial load
duke
parents:
diff changeset
80 // loader data for bootstrap class loader
a61af66fc99e Initial load
duke
parents:
diff changeset
81 final LoaderData bootstrapLoaderData = new LoaderData();
a61af66fc99e Initial load
duke
parents:
diff changeset
82 if (verbose) {
a61af66fc99e Initial load
duke
parents:
diff changeset
83 err.print("finding class loader instances ..");
a61af66fc99e Initial load
duke
parents:
diff changeset
84 }
a61af66fc99e Initial load
duke
parents:
diff changeset
85
a61af66fc99e Initial load
duke
parents:
diff changeset
86 VM vm = VM.getVM();
a61af66fc99e Initial load
duke
parents:
diff changeset
87 ObjectHeap heap = vm.getObjectHeap();
a61af66fc99e Initial load
duke
parents:
diff changeset
88 Klass classLoaderKlass = vm.getSystemDictionary().getClassLoaderKlass();
a61af66fc99e Initial load
duke
parents:
diff changeset
89 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
90 heap.iterateObjectsOfKlass(new DefaultHeapVisitor() {
a61af66fc99e Initial load
duke
parents:
diff changeset
91 public boolean doObj(Oop oop) {
a61af66fc99e Initial load
duke
parents:
diff changeset
92 loaderMap.put(oop, new LoaderData());
a61af66fc99e Initial load
duke
parents:
diff changeset
93 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
94 }
a61af66fc99e Initial load
duke
parents:
diff changeset
95 }, classLoaderKlass);
a61af66fc99e Initial load
duke
parents:
diff changeset
96 } catch (Exception se) {
a61af66fc99e Initial load
duke
parents:
diff changeset
97 se.printStackTrace();
a61af66fc99e Initial load
duke
parents:
diff changeset
98 }
a61af66fc99e Initial load
duke
parents:
diff changeset
99
a61af66fc99e Initial load
duke
parents:
diff changeset
100 if (verbose) {
a61af66fc99e Initial load
duke
parents:
diff changeset
101 err.println("done.");
a61af66fc99e Initial load
duke
parents:
diff changeset
102 err.print("computing per loader stat ..");
a61af66fc99e Initial load
duke
parents:
diff changeset
103 }
a61af66fc99e Initial load
duke
parents:
diff changeset
104
a61af66fc99e Initial load
duke
parents:
diff changeset
105 SystemDictionary dict = VM.getVM().getSystemDictionary();
14909
4ca6dc0799b6 Backout jdk9 merge
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 14316
diff changeset
106 dict.classesDo(new SystemDictionary.ClassAndLoaderVisitor() {
4ca6dc0799b6 Backout jdk9 merge
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 14316
diff changeset
107 public void visit(Klass k, Oop loader) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
108 if (! (k instanceof InstanceKlass)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
109 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
110 }
a61af66fc99e Initial load
duke
parents:
diff changeset
111 LoaderData ld = (loader != null) ? (LoaderData)loaderMap.get(loader)
a61af66fc99e Initial load
duke
parents:
diff changeset
112 : bootstrapLoaderData;
a61af66fc99e Initial load
duke
parents:
diff changeset
113 if (ld != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
114 ld.numClasses++;
a61af66fc99e Initial load
duke
parents:
diff changeset
115 long size = computeSize((InstanceKlass)k);
a61af66fc99e Initial load
duke
parents:
diff changeset
116 ld.classDetail.add(new ClassData(k, size));
a61af66fc99e Initial load
duke
parents:
diff changeset
117 ld.classSize += size;
a61af66fc99e Initial load
duke
parents:
diff changeset
118 }
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 if (verbose) {
a61af66fc99e Initial load
duke
parents:
diff changeset
123 err.println("done.");
a61af66fc99e Initial load
duke
parents:
diff changeset
124 err.print("please wait.. computing liveness");
a61af66fc99e Initial load
duke
parents:
diff changeset
125 }
a61af66fc99e Initial load
duke
parents:
diff changeset
126
a61af66fc99e Initial load
duke
parents:
diff changeset
127 // compute reverse pointer analysis (takes long time for larger app)
a61af66fc99e Initial load
duke
parents:
diff changeset
128 ReversePtrsAnalysis analysis = new ReversePtrsAnalysis();
a61af66fc99e Initial load
duke
parents:
diff changeset
129
a61af66fc99e Initial load
duke
parents:
diff changeset
130 if (verbose) {
a61af66fc99e Initial load
duke
parents:
diff changeset
131 analysis.setHeapProgressThunk(new HeapProgressThunk() {
a61af66fc99e Initial load
duke
parents:
diff changeset
132 public void heapIterationFractionUpdate(double fractionOfHeapVisited) {
a61af66fc99e Initial load
duke
parents:
diff changeset
133 err.print('.');
a61af66fc99e Initial load
duke
parents:
diff changeset
134 }
a61af66fc99e Initial load
duke
parents:
diff changeset
135 // This will be called after the iteration is complete
a61af66fc99e Initial load
duke
parents:
diff changeset
136 public void heapIterationComplete() {
a61af66fc99e Initial load
duke
parents:
diff changeset
137 err.println("done.");
a61af66fc99e Initial load
duke
parents:
diff changeset
138 }
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 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
143 analysis.run();
a61af66fc99e Initial load
duke
parents:
diff changeset
144 } catch (Exception e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
145 // e.printStackTrace();
a61af66fc99e Initial load
duke
parents:
diff changeset
146 if (verbose)
a61af66fc99e Initial load
duke
parents:
diff changeset
147 err.println("liveness analysis may be inaccurate ...");
a61af66fc99e Initial load
duke
parents:
diff changeset
148 }
a61af66fc99e Initial load
duke
parents:
diff changeset
149 ReversePtrs liveness = VM.getVM().getRevPtrs();
a61af66fc99e Initial load
duke
parents:
diff changeset
150
a61af66fc99e Initial load
duke
parents:
diff changeset
151 out.println("class_loader\tclasses\tbytes\tparent_loader\talive?\ttype");
a61af66fc99e Initial load
duke
parents:
diff changeset
152 out.println();
a61af66fc99e Initial load
duke
parents:
diff changeset
153
a61af66fc99e Initial load
duke
parents:
diff changeset
154 long numClassLoaders = 1L;
a61af66fc99e Initial load
duke
parents:
diff changeset
155 long totalNumClasses = bootstrapLoaderData.numClasses;
a61af66fc99e Initial load
duke
parents:
diff changeset
156 long totalClassSize = bootstrapLoaderData.classSize;
a61af66fc99e Initial load
duke
parents:
diff changeset
157 long numAliveLoaders = 1L;
a61af66fc99e Initial load
duke
parents:
diff changeset
158 long numDeadLoaders = 0L;
a61af66fc99e Initial load
duke
parents:
diff changeset
159
a61af66fc99e Initial load
duke
parents:
diff changeset
160 // print bootstrap loader details
a61af66fc99e Initial load
duke
parents:
diff changeset
161 out.print("<bootstrap>");
a61af66fc99e Initial load
duke
parents:
diff changeset
162 out.print('\t');
a61af66fc99e Initial load
duke
parents:
diff changeset
163 out.print(bootstrapLoaderData.numClasses);
a61af66fc99e Initial load
duke
parents:
diff changeset
164 out.print('\t');
a61af66fc99e Initial load
duke
parents:
diff changeset
165 out.print(bootstrapLoaderData.classSize);
a61af66fc99e Initial load
duke
parents:
diff changeset
166 out.print('\t');
a61af66fc99e Initial load
duke
parents:
diff changeset
167 out.print(" null ");
a61af66fc99e Initial load
duke
parents:
diff changeset
168 out.print('\t');
a61af66fc99e Initial load
duke
parents:
diff changeset
169 // bootstrap loader is always alive
a61af66fc99e Initial load
duke
parents:
diff changeset
170 out.print("live");
a61af66fc99e Initial load
duke
parents:
diff changeset
171 out.print('\t');
a61af66fc99e Initial load
duke
parents:
diff changeset
172 out.println("<internal>");
a61af66fc99e Initial load
duke
parents:
diff changeset
173
a61af66fc99e Initial load
duke
parents:
diff changeset
174 for (Iterator keyItr = loaderMap.keySet().iterator(); keyItr.hasNext();) {
a61af66fc99e Initial load
duke
parents:
diff changeset
175 Oop loader = (Oop) keyItr.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
176 LoaderData data = (LoaderData) loaderMap.get(loader);
a61af66fc99e Initial load
duke
parents:
diff changeset
177 numClassLoaders ++;
a61af66fc99e Initial load
duke
parents:
diff changeset
178 totalNumClasses += data.numClasses;
a61af66fc99e Initial load
duke
parents:
diff changeset
179 totalClassSize += data.classSize;
a61af66fc99e Initial load
duke
parents:
diff changeset
180
a61af66fc99e Initial load
duke
parents:
diff changeset
181 out.print(loader.getHandle());
a61af66fc99e Initial load
duke
parents:
diff changeset
182 out.print('\t');
a61af66fc99e Initial load
duke
parents:
diff changeset
183 out.print(data.numClasses);
a61af66fc99e Initial load
duke
parents:
diff changeset
184 out.print('\t');
a61af66fc99e Initial load
duke
parents:
diff changeset
185 out.print(data.classSize);
a61af66fc99e Initial load
duke
parents:
diff changeset
186 out.print('\t');
a61af66fc99e Initial load
duke
parents:
diff changeset
187
a61af66fc99e Initial load
duke
parents:
diff changeset
188 class ParentFinder extends DefaultOopVisitor {
a61af66fc99e Initial load
duke
parents:
diff changeset
189 public void doOop(OopField field, boolean isVMField) {
a61af66fc99e Initial load
duke
parents:
diff changeset
190 if (field.getID().getName().equals("parent")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
191 parent = field.getValue(getObj());
a61af66fc99e Initial load
duke
parents:
diff changeset
192 }
a61af66fc99e Initial load
duke
parents:
diff changeset
193 }
a61af66fc99e Initial load
duke
parents:
diff changeset
194 private Oop parent = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
195 public Oop getParent() { return parent; }
a61af66fc99e Initial load
duke
parents:
diff changeset
196 }
a61af66fc99e Initial load
duke
parents:
diff changeset
197
a61af66fc99e Initial load
duke
parents:
diff changeset
198 ParentFinder parentFinder = new ParentFinder();
a61af66fc99e Initial load
duke
parents:
diff changeset
199 loader.iterate(parentFinder, false);
a61af66fc99e Initial load
duke
parents:
diff changeset
200 Oop parent = parentFinder.getParent();
a61af66fc99e Initial load
duke
parents:
diff changeset
201 out.print((parent != null)? parent.getHandle().toString() : " null ");
a61af66fc99e Initial load
duke
parents:
diff changeset
202 out.print('\t');
a61af66fc99e Initial load
duke
parents:
diff changeset
203 boolean alive = (liveness != null) ? (liveness.get(loader) != null) : true;
a61af66fc99e Initial load
duke
parents:
diff changeset
204 out.print(alive? "live" : "dead");
a61af66fc99e Initial load
duke
parents:
diff changeset
205 if (alive) numAliveLoaders++; else numDeadLoaders++;
a61af66fc99e Initial load
duke
parents:
diff changeset
206 out.print('\t');
a61af66fc99e Initial load
duke
parents:
diff changeset
207 Klass loaderKlass = loader.getKlass();
a61af66fc99e Initial load
duke
parents:
diff changeset
208 if (loaderKlass != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
209 out.print(loaderKlass.getName().asString());
a61af66fc99e Initial load
duke
parents:
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
212 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
213 out.print(" null! ");
a61af66fc99e Initial load
duke
parents:
diff changeset
214 }
a61af66fc99e Initial load
duke
parents:
diff changeset
215 out.println();
a61af66fc99e Initial load
duke
parents:
diff changeset
216 }
a61af66fc99e Initial load
duke
parents:
diff changeset
217
a61af66fc99e Initial load
duke
parents:
diff changeset
218 out.println();
a61af66fc99e Initial load
duke
parents:
diff changeset
219 // summary line
a61af66fc99e Initial load
duke
parents:
diff changeset
220 out.print("total = ");
a61af66fc99e Initial load
duke
parents:
diff changeset
221 out.print(numClassLoaders);
a61af66fc99e Initial load
duke
parents:
diff changeset
222 out.print('\t');
a61af66fc99e Initial load
duke
parents:
diff changeset
223 out.print(totalNumClasses);
a61af66fc99e Initial load
duke
parents:
diff changeset
224 out.print('\t');
a61af66fc99e Initial load
duke
parents:
diff changeset
225 out.print(totalClassSize);
a61af66fc99e Initial load
duke
parents:
diff changeset
226 out.print('\t');
a61af66fc99e Initial load
duke
parents:
diff changeset
227 out.print(" N/A ");
a61af66fc99e Initial load
duke
parents:
diff changeset
228 out.print('\t');
a61af66fc99e Initial load
duke
parents:
diff changeset
229 out.print("alive=");
a61af66fc99e Initial load
duke
parents:
diff changeset
230 out.print(numAliveLoaders);
a61af66fc99e Initial load
duke
parents:
diff changeset
231 out.print(", dead=");
a61af66fc99e Initial load
duke
parents:
diff changeset
232 out.print(numDeadLoaders);
a61af66fc99e Initial load
duke
parents:
diff changeset
233 out.print('\t');
a61af66fc99e Initial load
duke
parents:
diff changeset
234 out.print(" N/A ");
a61af66fc99e Initial load
duke
parents:
diff changeset
235 out.println();
a61af66fc99e Initial load
duke
parents:
diff changeset
236 }
a61af66fc99e Initial load
duke
parents:
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
247 private long computeSize(InstanceKlass k) {
a61af66fc99e Initial load
duke
parents:
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
280 }
a61af66fc99e Initial load
duke
parents:
diff changeset
281
a61af66fc99e Initial load
duke
parents:
diff changeset
282 return size;
a61af66fc99e Initial load
duke
parents:
diff changeset
283 }
a61af66fc99e Initial load
duke
parents:
diff changeset
284 }