src/share/vm/memory/heapInspection.hpp

Fri, 01 Feb 2013 23:48:08 +0100

author
ctornqvi
date
Fri, 01 Feb 2013 23:48:08 +0100
changeset 4512
4102b59539ce
parent 4497
16fb9f942703
child 4544
3c9bc17b9403
permissions
-rw-r--r--

8005012: Add WB APIs to better support NMT testing
Summary: Add WB API functions to enable better NMT testing
Reviewed-by: dholmes, zgu

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

mercurial