--- old/src/share/vm/gc/g1/g1HotCardCache.cpp 2016-04-06 17:17:21.030383627 +0200 +++ new/src/share/vm/gc/g1/g1HotCardCache.cpp 2016-04-06 17:17:20.890383625 +0200 @@ -36,7 +36,7 @@ _use_cache = true; _hot_cache_size = (size_t)1 << G1ConcRSLogCacheSize; - _hot_cache = ArrayAllocator::allocate(_hot_cache_size); + _hot_cache = ArrayAllocator::allocate(_hot_cache_size); reset_hot_cache_internal(); @@ -51,12 +51,12 @@ G1HotCardCache::~G1HotCardCache() { if (default_use_cache()) { assert(_hot_cache != NULL, "Logic"); - ArrayAllocator::free(_hot_cache, _hot_cache_size); + ArrayAllocator::free(_hot_cache, _hot_cache_size); _hot_cache = NULL; } } -jbyte* G1HotCardCache::insert(jbyte* card_ptr) { +volatile jbyte* G1HotCardCache::insert(volatile jbyte* card_ptr) { uint count = _card_counts.add_card_count(card_ptr); if (!_card_counts.is_hot(count)) { // The card is not hot so do not store it in the cache; @@ -66,7 +66,7 @@ // Otherwise, the card is hot. size_t index = Atomic::add(1, &_hot_cache_idx) - 1; size_t masked_index = index & (_hot_cache_size - 1); - jbyte* current_ptr = _hot_cache[masked_index]; + volatile jbyte* current_ptr = _hot_cache[masked_index]; // Try to store the new card pointer into the cache. Compare-and-swap to guard // against the unlikely event of a race resulting in another card pointer to @@ -74,9 +74,9 @@ // card_ptr in favor of the other option, which would be starting over. This // should be OK since card_ptr will likely be the older card already when/if // this ever happens. - jbyte* previous_ptr = (jbyte*)Atomic::cmpxchg_ptr(card_ptr, - &_hot_cache[masked_index], - current_ptr); + volatile jbyte* previous_ptr = (volatile jbyte*)Atomic::cmpxchg_ptr((jbyte*)card_ptr, + &_hot_cache[masked_index], + (jbyte*)current_ptr); return (previous_ptr == current_ptr) ? previous_ptr : card_ptr; } @@ -93,7 +93,7 @@ // The current worker has successfully claimed the chunk [start_idx..end_idx) end_idx = MIN2(end_idx, _hot_cache_size); for (size_t i = start_idx; i < end_idx; i++) { - jbyte* card_ptr = _hot_cache[i]; + volatile jbyte* card_ptr = _hot_cache[i]; if (card_ptr != NULL) { bool result = cl->do_card_ptr(card_ptr, worker_i); assert(result, "Closure should always return true");