Tue, 23 Nov 2010 13:22:55 -0800
6989984: Use standard include model for Hospot
Summary: Replaced MakeDeps and the includeDB files with more standardized solutions.
Reviewed-by: coleenp, kvn, kamg
ysr@777 | 1 | /* |
johnc@2021 | 2 | * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved. |
ysr@777 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
ysr@777 | 4 | * |
ysr@777 | 5 | * This code is free software; you can redistribute it and/or modify it |
ysr@777 | 6 | * under the terms of the GNU General Public License version 2 only, as |
ysr@777 | 7 | * published by the Free Software Foundation. |
ysr@777 | 8 | * |
ysr@777 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
ysr@777 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
ysr@777 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
ysr@777 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
ysr@777 | 13 | * accompanied this code). |
ysr@777 | 14 | * |
ysr@777 | 15 | * You should have received a copy of the GNU General Public License version |
ysr@777 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
ysr@777 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
ysr@777 | 18 | * |
trims@1907 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
trims@1907 | 20 | * or visit www.oracle.com if you need additional information or have any |
trims@1907 | 21 | * questions. |
ysr@777 | 22 | * |
ysr@777 | 23 | */ |
ysr@777 | 24 | |
stefank@2314 | 25 | #include "precompiled.hpp" |
stefank@2314 | 26 | #include "gc_implementation/g1/concurrentG1Refine.hpp" |
stefank@2314 | 27 | #include "gc_implementation/g1/concurrentG1RefineThread.hpp" |
stefank@2314 | 28 | #include "gc_implementation/g1/g1CollectedHeap.inline.hpp" |
stefank@2314 | 29 | #include "gc_implementation/g1/g1CollectorPolicy.hpp" |
stefank@2314 | 30 | #include "gc_implementation/g1/g1RemSet.hpp" |
stefank@2314 | 31 | #include "gc_implementation/g1/heapRegionSeq.inline.hpp" |
stefank@2314 | 32 | #include "memory/space.inline.hpp" |
stefank@2314 | 33 | #include "runtime/atomic.hpp" |
stefank@2314 | 34 | #include "utilities/copy.hpp" |
ysr@777 | 35 | |
johnc@1325 | 36 | // Possible sizes for the card counts cache: odd primes that roughly double in size. |
johnc@1325 | 37 | // (See jvmtiTagMap.cpp). |
johnc@1325 | 38 | int ConcurrentG1Refine::_cc_cache_sizes[] = { |
johnc@1325 | 39 | 16381, 32771, 76831, 150001, 307261, |
johnc@1325 | 40 | 614563, 1228891, 2457733, 4915219, 9830479, |
johnc@1325 | 41 | 19660831, 39321619, 78643219, 157286461, -1 |
johnc@1325 | 42 | }; |
johnc@1325 | 43 | |
ysr@777 | 44 | ConcurrentG1Refine::ConcurrentG1Refine() : |
johnc@1325 | 45 | _card_counts(NULL), _card_epochs(NULL), |
johnc@1325 | 46 | _n_card_counts(0), _max_n_card_counts(0), |
johnc@1325 | 47 | _cache_size_index(0), _expand_card_counts(false), |
ysr@777 | 48 | _hot_cache(NULL), |
ysr@777 | 49 | _def_use_cache(false), _use_cache(false), |
johnc@1325 | 50 | _n_periods(0), |
iveresov@1229 | 51 | _threads(NULL), _n_threads(0) |
ysr@777 | 52 | { |
iveresov@1546 | 53 | |
iveresov@1546 | 54 | // Ergomonically select initial concurrent refinement parameters |
tonyp@1717 | 55 | if (FLAG_IS_DEFAULT(G1ConcRefinementGreenZone)) { |
tonyp@1717 | 56 | FLAG_SET_DEFAULT(G1ConcRefinementGreenZone, MAX2<int>(ParallelGCThreads, 1)); |
iveresov@1546 | 57 | } |
tonyp@1717 | 58 | set_green_zone(G1ConcRefinementGreenZone); |
iveresov@1546 | 59 | |
tonyp@1717 | 60 | if (FLAG_IS_DEFAULT(G1ConcRefinementYellowZone)) { |
tonyp@1717 | 61 | FLAG_SET_DEFAULT(G1ConcRefinementYellowZone, green_zone() * 3); |
iveresov@1546 | 62 | } |
tonyp@1717 | 63 | set_yellow_zone(MAX2<int>(G1ConcRefinementYellowZone, green_zone())); |
iveresov@1546 | 64 | |
tonyp@1717 | 65 | if (FLAG_IS_DEFAULT(G1ConcRefinementRedZone)) { |
tonyp@1717 | 66 | FLAG_SET_DEFAULT(G1ConcRefinementRedZone, yellow_zone() * 2); |
iveresov@1546 | 67 | } |
tonyp@1717 | 68 | set_red_zone(MAX2<int>(G1ConcRefinementRedZone, yellow_zone())); |
iveresov@1546 | 69 | _n_worker_threads = thread_num(); |
iveresov@1546 | 70 | // We need one extra thread to do the young gen rset size sampling. |
iveresov@1546 | 71 | _n_threads = _n_worker_threads + 1; |
iveresov@1546 | 72 | reset_threshold_step(); |
iveresov@1546 | 73 | |
iveresov@1546 | 74 | _threads = NEW_C_HEAP_ARRAY(ConcurrentG1RefineThread*, _n_threads); |
iveresov@1546 | 75 | int worker_id_offset = (int)DirtyCardQueueSet::num_par_ids(); |
iveresov@1546 | 76 | ConcurrentG1RefineThread *next = NULL; |
iveresov@1546 | 77 | for (int i = _n_threads - 1; i >= 0; i--) { |
iveresov@1546 | 78 | ConcurrentG1RefineThread* t = new ConcurrentG1RefineThread(this, next, worker_id_offset, i); |
iveresov@1546 | 79 | assert(t != NULL, "Conc refine should have been created"); |
iveresov@1546 | 80 | assert(t->cg1r() == this, "Conc refine thread should refer to this"); |
iveresov@1546 | 81 | _threads[i] = t; |
iveresov@1546 | 82 | next = t; |
ysr@777 | 83 | } |
ysr@777 | 84 | } |
ysr@777 | 85 | |
iveresov@1546 | 86 | void ConcurrentG1Refine::reset_threshold_step() { |
tonyp@1717 | 87 | if (FLAG_IS_DEFAULT(G1ConcRefinementThresholdStep)) { |
iveresov@1546 | 88 | _thread_threshold_step = (yellow_zone() - green_zone()) / (worker_thread_num() + 1); |
iveresov@1546 | 89 | } else { |
tonyp@1717 | 90 | _thread_threshold_step = G1ConcRefinementThresholdStep; |
iveresov@1230 | 91 | } |
iveresov@1546 | 92 | } |
iveresov@1546 | 93 | |
iveresov@1546 | 94 | int ConcurrentG1Refine::thread_num() { |
tonyp@1717 | 95 | return MAX2<int>((G1ConcRefinementThreads > 0) ? G1ConcRefinementThreads : ParallelGCThreads, 1); |
iveresov@1230 | 96 | } |
iveresov@1230 | 97 | |
ysr@777 | 98 | void ConcurrentG1Refine::init() { |
johnc@1325 | 99 | if (G1ConcRSLogCacheSize > 0) { |
johnc@1325 | 100 | _g1h = G1CollectedHeap::heap(); |
johnc@1325 | 101 | _max_n_card_counts = |
johnc@1325 | 102 | (unsigned) (_g1h->g1_reserved_obj_bytes() >> CardTableModRefBS::card_shift); |
johnc@1325 | 103 | |
johnc@1325 | 104 | size_t max_card_num = ((size_t)1 << (sizeof(unsigned)*BitsPerByte-1)) - 1; |
johnc@1325 | 105 | guarantee(_max_n_card_counts < max_card_num, "card_num representation"); |
johnc@1325 | 106 | |
johnc@1325 | 107 | int desired = _max_n_card_counts / InitialCacheFraction; |
johnc@1325 | 108 | for (_cache_size_index = 0; |
johnc@1325 | 109 | _cc_cache_sizes[_cache_size_index] >= 0; _cache_size_index++) { |
johnc@1325 | 110 | if (_cc_cache_sizes[_cache_size_index] >= desired) break; |
johnc@1325 | 111 | } |
johnc@1325 | 112 | _cache_size_index = MAX2(0, (_cache_size_index - 1)); |
johnc@1325 | 113 | |
johnc@1325 | 114 | int initial_size = _cc_cache_sizes[_cache_size_index]; |
johnc@1325 | 115 | if (initial_size < 0) initial_size = _max_n_card_counts; |
johnc@1325 | 116 | |
johnc@1325 | 117 | // Make sure we don't go bigger than we will ever need |
johnc@1325 | 118 | _n_card_counts = MIN2((unsigned) initial_size, _max_n_card_counts); |
johnc@1325 | 119 | |
johnc@1325 | 120 | _card_counts = NEW_C_HEAP_ARRAY(CardCountCacheEntry, _n_card_counts); |
johnc@1325 | 121 | _card_epochs = NEW_C_HEAP_ARRAY(CardEpochCacheEntry, _n_card_counts); |
johnc@1325 | 122 | |
johnc@1325 | 123 | Copy::fill_to_bytes(&_card_counts[0], |
johnc@1325 | 124 | _n_card_counts * sizeof(CardCountCacheEntry)); |
johnc@1325 | 125 | Copy::fill_to_bytes(&_card_epochs[0], _n_card_counts * sizeof(CardEpochCacheEntry)); |
johnc@1325 | 126 | |
johnc@1325 | 127 | ModRefBarrierSet* bs = _g1h->mr_bs(); |
ysr@777 | 128 | guarantee(bs->is_a(BarrierSet::CardTableModRef), "Precondition"); |
johnc@1325 | 129 | _ct_bs = (CardTableModRefBS*)bs; |
johnc@1325 | 130 | _ct_bot = _ct_bs->byte_for_const(_g1h->reserved_region().start()); |
johnc@1325 | 131 | |
ysr@777 | 132 | _def_use_cache = true; |
ysr@777 | 133 | _use_cache = true; |
ysr@777 | 134 | _hot_cache_size = (1 << G1ConcRSLogCacheSize); |
ysr@777 | 135 | _hot_cache = NEW_C_HEAP_ARRAY(jbyte*, _hot_cache_size); |
ysr@777 | 136 | _n_hot = 0; |
ysr@777 | 137 | _hot_cache_idx = 0; |
johnc@1324 | 138 | |
johnc@1324 | 139 | // For refining the cards in the hot cache in parallel |
johnc@1324 | 140 | int n_workers = (ParallelGCThreads > 0 ? |
johnc@1325 | 141 | _g1h->workers()->total_workers() : 1); |
johnc@1324 | 142 | _hot_cache_par_chunk_size = MAX2(1, _hot_cache_size / n_workers); |
johnc@1324 | 143 | _hot_cache_par_claimed_idx = 0; |
ysr@777 | 144 | } |
ysr@777 | 145 | } |
ysr@777 | 146 | |
iveresov@1229 | 147 | void ConcurrentG1Refine::stop() { |
iveresov@1229 | 148 | if (_threads != NULL) { |
iveresov@1229 | 149 | for (int i = 0; i < _n_threads; i++) { |
iveresov@1229 | 150 | _threads[i]->stop(); |
iveresov@1229 | 151 | } |
iveresov@1229 | 152 | } |
iveresov@1229 | 153 | } |
iveresov@1229 | 154 | |
iveresov@1546 | 155 | void ConcurrentG1Refine::reinitialize_threads() { |
iveresov@1546 | 156 | reset_threshold_step(); |
iveresov@1546 | 157 | if (_threads != NULL) { |
iveresov@1546 | 158 | for (int i = 0; i < _n_threads; i++) { |
iveresov@1546 | 159 | _threads[i]->initialize(); |
iveresov@1546 | 160 | } |
iveresov@1546 | 161 | } |
iveresov@1546 | 162 | } |
iveresov@1546 | 163 | |
ysr@777 | 164 | ConcurrentG1Refine::~ConcurrentG1Refine() { |
johnc@1325 | 165 | if (G1ConcRSLogCacheSize > 0) { |
ysr@777 | 166 | assert(_card_counts != NULL, "Logic"); |
johnc@1325 | 167 | FREE_C_HEAP_ARRAY(CardCountCacheEntry, _card_counts); |
johnc@1325 | 168 | assert(_card_epochs != NULL, "Logic"); |
johnc@1325 | 169 | FREE_C_HEAP_ARRAY(CardEpochCacheEntry, _card_epochs); |
ysr@777 | 170 | assert(_hot_cache != NULL, "Logic"); |
ysr@777 | 171 | FREE_C_HEAP_ARRAY(jbyte*, _hot_cache); |
ysr@777 | 172 | } |
iveresov@1229 | 173 | if (_threads != NULL) { |
iveresov@1229 | 174 | for (int i = 0; i < _n_threads; i++) { |
iveresov@1229 | 175 | delete _threads[i]; |
iveresov@1229 | 176 | } |
iveresov@1234 | 177 | FREE_C_HEAP_ARRAY(ConcurrentG1RefineThread*, _threads); |
ysr@777 | 178 | } |
ysr@777 | 179 | } |
ysr@777 | 180 | |
iveresov@1229 | 181 | void ConcurrentG1Refine::threads_do(ThreadClosure *tc) { |
iveresov@1229 | 182 | if (_threads != NULL) { |
iveresov@1229 | 183 | for (int i = 0; i < _n_threads; i++) { |
iveresov@1229 | 184 | tc->do_thread(_threads[i]); |
iveresov@1229 | 185 | } |
ysr@777 | 186 | } |
ysr@777 | 187 | } |
ysr@777 | 188 | |
johnc@1325 | 189 | bool ConcurrentG1Refine::is_young_card(jbyte* card_ptr) { |
johnc@1325 | 190 | HeapWord* start = _ct_bs->addr_for(card_ptr); |
johnc@1325 | 191 | HeapRegion* r = _g1h->heap_region_containing(start); |
johnc@1325 | 192 | if (r != NULL && r->is_young()) { |
johnc@1325 | 193 | return true; |
johnc@1325 | 194 | } |
johnc@1325 | 195 | // This card is not associated with a heap region |
johnc@1325 | 196 | // so can't be young. |
johnc@1325 | 197 | return false; |
ysr@777 | 198 | } |
ysr@777 | 199 | |
johnc@1325 | 200 | jbyte* ConcurrentG1Refine::add_card_count(jbyte* card_ptr, int* count, bool* defer) { |
johnc@1325 | 201 | unsigned new_card_num = ptr_2_card_num(card_ptr); |
johnc@1325 | 202 | unsigned bucket = hash(new_card_num); |
johnc@1325 | 203 | assert(0 <= bucket && bucket < _n_card_counts, "Bounds"); |
johnc@1325 | 204 | |
johnc@1325 | 205 | CardCountCacheEntry* count_ptr = &_card_counts[bucket]; |
johnc@1325 | 206 | CardEpochCacheEntry* epoch_ptr = &_card_epochs[bucket]; |
johnc@1325 | 207 | |
johnc@1325 | 208 | // We have to construct a new entry if we haven't updated the counts |
johnc@1325 | 209 | // during the current period, or if the count was updated for a |
johnc@1325 | 210 | // different card number. |
johnc@1325 | 211 | unsigned int new_epoch = (unsigned int) _n_periods; |
johnc@1325 | 212 | julong new_epoch_entry = make_epoch_entry(new_card_num, new_epoch); |
johnc@1325 | 213 | |
johnc@1325 | 214 | while (true) { |
johnc@1325 | 215 | // Fetch the previous epoch value |
johnc@1325 | 216 | julong prev_epoch_entry = epoch_ptr->_value; |
johnc@1325 | 217 | julong cas_res; |
johnc@1325 | 218 | |
johnc@1325 | 219 | if (extract_epoch(prev_epoch_entry) != new_epoch) { |
johnc@1325 | 220 | // This entry has not yet been updated during this period. |
johnc@1325 | 221 | // Note: we update the epoch value atomically to ensure |
johnc@1325 | 222 | // that there is only one winner that updates the cached |
johnc@1325 | 223 | // card_ptr value even though all the refine threads share |
johnc@1325 | 224 | // the same epoch value. |
johnc@1325 | 225 | |
johnc@1325 | 226 | cas_res = (julong) Atomic::cmpxchg((jlong) new_epoch_entry, |
johnc@1325 | 227 | (volatile jlong*)&epoch_ptr->_value, |
johnc@1325 | 228 | (jlong) prev_epoch_entry); |
johnc@1325 | 229 | |
johnc@1325 | 230 | if (cas_res == prev_epoch_entry) { |
johnc@1325 | 231 | // We have successfully won the race to update the |
johnc@1325 | 232 | // epoch and card_num value. Make it look like the |
johnc@1325 | 233 | // count and eviction count were previously cleared. |
johnc@1325 | 234 | count_ptr->_count = 1; |
johnc@1325 | 235 | count_ptr->_evict_count = 0; |
johnc@1325 | 236 | *count = 0; |
johnc@1325 | 237 | // We can defer the processing of card_ptr |
johnc@1325 | 238 | *defer = true; |
johnc@1325 | 239 | return card_ptr; |
johnc@1325 | 240 | } |
johnc@1325 | 241 | // We did not win the race to update the epoch field, so some other |
johnc@1325 | 242 | // thread must have done it. The value that gets returned by CAS |
johnc@1325 | 243 | // should be the new epoch value. |
johnc@1325 | 244 | assert(extract_epoch(cas_res) == new_epoch, "unexpected epoch"); |
johnc@1325 | 245 | // We could 'continue' here or just re-read the previous epoch value |
johnc@1325 | 246 | prev_epoch_entry = epoch_ptr->_value; |
johnc@1325 | 247 | } |
johnc@1325 | 248 | |
johnc@1325 | 249 | // The epoch entry for card_ptr has been updated during this period. |
johnc@1325 | 250 | unsigned old_card_num = extract_card_num(prev_epoch_entry); |
johnc@1325 | 251 | |
johnc@1325 | 252 | // The card count that will be returned to caller |
johnc@1325 | 253 | *count = count_ptr->_count; |
johnc@1325 | 254 | |
johnc@1325 | 255 | // Are we updating the count for the same card? |
johnc@1325 | 256 | if (new_card_num == old_card_num) { |
johnc@1325 | 257 | // Same card - just update the count. We could have more than one |
johnc@1325 | 258 | // thread racing to update count for the current card. It should be |
johnc@1325 | 259 | // OK not to use a CAS as the only penalty should be some missed |
johnc@1325 | 260 | // increments of the count which delays identifying the card as "hot". |
johnc@1325 | 261 | |
johnc@1325 | 262 | if (*count < max_jubyte) count_ptr->_count++; |
johnc@1325 | 263 | // We can defer the processing of card_ptr |
johnc@1325 | 264 | *defer = true; |
johnc@1325 | 265 | return card_ptr; |
johnc@1325 | 266 | } |
johnc@1325 | 267 | |
johnc@1325 | 268 | // Different card - evict old card info |
johnc@1325 | 269 | if (count_ptr->_evict_count < max_jubyte) count_ptr->_evict_count++; |
johnc@1325 | 270 | if (count_ptr->_evict_count > G1CardCountCacheExpandThreshold) { |
johnc@1325 | 271 | // Trigger a resize the next time we clear |
johnc@1325 | 272 | _expand_card_counts = true; |
johnc@1325 | 273 | } |
johnc@1325 | 274 | |
johnc@1325 | 275 | cas_res = (julong) Atomic::cmpxchg((jlong) new_epoch_entry, |
johnc@1325 | 276 | (volatile jlong*)&epoch_ptr->_value, |
johnc@1325 | 277 | (jlong) prev_epoch_entry); |
johnc@1325 | 278 | |
johnc@1325 | 279 | if (cas_res == prev_epoch_entry) { |
johnc@1325 | 280 | // We successfully updated the card num value in the epoch entry |
johnc@1325 | 281 | count_ptr->_count = 0; // initialize counter for new card num |
johnc@2021 | 282 | jbyte* old_card_ptr = card_num_2_ptr(old_card_num); |
johnc@1325 | 283 | |
johnc@1325 | 284 | // Even though the region containg the card at old_card_num was not |
johnc@1325 | 285 | // in the young list when old_card_num was recorded in the epoch |
johnc@1325 | 286 | // cache it could have been added to the free list and subsequently |
johnc@2021 | 287 | // added to the young list in the intervening time. See CR 6817995. |
johnc@2021 | 288 | // We do not deal with this case here - it will be handled in |
johnc@2021 | 289 | // HeapRegion::oops_on_card_seq_iterate_careful after it has been |
johnc@2021 | 290 | // determined that the region containing the card has been allocated |
johnc@2021 | 291 | // to, and it's safe to check the young type of the region. |
johnc@1325 | 292 | |
johnc@1325 | 293 | // We do not want to defer processing of card_ptr in this case |
johnc@1325 | 294 | // (we need to refine old_card_ptr and card_ptr) |
johnc@1325 | 295 | *defer = false; |
johnc@1325 | 296 | return old_card_ptr; |
johnc@1325 | 297 | } |
johnc@1325 | 298 | // Someone else beat us - try again. |
johnc@1325 | 299 | } |
johnc@1325 | 300 | } |
johnc@1325 | 301 | |
johnc@1325 | 302 | jbyte* ConcurrentG1Refine::cache_insert(jbyte* card_ptr, bool* defer) { |
johnc@1325 | 303 | int count; |
johnc@1325 | 304 | jbyte* cached_ptr = add_card_count(card_ptr, &count, defer); |
johnc@1325 | 305 | assert(cached_ptr != NULL, "bad cached card ptr"); |
johnc@1681 | 306 | |
johnc@2021 | 307 | // We've just inserted a card pointer into the card count cache |
johnc@2021 | 308 | // and got back the card that we just inserted or (evicted) the |
johnc@2021 | 309 | // previous contents of that count slot. |
johnc@1681 | 310 | |
johnc@2021 | 311 | // The card we got back could be in a young region. When the |
johnc@2021 | 312 | // returned card (if evicted) was originally inserted, we had |
johnc@2021 | 313 | // determined that its containing region was not young. However |
johnc@2021 | 314 | // it is possible for the region to be freed during a cleanup |
johnc@2021 | 315 | // pause, then reallocated and tagged as young which will result |
johnc@2021 | 316 | // in the returned card residing in a young region. |
johnc@2021 | 317 | // |
johnc@2021 | 318 | // We do not deal with this case here - the change from non-young |
johnc@2021 | 319 | // to young could be observed at any time - it will be handled in |
johnc@2021 | 320 | // HeapRegion::oops_on_card_seq_iterate_careful after it has been |
johnc@2021 | 321 | // determined that the region containing the card has been allocated |
johnc@2021 | 322 | // to. |
johnc@1325 | 323 | |
johnc@1325 | 324 | // The card pointer we obtained from card count cache is not hot |
johnc@1325 | 325 | // so do not store it in the cache; return it for immediate |
johnc@1325 | 326 | // refining. |
ysr@777 | 327 | if (count < G1ConcRSHotCardLimit) { |
johnc@1325 | 328 | return cached_ptr; |
ysr@777 | 329 | } |
johnc@1325 | 330 | |
johnc@2021 | 331 | // Otherwise, the pointer we got from the _card_counts cache is hot. |
ysr@777 | 332 | jbyte* res = NULL; |
ysr@777 | 333 | MutexLockerEx x(HotCardCache_lock, Mutex::_no_safepoint_check_flag); |
ysr@777 | 334 | if (_n_hot == _hot_cache_size) { |
ysr@777 | 335 | res = _hot_cache[_hot_cache_idx]; |
ysr@777 | 336 | _n_hot--; |
ysr@777 | 337 | } |
ysr@777 | 338 | // Now _n_hot < _hot_cache_size, and we can insert at _hot_cache_idx. |
johnc@1325 | 339 | _hot_cache[_hot_cache_idx] = cached_ptr; |
ysr@777 | 340 | _hot_cache_idx++; |
ysr@777 | 341 | if (_hot_cache_idx == _hot_cache_size) _hot_cache_idx = 0; |
ysr@777 | 342 | _n_hot++; |
johnc@1325 | 343 | |
johnc@2021 | 344 | // The card obtained from the hot card cache could be in a young |
johnc@2021 | 345 | // region. See above on how this can happen. |
johnc@1325 | 346 | |
ysr@777 | 347 | return res; |
ysr@777 | 348 | } |
ysr@777 | 349 | |
johnc@2060 | 350 | void ConcurrentG1Refine::clean_up_cache(int worker_i, |
johnc@2060 | 351 | G1RemSet* g1rs, |
johnc@2060 | 352 | DirtyCardQueue* into_cset_dcq) { |
ysr@777 | 353 | assert(!use_cache(), "cache should be disabled"); |
johnc@1324 | 354 | int start_idx; |
johnc@1324 | 355 | |
johnc@1324 | 356 | while ((start_idx = _hot_cache_par_claimed_idx) < _n_hot) { // read once |
johnc@1324 | 357 | int end_idx = start_idx + _hot_cache_par_chunk_size; |
johnc@1324 | 358 | |
johnc@1324 | 359 | if (start_idx == |
johnc@1324 | 360 | Atomic::cmpxchg(end_idx, &_hot_cache_par_claimed_idx, start_idx)) { |
johnc@1324 | 361 | // The current worker has successfully claimed the chunk [start_idx..end_idx) |
johnc@1324 | 362 | end_idx = MIN2(end_idx, _n_hot); |
johnc@1324 | 363 | for (int i = start_idx; i < end_idx; i++) { |
johnc@1324 | 364 | jbyte* entry = _hot_cache[i]; |
johnc@1324 | 365 | if (entry != NULL) { |
johnc@2060 | 366 | if (g1rs->concurrentRefineOneCard(entry, worker_i, true)) { |
johnc@2060 | 367 | // 'entry' contains references that point into the current |
johnc@2060 | 368 | // collection set. We need to record 'entry' in the DCQS |
johnc@2060 | 369 | // that's used for that purpose. |
johnc@2060 | 370 | // |
johnc@2060 | 371 | // The only time we care about recording cards that contain |
johnc@2060 | 372 | // references that point into the collection set is during |
johnc@2060 | 373 | // RSet updating while within an evacuation pause. |
johnc@2060 | 374 | // In this case worker_i should be the id of a GC worker thread |
johnc@2060 | 375 | assert(SafepointSynchronize::is_at_safepoint(), "not during an evacuation pause"); |
johnc@2060 | 376 | assert(worker_i < (int) DirtyCardQueueSet::num_par_ids(), "incorrect worker id"); |
johnc@2060 | 377 | into_cset_dcq->enqueue(entry); |
johnc@2060 | 378 | } |
johnc@1324 | 379 | } |
johnc@1324 | 380 | } |
ysr@777 | 381 | } |
ysr@777 | 382 | } |
ysr@777 | 383 | } |
ysr@777 | 384 | |
johnc@1325 | 385 | void ConcurrentG1Refine::expand_card_count_cache() { |
johnc@1325 | 386 | if (_n_card_counts < _max_n_card_counts) { |
johnc@1325 | 387 | int new_idx = _cache_size_index+1; |
johnc@1325 | 388 | int new_size = _cc_cache_sizes[new_idx]; |
johnc@1325 | 389 | if (new_size < 0) new_size = _max_n_card_counts; |
johnc@1325 | 390 | |
johnc@1325 | 391 | // Make sure we don't go bigger than we will ever need |
johnc@1325 | 392 | new_size = MIN2((unsigned) new_size, _max_n_card_counts); |
johnc@1325 | 393 | |
johnc@1325 | 394 | // Expand the card count and card epoch tables |
johnc@1325 | 395 | if (new_size > (int)_n_card_counts) { |
johnc@1325 | 396 | // We can just free and allocate a new array as we're |
johnc@1325 | 397 | // not interested in preserving the contents |
johnc@1325 | 398 | assert(_card_counts != NULL, "Logic!"); |
johnc@1325 | 399 | assert(_card_epochs != NULL, "Logic!"); |
johnc@1325 | 400 | FREE_C_HEAP_ARRAY(CardCountCacheEntry, _card_counts); |
johnc@1325 | 401 | FREE_C_HEAP_ARRAY(CardEpochCacheEntry, _card_epochs); |
johnc@1325 | 402 | _n_card_counts = new_size; |
johnc@1325 | 403 | _card_counts = NEW_C_HEAP_ARRAY(CardCountCacheEntry, _n_card_counts); |
johnc@1325 | 404 | _card_epochs = NEW_C_HEAP_ARRAY(CardEpochCacheEntry, _n_card_counts); |
johnc@1325 | 405 | _cache_size_index = new_idx; |
ysr@777 | 406 | } |
ysr@777 | 407 | } |
ysr@777 | 408 | } |
ysr@777 | 409 | |
johnc@1325 | 410 | void ConcurrentG1Refine::clear_and_record_card_counts() { |
johnc@1325 | 411 | if (G1ConcRSLogCacheSize == 0) return; |
johnc@1325 | 412 | |
johnc@1325 | 413 | #ifndef PRODUCT |
johnc@1325 | 414 | double start = os::elapsedTime(); |
johnc@1325 | 415 | #endif |
johnc@1325 | 416 | |
johnc@1325 | 417 | if (_expand_card_counts) { |
johnc@1325 | 418 | expand_card_count_cache(); |
johnc@1325 | 419 | _expand_card_counts = false; |
johnc@1325 | 420 | // Only need to clear the epochs. |
johnc@1325 | 421 | Copy::fill_to_bytes(&_card_epochs[0], _n_card_counts * sizeof(CardEpochCacheEntry)); |
ysr@777 | 422 | } |
ysr@777 | 423 | |
johnc@1325 | 424 | int this_epoch = (int) _n_periods; |
johnc@1325 | 425 | assert((this_epoch+1) <= max_jint, "to many periods"); |
johnc@1325 | 426 | // Update epoch |
johnc@1325 | 427 | _n_periods++; |
johnc@1325 | 428 | |
johnc@1325 | 429 | #ifndef PRODUCT |
johnc@1325 | 430 | double elapsed = os::elapsedTime() - start; |
johnc@1325 | 431 | _g1h->g1_policy()->record_cc_clear_time(elapsed * 1000.0); |
johnc@1325 | 432 | #endif |
ysr@777 | 433 | } |
tonyp@1454 | 434 | |
tonyp@1454 | 435 | void ConcurrentG1Refine::print_worker_threads_on(outputStream* st) const { |
tonyp@1454 | 436 | for (int i = 0; i < _n_threads; ++i) { |
tonyp@1454 | 437 | _threads[i]->print_on(st); |
tonyp@1454 | 438 | st->cr(); |
tonyp@1454 | 439 | } |
tonyp@1454 | 440 | } |