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

Wed, 27 Apr 2016 01:25:04 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:25:04 +0800
changeset 0
f90c822e73f8
child 6876
710a3c8b516e
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #include "precompiled.hpp"
aoqi@0 26 #include "gc_implementation/g1/dirtyCardQueue.hpp"
aoqi@0 27 #include "gc_implementation/g1/g1CollectedHeap.inline.hpp"
aoqi@0 28 #include "gc_implementation/g1/g1HotCardCache.hpp"
aoqi@0 29 #include "gc_implementation/g1/g1RemSet.hpp"
aoqi@0 30 #include "gc_implementation/g1/heapRegion.hpp"
aoqi@0 31 #include "runtime/atomic.hpp"
aoqi@0 32
aoqi@0 33 G1HotCardCache::G1HotCardCache(G1CollectedHeap *g1h):
aoqi@0 34 _g1h(g1h), _hot_cache(NULL), _use_cache(false), _card_counts(g1h) {}
aoqi@0 35
aoqi@0 36 void G1HotCardCache::initialize() {
aoqi@0 37 if (default_use_cache()) {
aoqi@0 38 _use_cache = true;
aoqi@0 39
aoqi@0 40 _hot_cache_size = (1 << G1ConcRSLogCacheSize);
aoqi@0 41 _hot_cache = NEW_C_HEAP_ARRAY(jbyte*, _hot_cache_size, mtGC);
aoqi@0 42
aoqi@0 43 _n_hot = 0;
aoqi@0 44 _hot_cache_idx = 0;
aoqi@0 45
aoqi@0 46 // For refining the cards in the hot cache in parallel
aoqi@0 47 uint n_workers = (ParallelGCThreads > 0 ?
aoqi@0 48 _g1h->workers()->total_workers() : 1);
aoqi@0 49 _hot_cache_par_chunk_size = MAX2(1, _hot_cache_size / (int)n_workers);
aoqi@0 50 _hot_cache_par_claimed_idx = 0;
aoqi@0 51
aoqi@0 52 _card_counts.initialize();
aoqi@0 53 }
aoqi@0 54 }
aoqi@0 55
aoqi@0 56 G1HotCardCache::~G1HotCardCache() {
aoqi@0 57 if (default_use_cache()) {
aoqi@0 58 assert(_hot_cache != NULL, "Logic");
aoqi@0 59 FREE_C_HEAP_ARRAY(jbyte*, _hot_cache, mtGC);
aoqi@0 60 }
aoqi@0 61 }
aoqi@0 62
aoqi@0 63 jbyte* G1HotCardCache::insert(jbyte* card_ptr) {
aoqi@0 64 uint count = _card_counts.add_card_count(card_ptr);
aoqi@0 65 if (!_card_counts.is_hot(count)) {
aoqi@0 66 // The card is not hot so do not store it in the cache;
aoqi@0 67 // return it for immediate refining.
aoqi@0 68 return card_ptr;
aoqi@0 69 }
aoqi@0 70
aoqi@0 71 // Otherwise, the card is hot.
aoqi@0 72 jbyte* res = NULL;
aoqi@0 73 MutexLockerEx x(HotCardCache_lock, Mutex::_no_safepoint_check_flag);
aoqi@0 74 if (_n_hot == _hot_cache_size) {
aoqi@0 75 res = _hot_cache[_hot_cache_idx];
aoqi@0 76 _n_hot--;
aoqi@0 77 }
aoqi@0 78
aoqi@0 79 // Now _n_hot < _hot_cache_size, and we can insert at _hot_cache_idx.
aoqi@0 80 _hot_cache[_hot_cache_idx] = card_ptr;
aoqi@0 81 _hot_cache_idx++;
aoqi@0 82
aoqi@0 83 if (_hot_cache_idx == _hot_cache_size) {
aoqi@0 84 // Wrap around
aoqi@0 85 _hot_cache_idx = 0;
aoqi@0 86 }
aoqi@0 87 _n_hot++;
aoqi@0 88
aoqi@0 89 return res;
aoqi@0 90 }
aoqi@0 91
aoqi@0 92 void G1HotCardCache::drain(uint worker_i,
aoqi@0 93 G1RemSet* g1rs,
aoqi@0 94 DirtyCardQueue* into_cset_dcq) {
aoqi@0 95 if (!default_use_cache()) {
aoqi@0 96 assert(_hot_cache == NULL, "Logic");
aoqi@0 97 return;
aoqi@0 98 }
aoqi@0 99
aoqi@0 100 assert(_hot_cache != NULL, "Logic");
aoqi@0 101 assert(!use_cache(), "cache should be disabled");
aoqi@0 102 int start_idx;
aoqi@0 103
aoqi@0 104 while ((start_idx = _hot_cache_par_claimed_idx) < _n_hot) { // read once
aoqi@0 105 int end_idx = start_idx + _hot_cache_par_chunk_size;
aoqi@0 106
aoqi@0 107 if (start_idx ==
aoqi@0 108 Atomic::cmpxchg(end_idx, &_hot_cache_par_claimed_idx, start_idx)) {
aoqi@0 109 // The current worker has successfully claimed the chunk [start_idx..end_idx)
aoqi@0 110 end_idx = MIN2(end_idx, _n_hot);
aoqi@0 111 for (int i = start_idx; i < end_idx; i++) {
aoqi@0 112 jbyte* card_ptr = _hot_cache[i];
aoqi@0 113 if (card_ptr != NULL) {
aoqi@0 114 if (g1rs->refine_card(card_ptr, worker_i, true)) {
aoqi@0 115 // The part of the heap spanned by the card contains references
aoqi@0 116 // that point into the current collection set.
aoqi@0 117 // We need to record the card pointer in the DirtyCardQueueSet
aoqi@0 118 // that we use for such cards.
aoqi@0 119 //
aoqi@0 120 // The only time we care about recording cards that contain
aoqi@0 121 // references that point into the collection set is during
aoqi@0 122 // RSet updating while within an evacuation pause.
aoqi@0 123 // In this case worker_i should be the id of a GC worker thread
aoqi@0 124 assert(SafepointSynchronize::is_at_safepoint(), "Should be at a safepoint");
aoqi@0 125 assert(worker_i < (ParallelGCThreads == 0 ? 1 : ParallelGCThreads),
aoqi@0 126 err_msg("incorrect worker id: "UINT32_FORMAT, worker_i));
aoqi@0 127
aoqi@0 128 into_cset_dcq->enqueue(card_ptr);
aoqi@0 129 }
aoqi@0 130 }
aoqi@0 131 }
aoqi@0 132 }
aoqi@0 133 }
aoqi@0 134 // The existing entries in the hot card cache, which were just refined
aoqi@0 135 // above, are discarded prior to re-enabling the cache near the end of the GC.
aoqi@0 136 }
aoqi@0 137
aoqi@0 138 void G1HotCardCache::resize_card_counts(size_t heap_capacity) {
aoqi@0 139 _card_counts.resize(heap_capacity);
aoqi@0 140 }
aoqi@0 141
aoqi@0 142 void G1HotCardCache::reset_card_counts(HeapRegion* hr) {
aoqi@0 143 _card_counts.clear_region(hr);
aoqi@0 144 }
aoqi@0 145
aoqi@0 146 void G1HotCardCache::reset_card_counts() {
aoqi@0 147 _card_counts.clear_all();
aoqi@0 148 }

mercurial