< prev index next >

src/hotspot/share/gc/g1/g1HotCardCache.cpp

Print this page




  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(1u, &_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
  76   // this ever happens.
  77   jbyte* previous_ptr = (jbyte*)Atomic::cmpxchg_ptr(card_ptr,
  78                                                     &_hot_cache[masked_index],
  79                                                     current_ptr);
  80   return (previous_ptr == current_ptr) ? previous_ptr : card_ptr;
  81 }
  82 
  83 void G1HotCardCache::drain(CardTableEntryClosure* cl, uint worker_i) {
  84   assert(default_use_cache(), "Drain only necessary if we use the hot card cache.");
  85 
  86   assert(_hot_cache != NULL, "Logic");
  87   assert(!use_cache(), "cache should be disabled");
  88 
  89   while (_hot_cache_par_claimed_idx < _hot_cache_size) {
  90     size_t end_idx = Atomic::add(_hot_cache_par_chunk_size,
  91                                  &_hot_cache_par_claimed_idx);
  92     size_t start_idx = end_idx - _hot_cache_par_chunk_size;
  93     // The current worker has successfully claimed the chunk [start_idx..end_idx)
  94     end_idx = MIN2(end_idx, _hot_cache_size);
  95     for (size_t i = start_idx; i < end_idx; i++) {
  96       jbyte* card_ptr = _hot_cache[i];
  97       if (card_ptr != NULL) {


  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(1u, &_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
  76   // this ever happens.
  77   jbyte* previous_ptr = Atomic::cmpxchg(card_ptr,
  78                                         &_hot_cache[masked_index],
  79                                         current_ptr);
  80   return (previous_ptr == current_ptr) ? previous_ptr : card_ptr;
  81 }
  82 
  83 void G1HotCardCache::drain(CardTableEntryClosure* cl, uint worker_i) {
  84   assert(default_use_cache(), "Drain only necessary if we use the hot card cache.");
  85 
  86   assert(_hot_cache != NULL, "Logic");
  87   assert(!use_cache(), "cache should be disabled");
  88 
  89   while (_hot_cache_par_claimed_idx < _hot_cache_size) {
  90     size_t end_idx = Atomic::add(_hot_cache_par_chunk_size,
  91                                  &_hot_cache_par_claimed_idx);
  92     size_t start_idx = end_idx - _hot_cache_par_chunk_size;
  93     // The current worker has successfully claimed the chunk [start_idx..end_idx)
  94     end_idx = MIN2(end_idx, _hot_cache_size);
  95     for (size_t i = start_idx; i < end_idx; i++) {
  96       jbyte* card_ptr = _hot_cache[i];
  97       if (card_ptr != NULL) {
< prev index next >