src/hotspot/share/gc/g1/g1HotCardCache.cpp
changeset 59319 9ee940f1de90
parent 59252 623722a6aeb9
equal deleted inserted replaced
59318:70021dbed82b 59319:9ee940f1de90
    30 #include "runtime/atomic.hpp"
    30 #include "runtime/atomic.hpp"
    31 
    31 
    32 G1HotCardCache::G1HotCardCache(G1CollectedHeap *g1h):
    32 G1HotCardCache::G1HotCardCache(G1CollectedHeap *g1h):
    33   _g1h(g1h), _use_cache(false), _card_counts(g1h),
    33   _g1h(g1h), _use_cache(false), _card_counts(g1h),
    34   _hot_cache(NULL), _hot_cache_size(0), _hot_cache_par_chunk_size(0),
    34   _hot_cache(NULL), _hot_cache_size(0), _hot_cache_par_chunk_size(0),
    35   _hot_cache_idx(0), _hot_cache_par_claimed_idx(0)
    35   _hot_cache_idx(0), _hot_cache_par_claimed_idx(0), _cache_wrapped_around(false)
    36 {}
    36 {}
    37 
    37 
    38 void G1HotCardCache::initialize(G1RegionToSpaceMapper* card_counts_storage) {
    38 void G1HotCardCache::initialize(G1RegionToSpaceMapper* card_counts_storage) {
    39   if (default_use_cache()) {
    39   if (default_use_cache()) {
    40     _use_cache = true;
    40     _use_cache = true;
    45     reset_hot_cache_internal();
    45     reset_hot_cache_internal();
    46 
    46 
    47     // For refining the cards in the hot cache in parallel
    47     // For refining the cards in the hot cache in parallel
    48     _hot_cache_par_chunk_size = ClaimChunkSize;
    48     _hot_cache_par_chunk_size = ClaimChunkSize;
    49     _hot_cache_par_claimed_idx = 0;
    49     _hot_cache_par_claimed_idx = 0;
       
    50 
       
    51     _cache_wrapped_around = false;
    50 
    52 
    51     _card_counts.initialize(card_counts_storage);
    53     _card_counts.initialize(card_counts_storage);
    52   }
    54   }
    53 }
    55 }
    54 
    56 
    67     // return it for immediate refining.
    69     // return it for immediate refining.
    68     return card_ptr;
    70     return card_ptr;
    69   }
    71   }
    70   // Otherwise, the card is hot.
    72   // Otherwise, the card is hot.
    71   size_t index = Atomic::add(&_hot_cache_idx, 1u) - 1;
    73   size_t index = Atomic::add(&_hot_cache_idx, 1u) - 1;
       
    74   if (index == _hot_cache_size) {
       
    75     // Can use relaxed store because all racing threads are writing the same
       
    76     // value and there aren't any concurrent readers.
       
    77     Atomic::store(&_cache_wrapped_around, true);
       
    78   }
    72   size_t masked_index = index & (_hot_cache_size - 1);
    79   size_t masked_index = index & (_hot_cache_size - 1);
    73   CardValue* current_ptr = _hot_cache[masked_index];
    80   CardValue* current_ptr = _hot_cache[masked_index];
    74 
    81 
    75   // Try to store the new card pointer into the cache. Compare-and-swap to guard
    82   // Try to store the new card pointer into the cache. Compare-and-swap to guard
    76   // against the unlikely event of a race resulting in another card pointer to
    83   // against the unlikely event of a race resulting in another card pointer to