1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/gc_implementation/g1/g1HotCardCache.hpp Wed Apr 27 01:25:04 2016 +0800 1.3 @@ -0,0 +1,128 @@ 1.4 +/* 1.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +#ifndef SHARE_VM_GC_IMPLEMENTATION_G1_G1HOTCARDCACHE_HPP 1.29 +#define SHARE_VM_GC_IMPLEMENTATION_G1_G1HOTCARDCACHE_HPP 1.30 + 1.31 +#include "gc_implementation/g1/g1_globals.hpp" 1.32 +#include "gc_implementation/g1/g1CardCounts.hpp" 1.33 +#include "memory/allocation.hpp" 1.34 +#include "runtime/safepoint.hpp" 1.35 +#include "runtime/thread.inline.hpp" 1.36 +#include "utilities/globalDefinitions.hpp" 1.37 + 1.38 +class DirtyCardQueue; 1.39 +class G1CollectedHeap; 1.40 +class G1RemSet; 1.41 +class HeapRegion; 1.42 + 1.43 +// An evicting cache of cards that have been logged by the G1 post 1.44 +// write barrier. Placing a card in the cache delays the refinement 1.45 +// of the card until the card is evicted, or the cache is drained 1.46 +// during the next evacuation pause. 1.47 +// 1.48 +// The first thing the G1 post write barrier does is to check whether 1.49 +// the card containing the updated pointer is already dirty and, if 1.50 +// so, skips the remaining code in the barrier. 1.51 +// 1.52 +// Delaying the refinement of a card will make the card fail the 1.53 +// first is_dirty check in the write barrier, skipping the remainder 1.54 +// of the write barrier. 1.55 +// 1.56 +// This can significantly reduce the overhead of the write barrier 1.57 +// code, increasing throughput. 1.58 + 1.59 +class G1HotCardCache: public CHeapObj<mtGC> { 1.60 + G1CollectedHeap* _g1h; 1.61 + 1.62 + // The card cache table 1.63 + jbyte** _hot_cache; 1.64 + 1.65 + int _hot_cache_size; 1.66 + int _n_hot; 1.67 + int _hot_cache_idx; 1.68 + 1.69 + int _hot_cache_par_chunk_size; 1.70 + volatile int _hot_cache_par_claimed_idx; 1.71 + 1.72 + bool _use_cache; 1.73 + 1.74 + G1CardCounts _card_counts; 1.75 + 1.76 + bool default_use_cache() const { 1.77 + return (G1ConcRSLogCacheSize > 0); 1.78 + } 1.79 + 1.80 + public: 1.81 + G1HotCardCache(G1CollectedHeap* g1h); 1.82 + ~G1HotCardCache(); 1.83 + 1.84 + void initialize(); 1.85 + 1.86 + bool use_cache() { return _use_cache; } 1.87 + 1.88 + void set_use_cache(bool b) { 1.89 + _use_cache = (b ? default_use_cache() : false); 1.90 + } 1.91 + 1.92 + // Returns the card to be refined or NULL. 1.93 + // 1.94 + // Increments the count for given the card. if the card is not 'hot', 1.95 + // it is returned for immediate refining. Otherwise the card is 1.96 + // added to the hot card cache. 1.97 + // If there is enough room in the hot card cache for the card we're 1.98 + // adding, NULL is returned and no further action in needed. 1.99 + // If we evict a card from the cache to make room for the new card, 1.100 + // the evicted card is then returned for refinement. 1.101 + jbyte* insert(jbyte* card_ptr); 1.102 + 1.103 + // Refine the cards that have delayed as a result of 1.104 + // being in the cache. 1.105 + void drain(uint worker_i, G1RemSet* g1rs, DirtyCardQueue* into_cset_dcq); 1.106 + 1.107 + // Set up for parallel processing of the cards in the hot cache 1.108 + void reset_hot_cache_claimed_index() { 1.109 + _hot_cache_par_claimed_idx = 0; 1.110 + } 1.111 + 1.112 + // Resets the hot card cache and discards the entries. 1.113 + void reset_hot_cache() { 1.114 + assert(SafepointSynchronize::is_at_safepoint(), "Should be at a safepoint"); 1.115 + assert(Thread::current()->is_VM_thread(), "Current thread should be the VMthread"); 1.116 + _hot_cache_idx = 0; _n_hot = 0; 1.117 + } 1.118 + 1.119 + bool hot_cache_is_empty() { return _n_hot == 0; } 1.120 + 1.121 + // Resizes the card counts table to match the given capacity 1.122 + void resize_card_counts(size_t heap_capacity); 1.123 + 1.124 + // Zeros the values in the card counts table for entire committed heap 1.125 + void reset_card_counts(); 1.126 + 1.127 + // Zeros the values in the card counts table for the given region 1.128 + void reset_card_counts(HeapRegion* hr); 1.129 +}; 1.130 + 1.131 +#endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1HOTCARDCACHE_HPP