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

Tue, 08 Aug 2017 15:57:29 +0800

author
aoqi
date
Tue, 08 Aug 2017 15:57:29 +0800
changeset 6876
710a3c8b516e
parent 6552
8847586c9037
parent 0
f90c822e73f8
child 7535
7ae4e26cb1e0
permissions
-rw-r--r--

merge

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 #ifndef SHARE_VM_GC_IMPLEMENTATION_G1_G1HOTCARDCACHE_HPP
aoqi@0 26 #define SHARE_VM_GC_IMPLEMENTATION_G1_G1HOTCARDCACHE_HPP
aoqi@0 27
aoqi@0 28 #include "gc_implementation/g1/g1_globals.hpp"
aoqi@0 29 #include "gc_implementation/g1/g1CardCounts.hpp"
aoqi@0 30 #include "memory/allocation.hpp"
aoqi@0 31 #include "runtime/safepoint.hpp"
aoqi@0 32 #include "runtime/thread.inline.hpp"
aoqi@0 33 #include "utilities/globalDefinitions.hpp"
aoqi@0 34
aoqi@0 35 class DirtyCardQueue;
aoqi@0 36 class G1CollectedHeap;
aoqi@0 37 class G1RemSet;
aoqi@0 38 class HeapRegion;
aoqi@0 39
aoqi@0 40 // An evicting cache of cards that have been logged by the G1 post
aoqi@0 41 // write barrier. Placing a card in the cache delays the refinement
aoqi@0 42 // of the card until the card is evicted, or the cache is drained
aoqi@0 43 // during the next evacuation pause.
aoqi@0 44 //
aoqi@0 45 // The first thing the G1 post write barrier does is to check whether
aoqi@0 46 // the card containing the updated pointer is already dirty and, if
aoqi@0 47 // so, skips the remaining code in the barrier.
aoqi@0 48 //
aoqi@0 49 // Delaying the refinement of a card will make the card fail the
aoqi@0 50 // first is_dirty check in the write barrier, skipping the remainder
aoqi@0 51 // of the write barrier.
aoqi@0 52 //
aoqi@0 53 // This can significantly reduce the overhead of the write barrier
aoqi@0 54 // code, increasing throughput.
aoqi@0 55
aoqi@0 56 class G1HotCardCache: public CHeapObj<mtGC> {
aoqi@0 57 G1CollectedHeap* _g1h;
aoqi@0 58
aoqi@0 59 // The card cache table
aoqi@0 60 jbyte** _hot_cache;
aoqi@0 61
aoqi@0 62 int _hot_cache_size;
aoqi@0 63 int _n_hot;
aoqi@0 64 int _hot_cache_idx;
aoqi@0 65
aoqi@0 66 int _hot_cache_par_chunk_size;
aoqi@0 67 volatile int _hot_cache_par_claimed_idx;
aoqi@0 68
aoqi@0 69 bool _use_cache;
aoqi@0 70
aoqi@0 71 G1CardCounts _card_counts;
aoqi@0 72
aoqi@0 73 bool default_use_cache() const {
aoqi@0 74 return (G1ConcRSLogCacheSize > 0);
aoqi@0 75 }
aoqi@0 76
aoqi@0 77 public:
aoqi@0 78 G1HotCardCache(G1CollectedHeap* g1h);
aoqi@0 79 ~G1HotCardCache();
aoqi@0 80
aoqi@0 81 void initialize();
aoqi@0 82
aoqi@0 83 bool use_cache() { return _use_cache; }
aoqi@0 84
aoqi@0 85 void set_use_cache(bool b) {
aoqi@0 86 _use_cache = (b ? default_use_cache() : false);
aoqi@0 87 }
aoqi@0 88
aoqi@0 89 // Returns the card to be refined or NULL.
aoqi@0 90 //
aoqi@0 91 // Increments the count for given the card. if the card is not 'hot',
aoqi@0 92 // it is returned for immediate refining. Otherwise the card is
aoqi@0 93 // added to the hot card cache.
aoqi@0 94 // If there is enough room in the hot card cache for the card we're
aoqi@0 95 // adding, NULL is returned and no further action in needed.
aoqi@0 96 // If we evict a card from the cache to make room for the new card,
aoqi@0 97 // the evicted card is then returned for refinement.
aoqi@0 98 jbyte* insert(jbyte* card_ptr);
aoqi@0 99
aoqi@0 100 // Refine the cards that have delayed as a result of
aoqi@0 101 // being in the cache.
aoqi@0 102 void drain(uint worker_i, G1RemSet* g1rs, DirtyCardQueue* into_cset_dcq);
aoqi@0 103
aoqi@0 104 // Set up for parallel processing of the cards in the hot cache
aoqi@0 105 void reset_hot_cache_claimed_index() {
aoqi@0 106 _hot_cache_par_claimed_idx = 0;
aoqi@0 107 }
aoqi@0 108
aoqi@0 109 // Resets the hot card cache and discards the entries.
aoqi@0 110 void reset_hot_cache() {
aoqi@0 111 assert(SafepointSynchronize::is_at_safepoint(), "Should be at a safepoint");
aoqi@0 112 assert(Thread::current()->is_VM_thread(), "Current thread should be the VMthread");
aoqi@0 113 _hot_cache_idx = 0; _n_hot = 0;
aoqi@0 114 }
aoqi@0 115
aoqi@0 116 bool hot_cache_is_empty() { return _n_hot == 0; }
aoqi@0 117
aoqi@0 118 // Resizes the card counts table to match the given capacity
aoqi@0 119 void resize_card_counts(size_t heap_capacity);
aoqi@0 120
aoqi@0 121 // Zeros the values in the card counts table for entire committed heap
aoqi@0 122 void reset_card_counts();
aoqi@0 123
aoqi@0 124 // Zeros the values in the card counts table for the given region
aoqi@0 125 void reset_card_counts(HeapRegion* hr);
aoqi@0 126 };
aoqi@0 127
aoqi@0 128 #endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1HOTCARDCACHE_HPP

mercurial