johnc@5078: /* johnc@5078: * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. johnc@5078: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. johnc@5078: * johnc@5078: * This code is free software; you can redistribute it and/or modify it johnc@5078: * under the terms of the GNU General Public License version 2 only, as johnc@5078: * published by the Free Software Foundation. johnc@5078: * johnc@5078: * This code is distributed in the hope that it will be useful, but WITHOUT johnc@5078: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or johnc@5078: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License johnc@5078: * version 2 for more details (a copy is included in the LICENSE file that johnc@5078: * accompanied this code). johnc@5078: * johnc@5078: * You should have received a copy of the GNU General Public License version johnc@5078: * 2 along with this work; if not, write to the Free Software Foundation, johnc@5078: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. johnc@5078: * johnc@5078: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA johnc@5078: * or visit www.oracle.com if you need additional information or have any johnc@5078: * questions. johnc@5078: * johnc@5078: */ johnc@5078: johnc@5078: #ifndef SHARE_VM_GC_IMPLEMENTATION_G1_G1HOTCARDCACHE_HPP johnc@5078: #define SHARE_VM_GC_IMPLEMENTATION_G1_G1HOTCARDCACHE_HPP johnc@5078: johnc@5078: #include "gc_implementation/g1/g1_globals.hpp" johnc@5078: #include "gc_implementation/g1/g1CardCounts.hpp" johnc@5078: #include "memory/allocation.hpp" johnc@5078: #include "runtime/safepoint.hpp" johnc@5078: #include "runtime/thread.inline.hpp" johnc@5078: #include "utilities/globalDefinitions.hpp" johnc@5078: johnc@5078: class DirtyCardQueue; johnc@5078: class G1CollectedHeap; johnc@5078: class G1RemSet; johnc@5078: class HeapRegion; johnc@5078: johnc@5078: // An evicting cache of cards that have been logged by the G1 post johnc@5078: // write barrier. Placing a card in the cache delays the refinement johnc@5078: // of the card until the card is evicted, or the cache is drained johnc@5078: // during the next evacuation pause. johnc@5078: // johnc@5078: // The first thing the G1 post write barrier does is to check whether johnc@5078: // the card containing the updated pointer is already dirty and, if johnc@5078: // so, skips the remaining code in the barrier. johnc@5078: // johnc@5078: // Delaying the refinement of a card will make the card fail the johnc@5078: // first is_dirty check in the write barrier, skipping the remainder johnc@5078: // of the write barrier. johnc@5078: // johnc@5078: // This can significantly reduce the overhead of the write barrier johnc@5078: // code, increasing throughput. johnc@5078: johnc@5078: class G1HotCardCache: public CHeapObj { johnc@5078: G1CollectedHeap* _g1h; johnc@5078: johnc@5078: // The card cache table johnc@5078: jbyte** _hot_cache; johnc@5078: johnc@5078: int _hot_cache_size; johnc@5078: int _n_hot; johnc@5078: int _hot_cache_idx; johnc@5078: johnc@5078: int _hot_cache_par_chunk_size; johnc@5078: volatile int _hot_cache_par_claimed_idx; johnc@5078: johnc@5078: bool _use_cache; johnc@5078: johnc@5078: G1CardCounts _card_counts; johnc@5078: johnc@5078: bool default_use_cache() const { johnc@5078: return (G1ConcRSLogCacheSize > 0); johnc@5078: } johnc@5078: johnc@5078: public: johnc@5078: G1HotCardCache(G1CollectedHeap* g1h); johnc@5078: ~G1HotCardCache(); johnc@5078: johnc@5078: void initialize(); johnc@5078: johnc@5078: bool use_cache() { return _use_cache; } johnc@5078: johnc@5078: void set_use_cache(bool b) { johnc@5078: _use_cache = (b ? default_use_cache() : false); johnc@5078: } johnc@5078: johnc@5078: // Returns the card to be refined or NULL. johnc@5078: // johnc@5078: // Increments the count for given the card. if the card is not 'hot', johnc@5078: // it is returned for immediate refining. Otherwise the card is johnc@5078: // added to the hot card cache. johnc@5078: // If there is enough room in the hot card cache for the card we're johnc@5078: // adding, NULL is returned and no further action in needed. johnc@5078: // If we evict a card from the cache to make room for the new card, johnc@5078: // the evicted card is then returned for refinement. johnc@5078: jbyte* insert(jbyte* card_ptr); johnc@5078: johnc@5078: // Refine the cards that have delayed as a result of johnc@5078: // being in the cache. johnc@5078: void drain(int worker_i, G1RemSet* g1rs, DirtyCardQueue* into_cset_dcq); johnc@5078: johnc@5078: // Set up for parallel processing of the cards in the hot cache johnc@5078: void reset_hot_cache_claimed_index() { johnc@5078: _hot_cache_par_claimed_idx = 0; johnc@5078: } johnc@5078: johnc@5078: // Resets the hot card cache and discards the entries. johnc@5078: void reset_hot_cache() { johnc@5078: assert(SafepointSynchronize::is_at_safepoint(), "Should be at a safepoint"); johnc@5078: assert(Thread::current()->is_VM_thread(), "Current thread should be the VMthread"); johnc@5078: _hot_cache_idx = 0; _n_hot = 0; johnc@5078: } johnc@5078: johnc@5078: bool hot_cache_is_empty() { return _n_hot == 0; } johnc@5078: johnc@5078: // Resizes the card counts table to match the given capacity johnc@5078: void resize_card_counts(size_t heap_capacity); johnc@5078: johnc@5078: // Zeros the values in the card counts table for entire committed heap johnc@5078: void reset_card_counts(); johnc@5078: johnc@5078: // Zeros the values in the card counts table for the given region johnc@5078: void reset_card_counts(HeapRegion* hr); johnc@5078: }; johnc@5078: johnc@5078: #endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1HOTCARDCACHE_HPP