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