annotate agent/src/share/classes/sun/jvm/hotspot/tools/PermStat.java @ 337:9ee9cf798b59 jdk7-b37

6754988: Update copyright year Summary: Update for files that have been modified starting July 2008 Reviewed-by: ohair, tbell
author xdono
date Thu, 02 Oct 2008 19:58:19 -0700
parents 7f601f7c9b48
children c18cbe5936b8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
337
9ee9cf798b59 6754988: Update copyright year
xdono
parents: 261
diff changeset
2 * Copyright 2003-2008 Sun Microsystems, Inc. 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 *
a61af66fc99e Initial load
duke
parents:
diff changeset
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
a61af66fc99e Initial load
duke
parents:
diff changeset
20 * CA 95054 USA or visit www.sun.com if you need additional information or
a61af66fc99e Initial load
duke
parents:
diff changeset
21 * have any questions.
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 /**
a61af66fc99e Initial load
duke
parents:
diff changeset
38 A command line tool to print perm. generation statistics.
a61af66fc99e Initial load
duke
parents:
diff changeset
39 */
a61af66fc99e Initial load
duke
parents:
diff changeset
40
a61af66fc99e Initial load
duke
parents:
diff changeset
41 public class PermStat extends Tool {
a61af66fc99e Initial load
duke
parents:
diff changeset
42 boolean verbose = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
43
a61af66fc99e Initial load
duke
parents:
diff changeset
44 public static void main(String[] args) {
a61af66fc99e Initial load
duke
parents:
diff changeset
45 PermStat ps = new PermStat();
a61af66fc99e Initial load
duke
parents:
diff changeset
46 ps.start(args);
a61af66fc99e Initial load
duke
parents:
diff changeset
47 ps.stop();
a61af66fc99e Initial load
duke
parents:
diff changeset
48 }
a61af66fc99e Initial load
duke
parents:
diff changeset
49
a61af66fc99e Initial load
duke
parents:
diff changeset
50 private static class ClassData {
a61af66fc99e Initial load
duke
parents:
diff changeset
51 Klass klass;
a61af66fc99e Initial load
duke
parents:
diff changeset
52 long size;
a61af66fc99e Initial load
duke
parents:
diff changeset
53
a61af66fc99e Initial load
duke
parents:
diff changeset
54 ClassData(Klass klass, long size) {
a61af66fc99e Initial load
duke
parents:
diff changeset
55 this.klass = klass; this.size = size;
a61af66fc99e Initial load
duke
parents:
diff changeset
56 }
a61af66fc99e Initial load
duke
parents:
diff changeset
57 }
a61af66fc99e Initial load
duke
parents:
diff changeset
58
a61af66fc99e Initial load
duke
parents:
diff changeset
59 private static class LoaderData {
a61af66fc99e Initial load
duke
parents:
diff changeset
60 long numClasses;
a61af66fc99e Initial load
duke
parents:
diff changeset
61 long classSize;
a61af66fc99e Initial load
duke
parents:
diff changeset
62 List classDetail = new ArrayList(); // List<ClassData>
a61af66fc99e Initial load
duke
parents:
diff changeset
63 }
a61af66fc99e Initial load
duke
parents:
diff changeset
64
a61af66fc99e Initial load
duke
parents:
diff changeset
65 public void run() {
a61af66fc99e Initial load
duke
parents:
diff changeset
66 printInternStringStatistics();
a61af66fc99e Initial load
duke
parents:
diff changeset
67 printClassLoaderStatistics();
a61af66fc99e Initial load
duke
parents:
diff changeset
68 }
a61af66fc99e Initial load
duke
parents:
diff changeset
69
a61af66fc99e Initial load
duke
parents:
diff changeset
70 private void printInternStringStatistics() {
a61af66fc99e Initial load
duke
parents:
diff changeset
71 class StringStat implements StringTable.StringVisitor {
a61af66fc99e Initial load
duke
parents:
diff changeset
72 private int count;
a61af66fc99e Initial load
duke
parents:
diff changeset
73 private long size;
a61af66fc99e Initial load
duke
parents:
diff changeset
74 private OopField stringValueField;
a61af66fc99e Initial load
duke
parents:
diff changeset
75
a61af66fc99e Initial load
duke
parents:
diff changeset
76 StringStat() {
a61af66fc99e Initial load
duke
parents:
diff changeset
77 VM vm = VM.getVM();
a61af66fc99e Initial load
duke
parents:
diff changeset
78 SystemDictionary sysDict = vm.getSystemDictionary();
a61af66fc99e Initial load
duke
parents:
diff changeset
79 InstanceKlass strKlass = sysDict.getStringKlass();
a61af66fc99e Initial load
duke
parents:
diff changeset
80 // String has a field named 'value' of type 'char[]'.
a61af66fc99e Initial load
duke
parents:
diff changeset
81 stringValueField = (OopField) strKlass.findField("value", "[C");
a61af66fc99e Initial load
duke
parents:
diff changeset
82 }
a61af66fc99e Initial load
duke
parents:
diff changeset
83
a61af66fc99e Initial load
duke
parents:
diff changeset
84 private long stringSize(Instance instance) {
a61af66fc99e Initial load
duke
parents:
diff changeset
85 // We include String content in size calculation.
a61af66fc99e Initial load
duke
parents:
diff changeset
86 return instance.getObjectSize() +
a61af66fc99e Initial load
duke
parents:
diff changeset
87 stringValueField.getValue(instance).getObjectSize();
a61af66fc99e Initial load
duke
parents:
diff changeset
88 }
a61af66fc99e Initial load
duke
parents:
diff changeset
89
a61af66fc99e Initial load
duke
parents:
diff changeset
90 public void visit(Instance str) {
a61af66fc99e Initial load
duke
parents:
diff changeset
91 count++;
a61af66fc99e Initial load
duke
parents:
diff changeset
92 size += stringSize(str);
a61af66fc99e Initial load
duke
parents:
diff changeset
93 }
a61af66fc99e Initial load
duke
parents:
diff changeset
94
a61af66fc99e Initial load
duke
parents:
diff changeset
95 public void print() {
a61af66fc99e Initial load
duke
parents:
diff changeset
96 System.out.println(count +
a61af66fc99e Initial load
duke
parents:
diff changeset
97 " intern Strings occupying " + size + " bytes.");
a61af66fc99e Initial load
duke
parents:
diff changeset
98 }
a61af66fc99e Initial load
duke
parents:
diff changeset
99 }
a61af66fc99e Initial load
duke
parents:
diff changeset
100
a61af66fc99e Initial load
duke
parents:
diff changeset
101 StringStat stat = new StringStat();
a61af66fc99e Initial load
duke
parents:
diff changeset
102 StringTable strTable = VM.getVM().getStringTable();
a61af66fc99e Initial load
duke
parents:
diff changeset
103 strTable.stringsDo(stat);
a61af66fc99e Initial load
duke
parents:
diff changeset
104 stat.print();
a61af66fc99e Initial load
duke
parents:
diff changeset
105 }
a61af66fc99e Initial load
duke
parents:
diff changeset
106
a61af66fc99e Initial load
duke
parents:
diff changeset
107 private void printClassLoaderStatistics() {
a61af66fc99e Initial load
duke
parents:
diff changeset
108 final PrintStream out = System.out;
a61af66fc99e Initial load
duke
parents:
diff changeset
109 final PrintStream err = System.err;
a61af66fc99e Initial load
duke
parents:
diff changeset
110 final Map loaderMap = new HashMap();
a61af66fc99e Initial load
duke
parents:
diff changeset
111 // loader data for bootstrap class loader
a61af66fc99e Initial load
duke
parents:
diff changeset
112 final LoaderData bootstrapLoaderData = new LoaderData();
a61af66fc99e Initial load
duke
parents:
diff changeset
113 if (verbose) {
a61af66fc99e Initial load
duke
parents:
diff changeset
114 err.print("finding class loader instances ..");
a61af66fc99e Initial load
duke
parents:
diff changeset
115 }
a61af66fc99e Initial load
duke
parents:
diff changeset
116
a61af66fc99e Initial load
duke
parents:
diff changeset
117 VM vm = VM.getVM();
a61af66fc99e Initial load
duke
parents:
diff changeset
118 ObjectHeap heap = vm.getObjectHeap();
a61af66fc99e Initial load
duke
parents:
diff changeset
119 Klass classLoaderKlass = vm.getSystemDictionary().getClassLoaderKlass();
a61af66fc99e Initial load
duke
parents:
diff changeset
120 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
121 heap.iterateObjectsOfKlass(new DefaultHeapVisitor() {
a61af66fc99e Initial load
duke
parents:
diff changeset
122 public boolean doObj(Oop oop) {
a61af66fc99e Initial load
duke
parents:
diff changeset
123 loaderMap.put(oop, new LoaderData());
a61af66fc99e Initial load
duke
parents:
diff changeset
124 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
125 }
a61af66fc99e Initial load
duke
parents:
diff changeset
126 }, classLoaderKlass);
a61af66fc99e Initial load
duke
parents:
diff changeset
127 } catch (Exception se) {
a61af66fc99e Initial load
duke
parents:
diff changeset
128 se.printStackTrace();
a61af66fc99e Initial load
duke
parents:
diff changeset
129 }
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 err.println("done.");
a61af66fc99e Initial load
duke
parents:
diff changeset
133 err.print("computing per loader stat ..");
a61af66fc99e Initial load
duke
parents:
diff changeset
134 }
a61af66fc99e Initial load
duke
parents:
diff changeset
135
a61af66fc99e Initial load
duke
parents:
diff changeset
136 SystemDictionary dict = VM.getVM().getSystemDictionary();
a61af66fc99e Initial load
duke
parents:
diff changeset
137 dict.classesDo(new SystemDictionary.ClassAndLoaderVisitor() {
a61af66fc99e Initial load
duke
parents:
diff changeset
138 public void visit(Klass k, Oop loader) {
a61af66fc99e Initial load
duke
parents:
diff changeset
139 if (! (k instanceof InstanceKlass)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
140 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
141 }
a61af66fc99e Initial load
duke
parents:
diff changeset
142 LoaderData ld = (loader != null) ? (LoaderData)loaderMap.get(loader)
a61af66fc99e Initial load
duke
parents:
diff changeset
143 : bootstrapLoaderData;
a61af66fc99e Initial load
duke
parents:
diff changeset
144 if (ld != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
145 ld.numClasses++;
a61af66fc99e Initial load
duke
parents:
diff changeset
146 long size = computeSize((InstanceKlass)k);
a61af66fc99e Initial load
duke
parents:
diff changeset
147 ld.classDetail.add(new ClassData(k, size));
a61af66fc99e Initial load
duke
parents:
diff changeset
148 ld.classSize += size;
a61af66fc99e Initial load
duke
parents:
diff changeset
149 }
a61af66fc99e Initial load
duke
parents:
diff changeset
150 }
a61af66fc99e Initial load
duke
parents:
diff changeset
151 });
a61af66fc99e Initial load
duke
parents:
diff changeset
152
a61af66fc99e Initial load
duke
parents:
diff changeset
153 if (verbose) {
a61af66fc99e Initial load
duke
parents:
diff changeset
154 err.println("done.");
a61af66fc99e Initial load
duke
parents:
diff changeset
155 err.print("please wait.. computing liveness");
a61af66fc99e Initial load
duke
parents:
diff changeset
156 }
a61af66fc99e Initial load
duke
parents:
diff changeset
157
a61af66fc99e Initial load
duke
parents:
diff changeset
158 // compute reverse pointer analysis (takes long time for larger app)
a61af66fc99e Initial load
duke
parents:
diff changeset
159 ReversePtrsAnalysis analysis = new ReversePtrsAnalysis();
a61af66fc99e Initial load
duke
parents:
diff changeset
160
a61af66fc99e Initial load
duke
parents:
diff changeset
161 if (verbose) {
a61af66fc99e Initial load
duke
parents:
diff changeset
162 analysis.setHeapProgressThunk(new HeapProgressThunk() {
a61af66fc99e Initial load
duke
parents:
diff changeset
163 public void heapIterationFractionUpdate(double fractionOfHeapVisited) {
a61af66fc99e Initial load
duke
parents:
diff changeset
164 err.print('.');
a61af66fc99e Initial load
duke
parents:
diff changeset
165 }
a61af66fc99e Initial load
duke
parents:
diff changeset
166 // This will be called after the iteration is complete
a61af66fc99e Initial load
duke
parents:
diff changeset
167 public void heapIterationComplete() {
a61af66fc99e Initial load
duke
parents:
diff changeset
168 err.println("done.");
a61af66fc99e Initial load
duke
parents:
diff changeset
169 }
a61af66fc99e Initial load
duke
parents:
diff changeset
170 });
a61af66fc99e Initial load
duke
parents:
diff changeset
171 }
a61af66fc99e Initial load
duke
parents:
diff changeset
172
a61af66fc99e Initial load
duke
parents:
diff changeset
173 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
174 analysis.run();
a61af66fc99e Initial load
duke
parents:
diff changeset
175 } catch (Exception e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
176 // e.printStackTrace();
a61af66fc99e Initial load
duke
parents:
diff changeset
177 if (verbose)
a61af66fc99e Initial load
duke
parents:
diff changeset
178 err.println("liveness analysis may be inaccurate ...");
a61af66fc99e Initial load
duke
parents:
diff changeset
179 }
a61af66fc99e Initial load
duke
parents:
diff changeset
180 ReversePtrs liveness = VM.getVM().getRevPtrs();
a61af66fc99e Initial load
duke
parents:
diff changeset
181
a61af66fc99e Initial load
duke
parents:
diff changeset
182 out.println("class_loader\tclasses\tbytes\tparent_loader\talive?\ttype");
a61af66fc99e Initial load
duke
parents:
diff changeset
183 out.println();
a61af66fc99e Initial load
duke
parents:
diff changeset
184
a61af66fc99e Initial load
duke
parents:
diff changeset
185 long numClassLoaders = 1L;
a61af66fc99e Initial load
duke
parents:
diff changeset
186 long totalNumClasses = bootstrapLoaderData.numClasses;
a61af66fc99e Initial load
duke
parents:
diff changeset
187 long totalClassSize = bootstrapLoaderData.classSize;
a61af66fc99e Initial load
duke
parents:
diff changeset
188 long numAliveLoaders = 1L;
a61af66fc99e Initial load
duke
parents:
diff changeset
189 long numDeadLoaders = 0L;
a61af66fc99e Initial load
duke
parents:
diff changeset
190
a61af66fc99e Initial load
duke
parents:
diff changeset
191 // print bootstrap loader details
a61af66fc99e Initial load
duke
parents:
diff changeset
192 out.print("<bootstrap>");
a61af66fc99e Initial load
duke
parents:
diff changeset
193 out.print('\t');
a61af66fc99e Initial load
duke
parents:
diff changeset
194 out.print(bootstrapLoaderData.numClasses);
a61af66fc99e Initial load
duke
parents:
diff changeset
195 out.print('\t');
a61af66fc99e Initial load
duke
parents:
diff changeset
196 out.print(bootstrapLoaderData.classSize);
a61af66fc99e Initial load
duke
parents:
diff changeset
197 out.print('\t');
a61af66fc99e Initial load
duke
parents:
diff changeset
198 out.print(" null ");
a61af66fc99e Initial load
duke
parents:
diff changeset
199 out.print('\t');
a61af66fc99e Initial load
duke
parents:
diff changeset
200 // bootstrap loader is always alive
a61af66fc99e Initial load
duke
parents:
diff changeset
201 out.print("live");
a61af66fc99e Initial load
duke
parents:
diff changeset
202 out.print('\t');
a61af66fc99e Initial load
duke
parents:
diff changeset
203 out.println("<internal>");
a61af66fc99e Initial load
duke
parents:
diff changeset
204
a61af66fc99e Initial load
duke
parents:
diff changeset
205 for (Iterator keyItr = loaderMap.keySet().iterator(); keyItr.hasNext();) {
a61af66fc99e Initial load
duke
parents:
diff changeset
206 Oop loader = (Oop) keyItr.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
207 LoaderData data = (LoaderData) loaderMap.get(loader);
a61af66fc99e Initial load
duke
parents:
diff changeset
208 numClassLoaders ++;
a61af66fc99e Initial load
duke
parents:
diff changeset
209 totalNumClasses += data.numClasses;
a61af66fc99e Initial load
duke
parents:
diff changeset
210 totalClassSize += data.classSize;
a61af66fc99e Initial load
duke
parents:
diff changeset
211
a61af66fc99e Initial load
duke
parents:
diff changeset
212 out.print(loader.getHandle());
a61af66fc99e Initial load
duke
parents:
diff changeset
213 out.print('\t');
a61af66fc99e Initial load
duke
parents:
diff changeset
214 out.print(data.numClasses);
a61af66fc99e Initial load
duke
parents:
diff changeset
215 out.print('\t');
a61af66fc99e Initial load
duke
parents:
diff changeset
216 out.print(data.classSize);
a61af66fc99e Initial load
duke
parents:
diff changeset
217 out.print('\t');
a61af66fc99e Initial load
duke
parents:
diff changeset
218
a61af66fc99e Initial load
duke
parents:
diff changeset
219 class ParentFinder extends DefaultOopVisitor {
a61af66fc99e Initial load
duke
parents:
diff changeset
220 public void doOop(OopField field, boolean isVMField) {
a61af66fc99e Initial load
duke
parents:
diff changeset
221 if (field.getID().getName().equals("parent")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
222 parent = field.getValue(getObj());
a61af66fc99e Initial load
duke
parents:
diff changeset
223 }
a61af66fc99e Initial load
duke
parents:
diff changeset
224 }
a61af66fc99e Initial load
duke
parents:
diff changeset
225 private Oop parent = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
226 public Oop getParent() { return parent; }
a61af66fc99e Initial load
duke
parents:
diff changeset
227 }
a61af66fc99e Initial load
duke
parents:
diff changeset
228
a61af66fc99e Initial load
duke
parents:
diff changeset
229 ParentFinder parentFinder = new ParentFinder();
a61af66fc99e Initial load
duke
parents:
diff changeset
230 loader.iterate(parentFinder, false);
a61af66fc99e Initial load
duke
parents:
diff changeset
231 Oop parent = parentFinder.getParent();
a61af66fc99e Initial load
duke
parents:
diff changeset
232 out.print((parent != null)? parent.getHandle().toString() : " null ");
a61af66fc99e Initial load
duke
parents:
diff changeset
233 out.print('\t');
a61af66fc99e Initial load
duke
parents:
diff changeset
234 boolean alive = (liveness != null) ? (liveness.get(loader) != null) : true;
a61af66fc99e Initial load
duke
parents:
diff changeset
235 out.print(alive? "live" : "dead");
a61af66fc99e Initial load
duke
parents:
diff changeset
236 if (alive) numAliveLoaders++; else numDeadLoaders++;
a61af66fc99e Initial load
duke
parents:
diff changeset
237 out.print('\t');
a61af66fc99e Initial load
duke
parents:
diff changeset
238 Klass loaderKlass = loader.getKlass();
a61af66fc99e Initial load
duke
parents:
diff changeset
239 if (loaderKlass != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
240 out.print(loaderKlass.getName().asString());
a61af66fc99e Initial load
duke
parents:
diff changeset
241 out.print('@');
a61af66fc99e Initial load
duke
parents:
diff changeset
242 out.print(loader.getKlass().getHandle());
a61af66fc99e Initial load
duke
parents:
diff changeset
243 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
244 out.print(" null! ");
a61af66fc99e Initial load
duke
parents:
diff changeset
245 }
a61af66fc99e Initial load
duke
parents:
diff changeset
246 out.println();
a61af66fc99e Initial load
duke
parents:
diff changeset
247 }
a61af66fc99e Initial load
duke
parents:
diff changeset
248
a61af66fc99e Initial load
duke
parents:
diff changeset
249 out.println();
a61af66fc99e Initial load
duke
parents:
diff changeset
250 // summary line
a61af66fc99e Initial load
duke
parents:
diff changeset
251 out.print("total = ");
a61af66fc99e Initial load
duke
parents:
diff changeset
252 out.print(numClassLoaders);
a61af66fc99e Initial load
duke
parents:
diff changeset
253 out.print('\t');
a61af66fc99e Initial load
duke
parents:
diff changeset
254 out.print(totalNumClasses);
a61af66fc99e Initial load
duke
parents:
diff changeset
255 out.print('\t');
a61af66fc99e Initial load
duke
parents:
diff changeset
256 out.print(totalClassSize);
a61af66fc99e Initial load
duke
parents:
diff changeset
257 out.print('\t');
a61af66fc99e Initial load
duke
parents:
diff changeset
258 out.print(" N/A ");
a61af66fc99e Initial load
duke
parents:
diff changeset
259 out.print('\t');
a61af66fc99e Initial load
duke
parents:
diff changeset
260 out.print("alive=");
a61af66fc99e Initial load
duke
parents:
diff changeset
261 out.print(numAliveLoaders);
a61af66fc99e Initial load
duke
parents:
diff changeset
262 out.print(", dead=");
a61af66fc99e Initial load
duke
parents:
diff changeset
263 out.print(numDeadLoaders);
a61af66fc99e Initial load
duke
parents:
diff changeset
264 out.print('\t');
a61af66fc99e Initial load
duke
parents:
diff changeset
265 out.print(" N/A ");
a61af66fc99e Initial load
duke
parents:
diff changeset
266 out.println();
a61af66fc99e Initial load
duke
parents:
diff changeset
267 }
a61af66fc99e Initial load
duke
parents:
diff changeset
268
261
7f601f7c9b48 6731726: jmap -permstat reports only 50-60% of permgen memory usage.
martin
parents: 0
diff changeset
269 private static long objectSize(Oop oop) {
7f601f7c9b48 6731726: jmap -permstat reports only 50-60% of permgen memory usage.
martin
parents: 0
diff changeset
270 return oop == null ? 0L : oop.getObjectSize();
7f601f7c9b48 6731726: jmap -permstat reports only 50-60% of permgen memory usage.
martin
parents: 0
diff changeset
271 }
7f601f7c9b48 6731726: jmap -permstat reports only 50-60% of permgen memory usage.
martin
parents: 0
diff changeset
272
7f601f7c9b48 6731726: jmap -permstat reports only 50-60% of permgen memory usage.
martin
parents: 0
diff changeset
273 // Don't count the shared empty arrays
7f601f7c9b48 6731726: jmap -permstat reports only 50-60% of permgen memory usage.
martin
parents: 0
diff changeset
274 private static long arraySize(Array arr) {
7f601f7c9b48 6731726: jmap -permstat reports only 50-60% of permgen memory usage.
martin
parents: 0
diff changeset
275 return arr.getLength() != 0L ? arr.getObjectSize() : 0L;
7f601f7c9b48 6731726: jmap -permstat reports only 50-60% of permgen memory usage.
martin
parents: 0
diff changeset
276 }
7f601f7c9b48 6731726: jmap -permstat reports only 50-60% of permgen memory usage.
martin
parents: 0
diff changeset
277
0
a61af66fc99e Initial load
duke
parents:
diff changeset
278 private long computeSize(InstanceKlass k) {
a61af66fc99e Initial load
duke
parents:
diff changeset
279 long size = 0L;
261
7f601f7c9b48 6731726: jmap -permstat reports only 50-60% of permgen memory usage.
martin
parents: 0
diff changeset
280 // the InstanceKlass object itself
0
a61af66fc99e Initial load
duke
parents:
diff changeset
281 size += k.getObjectSize();
a61af66fc99e Initial load
duke
parents:
diff changeset
282
261
7f601f7c9b48 6731726: jmap -permstat reports only 50-60% of permgen memory usage.
martin
parents: 0
diff changeset
283 // Constant pool
7f601f7c9b48 6731726: jmap -permstat reports only 50-60% of permgen memory usage.
martin
parents: 0
diff changeset
284 ConstantPool cp = k.getConstants();
7f601f7c9b48 6731726: jmap -permstat reports only 50-60% of permgen memory usage.
martin
parents: 0
diff changeset
285 size += cp.getObjectSize();
7f601f7c9b48 6731726: jmap -permstat reports only 50-60% of permgen memory usage.
martin
parents: 0
diff changeset
286 size += objectSize(cp.getCache());
7f601f7c9b48 6731726: jmap -permstat reports only 50-60% of permgen memory usage.
martin
parents: 0
diff changeset
287 size += objectSize(cp.getTags());
7f601f7c9b48 6731726: jmap -permstat reports only 50-60% of permgen memory usage.
martin
parents: 0
diff changeset
288
7f601f7c9b48 6731726: jmap -permstat reports only 50-60% of permgen memory usage.
martin
parents: 0
diff changeset
289 // Interfaces
7f601f7c9b48 6731726: jmap -permstat reports only 50-60% of permgen memory usage.
martin
parents: 0
diff changeset
290 size += arraySize(k.getLocalInterfaces());
7f601f7c9b48 6731726: jmap -permstat reports only 50-60% of permgen memory usage.
martin
parents: 0
diff changeset
291 size += arraySize(k.getTransitiveInterfaces());
7f601f7c9b48 6731726: jmap -permstat reports only 50-60% of permgen memory usage.
martin
parents: 0
diff changeset
292
7f601f7c9b48 6731726: jmap -permstat reports only 50-60% of permgen memory usage.
martin
parents: 0
diff changeset
293 // Inner classes
7f601f7c9b48 6731726: jmap -permstat reports only 50-60% of permgen memory usage.
martin
parents: 0
diff changeset
294 size += objectSize(k.getInnerClasses());
0
a61af66fc99e Initial load
duke
parents:
diff changeset
295
261
7f601f7c9b48 6731726: jmap -permstat reports only 50-60% of permgen memory usage.
martin
parents: 0
diff changeset
296 // Fields
7f601f7c9b48 6731726: jmap -permstat reports only 50-60% of permgen memory usage.
martin
parents: 0
diff changeset
297 size += objectSize(k.getFields());
7f601f7c9b48 6731726: jmap -permstat reports only 50-60% of permgen memory usage.
martin
parents: 0
diff changeset
298
7f601f7c9b48 6731726: jmap -permstat reports only 50-60% of permgen memory usage.
martin
parents: 0
diff changeset
299 // Methods
7f601f7c9b48 6731726: jmap -permstat reports only 50-60% of permgen memory usage.
martin
parents: 0
diff changeset
300 ObjArray methods = k.getMethods();
7f601f7c9b48 6731726: jmap -permstat reports only 50-60% of permgen memory usage.
martin
parents: 0
diff changeset
301 int nmethods = (int) methods.getLength();
7f601f7c9b48 6731726: jmap -permstat reports only 50-60% of permgen memory usage.
martin
parents: 0
diff changeset
302 if (nmethods != 0L) {
7f601f7c9b48 6731726: jmap -permstat reports only 50-60% of permgen memory usage.
martin
parents: 0
diff changeset
303 size += methods.getObjectSize();
7f601f7c9b48 6731726: jmap -permstat reports only 50-60% of permgen memory usage.
martin
parents: 0
diff changeset
304 for (int i = 0; i < nmethods; ++i) {
7f601f7c9b48 6731726: jmap -permstat reports only 50-60% of permgen memory usage.
martin
parents: 0
diff changeset
305 Method m = (Method) methods.getObjAt(i);
7f601f7c9b48 6731726: jmap -permstat reports only 50-60% of permgen memory usage.
martin
parents: 0
diff changeset
306 size += m.getObjectSize();
7f601f7c9b48 6731726: jmap -permstat reports only 50-60% of permgen memory usage.
martin
parents: 0
diff changeset
307 size += objectSize(m.getConstMethod());
7f601f7c9b48 6731726: jmap -permstat reports only 50-60% of permgen memory usage.
martin
parents: 0
diff changeset
308 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
309 }
a61af66fc99e Initial load
duke
parents:
diff changeset
310
261
7f601f7c9b48 6731726: jmap -permstat reports only 50-60% of permgen memory usage.
martin
parents: 0
diff changeset
311 // MethodOrdering - an int array that records the original
7f601f7c9b48 6731726: jmap -permstat reports only 50-60% of permgen memory usage.
martin
parents: 0
diff changeset
312 // ordering of methods in the class file
7f601f7c9b48 6731726: jmap -permstat reports only 50-60% of permgen memory usage.
martin
parents: 0
diff changeset
313 size += arraySize(k.getMethodOrdering());
0
a61af66fc99e Initial load
duke
parents:
diff changeset
314
a61af66fc99e Initial load
duke
parents:
diff changeset
315 return size;
a61af66fc99e Initial load
duke
parents:
diff changeset
316 }
a61af66fc99e Initial load
duke
parents:
diff changeset
317 }