20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "gc_implementation/g1/dirtyCardQueue.hpp"
27 #include "gc_implementation/g1/g1CollectedHeap.inline.hpp"
28 #include "gc_implementation/g1/g1HotCardCache.hpp"
29 #include "gc_implementation/g1/g1RemSet.hpp"
30 #include "runtime/atomic.inline.hpp"
31
32 G1HotCardCache::G1HotCardCache(G1CollectedHeap *g1h):
33 _g1h(g1h), _hot_cache(NULL), _use_cache(false), _card_counts(g1h) {}
34
35 void G1HotCardCache::initialize(G1RegionToSpaceMapper* card_counts_storage) {
36 if (default_use_cache()) {
37 _use_cache = true;
38
39 _hot_cache_size = (size_t)1 << G1ConcRSLogCacheSize;
40 _hot_cache = NEW_C_HEAP_ARRAY(jbyte*, _hot_cache_size, mtGC);
41
42 reset_hot_cache_internal();
43
44 // For refining the cards in the hot cache in parallel
45 _hot_cache_par_chunk_size = ClaimChunkSize;
46 _hot_cache_par_claimed_idx = 0;
47
48 _card_counts.initialize(card_counts_storage);
49 }
50 }
51
52 G1HotCardCache::~G1HotCardCache() {
53 if (default_use_cache()) {
54 assert(_hot_cache != NULL, "Logic");
55 FREE_C_HEAP_ARRAY(jbyte*, _hot_cache);
56 }
57 }
58
59 jbyte* G1HotCardCache::insert(jbyte* card_ptr) {
60 uint count = _card_counts.add_card_count(card_ptr);
61 if (!_card_counts.is_hot(count)) {
62 // The card is not hot so do not store it in the cache;
63 // return it for immediate refining.
64 return card_ptr;
65 }
66 // Otherwise, the card is hot.
67 size_t index = Atomic::add(1, &_hot_cache_idx) - 1;
68 size_t masked_index = index & (_hot_cache_size - 1);
69 jbyte* current_ptr = _hot_cache[masked_index];
70
71 // Try to store the new card pointer into the cache. Compare-and-swap to guard
72 // against the unlikely event of a race resulting in another card pointer to
73 // have already been written to the cache. In this case we will return
74 // card_ptr in favor of the other option, which would be starting over. This
75 // should be OK since card_ptr will likely be the older card already when/if
|
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "gc_implementation/g1/dirtyCardQueue.hpp"
27 #include "gc_implementation/g1/g1CollectedHeap.inline.hpp"
28 #include "gc_implementation/g1/g1HotCardCache.hpp"
29 #include "gc_implementation/g1/g1RemSet.hpp"
30 #include "runtime/atomic.inline.hpp"
31
32 G1HotCardCache::G1HotCardCache(G1CollectedHeap *g1h):
33 _g1h(g1h), _hot_cache(NULL), _use_cache(false), _card_counts(g1h) {}
34
35 void G1HotCardCache::initialize(G1RegionToSpaceMapper* card_counts_storage) {
36 if (default_use_cache()) {
37 _use_cache = true;
38
39 _hot_cache_size = (size_t)1 << G1ConcRSLogCacheSize;
40 _hot_cache = _hot_cache_memory.allocate(_hot_cache_size);
41
42 reset_hot_cache_internal();
43
44 // For refining the cards in the hot cache in parallel
45 _hot_cache_par_chunk_size = ClaimChunkSize;
46 _hot_cache_par_claimed_idx = 0;
47
48 _card_counts.initialize(card_counts_storage);
49 }
50 }
51
52 G1HotCardCache::~G1HotCardCache() {
53 if (default_use_cache()) {
54 assert(_hot_cache != NULL, "Logic");
55 _hot_cache_memory.free();
56 _hot_cache = NULL;
57 }
58 }
59
60 jbyte* G1HotCardCache::insert(jbyte* card_ptr) {
61 uint count = _card_counts.add_card_count(card_ptr);
62 if (!_card_counts.is_hot(count)) {
63 // The card is not hot so do not store it in the cache;
64 // return it for immediate refining.
65 return card_ptr;
66 }
67 // Otherwise, the card is hot.
68 size_t index = Atomic::add(1, &_hot_cache_idx) - 1;
69 size_t masked_index = index & (_hot_cache_size - 1);
70 jbyte* current_ptr = _hot_cache[masked_index];
71
72 // Try to store the new card pointer into the cache. Compare-and-swap to guard
73 // against the unlikely event of a race resulting in another card pointer to
74 // have already been written to the cache. In this case we will return
75 // card_ptr in favor of the other option, which would be starting over. This
76 // should be OK since card_ptr will likely be the older card already when/if
|