index

src/share/vm/gc_implementation/g1/g1HotCardCache.cpp

Print this page
rev 7184 : 6979279
rev 7185 : [mq]: rev1


  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 = (1 << G1ConcRSLogCacheSize);
  40     _hot_cache = NEW_C_HEAP_ARRAY(jbyte*, _hot_cache_size, mtGC);
  41 
  42     _n_hot = 0;
  43     _hot_cache_idx = 0;
  44 
  45     // For refining the cards in the hot cache in parallel

  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, mtGC);
  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   }


  81     _hot_cache_idx = 0;
  82   }
  83   _n_hot++;
  84 
  85   return res;
  86 }
  87 
  88 void G1HotCardCache::drain(uint worker_i,
  89                            G1RemSet* g1rs,
  90                            DirtyCardQueue* into_cset_dcq) {
  91   if (!default_use_cache()) {
  92     assert(_hot_cache == NULL, "Logic");
  93     return;
  94   }
  95 
  96   assert(_hot_cache != NULL, "Logic");
  97   assert(!use_cache(), "cache should be disabled");
  98   int start_idx;
  99 
 100   while ((start_idx = _hot_cache_par_claimed_idx) < _n_hot) { // read once
 101     int end_idx = start_idx + ClaimChunkSize;
 102 
 103     if (start_idx ==
 104         Atomic::cmpxchg(end_idx, &_hot_cache_par_claimed_idx, start_idx)) {
 105       // The current worker has successfully claimed the chunk [start_idx..end_idx)
 106       end_idx = MIN2(end_idx, _n_hot);
 107       for (int i = start_idx; i < end_idx; i++) {
 108         jbyte* card_ptr = _hot_cache[i];
 109         if (card_ptr != NULL) {
 110           if (g1rs->refine_card(card_ptr, worker_i, true)) {
 111             // The part of the heap spanned by the card contains references
 112             // that point into the current collection set.
 113             // We need to record the card pointer in the DirtyCardQueueSet
 114             // that we use for such cards.
 115             //
 116             // The only time we care about recording cards that contain
 117             // references that point into the collection set is during
 118             // RSet updating while within an evacuation pause.
 119             // In this case worker_i should be the id of a GC worker thread
 120             assert(SafepointSynchronize::is_at_safepoint(), "Should be at a safepoint");
 121             assert(worker_i < ParallelGCThreads,


  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 = (1 << G1ConcRSLogCacheSize);
  40     _hot_cache = NEW_C_HEAP_ARRAY(jbyte*, _hot_cache_size, mtGC);
  41 
  42     _n_hot = 0;
  43     _hot_cache_idx = 0;
  44 
  45     // For refining the cards in the hot cache in parallel
  46     _hot_cache_par_chunk_size = ClaimChunkSize;
  47     _hot_cache_par_claimed_idx = 0;
  48 
  49     _card_counts.initialize(card_counts_storage);
  50   }
  51 }
  52 
  53 G1HotCardCache::~G1HotCardCache() {
  54   if (default_use_cache()) {
  55     assert(_hot_cache != NULL, "Logic");
  56     FREE_C_HEAP_ARRAY(jbyte*, _hot_cache, mtGC);
  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   }


  82     _hot_cache_idx = 0;
  83   }
  84   _n_hot++;
  85 
  86   return res;
  87 }
  88 
  89 void G1HotCardCache::drain(uint worker_i,
  90                            G1RemSet* g1rs,
  91                            DirtyCardQueue* into_cset_dcq) {
  92   if (!default_use_cache()) {
  93     assert(_hot_cache == NULL, "Logic");
  94     return;
  95   }
  96 
  97   assert(_hot_cache != NULL, "Logic");
  98   assert(!use_cache(), "cache should be disabled");
  99   int start_idx;
 100 
 101   while ((start_idx = _hot_cache_par_claimed_idx) < _n_hot) { // read once
 102     int end_idx = start_idx + _hot_cache_par_chunk_size;
 103 
 104     if (start_idx ==
 105         Atomic::cmpxchg(end_idx, &_hot_cache_par_claimed_idx, start_idx)) {
 106       // The current worker has successfully claimed the chunk [start_idx..end_idx)
 107       end_idx = MIN2(end_idx, _n_hot);
 108       for (int i = start_idx; i < end_idx; i++) {
 109         jbyte* card_ptr = _hot_cache[i];
 110         if (card_ptr != NULL) {
 111           if (g1rs->refine_card(card_ptr, worker_i, true)) {
 112             // The part of the heap spanned by the card contains references
 113             // that point into the current collection set.
 114             // We need to record the card pointer in the DirtyCardQueueSet
 115             // that we use for such cards.
 116             //
 117             // The only time we care about recording cards that contain
 118             // references that point into the collection set is during
 119             // RSet updating while within an evacuation pause.
 120             // In this case worker_i should be the id of a GC worker thread
 121             assert(SafepointSynchronize::is_at_safepoint(), "Should be at a safepoint");
 122             assert(worker_i < ParallelGCThreads,
index