annotate src/share/vm/memory/heapInspection.hpp @ 10265:92ef81e2f571

8003557: NPG: Klass* const k should be const Klass* k. Summary: With NPG, const KlassOop klass which is in fact a definition converted to Klass* const, which is not the original intention. The right usage is converting them to const Klass*. Reviewed-by: coleenp, kvn Contributed-by: yumin.qi@oracle.com
author minqi
date Fri, 10 May 2013 08:27:30 -0700
parents 927a311d00f9
children f2110083203d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
7956
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
2 * Copyright (c) 2002, 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: 615
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 615
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: 615
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
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
25 #ifndef SHARE_VM_MEMORY_HEAPINSPECTION_HPP
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
26 #define SHARE_VM_MEMORY_HEAPINSPECTION_HPP
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
27
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
28 #include "memory/allocation.inline.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
29 #include "oops/oop.inline.hpp"
7956
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
30 #include "oops/annotations.hpp"
8001
db9981fd3124 8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
jprovino
parents: 6854
diff changeset
31 #include "utilities/macros.hpp"
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
32
6854
fb19af007ffc 7189254: Change makefiles for more flexibility to override defaults
jprovino
parents: 6725
diff changeset
33 #if INCLUDE_SERVICES
0
a61af66fc99e Initial load
duke
parents:
diff changeset
34
a61af66fc99e Initial load
duke
parents:
diff changeset
35
a61af66fc99e Initial load
duke
parents:
diff changeset
36 // HeapInspection
a61af66fc99e Initial load
duke
parents:
diff changeset
37
a61af66fc99e Initial load
duke
parents:
diff changeset
38 // KlassInfoTable is a bucket hash table that
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
39 // maps Klass*s to extra information:
0
a61af66fc99e Initial load
duke
parents:
diff changeset
40 // instance count and instance word size.
a61af66fc99e Initial load
duke
parents:
diff changeset
41 //
a61af66fc99e Initial load
duke
parents:
diff changeset
42 // A KlassInfoBucket is the head of a link list
a61af66fc99e Initial load
duke
parents:
diff changeset
43 // of KlassInfoEntry's
a61af66fc99e Initial load
duke
parents:
diff changeset
44 //
a61af66fc99e Initial load
duke
parents:
diff changeset
45 // KlassInfoHisto is a growable array of pointers
a61af66fc99e Initial load
duke
parents:
diff changeset
46 // to KlassInfoEntry's and is used to sort
a61af66fc99e Initial load
duke
parents:
diff changeset
47 // the entries.
a61af66fc99e Initial load
duke
parents:
diff changeset
48
7956
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
49 #define HEAP_INSPECTION_COLUMNS_DO(f) \
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
50 f(inst_size, InstSize, \
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
51 "Size of each object instance of the Java class") \
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
52 f(inst_count, InstCount, \
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
53 "Number of object instances of the Java class") \
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
54 f(inst_bytes, InstBytes, \
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
55 "This is usually (InstSize * InstNum). The only exception is " \
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
56 "java.lang.Class, whose InstBytes also includes the slots " \
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
57 "used to store static fields. InstBytes is not counted in " \
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
58 "ROAll, RWAll or Total") \
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
59 f(mirror_bytes, Mirror, \
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
60 "Size of the Klass::java_mirror() object") \
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
61 f(klass_bytes, KlassBytes, \
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
62 "Size of the InstanceKlass or ArrayKlass for this class. " \
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
63 "Note that this includes VTab, ITab, OopMap") \
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
64 f(secondary_supers_bytes, K_secondary_supers, \
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
65 "Number of bytes used by the Klass::secondary_supers() array") \
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
66 f(vtab_bytes, VTab, \
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
67 "Size of the embedded vtable in InstanceKlass") \
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
68 f(itab_bytes, ITab, \
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
69 "Size of the embedded itable in InstanceKlass") \
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
70 f(nonstatic_oopmap_bytes, OopMap, \
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
71 "Size of the embedded nonstatic_oop_map in InstanceKlass") \
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
72 f(methods_array_bytes, IK_methods, \
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
73 "Number of bytes used by the InstanceKlass::methods() array") \
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
74 f(method_ordering_bytes, IK_method_ordering, \
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
75 "Number of bytes used by the InstanceKlass::method_ordering() array") \
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
76 f(local_interfaces_bytes, IK_local_interfaces, \
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
77 "Number of bytes used by the InstanceKlass::local_interfaces() array") \
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
78 f(transitive_interfaces_bytes, IK_transitive_interfaces, \
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
79 "Number of bytes used by the InstanceKlass::transitive_interfaces() array") \
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
80 f(fields_bytes, IK_fields, \
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
81 "Number of bytes used by the InstanceKlass::fields() array") \
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
82 f(inner_classes_bytes, IK_inner_classes, \
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
83 "Number of bytes used by the InstanceKlass::inner_classes() array") \
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
84 f(signers_bytes, IK_signers, \
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
85 "Number of bytes used by the InstanceKlass::singers() array") \
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
86 f(class_annotations_bytes, class_annotations, \
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
87 "Size of class annotations") \
8031
927a311d00f9 8007320: NPG: move method annotations
coleenp
parents: 8003
diff changeset
88 f(class_type_annotations_bytes, class_type_annotations, \
927a311d00f9 8007320: NPG: move method annotations
coleenp
parents: 8003
diff changeset
89 "Size of class type annotations") \
7956
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
90 f(fields_annotations_bytes, fields_annotations, \
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
91 "Size of field annotations") \
8031
927a311d00f9 8007320: NPG: move method annotations
coleenp
parents: 8003
diff changeset
92 f(fields_type_annotations_bytes, fields_type_annotations, \
927a311d00f9 8007320: NPG: move method annotations
coleenp
parents: 8003
diff changeset
93 "Size of field type annotations") \
7956
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
94 f(methods_annotations_bytes, methods_annotations, \
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
95 "Size of method annotations") \
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
96 f(methods_parameter_annotations_bytes, methods_parameter_annotations, \
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
97 "Size of method parameter annotations") \
8031
927a311d00f9 8007320: NPG: move method annotations
coleenp
parents: 8003
diff changeset
98 f(methods_type_annotations_bytes, methods_type_annotations, \
927a311d00f9 8007320: NPG: move method annotations
coleenp
parents: 8003
diff changeset
99 "Size of methods type annotations") \
7956
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
100 f(methods_default_annotations_bytes, methods_default_annotations, \
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
101 "Size of methods default annotations") \
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
102 f(annotations_bytes, annotations, \
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
103 "Size of all annotations") \
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
104 f(cp_bytes, Cp, \
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
105 "Size of InstanceKlass::constants()") \
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
106 f(cp_tags_bytes, CpTags, \
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
107 "Size of InstanceKlass::constants()->tags()") \
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
108 f(cp_cache_bytes, CpCache, \
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
109 "Size of InstanceKlass::constants()->cache()") \
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
110 f(cp_operands_bytes, CpOperands, \
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
111 "Size of InstanceKlass::constants()->operands()") \
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
112 f(cp_refmap_bytes, CpRefMap, \
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
113 "Size of InstanceKlass::constants()->reference_map()") \
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
114 f(cp_all_bytes, CpAll, \
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
115 "Sum of Cp + CpTags + CpCache + CpOperands + CpRefMap") \
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
116 f(method_count, MethodCount, \
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
117 "Number of methods in this class") \
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
118 f(method_bytes, MethodBytes, \
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
119 "Size of the Method object") \
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
120 f(const_method_bytes, ConstMethod, \
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
121 "Size of the ConstMethod object") \
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
122 f(method_data_bytes, MethodData, \
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
123 "Size of the MethodData object") \
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
124 f(stackmap_bytes, StackMap, \
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
125 "Size of the stackmap_data") \
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
126 f(bytecode_bytes, Bytecodes, \
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
127 "Of the MethodBytes column, how much are the space taken up by bytecodes") \
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
128 f(method_all_bytes, MethodAll, \
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
129 "Sum of MethodBytes + Constmethod + Stackmap + Methoddata") \
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
130 f(ro_bytes, ROAll, \
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
131 "Size of all class meta data that could (potentially) be placed " \
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
132 "in read-only memory. (This could change with CDS design)") \
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
133 f(rw_bytes, RWAll, \
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
134 "Size of all class meta data that must be placed in read/write " \
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
135 "memory. (This could change with CDS design) ") \
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
136 f(total_bytes, Total, \
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
137 "ROAll + RWAll. Note that this does NOT include InstBytes.")
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
138
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
139 // Size statistics for a Klass - filled in by Klass::collect_statistics()
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
140 class KlassSizeStats {
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
141 public:
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
142 #define COUNT_KLASS_SIZE_STATS_FIELD(field, name, help) _index_ ## field,
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
143 #define DECLARE_KLASS_SIZE_STATS_FIELD(field, name, help) julong _ ## field;
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
144
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
145 enum {
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
146 HEAP_INSPECTION_COLUMNS_DO(COUNT_KLASS_SIZE_STATS_FIELD)
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
147 _num_columns
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
148 };
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
149
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
150 HEAP_INSPECTION_COLUMNS_DO(DECLARE_KLASS_SIZE_STATS_FIELD)
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
151
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
152 static int count(oop x) {
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
153 return (HeapWordSize * ((x) ? (x)->size() : 0));
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
154 }
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
155
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
156 static int count_array(objArrayOop x) {
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
157 return (HeapWordSize * ((x) ? (x)->size() : 0));
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
158 }
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
159
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
160 template <class T> static int count(T* x) {
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
161 return (HeapWordSize * ((x) ? (x)->size() : 0));
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
162 }
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
163
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
164 template <class T> static int count_array(T* x) {
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
165 if (x == NULL) {
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
166 return 0;
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
167 }
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
168 if (x->length() == 0) {
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
169 // This is a shared array, e.g., Universe::the_empty_int_array(). Don't
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
170 // count it to avoid double-counting.
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
171 return 0;
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
172 }
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
173 return HeapWordSize * x->size();
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
174 }
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
175 };
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
176
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
177
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
178
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
179
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
180 class KlassInfoEntry: public CHeapObj<mtInternal> {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
181 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
182 KlassInfoEntry* _next;
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
183 Klass* _klass;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
184 long _instance_count;
a61af66fc99e Initial load
duke
parents:
diff changeset
185 size_t _instance_words;
7956
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
186 long _index;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
187
a61af66fc99e Initial load
duke
parents:
diff changeset
188 public:
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
189 KlassInfoEntry(Klass* k, KlassInfoEntry* next) :
7956
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
190 _klass(k), _instance_count(0), _instance_words(0), _next(next), _index(-1)
0
a61af66fc99e Initial load
duke
parents:
diff changeset
191 {}
10265
92ef81e2f571 8003557: NPG: Klass* const k should be const Klass* k.
minqi
parents: 8031
diff changeset
192 KlassInfoEntry* next() const { return _next; }
92ef81e2f571 8003557: NPG: Klass* const k should be const Klass* k.
minqi
parents: 8031
diff changeset
193 bool is_equal(const Klass* k) { return k == _klass; }
92ef81e2f571 8003557: NPG: Klass* const k should be const Klass* k.
minqi
parents: 8031
diff changeset
194 Klass* klass() const { return _klass; }
92ef81e2f571 8003557: NPG: Klass* const k should be const Klass* k.
minqi
parents: 8031
diff changeset
195 long count() const { return _instance_count; }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
196 void set_count(long ct) { _instance_count = ct; }
10265
92ef81e2f571 8003557: NPG: Klass* const k should be const Klass* k.
minqi
parents: 8031
diff changeset
197 size_t words() const { return _instance_words; }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
198 void set_words(size_t wds) { _instance_words = wds; }
7956
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
199 void set_index(long index) { _index = index; }
10265
92ef81e2f571 8003557: NPG: Klass* const k should be const Klass* k.
minqi
parents: 8031
diff changeset
200 long index() const { return _index; }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
201 int compare(KlassInfoEntry* e1, KlassInfoEntry* e2);
a61af66fc99e Initial load
duke
parents:
diff changeset
202 void print_on(outputStream* st) const;
7956
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
203 const char* name() const;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
204 };
a61af66fc99e Initial load
duke
parents:
diff changeset
205
a61af66fc99e Initial load
duke
parents:
diff changeset
206 class KlassInfoClosure: public StackObj {
a61af66fc99e Initial load
duke
parents:
diff changeset
207 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
208 // Called for each KlassInfoEntry.
a61af66fc99e Initial load
duke
parents:
diff changeset
209 virtual void do_cinfo(KlassInfoEntry* cie) = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
210 };
a61af66fc99e Initial load
duke
parents:
diff changeset
211
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
212 class KlassInfoBucket: public CHeapObj<mtInternal> {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
213 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
214 KlassInfoEntry* _list;
a61af66fc99e Initial load
duke
parents:
diff changeset
215 KlassInfoEntry* list() { return _list; }
a61af66fc99e Initial load
duke
parents:
diff changeset
216 void set_list(KlassInfoEntry* l) { _list = l; }
a61af66fc99e Initial load
duke
parents:
diff changeset
217 public:
10265
92ef81e2f571 8003557: NPG: Klass* const k should be const Klass* k.
minqi
parents: 8031
diff changeset
218 KlassInfoEntry* lookup(Klass* k);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
219 void initialize() { _list = NULL; }
a61af66fc99e Initial load
duke
parents:
diff changeset
220 void empty();
a61af66fc99e Initial load
duke
parents:
diff changeset
221 void iterate(KlassInfoClosure* cic);
a61af66fc99e Initial load
duke
parents:
diff changeset
222 };
a61af66fc99e Initial load
duke
parents:
diff changeset
223
a61af66fc99e Initial load
duke
parents:
diff changeset
224 class KlassInfoTable: public StackObj {
a61af66fc99e Initial load
duke
parents:
diff changeset
225 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
226 int _size;
a61af66fc99e Initial load
duke
parents:
diff changeset
227
a61af66fc99e Initial load
duke
parents:
diff changeset
228 // An aligned reference address (typically the least
a61af66fc99e Initial load
duke
parents:
diff changeset
229 // address in the perm gen) used for hashing klass
a61af66fc99e Initial load
duke
parents:
diff changeset
230 // objects.
a61af66fc99e Initial load
duke
parents:
diff changeset
231 HeapWord* _ref;
a61af66fc99e Initial load
duke
parents:
diff changeset
232
a61af66fc99e Initial load
duke
parents:
diff changeset
233 KlassInfoBucket* _buckets;
10265
92ef81e2f571 8003557: NPG: Klass* const k should be const Klass* k.
minqi
parents: 8031
diff changeset
234 uint hash(const Klass* p);
92ef81e2f571 8003557: NPG: Klass* const k should be const Klass* k.
minqi
parents: 8031
diff changeset
235 KlassInfoEntry* lookup(Klass* k); // allocates if not found!
7956
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
236
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
237 class AllClassesFinder : public KlassClosure {
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
238 KlassInfoTable *_table;
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
239 public:
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
240 AllClassesFinder(KlassInfoTable* table) : _table(table) {}
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
241 virtual void do_klass(Klass* k);
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
242 };
0
a61af66fc99e Initial load
duke
parents:
diff changeset
243
a61af66fc99e Initial load
duke
parents:
diff changeset
244 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
245 // Table size
a61af66fc99e Initial load
duke
parents:
diff changeset
246 enum {
a61af66fc99e Initial load
duke
parents:
diff changeset
247 cit_size = 20011
a61af66fc99e Initial load
duke
parents:
diff changeset
248 };
7956
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
249 KlassInfoTable(int size, HeapWord* ref, bool need_class_stats);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
250 ~KlassInfoTable();
11
3c1dbcaaab1d 6621728: Heap inspection should not crash in the face of C-heap exhaustion
ysr
parents: 0
diff changeset
251 bool record_instance(const oop obj);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
252 void iterate(KlassInfoClosure* cic);
11
3c1dbcaaab1d 6621728: Heap inspection should not crash in the face of C-heap exhaustion
ysr
parents: 0
diff changeset
253 bool allocation_failed() { return _buckets == NULL; }
7956
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
254
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
255 friend class KlassInfoHisto;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
256 };
a61af66fc99e Initial load
duke
parents:
diff changeset
257
a61af66fc99e Initial load
duke
parents:
diff changeset
258 class KlassInfoHisto : public StackObj {
a61af66fc99e Initial load
duke
parents:
diff changeset
259 private:
7956
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
260 KlassInfoTable *_cit;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
261 GrowableArray<KlassInfoEntry*>* _elements;
a61af66fc99e Initial load
duke
parents:
diff changeset
262 GrowableArray<KlassInfoEntry*>* elements() const { return _elements; }
a61af66fc99e Initial load
duke
parents:
diff changeset
263 const char* _title;
a61af66fc99e Initial load
duke
parents:
diff changeset
264 const char* title() const { return _title; }
a61af66fc99e Initial load
duke
parents:
diff changeset
265 static int sort_helper(KlassInfoEntry** e1, KlassInfoEntry** e2);
a61af66fc99e Initial load
duke
parents:
diff changeset
266 void print_elements(outputStream* st) const;
7956
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
267 void print_class_stats(outputStream* st, bool csv_format, const char *columns);
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
268 julong annotations_bytes(Array<AnnotationArray*>* p) const;
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
269 const char *_selected_columns;
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
270 bool is_selected(const char *col_name);
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
271 void print_title(outputStream* st, bool csv_format,
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
272 bool selected_columns_table[], int width_table[],
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
273 const char *name_table[]);
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
274
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
275 template <class T> static int count_bytes(T* x) {
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
276 return (HeapWordSize * ((x) ? (x)->size() : 0));
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
277 }
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
278
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
279 template <class T> static int count_bytes_array(T* x) {
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
280 if (x == NULL) {
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
281 return 0;
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
282 }
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
283 if (x->length() == 0) {
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
284 // This is a shared array, e.g., Universe::the_empty_int_array(). Don't
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
285 // count it to avoid double-counting.
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
286 return 0;
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
287 }
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
288 return HeapWordSize * x->size();
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
289 }
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
290
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
291 // returns a format string to print a julong with the given width. E.g,
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
292 // printf(num_fmt(6), julong(10)) would print out the number 10 with 4
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
293 // leading spaces.
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
294 static void print_julong(outputStream* st, int width, julong n) {
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
295 int num_spaces = width - julong_width(n);
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
296 if (num_spaces > 0) {
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
297 st->print(str_fmt(num_spaces), "");
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
298 }
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
299 st->print(JULONG_FORMAT, n);
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
300 }
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
301
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
302 static char* perc_fmt(int width) {
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
303 static char buf[32];
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
304 jio_snprintf(buf, sizeof(buf), "%%%d.1f%%%%", width-1);
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
305 return buf;
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
306 }
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
307
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
308 static char* str_fmt(int width) {
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
309 static char buf[32];
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
310 jio_snprintf(buf, sizeof(buf), "%%%ds", width);
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
311 return buf;
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
312 }
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
313
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
314 static int julong_width(julong n) {
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
315 if (n == 0) {
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
316 return 1;
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
317 }
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
318 int w = 0;
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
319 while (n > 0) {
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
320 n /= 10;
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
321 w += 1;
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
322 }
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
323 return w;
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
324 }
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
325
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
326 static int col_width(julong n, const char *name) {
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
327 int w = julong_width(n);
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
328 int min = (int)(strlen(name));
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
329 if (w < min) {
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
330 w = min;
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
331 }
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
332 // add a leading space for separation.
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
333 return w + 1;
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
334 }
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
335
0
a61af66fc99e Initial load
duke
parents:
diff changeset
336 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
337 enum {
a61af66fc99e Initial load
duke
parents:
diff changeset
338 histo_initial_size = 1000
a61af66fc99e Initial load
duke
parents:
diff changeset
339 };
7956
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
340 KlassInfoHisto(KlassInfoTable* cit, const char* title,
0
a61af66fc99e Initial load
duke
parents:
diff changeset
341 int estimatedCount);
a61af66fc99e Initial load
duke
parents:
diff changeset
342 ~KlassInfoHisto();
a61af66fc99e Initial load
duke
parents:
diff changeset
343 void add(KlassInfoEntry* cie);
7956
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
344 void print_histo_on(outputStream* st, bool print_class_stats, bool csv_format, const char *columns);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
345 void sort();
a61af66fc99e Initial load
duke
parents:
diff changeset
346 };
a61af66fc99e Initial load
duke
parents:
diff changeset
347
6854
fb19af007ffc 7189254: Change makefiles for more flexibility to override defaults
jprovino
parents: 6725
diff changeset
348 #endif // INCLUDE_SERVICES
0
a61af66fc99e Initial load
duke
parents:
diff changeset
349
7956
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
350 class HeapInspection : public StackObj {
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
351 bool _csv_format; // "comma separated values" format for spreadsheet.
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
352 bool _print_help;
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
353 bool _print_class_stats;
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
354 const char* _columns;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
355 public:
7956
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
356 HeapInspection(bool csv_format, bool print_help,
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
357 bool print_class_stats, const char *columns) :
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
358 _csv_format(csv_format), _print_help(print_help),
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
359 _print_class_stats(print_class_stats), _columns(columns) {}
16fb9f942703 6479360: PrintClassHistogram improvements
acorn
parents: 6854
diff changeset
360 void heap_inspection(outputStream* st, bool need_prologue) NOT_SERVICES_RETURN;
6854
fb19af007ffc 7189254: Change makefiles for more flexibility to override defaults
jprovino
parents: 6725
diff changeset
361 static void find_instances_at_safepoint(Klass* k, GrowableArray<oop>* result) NOT_SERVICES_RETURN;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
362 };
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
363
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
364 #endif // SHARE_VM_MEMORY_HEAPINSPECTION_HPP