2007-12-01 00:00:00 +00:00
|
|
|
/*
|
2013-01-25 15:06:18 -05:00
|
|
|
* Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved.
|
2007-12-01 00:00:00 +00:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
|
|
*
|
|
|
|
* This code is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License version 2 only, as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* version 2 for more details (a copy is included in the LICENSE file that
|
|
|
|
* accompanied this code).
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License version
|
|
|
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
2010-05-27 19:08:38 -07:00
|
|
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
|
|
* or visit www.oracle.com if you need additional information or have any
|
|
|
|
* questions.
|
2007-12-01 00:00:00 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2010-11-23 13:22:55 -08:00
|
|
|
#ifndef SHARE_VM_MEMORY_HEAPINSPECTION_HPP
|
|
|
|
#define SHARE_VM_MEMORY_HEAPINSPECTION_HPP
|
|
|
|
|
|
|
|
#include "memory/allocation.inline.hpp"
|
|
|
|
#include "oops/oop.inline.hpp"
|
2013-01-25 15:06:18 -05:00
|
|
|
#include "oops/annotations.hpp"
|
2013-01-23 13:02:39 -05:00
|
|
|
#include "utilities/macros.hpp"
|
2010-11-23 13:22:55 -08:00
|
|
|
|
2012-10-10 14:35:58 -04:00
|
|
|
#if INCLUDE_SERVICES
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
// HeapInspection
|
|
|
|
|
|
|
|
// KlassInfoTable is a bucket hash table that
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
// maps Klass*s to extra information:
|
2007-12-01 00:00:00 +00:00
|
|
|
// instance count and instance word size.
|
|
|
|
//
|
|
|
|
// A KlassInfoBucket is the head of a link list
|
|
|
|
// of KlassInfoEntry's
|
|
|
|
//
|
|
|
|
// KlassInfoHisto is a growable array of pointers
|
|
|
|
// to KlassInfoEntry's and is used to sort
|
|
|
|
// the entries.
|
|
|
|
|
2013-01-25 15:06:18 -05:00
|
|
|
#define HEAP_INSPECTION_COLUMNS_DO(f) \
|
|
|
|
f(inst_size, InstSize, \
|
|
|
|
"Size of each object instance of the Java class") \
|
|
|
|
f(inst_count, InstCount, \
|
|
|
|
"Number of object instances of the Java class") \
|
|
|
|
f(inst_bytes, InstBytes, \
|
|
|
|
"This is usually (InstSize * InstNum). The only exception is " \
|
|
|
|
"java.lang.Class, whose InstBytes also includes the slots " \
|
|
|
|
"used to store static fields. InstBytes is not counted in " \
|
|
|
|
"ROAll, RWAll or Total") \
|
|
|
|
f(mirror_bytes, Mirror, \
|
|
|
|
"Size of the Klass::java_mirror() object") \
|
|
|
|
f(klass_bytes, KlassBytes, \
|
|
|
|
"Size of the InstanceKlass or ArrayKlass for this class. " \
|
|
|
|
"Note that this includes VTab, ITab, OopMap") \
|
|
|
|
f(secondary_supers_bytes, K_secondary_supers, \
|
|
|
|
"Number of bytes used by the Klass::secondary_supers() array") \
|
|
|
|
f(vtab_bytes, VTab, \
|
|
|
|
"Size of the embedded vtable in InstanceKlass") \
|
|
|
|
f(itab_bytes, ITab, \
|
|
|
|
"Size of the embedded itable in InstanceKlass") \
|
|
|
|
f(nonstatic_oopmap_bytes, OopMap, \
|
|
|
|
"Size of the embedded nonstatic_oop_map in InstanceKlass") \
|
|
|
|
f(methods_array_bytes, IK_methods, \
|
|
|
|
"Number of bytes used by the InstanceKlass::methods() array") \
|
|
|
|
f(method_ordering_bytes, IK_method_ordering, \
|
|
|
|
"Number of bytes used by the InstanceKlass::method_ordering() array") \
|
|
|
|
f(local_interfaces_bytes, IK_local_interfaces, \
|
|
|
|
"Number of bytes used by the InstanceKlass::local_interfaces() array") \
|
|
|
|
f(transitive_interfaces_bytes, IK_transitive_interfaces, \
|
|
|
|
"Number of bytes used by the InstanceKlass::transitive_interfaces() array") \
|
|
|
|
f(fields_bytes, IK_fields, \
|
|
|
|
"Number of bytes used by the InstanceKlass::fields() array") \
|
|
|
|
f(inner_classes_bytes, IK_inner_classes, \
|
|
|
|
"Number of bytes used by the InstanceKlass::inner_classes() array") \
|
|
|
|
f(signers_bytes, IK_signers, \
|
|
|
|
"Number of bytes used by the InstanceKlass::singers() array") \
|
|
|
|
f(class_annotations_bytes, class_annotations, \
|
|
|
|
"Size of class annotations") \
|
2013-02-11 14:06:22 -05:00
|
|
|
f(class_type_annotations_bytes, class_type_annotations, \
|
|
|
|
"Size of class type annotations") \
|
2013-01-25 15:06:18 -05:00
|
|
|
f(fields_annotations_bytes, fields_annotations, \
|
|
|
|
"Size of field annotations") \
|
2013-02-11 14:06:22 -05:00
|
|
|
f(fields_type_annotations_bytes, fields_type_annotations, \
|
|
|
|
"Size of field type annotations") \
|
2013-01-25 15:06:18 -05:00
|
|
|
f(methods_annotations_bytes, methods_annotations, \
|
|
|
|
"Size of method annotations") \
|
|
|
|
f(methods_parameter_annotations_bytes, methods_parameter_annotations, \
|
|
|
|
"Size of method parameter annotations") \
|
2013-02-11 14:06:22 -05:00
|
|
|
f(methods_type_annotations_bytes, methods_type_annotations, \
|
|
|
|
"Size of methods type annotations") \
|
2013-01-25 15:06:18 -05:00
|
|
|
f(methods_default_annotations_bytes, methods_default_annotations, \
|
|
|
|
"Size of methods default annotations") \
|
|
|
|
f(annotations_bytes, annotations, \
|
|
|
|
"Size of all annotations") \
|
|
|
|
f(cp_bytes, Cp, \
|
|
|
|
"Size of InstanceKlass::constants()") \
|
|
|
|
f(cp_tags_bytes, CpTags, \
|
|
|
|
"Size of InstanceKlass::constants()->tags()") \
|
|
|
|
f(cp_cache_bytes, CpCache, \
|
|
|
|
"Size of InstanceKlass::constants()->cache()") \
|
|
|
|
f(cp_operands_bytes, CpOperands, \
|
|
|
|
"Size of InstanceKlass::constants()->operands()") \
|
|
|
|
f(cp_refmap_bytes, CpRefMap, \
|
|
|
|
"Size of InstanceKlass::constants()->reference_map()") \
|
|
|
|
f(cp_all_bytes, CpAll, \
|
|
|
|
"Sum of Cp + CpTags + CpCache + CpOperands + CpRefMap") \
|
|
|
|
f(method_count, MethodCount, \
|
|
|
|
"Number of methods in this class") \
|
|
|
|
f(method_bytes, MethodBytes, \
|
|
|
|
"Size of the Method object") \
|
|
|
|
f(const_method_bytes, ConstMethod, \
|
|
|
|
"Size of the ConstMethod object") \
|
|
|
|
f(method_data_bytes, MethodData, \
|
|
|
|
"Size of the MethodData object") \
|
|
|
|
f(stackmap_bytes, StackMap, \
|
|
|
|
"Size of the stackmap_data") \
|
|
|
|
f(bytecode_bytes, Bytecodes, \
|
|
|
|
"Of the MethodBytes column, how much are the space taken up by bytecodes") \
|
|
|
|
f(method_all_bytes, MethodAll, \
|
|
|
|
"Sum of MethodBytes + Constmethod + Stackmap + Methoddata") \
|
|
|
|
f(ro_bytes, ROAll, \
|
|
|
|
"Size of all class meta data that could (potentially) be placed " \
|
|
|
|
"in read-only memory. (This could change with CDS design)") \
|
|
|
|
f(rw_bytes, RWAll, \
|
|
|
|
"Size of all class meta data that must be placed in read/write " \
|
|
|
|
"memory. (This could change with CDS design) ") \
|
|
|
|
f(total_bytes, Total, \
|
|
|
|
"ROAll + RWAll. Note that this does NOT include InstBytes.")
|
|
|
|
|
|
|
|
// Size statistics for a Klass - filled in by Klass::collect_statistics()
|
|
|
|
class KlassSizeStats {
|
|
|
|
public:
|
|
|
|
#define COUNT_KLASS_SIZE_STATS_FIELD(field, name, help) _index_ ## field,
|
|
|
|
#define DECLARE_KLASS_SIZE_STATS_FIELD(field, name, help) julong _ ## field;
|
|
|
|
|
|
|
|
enum {
|
|
|
|
HEAP_INSPECTION_COLUMNS_DO(COUNT_KLASS_SIZE_STATS_FIELD)
|
|
|
|
_num_columns
|
|
|
|
};
|
|
|
|
|
|
|
|
HEAP_INSPECTION_COLUMNS_DO(DECLARE_KLASS_SIZE_STATS_FIELD)
|
|
|
|
|
|
|
|
static int count(oop x) {
|
|
|
|
return (HeapWordSize * ((x) ? (x)->size() : 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
static int count_array(objArrayOop x) {
|
|
|
|
return (HeapWordSize * ((x) ? (x)->size() : 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class T> static int count(T* x) {
|
|
|
|
return (HeapWordSize * ((x) ? (x)->size() : 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class T> static int count_array(T* x) {
|
|
|
|
if (x == NULL) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (x->length() == 0) {
|
|
|
|
// This is a shared array, e.g., Universe::the_empty_int_array(). Don't
|
|
|
|
// count it to avoid double-counting.
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return HeapWordSize * x->size();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-06-28 17:03:16 -04:00
|
|
|
class KlassInfoEntry: public CHeapObj<mtInternal> {
|
2007-12-01 00:00:00 +00:00
|
|
|
private:
|
|
|
|
KlassInfoEntry* _next;
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
Klass* _klass;
|
2007-12-01 00:00:00 +00:00
|
|
|
long _instance_count;
|
|
|
|
size_t _instance_words;
|
2013-01-25 15:06:18 -05:00
|
|
|
long _index;
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
public:
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
KlassInfoEntry(Klass* k, KlassInfoEntry* next) :
|
2013-01-25 15:06:18 -05:00
|
|
|
_klass(k), _instance_count(0), _instance_words(0), _next(next), _index(-1)
|
2007-12-01 00:00:00 +00:00
|
|
|
{}
|
2013-05-10 08:27:30 -07:00
|
|
|
KlassInfoEntry* next() const { return _next; }
|
|
|
|
bool is_equal(const Klass* k) { return k == _klass; }
|
|
|
|
Klass* klass() const { return _klass; }
|
|
|
|
long count() const { return _instance_count; }
|
2007-12-01 00:00:00 +00:00
|
|
|
void set_count(long ct) { _instance_count = ct; }
|
2013-05-10 08:27:30 -07:00
|
|
|
size_t words() const { return _instance_words; }
|
2007-12-01 00:00:00 +00:00
|
|
|
void set_words(size_t wds) { _instance_words = wds; }
|
2013-01-25 15:06:18 -05:00
|
|
|
void set_index(long index) { _index = index; }
|
2013-05-10 08:27:30 -07:00
|
|
|
long index() const { return _index; }
|
2007-12-01 00:00:00 +00:00
|
|
|
int compare(KlassInfoEntry* e1, KlassInfoEntry* e2);
|
|
|
|
void print_on(outputStream* st) const;
|
2013-01-25 15:06:18 -05:00
|
|
|
const char* name() const;
|
2007-12-01 00:00:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class KlassInfoClosure: public StackObj {
|
|
|
|
public:
|
|
|
|
// Called for each KlassInfoEntry.
|
|
|
|
virtual void do_cinfo(KlassInfoEntry* cie) = 0;
|
|
|
|
};
|
|
|
|
|
2012-06-28 17:03:16 -04:00
|
|
|
class KlassInfoBucket: public CHeapObj<mtInternal> {
|
2007-12-01 00:00:00 +00:00
|
|
|
private:
|
|
|
|
KlassInfoEntry* _list;
|
|
|
|
KlassInfoEntry* list() { return _list; }
|
|
|
|
void set_list(KlassInfoEntry* l) { _list = l; }
|
|
|
|
public:
|
2013-05-10 08:27:30 -07:00
|
|
|
KlassInfoEntry* lookup(Klass* k);
|
2007-12-01 00:00:00 +00:00
|
|
|
void initialize() { _list = NULL; }
|
|
|
|
void empty();
|
|
|
|
void iterate(KlassInfoClosure* cic);
|
|
|
|
};
|
|
|
|
|
|
|
|
class KlassInfoTable: public StackObj {
|
|
|
|
private:
|
|
|
|
int _size;
|
|
|
|
|
|
|
|
// An aligned reference address (typically the least
|
|
|
|
// address in the perm gen) used for hashing klass
|
|
|
|
// objects.
|
|
|
|
HeapWord* _ref;
|
|
|
|
|
|
|
|
KlassInfoBucket* _buckets;
|
2013-05-10 08:27:30 -07:00
|
|
|
uint hash(const Klass* p);
|
|
|
|
KlassInfoEntry* lookup(Klass* k); // allocates if not found!
|
2013-01-25 15:06:18 -05:00
|
|
|
|
|
|
|
class AllClassesFinder : public KlassClosure {
|
|
|
|
KlassInfoTable *_table;
|
|
|
|
public:
|
|
|
|
AllClassesFinder(KlassInfoTable* table) : _table(table) {}
|
|
|
|
virtual void do_klass(Klass* k);
|
|
|
|
};
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
// Table size
|
|
|
|
enum {
|
|
|
|
cit_size = 20011
|
|
|
|
};
|
2013-01-25 15:06:18 -05:00
|
|
|
KlassInfoTable(int size, HeapWord* ref, bool need_class_stats);
|
2007-12-01 00:00:00 +00:00
|
|
|
~KlassInfoTable();
|
2008-02-26 15:57:49 -08:00
|
|
|
bool record_instance(const oop obj);
|
2007-12-01 00:00:00 +00:00
|
|
|
void iterate(KlassInfoClosure* cic);
|
2008-02-26 15:57:49 -08:00
|
|
|
bool allocation_failed() { return _buckets == NULL; }
|
2013-01-25 15:06:18 -05:00
|
|
|
|
|
|
|
friend class KlassInfoHisto;
|
2007-12-01 00:00:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class KlassInfoHisto : public StackObj {
|
|
|
|
private:
|
2013-01-25 15:06:18 -05:00
|
|
|
KlassInfoTable *_cit;
|
2007-12-01 00:00:00 +00:00
|
|
|
GrowableArray<KlassInfoEntry*>* _elements;
|
|
|
|
GrowableArray<KlassInfoEntry*>* elements() const { return _elements; }
|
|
|
|
const char* _title;
|
|
|
|
const char* title() const { return _title; }
|
|
|
|
static int sort_helper(KlassInfoEntry** e1, KlassInfoEntry** e2);
|
|
|
|
void print_elements(outputStream* st) const;
|
2013-01-25 15:06:18 -05:00
|
|
|
void print_class_stats(outputStream* st, bool csv_format, const char *columns);
|
|
|
|
julong annotations_bytes(Array<AnnotationArray*>* p) const;
|
|
|
|
const char *_selected_columns;
|
|
|
|
bool is_selected(const char *col_name);
|
|
|
|
void print_title(outputStream* st, bool csv_format,
|
|
|
|
bool selected_columns_table[], int width_table[],
|
|
|
|
const char *name_table[]);
|
|
|
|
|
|
|
|
template <class T> static int count_bytes(T* x) {
|
|
|
|
return (HeapWordSize * ((x) ? (x)->size() : 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class T> static int count_bytes_array(T* x) {
|
|
|
|
if (x == NULL) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (x->length() == 0) {
|
|
|
|
// This is a shared array, e.g., Universe::the_empty_int_array(). Don't
|
|
|
|
// count it to avoid double-counting.
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return HeapWordSize * x->size();
|
|
|
|
}
|
|
|
|
|
|
|
|
// returns a format string to print a julong with the given width. E.g,
|
|
|
|
// printf(num_fmt(6), julong(10)) would print out the number 10 with 4
|
|
|
|
// leading spaces.
|
|
|
|
static void print_julong(outputStream* st, int width, julong n) {
|
|
|
|
int num_spaces = width - julong_width(n);
|
|
|
|
if (num_spaces > 0) {
|
|
|
|
st->print(str_fmt(num_spaces), "");
|
|
|
|
}
|
|
|
|
st->print(JULONG_FORMAT, n);
|
|
|
|
}
|
|
|
|
|
|
|
|
static char* perc_fmt(int width) {
|
|
|
|
static char buf[32];
|
|
|
|
jio_snprintf(buf, sizeof(buf), "%%%d.1f%%%%", width-1);
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char* str_fmt(int width) {
|
|
|
|
static char buf[32];
|
|
|
|
jio_snprintf(buf, sizeof(buf), "%%%ds", width);
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int julong_width(julong n) {
|
|
|
|
if (n == 0) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
int w = 0;
|
|
|
|
while (n > 0) {
|
|
|
|
n /= 10;
|
|
|
|
w += 1;
|
|
|
|
}
|
|
|
|
return w;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int col_width(julong n, const char *name) {
|
|
|
|
int w = julong_width(n);
|
|
|
|
int min = (int)(strlen(name));
|
|
|
|
if (w < min) {
|
|
|
|
w = min;
|
|
|
|
}
|
|
|
|
// add a leading space for separation.
|
|
|
|
return w + 1;
|
|
|
|
}
|
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
public:
|
|
|
|
enum {
|
|
|
|
histo_initial_size = 1000
|
|
|
|
};
|
2013-01-25 15:06:18 -05:00
|
|
|
KlassInfoHisto(KlassInfoTable* cit, const char* title,
|
2007-12-01 00:00:00 +00:00
|
|
|
int estimatedCount);
|
|
|
|
~KlassInfoHisto();
|
|
|
|
void add(KlassInfoEntry* cie);
|
2013-01-25 15:06:18 -05:00
|
|
|
void print_histo_on(outputStream* st, bool print_class_stats, bool csv_format, const char *columns);
|
2007-12-01 00:00:00 +00:00
|
|
|
void sort();
|
|
|
|
};
|
|
|
|
|
2012-10-10 14:35:58 -04:00
|
|
|
#endif // INCLUDE_SERVICES
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2013-01-25 15:06:18 -05:00
|
|
|
class HeapInspection : public StackObj {
|
|
|
|
bool _csv_format; // "comma separated values" format for spreadsheet.
|
|
|
|
bool _print_help;
|
|
|
|
bool _print_class_stats;
|
|
|
|
const char* _columns;
|
2007-12-01 00:00:00 +00:00
|
|
|
public:
|
2013-01-25 15:06:18 -05:00
|
|
|
HeapInspection(bool csv_format, bool print_help,
|
|
|
|
bool print_class_stats, const char *columns) :
|
|
|
|
_csv_format(csv_format), _print_help(print_help),
|
|
|
|
_print_class_stats(print_class_stats), _columns(columns) {}
|
|
|
|
void heap_inspection(outputStream* st, bool need_prologue) NOT_SERVICES_RETURN;
|
2012-10-10 14:35:58 -04:00
|
|
|
static void find_instances_at_safepoint(Klass* k, GrowableArray<oop>* result) NOT_SERVICES_RETURN;
|
2007-12-01 00:00:00 +00:00
|
|
|
};
|
2010-11-23 13:22:55 -08:00
|
|
|
|
|
|
|
#endif // SHARE_VM_MEMORY_HEAPINSPECTION_HPP
|