Wed, 30 Sep 2009 14:50:51 -0400
6890137: G1: revamp reachable object dump
Summary: Revamp the reachable object dump debugging facility.
Reviewed-by: jmasa, apetrusenko
1 /*
2 * Copyright 2001-2009 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 *
23 */
25 // Forward decl
26 class ConcurrentG1RefineThread;
27 class G1RemSet;
29 class ConcurrentG1Refine: public CHeapObj {
30 ConcurrentG1RefineThread** _threads;
31 int _n_threads;
33 // The cache for card refinement.
34 bool _use_cache;
35 bool _def_use_cache;
37 size_t _n_periods; // Used as clearing epoch
39 // An evicting cache of the number of times each card
40 // is accessed. Reduces, but does not eliminate, the amount
41 // of duplicated processing of dirty cards.
43 enum SomePrivateConstants {
44 epoch_bits = 32,
45 card_num_shift = epoch_bits,
46 epoch_mask = AllBits,
47 card_num_mask = AllBits,
49 // The initial cache size is approximately this fraction
50 // of a maximal cache (i.e. the size needed for all cards
51 // in the heap)
52 InitialCacheFraction = 512
53 };
55 const static julong card_num_mask_in_place =
56 (julong) card_num_mask << card_num_shift;
58 typedef struct {
59 julong _value; // | card_num | epoch |
60 } CardEpochCacheEntry;
62 julong make_epoch_entry(unsigned int card_num, unsigned int epoch) {
63 assert(0 <= card_num && card_num < _max_n_card_counts, "Bounds");
64 assert(0 <= epoch && epoch <= _n_periods, "must be");
66 return ((julong) card_num << card_num_shift) | epoch;
67 }
69 unsigned int extract_epoch(julong v) {
70 return (v & epoch_mask);
71 }
73 unsigned int extract_card_num(julong v) {
74 return (v & card_num_mask_in_place) >> card_num_shift;
75 }
77 typedef struct {
78 unsigned char _count;
79 unsigned char _evict_count;
80 } CardCountCacheEntry;
82 CardCountCacheEntry* _card_counts;
83 CardEpochCacheEntry* _card_epochs;
85 // The current number of buckets in the card count cache
86 unsigned _n_card_counts;
88 // The max number of buckets required for the number of
89 // cards for the entire reserved heap
90 unsigned _max_n_card_counts;
92 // Possible sizes of the cache: odd primes that roughly double in size.
93 // (See jvmtiTagMap.cpp).
94 static int _cc_cache_sizes[];
96 // The index in _cc_cache_sizes corresponding to the size of
97 // _card_counts.
98 int _cache_size_index;
100 bool _expand_card_counts;
102 const jbyte* _ct_bot;
104 jbyte** _hot_cache;
105 int _hot_cache_size;
106 int _n_hot;
107 int _hot_cache_idx;
109 int _hot_cache_par_chunk_size;
110 volatile int _hot_cache_par_claimed_idx;
112 // Needed to workaround 6817995
113 CardTableModRefBS* _ct_bs;
114 G1CollectedHeap* _g1h;
116 // Expands the array that holds the card counts to the next size up
117 void expand_card_count_cache();
119 // hash a given key (index of card_ptr) with the specified size
120 static unsigned int hash(size_t key, int size) {
121 return (unsigned int) key % size;
122 }
124 // hash a given key (index of card_ptr)
125 unsigned int hash(size_t key) {
126 return hash(key, _n_card_counts);
127 }
129 unsigned ptr_2_card_num(jbyte* card_ptr) {
130 return (unsigned) (card_ptr - _ct_bot);
131 }
133 jbyte* card_num_2_ptr(unsigned card_num) {
134 return (jbyte*) (_ct_bot + card_num);
135 }
137 // Returns the count of this card after incrementing it.
138 jbyte* add_card_count(jbyte* card_ptr, int* count, bool* defer);
140 // Returns true if this card is in a young region
141 bool is_young_card(jbyte* card_ptr);
143 public:
144 ConcurrentG1Refine();
145 ~ConcurrentG1Refine();
147 void init(); // Accomplish some initialization that has to wait.
148 void stop();
150 // Iterate over the conc refine threads
151 void threads_do(ThreadClosure *tc);
153 // If this is the first entry for the slot, writes into the cache and
154 // returns NULL. If it causes an eviction, returns the evicted pointer.
155 // Otherwise, its a cache hit, and returns NULL.
156 jbyte* cache_insert(jbyte* card_ptr, bool* defer);
158 // Process the cached entries.
159 void clean_up_cache(int worker_i, G1RemSet* g1rs);
161 // Set up for parallel processing of the cards in the hot cache
162 void clear_hot_cache_claimed_index() {
163 _hot_cache_par_claimed_idx = 0;
164 }
166 // Discard entries in the hot cache.
167 void clear_hot_cache() {
168 _hot_cache_idx = 0; _n_hot = 0;
169 }
171 bool hot_cache_is_empty() { return _n_hot == 0; }
173 bool use_cache() { return _use_cache; }
174 void set_use_cache(bool b) {
175 if (b) _use_cache = _def_use_cache;
176 else _use_cache = false;
177 }
179 void clear_and_record_card_counts();
181 static size_t thread_num();
183 void print_worker_threads_on(outputStream* st) const;
184 };