johnc@5078: /* drchase@6680: * Copyright (c) 2013, 2014, 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_G1CARDCOUNTS_HPP johnc@5078: #define SHARE_VM_GC_IMPLEMENTATION_G1_G1CARDCOUNTS_HPP johnc@5078: tschatzl@7051: #include "gc_implementation/g1/g1RegionToSpaceMapper.hpp" johnc@5078: #include "memory/allocation.hpp" johnc@5078: #include "runtime/virtualspace.hpp" johnc@5078: #include "utilities/globalDefinitions.hpp" johnc@5078: johnc@5078: class CardTableModRefBS; tschatzl@7051: class G1CardCounts; johnc@5078: class G1CollectedHeap; tschatzl@7051: class G1RegionToSpaceMapper; johnc@5078: class HeapRegion; johnc@5078: tschatzl@7051: class G1CardCountsMappingChangedListener : public G1MappingChangedListener { tschatzl@7051: private: tschatzl@7051: G1CardCounts* _counts; tschatzl@7051: public: tschatzl@7051: void set_cardcounts(G1CardCounts* counts) { _counts = counts; } tschatzl@7051: tschatzl@7257: virtual void on_commit(uint start_idx, size_t num_regions, bool zero_filled); tschatzl@7051: }; tschatzl@7051: johnc@5078: // Table to track the number of times a card has been refined. Once johnc@5078: // a card has been refined a certain number of times, it is johnc@5078: // considered 'hot' and its refinement is delayed by inserting the johnc@5078: // card into the hot card cache. The card will then be refined when johnc@5078: // it is evicted from the hot card cache, or when the hot card cache johnc@5078: // is 'drained' during the next evacuation pause. johnc@5078: johnc@5078: class G1CardCounts: public CHeapObj { tschatzl@7051: G1CardCountsMappingChangedListener _listener; tschatzl@7051: johnc@5078: G1CollectedHeap* _g1h; johnc@5078: johnc@5078: // The table of counts johnc@5078: jubyte* _card_counts; johnc@5078: johnc@5078: // Max capacity of the reserved space for the counts table johnc@5078: size_t _reserved_max_card_num; johnc@5078: johnc@5078: // CardTable bottom. johnc@5078: const jbyte* _ct_bot; johnc@5078: johnc@5078: // Barrier set johnc@5078: CardTableModRefBS* _ct_bs; johnc@5078: johnc@5078: // Returns true if the card counts table has been reserved. johnc@5078: bool has_reserved_count_table() { return _card_counts != NULL; } johnc@5078: johnc@5078: // Returns true if the card counts table has been reserved and committed. johnc@5078: bool has_count_table() { tschatzl@7051: return has_reserved_count_table(); johnc@5078: } johnc@5078: johnc@5078: size_t ptr_2_card_num(const jbyte* card_ptr) { johnc@5078: assert(card_ptr >= _ct_bot, shade@5709: err_msg("Invalid card pointer: " johnc@5078: "card_ptr: " PTR_FORMAT ", " johnc@5078: "_ct_bot: " PTR_FORMAT, drchase@6680: p2i(card_ptr), p2i(_ct_bot))); johnc@5078: size_t card_num = pointer_delta(card_ptr, _ct_bot, sizeof(jbyte)); tschatzl@7051: assert(card_num >= 0 && card_num < _reserved_max_card_num, drchase@6680: err_msg("card pointer out of range: " PTR_FORMAT, p2i(card_ptr))); johnc@5078: return card_num; johnc@5078: } johnc@5078: johnc@5078: jbyte* card_num_2_ptr(size_t card_num) { tschatzl@7051: assert(card_num >= 0 && card_num < _reserved_max_card_num, kevinw@9327: err_msg("card num out of range: " SIZE_FORMAT, card_num)); johnc@5078: return (jbyte*) (_ct_bot + card_num); johnc@5078: } johnc@5078: johnc@5078: // Clear the counts table for the given (exclusive) index range. johnc@5078: void clear_range(size_t from_card_num, size_t to_card_num); johnc@5078: johnc@5078: public: johnc@5078: G1CardCounts(G1CollectedHeap* g1h); johnc@5078: tschatzl@7051: void initialize(G1RegionToSpaceMapper* mapper); johnc@5078: johnc@5078: // Increments the refinement count for the given card. johnc@5078: // Returns the pre-increment count value. johnc@5078: uint add_card_count(jbyte* card_ptr); johnc@5078: johnc@5078: // Returns true if the given count is high enough to be considered johnc@5078: // 'hot'; false otherwise. johnc@5078: bool is_hot(uint count); johnc@5078: johnc@5078: // Clears the card counts for the cards spanned by the region johnc@5078: void clear_region(HeapRegion* hr); johnc@5078: tschatzl@7051: // Clears the card counts for the cards spanned by the MemRegion tschatzl@7051: void clear_range(MemRegion mr); tschatzl@7051: johnc@5078: // Clear the entire card counts table during GC. johnc@5078: void clear_all(); johnc@5078: }; johnc@5078: johnc@5078: #endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1CARDCOUNTS_HPP