src/share/vm/memory/heapInspection.hpp

Thu, 21 Aug 2014 13:57:51 -0700

author
iklam
date
Thu, 21 Aug 2014 13:57:51 -0700
changeset 7089
6e0cb14ce59b
parent 6680
78bbf4d43a14
child 6876
710a3c8b516e
permissions
-rw-r--r--

8046070: Class Data Sharing clean up and refactoring
Summary: Cleaned up CDS to be more configurable, maintainable and extensible
Reviewed-by: dholmes, coleenp, acorn, mchung

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

mercurial