2007-12-01 00:00:00 +00:00
|
|
|
/*
|
2020-01-09 17:38:41 -05:00
|
|
|
* Copyright (c) 2002, 2020, 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
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2019-01-10 15:13:51 -05:00
|
|
|
#ifndef SHARE_MEMORY_HEAPINSPECTION_HPP
|
|
|
|
#define SHARE_MEMORY_HEAPINSPECTION_HPP
|
2010-11-23 13:22:55 -08:00
|
|
|
|
2015-02-13 14:37:35 +01:00
|
|
|
#include "memory/allocation.hpp"
|
|
|
|
#include "oops/objArrayOop.hpp"
|
|
|
|
#include "oops/oop.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.
|
|
|
|
|
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;
|
2015-02-11 15:22:43 -08:00
|
|
|
bool _do_print; // True if we should print this class when printing the class hierarchy.
|
|
|
|
GrowableArray<KlassInfoEntry*>* _subclasses;
|
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) :
|
2018-08-08 15:31:07 +02:00
|
|
|
_next(next), _klass(k), _instance_count(0), _instance_words(0), _index(-1),
|
2015-02-11 15:22:43 -08:00
|
|
|
_do_print(false), _subclasses(NULL)
|
2007-12-01 00:00:00 +00:00
|
|
|
{}
|
2015-02-11 15:22:43 -08:00
|
|
|
~KlassInfoEntry();
|
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; }
|
2015-02-11 15:22:43 -08:00
|
|
|
GrowableArray<KlassInfoEntry*>* subclasses() const { return _subclasses; }
|
|
|
|
void add_subclass(KlassInfoEntry* cie);
|
|
|
|
void set_do_print(bool do_print) { _do_print = do_print; }
|
|
|
|
bool do_print() const { return _do_print; }
|
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
|
|
|
};
|
|
|
|
|
2013-06-05 09:44:03 +02: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:
|
2013-06-10 11:30:51 +02:00
|
|
|
static const int _num_buckets = 20011;
|
|
|
|
size_t _size_of_instances_in_words;
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
// 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
|
|
|
|
2018-08-31 07:03:46 -04:00
|
|
|
class AllClassesFinder;
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
public:
|
2015-02-11 15:22:43 -08:00
|
|
|
KlassInfoTable(bool add_all_classes);
|
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-06-10 11:30:51 +02:00
|
|
|
size_t size_of_instances_in_words() const;
|
2013-01-25 15:06:18 -05:00
|
|
|
|
|
|
|
friend class KlassInfoHisto;
|
2015-02-11 15:22:43 -08:00
|
|
|
friend class KlassHierarchy;
|
|
|
|
};
|
|
|
|
|
|
|
|
class KlassHierarchy : AllStatic {
|
|
|
|
public:
|
|
|
|
static void print_class_hierarchy(outputStream* st, bool print_interfaces, bool print_subclasses,
|
|
|
|
char* classname);
|
|
|
|
|
|
|
|
private:
|
|
|
|
static void set_do_print_for_class_hierarchy(KlassInfoEntry* cie, KlassInfoTable* cit,
|
|
|
|
bool print_subclasse);
|
|
|
|
static void print_class(outputStream* st, KlassInfoEntry* cie, bool print_subclasses);
|
2007-12-01 00:00:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class KlassInfoHisto : public StackObj {
|
|
|
|
private:
|
2013-06-10 11:30:51 +02:00
|
|
|
static const int _histo_initial_size = 1000;
|
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; }
|
|
|
|
static int sort_helper(KlassInfoEntry** e1, KlassInfoEntry** e2);
|
|
|
|
void print_elements(outputStream* st) const;
|
2013-01-25 15:06:18 -05:00
|
|
|
bool is_selected(const char *col_name);
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void print_julong(outputStream* st, int width, julong n) {
|
|
|
|
int num_spaces = width - julong_width(n);
|
|
|
|
if (num_spaces > 0) {
|
2015-10-09 16:39:37 +02:00
|
|
|
st->print("%*s", num_spaces, "");
|
2013-01-25 15:06:18 -05:00
|
|
|
}
|
|
|
|
st->print(JULONG_FORMAT, n);
|
|
|
|
}
|
|
|
|
|
|
|
|
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:
|
2016-02-05 08:59:36 +01:00
|
|
|
KlassInfoHisto(KlassInfoTable* cit);
|
2007-12-01 00:00:00 +00:00
|
|
|
~KlassInfoHisto();
|
|
|
|
void add(KlassInfoEntry* cie);
|
2020-01-09 17:38:41 -05:00
|
|
|
void print_histo_on(outputStream* st);
|
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
|
|
|
|
2014-01-23 14:47:23 +01:00
|
|
|
// These declarations are needed since the declaration of KlassInfoTable and
|
2013-06-10 11:30:51 +02:00
|
|
|
// KlassInfoClosure are guarded by #if INLCUDE_SERVICES
|
|
|
|
class KlassInfoTable;
|
|
|
|
class KlassInfoClosure;
|
|
|
|
|
2013-01-25 15:06:18 -05:00
|
|
|
class HeapInspection : public StackObj {
|
2007-12-01 00:00:00 +00:00
|
|
|
public:
|
2013-06-10 11:30:51 +02:00
|
|
|
void heap_inspection(outputStream* st) NOT_SERVICES_RETURN;
|
2014-11-12 13:55:59 +01:00
|
|
|
size_t populate_table(KlassInfoTable* cit, BoolObjectClosure* filter = NULL) NOT_SERVICES_RETURN_(0);
|
2012-10-10 14:35:58 -04:00
|
|
|
static void find_instances_at_safepoint(Klass* k, GrowableArray<oop>* result) NOT_SERVICES_RETURN;
|
2013-06-10 11:30:51 +02:00
|
|
|
private:
|
|
|
|
void iterate_over_heap(KlassInfoTable* cit, BoolObjectClosure* filter = NULL);
|
2007-12-01 00:00:00 +00:00
|
|
|
};
|
2010-11-23 13:22:55 -08:00
|
|
|
|
2019-01-10 15:13:51 -05:00
|
|
|
#endif // SHARE_MEMORY_HEAPINSPECTION_HPP
|