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