src/share/vm/memory/heapInspection.hpp

Thu, 28 Jun 2012 17:03:16 -0400

author
zgu
date
Thu, 28 Jun 2012 17:03:16 -0400
changeset 3900
d2a62e0f25eb
parent 2314
f95d63e2154a
child 4037
da91efe96a93
permissions
-rw-r--r--

6995781: Native Memory Tracking (Phase 1)
7151532: DCmd for hotspot native memory tracking
Summary: Implementation of native memory tracking phase 1, which tracks VM native memory usage, and related DCmd
Reviewed-by: acorn, coleenp, fparain

duke@435 1 /*
stefank@2314 2 * Copyright (c) 2002, 2010, 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"
stefank@2314 30
duke@435 31 #ifndef SERVICES_KERNEL
duke@435 32
duke@435 33
duke@435 34 // HeapInspection
duke@435 35
duke@435 36 // KlassInfoTable is a bucket hash table that
duke@435 37 // maps klassOops to extra information:
duke@435 38 // instance count and instance word size.
duke@435 39 //
duke@435 40 // A KlassInfoBucket is the head of a link list
duke@435 41 // of KlassInfoEntry's
duke@435 42 //
duke@435 43 // KlassInfoHisto is a growable array of pointers
duke@435 44 // to KlassInfoEntry's and is used to sort
duke@435 45 // the entries.
duke@435 46
zgu@3900 47 class KlassInfoEntry: public CHeapObj<mtInternal> {
duke@435 48 private:
duke@435 49 KlassInfoEntry* _next;
duke@435 50 klassOop _klass;
duke@435 51 long _instance_count;
duke@435 52 size_t _instance_words;
duke@435 53
duke@435 54 public:
duke@435 55 KlassInfoEntry(klassOop k, KlassInfoEntry* next) :
duke@435 56 _klass(k), _instance_count(0), _instance_words(0), _next(next)
duke@435 57 {}
duke@435 58 KlassInfoEntry* next() { return _next; }
duke@435 59 bool is_equal(klassOop k) { return k == _klass; }
duke@435 60 klassOop klass() { return _klass; }
duke@435 61 long count() { return _instance_count; }
duke@435 62 void set_count(long ct) { _instance_count = ct; }
duke@435 63 size_t words() { return _instance_words; }
duke@435 64 void set_words(size_t wds) { _instance_words = wds; }
duke@435 65 int compare(KlassInfoEntry* e1, KlassInfoEntry* e2);
duke@435 66 void print_on(outputStream* st) const;
duke@435 67 };
duke@435 68
duke@435 69 class KlassInfoClosure: public StackObj {
duke@435 70 public:
duke@435 71 // Called for each KlassInfoEntry.
duke@435 72 virtual void do_cinfo(KlassInfoEntry* cie) = 0;
duke@435 73 };
duke@435 74
zgu@3900 75 class KlassInfoBucket: public CHeapObj<mtInternal> {
duke@435 76 private:
duke@435 77 KlassInfoEntry* _list;
duke@435 78 KlassInfoEntry* list() { return _list; }
duke@435 79 void set_list(KlassInfoEntry* l) { _list = l; }
duke@435 80 public:
duke@435 81 KlassInfoEntry* lookup(const klassOop k);
duke@435 82 void initialize() { _list = NULL; }
duke@435 83 void empty();
duke@435 84 void iterate(KlassInfoClosure* cic);
duke@435 85 };
duke@435 86
duke@435 87 class KlassInfoTable: public StackObj {
duke@435 88 private:
duke@435 89 int _size;
duke@435 90
duke@435 91 // An aligned reference address (typically the least
duke@435 92 // address in the perm gen) used for hashing klass
duke@435 93 // objects.
duke@435 94 HeapWord* _ref;
duke@435 95
duke@435 96 KlassInfoBucket* _buckets;
duke@435 97 uint hash(klassOop p);
duke@435 98 KlassInfoEntry* lookup(const klassOop k);
duke@435 99
duke@435 100 public:
duke@435 101 // Table size
duke@435 102 enum {
duke@435 103 cit_size = 20011
duke@435 104 };
duke@435 105 KlassInfoTable(int size, HeapWord* ref);
duke@435 106 ~KlassInfoTable();
ysr@446 107 bool record_instance(const oop obj);
duke@435 108 void iterate(KlassInfoClosure* cic);
ysr@446 109 bool allocation_failed() { return _buckets == NULL; }
duke@435 110 };
duke@435 111
duke@435 112 class KlassInfoHisto : public StackObj {
duke@435 113 private:
duke@435 114 GrowableArray<KlassInfoEntry*>* _elements;
duke@435 115 GrowableArray<KlassInfoEntry*>* elements() const { return _elements; }
duke@435 116 const char* _title;
duke@435 117 const char* title() const { return _title; }
duke@435 118 static int sort_helper(KlassInfoEntry** e1, KlassInfoEntry** e2);
duke@435 119 void print_elements(outputStream* st) const;
duke@435 120 public:
duke@435 121 enum {
duke@435 122 histo_initial_size = 1000
duke@435 123 };
duke@435 124 KlassInfoHisto(const char* title,
duke@435 125 int estimatedCount);
duke@435 126 ~KlassInfoHisto();
duke@435 127 void add(KlassInfoEntry* cie);
duke@435 128 void print_on(outputStream* st) const;
duke@435 129 void sort();
duke@435 130 };
duke@435 131
duke@435 132 #endif // SERVICES_KERNEL
duke@435 133
duke@435 134 class HeapInspection : public AllStatic {
duke@435 135 public:
ysr@1050 136 static void heap_inspection(outputStream* st, bool need_prologue) KERNEL_RETURN;
duke@435 137 static void find_instances_at_safepoint(klassOop k, GrowableArray<oop>* result) KERNEL_RETURN;
duke@435 138 };
stefank@2314 139
stefank@2314 140 #endif // SHARE_VM_MEMORY_HEAPINSPECTION_HPP

mercurial