Mercurial > hg > graal-compiler
comparison 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 |
comparison
equal
deleted
inserted
replaced
889:15c5903cf9e1 | 890:6cb8e9df7174 |
---|---|
27 class G1RemSet; | 27 class G1RemSet; |
28 | 28 |
29 class ConcurrentG1Refine: public CHeapObj { | 29 class ConcurrentG1Refine: public CHeapObj { |
30 ConcurrentG1RefineThread** _threads; | 30 ConcurrentG1RefineThread** _threads; |
31 int _n_threads; | 31 int _n_threads; |
32 | |
32 // The cache for card refinement. | 33 // The cache for card refinement. |
33 bool _use_cache; | 34 bool _use_cache; |
34 bool _def_use_cache; | 35 bool _def_use_cache; |
35 size_t _n_periods; | |
36 size_t _total_cards; | |
37 size_t _total_travs; | |
38 | 36 |
39 unsigned char* _card_counts; | 37 size_t _n_periods; // Used as clearing epoch |
40 unsigned _n_card_counts; | 38 |
41 const jbyte* _ct_bot; | 39 // An evicting cache of the number of times each card |
42 unsigned* _cur_card_count_histo; | 40 // is accessed. Reduces, but does not eliminate, the amount |
43 unsigned* _cum_card_count_histo; | 41 // of duplicated processing of dirty cards. |
42 | |
43 enum SomePrivateConstants { | |
44 epoch_bits = 32, | |
45 card_num_shift = epoch_bits, | |
46 epoch_mask = AllBits, | |
47 card_num_mask = AllBits, | |
48 | |
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 }; | |
54 | |
55 const static julong card_num_mask_in_place = | |
56 (julong) card_num_mask << card_num_shift; | |
57 | |
58 typedef struct { | |
59 julong _value; // | card_num | epoch | | |
60 } CardEpochCacheEntry; | |
61 | |
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"); | |
65 | |
66 return ((julong) card_num << card_num_shift) | epoch; | |
67 } | |
68 | |
69 unsigned int extract_epoch(julong v) { | |
70 return (v & epoch_mask); | |
71 } | |
72 | |
73 unsigned int extract_card_num(julong v) { | |
74 return (v & card_num_mask_in_place) >> card_num_shift; | |
75 } | |
76 | |
77 typedef struct { | |
78 unsigned char _count; | |
79 unsigned char _evict_count; | |
80 } CardCountCacheEntry; | |
81 | |
82 CardCountCacheEntry* _card_counts; | |
83 CardEpochCacheEntry* _card_epochs; | |
84 | |
85 // The current number of buckets in the card count cache | |
86 unsigned _n_card_counts; | |
87 | |
88 // The max number of buckets required for the number of | |
89 // cards for the entire reserved heap | |
90 unsigned _max_n_card_counts; | |
91 | |
92 // Possible sizes of the cache: odd primes that roughly double in size. | |
93 // (See jvmtiTagMap.cpp). | |
94 static int _cc_cache_sizes[]; | |
95 | |
96 // The index in _cc_cache_sizes corresponding to the size of | |
97 // _card_counts. | |
98 int _cache_size_index; | |
99 | |
100 bool _expand_card_counts; | |
101 | |
102 const jbyte* _ct_bot; | |
44 | 103 |
45 jbyte** _hot_cache; | 104 jbyte** _hot_cache; |
46 int _hot_cache_size; | 105 int _hot_cache_size; |
47 int _n_hot; | 106 int _n_hot; |
48 int _hot_cache_idx; | 107 int _hot_cache_idx; |
49 | 108 |
50 int _hot_cache_par_chunk_size; | 109 int _hot_cache_par_chunk_size; |
51 volatile int _hot_cache_par_claimed_idx; | 110 volatile int _hot_cache_par_claimed_idx; |
52 | 111 |
112 // Needed to workaround 6817995 | |
113 CardTableModRefBS* _ct_bs; | |
114 G1CollectedHeap* _g1h; | |
115 | |
116 // Expands the array that holds the card counts to the next size up | |
117 void expand_card_count_cache(); | |
118 | |
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 } | |
123 | |
124 // hash a given key (index of card_ptr) | |
125 unsigned int hash(size_t key) { | |
126 return hash(key, _n_card_counts); | |
127 } | |
128 | |
129 unsigned ptr_2_card_num(jbyte* card_ptr) { | |
130 return (unsigned) (card_ptr - _ct_bot); | |
131 } | |
132 | |
133 jbyte* card_num_2_ptr(unsigned card_num) { | |
134 return (jbyte*) (_ct_bot + card_num); | |
135 } | |
136 | |
53 // Returns the count of this card after incrementing it. | 137 // Returns the count of this card after incrementing it. |
54 int add_card_count(jbyte* card_ptr); | 138 jbyte* add_card_count(jbyte* card_ptr, int* count, bool* defer); |
55 | 139 |
56 void print_card_count_histo_range(unsigned* histo, int from, int to, | 140 // Returns true if this card is in a young region |
57 float& cum_card_pct, | 141 bool is_young_card(jbyte* card_ptr); |
58 float& cum_travs_pct); | 142 |
59 public: | 143 public: |
60 ConcurrentG1Refine(); | 144 ConcurrentG1Refine(); |
61 ~ConcurrentG1Refine(); | 145 ~ConcurrentG1Refine(); |
62 | 146 |
63 void init(); // Accomplish some initialization that has to wait. | 147 void init(); // Accomplish some initialization that has to wait. |
67 void threads_do(ThreadClosure *tc); | 151 void threads_do(ThreadClosure *tc); |
68 | 152 |
69 // If this is the first entry for the slot, writes into the cache and | 153 // If this is the first entry for the slot, writes into the cache and |
70 // returns NULL. If it causes an eviction, returns the evicted pointer. | 154 // returns NULL. If it causes an eviction, returns the evicted pointer. |
71 // Otherwise, its a cache hit, and returns NULL. | 155 // Otherwise, its a cache hit, and returns NULL. |
72 jbyte* cache_insert(jbyte* card_ptr); | 156 jbyte* cache_insert(jbyte* card_ptr, bool* defer); |
73 | 157 |
74 // Process the cached entries. | 158 // Process the cached entries. |
75 void clean_up_cache(int worker_i, G1RemSet* g1rs); | 159 void clean_up_cache(int worker_i, G1RemSet* g1rs); |
76 | 160 |
77 // Set up for parallel processing of the cards in the hot cache | 161 // Set up for parallel processing of the cards in the hot cache |
91 if (b) _use_cache = _def_use_cache; | 175 if (b) _use_cache = _def_use_cache; |
92 else _use_cache = false; | 176 else _use_cache = false; |
93 } | 177 } |
94 | 178 |
95 void clear_and_record_card_counts(); | 179 void clear_and_record_card_counts(); |
96 void print_final_card_counts(); | |
97 | 180 |
98 static size_t thread_num(); | 181 static size_t thread_num(); |
99 }; | 182 }; |