Mercurial > hg > truffle
annotate agent/src/share/classes/sun/jvm/hotspot/oops/ObjectHistogramElement.java @ 7587:4a916f2ce331
8003985: Support @Contended Annotation - JEP 142
Summary: HotSpot changes to support @Contended annotation.
Reviewed-by: coleenp, kvn, jrose
Contributed-by: Aleksey Shipilev <aleksey.shipilev@oracle.com>
author | jwilhelm |
---|---|
date | Mon, 14 Jan 2013 15:17:47 +0100 |
parents | da91efe96a93 |
children |
rev | line source |
---|---|
0 | 1 /* |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
1552
diff
changeset
|
2 * Copyright (c) 2000, 2012, 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 Klass bottom = oak.getBottomKlass(); | |
88 int dim = (int) oak.getDimension(); | |
89 StringBuffer buf = new StringBuffer(); | |
90 if (bottom instanceof TypeArrayKlass) { | |
91 buf.append(((TypeArrayKlass) bottom).getElementTypeName()); | |
92 } else if (bottom instanceof InstanceKlass) { | |
93 buf.append(bottom.getName().asString().replace('/', '.')); | |
94 } else { | |
95 throw new RuntimeException("should not reach here"); | |
96 } | |
97 for (int i=0; i < dim; i++) { | |
98 buf.append("[]"); | |
99 } | |
100 return buf.toString(); | |
101 } | |
102 } | |
103 return getInternalName(k); | |
104 } | |
105 | |
106 public static void titleOn(PrintStream tty) { | |
107 tty.println("Object Histogram:"); | |
108 tty.println(); | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
109 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
|
110 tty.println("--------------------------------------------------------------------------"); |
0 | 111 } |
112 | |
113 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
|
114 tty.print(count + "\t" + size + "\t"); |
0 | 115 tty.print(getDescription()); |
116 tty.println(); | |
117 } | |
118 } |