Mercurial > hg > graal-compiler
annotate agent/src/share/classes/sun/jvm/hotspot/oops/ObjectHistogramElement.java @ 2411:63997f575155
7031614: jmap -permstat fails with java.lang.InternalError in sun.jvm.hotspot.oops.OopField.getValue
Reviewed-by: kvn, dcubed
author | never |
---|---|
date | Wed, 30 Mar 2011 07:47:19 -0700 |
parents | c18cbe5936b8 |
children | da91efe96a93 |
rev | line source |
---|---|
0 | 1 /* |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
196
diff
changeset
|
2 * Copyright (c) 2000, 2008, 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:
196
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
196
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:
196
diff
changeset
|
21 * questions. |
0 | 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(); | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
113 tty.println("num " + "\t" + " #instances" + "\t" + "#bytes" + "\t" + "Class description"); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
114 tty.println("--------------------------------------------------------------------------"); |
0 | 115 } |
116 | |
117 public void printOn(PrintStream tty) { | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
118 tty.print(count + "\t" + size + "\t"); |
0 | 119 tty.print(getDescription()); |
120 tty.println(); | |
121 } | |
122 } |