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

Thu, 18 Sep 2014 11:27:59 +0200

author
mlarsson
date
Thu, 18 Sep 2014 11:27:59 +0200
changeset 7652
ae374055ebce
parent 7195
c02ec279b062
child 7653
b6a1bf5222c5
permissions
-rw-r--r--

8053998: Hot card cache flush chunk size too coarse grained
Summary: Changed the chunk size to a smaller fixed number.
Reviewed-by: tschatzl, mgerdin

     1 /*
     2  * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     8  *
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    12  * version 2 for more details (a copy is included in the LICENSE file that
    13  * accompanied this code).
    14  *
    15  * You should have received a copy of the GNU General Public License version
    16  * 2 along with this work; if not, write to the Free Software Foundation,
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    18  *
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    20  * or visit www.oracle.com if you need additional information or have any
    21  * questions.
    22  *
    23  */
    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.hpp"
    32 G1HotCardCache::G1HotCardCache(G1CollectedHeap *g1h):
    33   _g1h(g1h), _hot_cache(NULL), _use_cache(false), _card_counts(g1h) {}
    35 void G1HotCardCache::initialize(G1RegionToSpaceMapper* card_counts_storage) {
    36   if (default_use_cache()) {
    37     _use_cache = true;
    39     _hot_cache_size = (1 << G1ConcRSLogCacheSize);
    40     _hot_cache = NEW_C_HEAP_ARRAY(jbyte*, _hot_cache_size, mtGC);
    42     _n_hot = 0;
    43     _hot_cache_idx = 0;
    45     // For refining the cards in the hot cache in parallel
    46     _hot_cache_par_chunk_size = (int)(ParallelGCThreads > 0 ? ClaimChunkSize : _hot_cache_size);
    47     _hot_cache_par_claimed_idx = 0;
    49     _card_counts.initialize(card_counts_storage);
    50   }
    51 }
    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 }
    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   }
    68   // Otherwise, the card is hot.
    69   jbyte* res = NULL;
    70   MutexLockerEx x(HotCardCache_lock, Mutex::_no_safepoint_check_flag);
    71   if (_n_hot == _hot_cache_size) {
    72     res = _hot_cache[_hot_cache_idx];
    73     _n_hot--;
    74   }
    76   // Now _n_hot < _hot_cache_size, and we can insert at _hot_cache_idx.
    77   _hot_cache[_hot_cache_idx] = card_ptr;
    78   _hot_cache_idx++;
    80   if (_hot_cache_idx == _hot_cache_size) {
    81     // Wrap around
    82     _hot_cache_idx = 0;
    83   }
    84   _n_hot++;
    86   return res;
    87 }
    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   }
    97   assert(_hot_cache != NULL, "Logic");
    98   assert(!use_cache(), "cache should be disabled");
    99   int start_idx;
   101   while ((start_idx = _hot_cache_par_claimed_idx) < _n_hot) { // read once
   102     int end_idx = start_idx + _hot_cache_par_chunk_size;
   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 == 0 ? 1 : ParallelGCThreads),
   123                    err_msg("incorrect worker id: "UINT32_FORMAT, worker_i));
   125             into_cset_dcq->enqueue(card_ptr);
   126           }
   127         }
   128       }
   129     }
   130   }
   131   // The existing entries in the hot card cache, which were just refined
   132   // above, are discarded prior to re-enabling the cache near the end of the GC.
   133 }
   135 void G1HotCardCache::reset_card_counts(HeapRegion* hr) {
   136   _card_counts.clear_region(hr);
   137 }
   139 void G1HotCardCache::reset_card_counts() {
   140   _card_counts.clear_all();
   141 }

mercurial