--- old/src/hotspot/share/gc/g1/g1HotCardCache.cpp 2019-10-22 14:06:41.581275329 +0200 +++ new/src/hotspot/share/gc/g1/g1HotCardCache.cpp 2019-10-22 14:06:41.241264657 +0200 @@ -32,7 +32,7 @@ G1HotCardCache::G1HotCardCache(G1CollectedHeap *g1h): _g1h(g1h), _use_cache(false), _card_counts(g1h), _hot_cache(NULL), _hot_cache_size(0), _hot_cache_par_chunk_size(0), - _hot_cache_idx(0), _hot_cache_par_claimed_idx(0) + _hot_cache_idx(0), _hot_cache_par_claimed_idx(0), _cache_wrapped_around(false) {} void G1HotCardCache::initialize(G1RegionToSpaceMapper* card_counts_storage) { @@ -48,6 +48,8 @@ _hot_cache_par_chunk_size = ClaimChunkSize; _hot_cache_par_claimed_idx = 0; + _cache_wrapped_around = false; + _card_counts.initialize(card_counts_storage); } } @@ -69,6 +71,11 @@ } // Otherwise, the card is hot. size_t index = Atomic::add(1u, &_hot_cache_idx) - 1; + // This does not need an atomic update. Racing threads may at most write the + // same value. + if (index == _hot_cache_size) { + _cache_wrapped_around = true; + } size_t masked_index = index & (_hot_cache_size - 1); CardValue* current_ptr = _hot_cache[masked_index];