annotate src/share/vm/gc_implementation/g1/concurrentG1Refine.hpp @ 890:6cb8e9df7174

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