1 #ifdef USE_PRAGMA_IDENT_HDR 2 #pragma ident "@(#)heapInspection.hpp 1.17 07/07/02 11:47:11 JVM" 3 #endif 4 /* 5 * Copyright 2002-2006 Sun Microsystems, Inc. All Rights Reserved. 6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 7 * 8 * This code is free software; you can redistribute it and/or modify it 9 * under the terms of the GNU General Public License version 2 only, as 10 * published by the Free Software Foundation. 11 * 12 * This code is distributed in the hope that it will be useful, but WITHOUT 13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 15 * version 2 for more details (a copy is included in the LICENSE file that 16 * accompanied this code). 17 * 18 * You should have received a copy of the GNU General Public License version 19 * 2 along with this work; if not, write to the Free Software Foundation, 20 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 21 * 22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 23 * CA 95054 USA or visit www.sun.com if you need additional information or 24 * have any questions. 25 * 26 */ 27 28 #ifndef SERVICES_KERNEL 29 30 31 // HeapInspection 32 33 // KlassInfoTable is a bucket hash table that 34 // maps klassOops to extra information: 35 // instance count and instance word size. 36 // 37 // A KlassInfoBucket is the head of a link list 38 // of KlassInfoEntry's 39 // 40 // KlassInfoHisto is a growable array of pointers 41 // to KlassInfoEntry's and is used to sort 42 // the entries. 43 44 class KlassInfoEntry: public CHeapObj { 45 private: 46 KlassInfoEntry* _next; 47 klassOop _klass; 48 long _instance_count; 49 size_t _instance_words; 50 51 public: 52 KlassInfoEntry(klassOop k, KlassInfoEntry* next) : 53 _klass(k), _instance_count(0), _instance_words(0), _next(next) 54 {} 55 KlassInfoEntry* next() { return _next; } 56 bool is_equal(klassOop k) { return k == _klass; } 57 klassOop klass() { return _klass; } 58 long count() { return _instance_count; } 59 void set_count(long ct) { _instance_count = ct; } 60 size_t words() { return _instance_words; } 61 void set_words(size_t wds) { _instance_words = wds; } 62 int compare(KlassInfoEntry* e1, KlassInfoEntry* e2); 63 void print_on(outputStream* st) const; 64 }; 65 66 class KlassInfoClosure: public StackObj { 67 public: 68 // Called for each KlassInfoEntry. 69 virtual void do_cinfo(KlassInfoEntry* cie) = 0; 70 }; 71 72 class KlassInfoBucket: public CHeapObj { 73 private: 74 KlassInfoEntry* _list; 75 KlassInfoEntry* list() { return _list; } 76 void set_list(KlassInfoEntry* l) { _list = l; } 77 public: 78 KlassInfoEntry* lookup(const klassOop k); 79 void initialize() { _list = NULL; } 80 void empty(); 81 void iterate(KlassInfoClosure* cic); 82 }; 83 84 class KlassInfoTable: public StackObj { 85 private: 86 int _size; 87 88 // An aligned reference address (typically the least 89 // address in the perm gen) used for hashing klass 90 // objects. 91 HeapWord* _ref; 92 93 KlassInfoBucket* _buckets; 94 uint hash(klassOop p); 95 KlassInfoEntry* lookup(const klassOop k); 96 97 public: 98 // Table size 99 enum { 100 cit_size = 20011 101 }; 102 KlassInfoTable(int size, HeapWord* ref); 103 ~KlassInfoTable(); 104 void record_instance(const oop obj); 105 void iterate(KlassInfoClosure* cic); 106 }; 107 108 class KlassInfoHisto : public StackObj { 109 private: 110 GrowableArray<KlassInfoEntry*>* _elements; 111 GrowableArray<KlassInfoEntry*>* elements() const { return _elements; } 112 const char* _title; 113 const char* title() const { return _title; } 114 static int sort_helper(KlassInfoEntry** e1, KlassInfoEntry** e2); 115 void print_elements(outputStream* st) const; 116 public: 117 enum { 118 histo_initial_size = 1000 119 }; 120 KlassInfoHisto(const char* title, 121 int estimatedCount); 122 ~KlassInfoHisto(); 123 void add(KlassInfoEntry* cie); 124 void print_on(outputStream* st) const; 125 void sort(); 126 }; 127 128 #endif // SERVICES_KERNEL 129 130 class HeapInspection : public AllStatic { 131 public: 132 static void heap_inspection(outputStream* st) KERNEL_RETURN; 133 static void find_instances_at_safepoint(klassOop k, GrowableArray<oop>* result) KERNEL_RETURN; 134 };