annotate src/share/vm/memory/heapInspection.hpp @ 453:c96030fff130

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