src/share/vm/memory/heapInspection.hpp

Thu, 26 Sep 2013 10:25:02 -0400

author
hseigel
date
Thu, 26 Sep 2013 10:25:02 -0400
changeset 5784
190899198332
parent 5386
2cbc8f3011a0
child 5848
ac9cb1d5a202
permissions
-rw-r--r--

7195622: CheckUnhandledOops has limited usefulness now
Summary: Enable CHECK_UNHANDLED_OOPS in fastdebug builds across all supported platforms.
Reviewed-by: coleenp, hseigel, dholmes, stefank, twisti, ihse, rdurbin
Contributed-by: lois.foltan@oracle.com

duke@435 1 /*
acorn@4497 2 * Copyright (c) 2002, 2013, 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@4497 76 f(local_interfaces_bytes, IK_local_interfaces, \
acorn@4497 77 "Number of bytes used by the InstanceKlass::local_interfaces() array") \
acorn@4497 78 f(transitive_interfaces_bytes, IK_transitive_interfaces, \
acorn@4497 79 "Number of bytes used by the InstanceKlass::transitive_interfaces() array") \
acorn@4497 80 f(fields_bytes, IK_fields, \
acorn@4497 81 "Number of bytes used by the InstanceKlass::fields() array") \
acorn@4497 82 f(inner_classes_bytes, IK_inner_classes, \
acorn@4497 83 "Number of bytes used by the InstanceKlass::inner_classes() array") \
acorn@4497 84 f(signers_bytes, IK_signers, \
acorn@4497 85 "Number of bytes used by the InstanceKlass::singers() array") \
acorn@4497 86 f(class_annotations_bytes, class_annotations, \
acorn@4497 87 "Size of class annotations") \
coleenp@4572 88 f(class_type_annotations_bytes, class_type_annotations, \
coleenp@4572 89 "Size of class type annotations") \
acorn@4497 90 f(fields_annotations_bytes, fields_annotations, \
acorn@4497 91 "Size of field annotations") \
coleenp@4572 92 f(fields_type_annotations_bytes, fields_type_annotations, \
coleenp@4572 93 "Size of field type annotations") \
acorn@4497 94 f(methods_annotations_bytes, methods_annotations, \
acorn@4497 95 "Size of method annotations") \
acorn@4497 96 f(methods_parameter_annotations_bytes, methods_parameter_annotations, \
acorn@4497 97 "Size of method parameter annotations") \
coleenp@4572 98 f(methods_type_annotations_bytes, methods_type_annotations, \
coleenp@4572 99 "Size of methods type annotations") \
acorn@4497 100 f(methods_default_annotations_bytes, methods_default_annotations, \
acorn@4497 101 "Size of methods default annotations") \
acorn@4497 102 f(annotations_bytes, annotations, \
acorn@4497 103 "Size of all annotations") \
acorn@4497 104 f(cp_bytes, Cp, \
acorn@4497 105 "Size of InstanceKlass::constants()") \
acorn@4497 106 f(cp_tags_bytes, CpTags, \
acorn@4497 107 "Size of InstanceKlass::constants()->tags()") \
acorn@4497 108 f(cp_cache_bytes, CpCache, \
acorn@4497 109 "Size of InstanceKlass::constants()->cache()") \
acorn@4497 110 f(cp_operands_bytes, CpOperands, \
acorn@4497 111 "Size of InstanceKlass::constants()->operands()") \
acorn@4497 112 f(cp_refmap_bytes, CpRefMap, \
acorn@4497 113 "Size of InstanceKlass::constants()->reference_map()") \
acorn@4497 114 f(cp_all_bytes, CpAll, \
acorn@4497 115 "Sum of Cp + CpTags + CpCache + CpOperands + CpRefMap") \
acorn@4497 116 f(method_count, MethodCount, \
acorn@4497 117 "Number of methods in this class") \
acorn@4497 118 f(method_bytes, MethodBytes, \
acorn@4497 119 "Size of the Method object") \
acorn@4497 120 f(const_method_bytes, ConstMethod, \
acorn@4497 121 "Size of the ConstMethod object") \
acorn@4497 122 f(method_data_bytes, MethodData, \
acorn@4497 123 "Size of the MethodData object") \
acorn@4497 124 f(stackmap_bytes, StackMap, \
acorn@4497 125 "Size of the stackmap_data") \
acorn@4497 126 f(bytecode_bytes, Bytecodes, \
acorn@4497 127 "Of the MethodBytes column, how much are the space taken up by bytecodes") \
acorn@4497 128 f(method_all_bytes, MethodAll, \
acorn@4497 129 "Sum of MethodBytes + Constmethod + Stackmap + Methoddata") \
acorn@4497 130 f(ro_bytes, ROAll, \
acorn@4497 131 "Size of all class meta data that could (potentially) be placed " \
acorn@4497 132 "in read-only memory. (This could change with CDS design)") \
acorn@4497 133 f(rw_bytes, RWAll, \
acorn@4497 134 "Size of all class meta data that must be placed in read/write " \
acorn@4497 135 "memory. (This could change with CDS design) ") \
acorn@4497 136 f(total_bytes, Total, \
acorn@4497 137 "ROAll + RWAll. Note that this does NOT include InstBytes.")
acorn@4497 138
acorn@4497 139 // Size statistics for a Klass - filled in by Klass::collect_statistics()
acorn@4497 140 class KlassSizeStats {
acorn@4497 141 public:
acorn@4497 142 #define COUNT_KLASS_SIZE_STATS_FIELD(field, name, help) _index_ ## field,
acorn@4497 143 #define DECLARE_KLASS_SIZE_STATS_FIELD(field, name, help) julong _ ## field;
acorn@4497 144
acorn@4497 145 enum {
acorn@4497 146 HEAP_INSPECTION_COLUMNS_DO(COUNT_KLASS_SIZE_STATS_FIELD)
acorn@4497 147 _num_columns
acorn@4497 148 };
acorn@4497 149
acorn@4497 150 HEAP_INSPECTION_COLUMNS_DO(DECLARE_KLASS_SIZE_STATS_FIELD)
acorn@4497 151
acorn@4497 152 static int count(oop x) {
hseigel@5784 153 return (HeapWordSize * (((x) != NULL) ? (x)->size() : 0));
acorn@4497 154 }
acorn@4497 155
acorn@4497 156 static int count_array(objArrayOop x) {
hseigel@5784 157 return (HeapWordSize * (((x) != NULL) ? (x)->size() : 0));
acorn@4497 158 }
acorn@4497 159
acorn@4497 160 template <class T> static int count(T* x) {
acorn@4497 161 return (HeapWordSize * ((x) ? (x)->size() : 0));
acorn@4497 162 }
acorn@4497 163
acorn@4497 164 template <class T> static int count_array(T* x) {
acorn@4497 165 if (x == NULL) {
acorn@4497 166 return 0;
acorn@4497 167 }
acorn@4497 168 if (x->length() == 0) {
acorn@4497 169 // This is a shared array, e.g., Universe::the_empty_int_array(). Don't
acorn@4497 170 // count it to avoid double-counting.
acorn@4497 171 return 0;
acorn@4497 172 }
acorn@4497 173 return HeapWordSize * x->size();
acorn@4497 174 }
acorn@4497 175 };
acorn@4497 176
acorn@4497 177
acorn@4497 178
acorn@4497 179
zgu@3900 180 class KlassInfoEntry: public CHeapObj<mtInternal> {
duke@435 181 private:
duke@435 182 KlassInfoEntry* _next;
coleenp@4037 183 Klass* _klass;
duke@435 184 long _instance_count;
duke@435 185 size_t _instance_words;
acorn@4497 186 long _index;
duke@435 187
duke@435 188 public:
coleenp@4037 189 KlassInfoEntry(Klass* k, KlassInfoEntry* next) :
acorn@4497 190 _klass(k), _instance_count(0), _instance_words(0), _next(next), _index(-1)
duke@435 191 {}
minqi@5097 192 KlassInfoEntry* next() const { return _next; }
minqi@5097 193 bool is_equal(const Klass* k) { return k == _klass; }
minqi@5097 194 Klass* klass() const { return _klass; }
minqi@5097 195 long count() const { return _instance_count; }
duke@435 196 void set_count(long ct) { _instance_count = ct; }
minqi@5097 197 size_t words() const { return _instance_words; }
duke@435 198 void set_words(size_t wds) { _instance_words = wds; }
acorn@4497 199 void set_index(long index) { _index = index; }
minqi@5097 200 long index() const { return _index; }
duke@435 201 int compare(KlassInfoEntry* e1, KlassInfoEntry* e2);
duke@435 202 void print_on(outputStream* st) const;
acorn@4497 203 const char* name() const;
duke@435 204 };
duke@435 205
ehelin@5386 206 class KlassInfoClosure : public StackObj {
ehelin@5386 207 public:
ehelin@5386 208 // Called for each KlassInfoEntry.
ehelin@5386 209 virtual void do_cinfo(KlassInfoEntry* cie) = 0;
ehelin@5386 210 };
ehelin@5386 211
zgu@3900 212 class KlassInfoBucket: public CHeapObj<mtInternal> {
duke@435 213 private:
duke@435 214 KlassInfoEntry* _list;
duke@435 215 KlassInfoEntry* list() { return _list; }
duke@435 216 void set_list(KlassInfoEntry* l) { _list = l; }
duke@435 217 public:
minqi@5097 218 KlassInfoEntry* lookup(Klass* k);
duke@435 219 void initialize() { _list = NULL; }
duke@435 220 void empty();
duke@435 221 void iterate(KlassInfoClosure* cic);
duke@435 222 };
duke@435 223
duke@435 224 class KlassInfoTable: public StackObj {
duke@435 225 private:
duke@435 226 int _size;
sla@5237 227 static const int _num_buckets = 20011;
sla@5237 228 size_t _size_of_instances_in_words;
duke@435 229
duke@435 230 // An aligned reference address (typically the least
duke@435 231 // address in the perm gen) used for hashing klass
duke@435 232 // objects.
duke@435 233 HeapWord* _ref;
duke@435 234
duke@435 235 KlassInfoBucket* _buckets;
minqi@5097 236 uint hash(const Klass* p);
minqi@5097 237 KlassInfoEntry* lookup(Klass* k); // allocates if not found!
acorn@4497 238
acorn@4497 239 class AllClassesFinder : public KlassClosure {
acorn@4497 240 KlassInfoTable *_table;
acorn@4497 241 public:
acorn@4497 242 AllClassesFinder(KlassInfoTable* table) : _table(table) {}
acorn@4497 243 virtual void do_klass(Klass* k);
acorn@4497 244 };
duke@435 245
duke@435 246 public:
sla@5237 247 KlassInfoTable(bool need_class_stats);
duke@435 248 ~KlassInfoTable();
ysr@446 249 bool record_instance(const oop obj);
duke@435 250 void iterate(KlassInfoClosure* cic);
ysr@446 251 bool allocation_failed() { return _buckets == NULL; }
sla@5237 252 size_t size_of_instances_in_words() const;
acorn@4497 253
acorn@4497 254 friend class KlassInfoHisto;
duke@435 255 };
duke@435 256
duke@435 257 class KlassInfoHisto : public StackObj {
duke@435 258 private:
sla@5237 259 static const int _histo_initial_size = 1000;
acorn@4497 260 KlassInfoTable *_cit;
duke@435 261 GrowableArray<KlassInfoEntry*>* _elements;
duke@435 262 GrowableArray<KlassInfoEntry*>* elements() const { return _elements; }
duke@435 263 const char* _title;
duke@435 264 const char* title() const { return _title; }
duke@435 265 static int sort_helper(KlassInfoEntry** e1, KlassInfoEntry** e2);
duke@435 266 void print_elements(outputStream* st) const;
acorn@4497 267 void print_class_stats(outputStream* st, bool csv_format, const char *columns);
acorn@4497 268 julong annotations_bytes(Array<AnnotationArray*>* p) const;
acorn@4497 269 const char *_selected_columns;
acorn@4497 270 bool is_selected(const char *col_name);
acorn@4497 271 void print_title(outputStream* st, bool csv_format,
acorn@4497 272 bool selected_columns_table[], int width_table[],
acorn@4497 273 const char *name_table[]);
acorn@4497 274
acorn@4497 275 template <class T> static int count_bytes(T* x) {
acorn@4497 276 return (HeapWordSize * ((x) ? (x)->size() : 0));
acorn@4497 277 }
acorn@4497 278
acorn@4497 279 template <class T> static int count_bytes_array(T* x) {
acorn@4497 280 if (x == NULL) {
acorn@4497 281 return 0;
acorn@4497 282 }
acorn@4497 283 if (x->length() == 0) {
acorn@4497 284 // This is a shared array, e.g., Universe::the_empty_int_array(). Don't
acorn@4497 285 // count it to avoid double-counting.
acorn@4497 286 return 0;
acorn@4497 287 }
acorn@4497 288 return HeapWordSize * x->size();
acorn@4497 289 }
acorn@4497 290
acorn@4497 291 // returns a format string to print a julong with the given width. E.g,
acorn@4497 292 // printf(num_fmt(6), julong(10)) would print out the number 10 with 4
acorn@4497 293 // leading spaces.
acorn@4497 294 static void print_julong(outputStream* st, int width, julong n) {
acorn@4497 295 int num_spaces = width - julong_width(n);
acorn@4497 296 if (num_spaces > 0) {
acorn@4497 297 st->print(str_fmt(num_spaces), "");
acorn@4497 298 }
acorn@4497 299 st->print(JULONG_FORMAT, n);
acorn@4497 300 }
acorn@4497 301
acorn@4497 302 static char* perc_fmt(int width) {
acorn@4497 303 static char buf[32];
acorn@4497 304 jio_snprintf(buf, sizeof(buf), "%%%d.1f%%%%", width-1);
acorn@4497 305 return buf;
acorn@4497 306 }
acorn@4497 307
acorn@4497 308 static char* str_fmt(int width) {
acorn@4497 309 static char buf[32];
acorn@4497 310 jio_snprintf(buf, sizeof(buf), "%%%ds", width);
acorn@4497 311 return buf;
acorn@4497 312 }
acorn@4497 313
acorn@4497 314 static int julong_width(julong n) {
acorn@4497 315 if (n == 0) {
acorn@4497 316 return 1;
acorn@4497 317 }
acorn@4497 318 int w = 0;
acorn@4497 319 while (n > 0) {
acorn@4497 320 n /= 10;
acorn@4497 321 w += 1;
acorn@4497 322 }
acorn@4497 323 return w;
acorn@4497 324 }
acorn@4497 325
acorn@4497 326 static int col_width(julong n, const char *name) {
acorn@4497 327 int w = julong_width(n);
acorn@4497 328 int min = (int)(strlen(name));
acorn@4497 329 if (w < min) {
acorn@4497 330 w = min;
acorn@4497 331 }
acorn@4497 332 // add a leading space for separation.
acorn@4497 333 return w + 1;
acorn@4497 334 }
acorn@4497 335
duke@435 336 public:
sla@5237 337 KlassInfoHisto(KlassInfoTable* cit, const char* title);
duke@435 338 ~KlassInfoHisto();
duke@435 339 void add(KlassInfoEntry* cie);
acorn@4497 340 void print_histo_on(outputStream* st, bool print_class_stats, bool csv_format, const char *columns);
duke@435 341 void sort();
duke@435 342 };
duke@435 343
jprovino@4165 344 #endif // INCLUDE_SERVICES
duke@435 345
sla@5237 346 // These declarations are needed since teh declaration of KlassInfoTable and
sla@5237 347 // KlassInfoClosure are guarded by #if INLCUDE_SERVICES
sla@5237 348 class KlassInfoTable;
sla@5237 349 class KlassInfoClosure;
sla@5237 350
acorn@4497 351 class HeapInspection : public StackObj {
acorn@4497 352 bool _csv_format; // "comma separated values" format for spreadsheet.
acorn@4497 353 bool _print_help;
acorn@4497 354 bool _print_class_stats;
acorn@4497 355 const char* _columns;
duke@435 356 public:
acorn@4497 357 HeapInspection(bool csv_format, bool print_help,
acorn@4497 358 bool print_class_stats, const char *columns) :
acorn@4497 359 _csv_format(csv_format), _print_help(print_help),
acorn@4497 360 _print_class_stats(print_class_stats), _columns(columns) {}
sla@5237 361 void heap_inspection(outputStream* st) NOT_SERVICES_RETURN;
sla@5237 362 size_t populate_table(KlassInfoTable* cit, BoolObjectClosure* filter = NULL) NOT_SERVICES_RETURN;
jprovino@4165 363 static void find_instances_at_safepoint(Klass* k, GrowableArray<oop>* result) NOT_SERVICES_RETURN;
sla@5237 364 private:
sla@5237 365 void iterate_over_heap(KlassInfoTable* cit, BoolObjectClosure* filter = NULL);
duke@435 366 };
stefank@2314 367
stefank@2314 368 #endif // SHARE_VM_MEMORY_HEAPINSPECTION_HPP

mercurial