author | coleenp |
Sun, 13 Apr 2008 17:43:42 -0400 | |
changeset 360 | 21d113ecbf6a |
parent 1 | 489c9b5090e2 |
child 670 | ddf3e9583f2f |
permissions | -rw-r--r-- |
1 | 1 |
/* |
2 |
* Copyright 2000-2006 Sun Microsystems, Inc. All Rights Reserved. |
|
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 |
* |
|
19 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
20 |
* CA 95054 USA or visit www.sun.com if you need additional information or |
|
21 |
* have any questions. |
|
22 |
* |
|
23 |
*/ |
|
24 |
||
25 |
package sun.jvm.hotspot.oops; |
|
26 |
||
27 |
import java.io.*; |
|
28 |
import java.util.*; |
|
29 |
import sun.jvm.hotspot.memory.*; |
|
30 |
import sun.jvm.hotspot.runtime.*; |
|
31 |
||
32 |
public class ObjectHistogramElement { |
|
33 |
||
34 |
private Klass klass; |
|
35 |
private long count; // Number of instances of klass |
|
36 |
private long size; // Total size of all these instances |
|
37 |
||
38 |
public ObjectHistogramElement(Klass k) { |
|
39 |
klass = k; |
|
40 |
count = 0; |
|
41 |
size = 0; |
|
42 |
} |
|
43 |
||
44 |
public void updateWith(Oop obj) { |
|
45 |
count = count + 1; |
|
46 |
size = size + obj.getObjectSize(); |
|
47 |
} |
|
48 |
||
49 |
public int compare(ObjectHistogramElement other) { |
|
50 |
return (int) (other.size - size); |
|
51 |
} |
|
52 |
||
53 |
/** Klass for this ObjectHistogramElement */ |
|
54 |
public Klass getKlass() { |
|
55 |
return klass; |
|
56 |
} |
|
57 |
||
58 |
/** Number of instances of klass */ |
|
59 |
public long getCount() { |
|
60 |
return count; |
|
61 |
} |
|
62 |
||
63 |
/** Total size of all these instances */ |
|
64 |
public long getSize() { |
|
65 |
return size; |
|
66 |
} |
|
67 |
||
68 |
private String getInternalName(Klass k) { |
|
69 |
ByteArrayOutputStream bos = new ByteArrayOutputStream(); |
|
70 |
getKlass().printValueOn(new PrintStream(bos)); |
|
71 |
// '*' is used to denote VM internal klasses. |
|
72 |
return "* " + bos.toString(); |
|
73 |
} |
|
74 |
||
75 |
/** Human readable description **/ |
|
76 |
public String getDescription() { |
|
77 |
Klass k = getKlass(); |
|
78 |
if (k instanceof InstanceKlass) { |
|
79 |
return k.getName().asString().replace('/', '.'); |
|
80 |
} else if (k instanceof ArrayKlass) { |
|
81 |
ArrayKlass ak = (ArrayKlass) k; |
|
82 |
if (k instanceof TypeArrayKlass) { |
|
83 |
TypeArrayKlass tak = (TypeArrayKlass) ak; |
|
84 |
return tak.getElementTypeName() + "[]"; |
|
85 |
} else if (k instanceof ObjArrayKlass) { |
|
86 |
ObjArrayKlass oak = (ObjArrayKlass) ak; |
|
87 |
// See whether it's a "system objArray" |
|
88 |
if (oak.equals(VM.getVM().getUniverse().systemObjArrayKlassObj())) { |
|
89 |
return "* System ObjArray"; |
|
90 |
} |
|
91 |
Klass bottom = oak.getBottomKlass(); |
|
92 |
int dim = (int) oak.getDimension(); |
|
93 |
StringBuffer buf = new StringBuffer(); |
|
94 |
if (bottom instanceof TypeArrayKlass) { |
|
95 |
buf.append(((TypeArrayKlass) bottom).getElementTypeName()); |
|
96 |
} else if (bottom instanceof InstanceKlass) { |
|
97 |
buf.append(bottom.getName().asString().replace('/', '.')); |
|
98 |
} else { |
|
99 |
throw new RuntimeException("should not reach here"); |
|
100 |
} |
|
101 |
for (int i=0; i < dim; i++) { |
|
102 |
buf.append("[]"); |
|
103 |
} |
|
104 |
return buf.toString(); |
|
105 |
} |
|
106 |
} |
|
107 |
return getInternalName(k); |
|
108 |
} |
|
109 |
||
110 |
public static void titleOn(PrintStream tty) { |
|
111 |
tty.println("Object Histogram:"); |
|
112 |
tty.println(); |
|
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
113 |
tty.println("num " + "\t" + " #instances" + "\t" + "#bytes" + "\t" + "Class description"); |
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
114 |
tty.println("--------------------------------------------------------------------------"); |
1 | 115 |
} |
116 |
||
117 |
public void printOn(PrintStream tty) { |
|
360
21d113ecbf6a
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
1
diff
changeset
|
118 |
tty.print(count + "\t" + size + "\t"); |
1 | 119 |
tty.print(getDescription()); |
120 |
tty.println(); |
|
121 |
} |
|
122 |
} |