Path: blob/master/src/hotspot/share/gc/g1/g1CardCounts.hpp
40960 views
/*1* Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_GC_G1_G1CARDCOUNTS_HPP25#define SHARE_GC_G1_G1CARDCOUNTS_HPP2627#include "gc/g1/g1CardTable.hpp"28#include "gc/g1/g1RegionToSpaceMapper.hpp"29#include "memory/allocation.hpp"30#include "memory/virtualspace.hpp"31#include "utilities/globalDefinitions.hpp"3233class CardTableBarrierSet;34class G1CardCounts;35class G1CollectedHeap;36class G1RegionToSpaceMapper;37class HeapRegion;3839class G1CardCountsMappingChangedListener : public G1MappingChangedListener {40private:41G1CardCounts* _counts;42public:43void set_cardcounts(G1CardCounts* counts) { _counts = counts; }4445virtual void on_commit(uint start_idx, size_t num_regions, bool zero_filled);46};4748// Table to track the number of times a card has been refined. Once49// a card has been refined a certain number of times, it is50// considered 'hot' and its refinement is delayed by inserting the51// card into the hot card cache. The card will then be refined when52// it is evicted from the hot card cache, or when the hot card cache53// is 'drained' during the next evacuation pause.5455class G1CardCounts: public CHeapObj<mtGC> {56public:57typedef CardTable::CardValue CardValue;5859private:60G1CardCountsMappingChangedListener _listener;6162G1CollectedHeap* _g1h;63G1CardTable* _ct;6465// The table of counts66uint8_t* _card_counts;6768// Max capacity of the reserved space for the counts table69size_t _reserved_max_card_num;7071// CardTable bottom.72const CardValue* _ct_bot;7374// Returns true if the card counts table has been reserved.75bool has_reserved_count_table() { return _card_counts != NULL; }7677// Returns true if the card counts table has been reserved and committed.78bool has_count_table() {79return has_reserved_count_table();80}8182size_t ptr_2_card_num(const CardValue* card_ptr) {83assert(card_ptr >= _ct_bot,84"Invalid card pointer: "85"card_ptr: " PTR_FORMAT ", "86"_ct_bot: " PTR_FORMAT,87p2i(card_ptr), p2i(_ct_bot));88size_t card_num = pointer_delta(card_ptr, _ct_bot, sizeof(CardValue));89assert(card_num < _reserved_max_card_num,90"card pointer out of range: " PTR_FORMAT, p2i(card_ptr));91return card_num;92}9394CardValue* card_num_2_ptr(size_t card_num) {95assert(card_num < _reserved_max_card_num,96"card num out of range: " SIZE_FORMAT, card_num);97return (CardValue*) (_ct_bot + card_num);98}99100// Clear the counts table for the given (exclusive) index range.101void clear_range(size_t from_card_num, size_t to_card_num);102103public:104G1CardCounts(G1CollectedHeap* g1h);105106// Return the number of slots needed for a card counts table107// that covers mem_region_words words.108static size_t compute_size(size_t mem_region_size_in_words);109110// Returns how many bytes of the heap a single byte of the card counts table111// corresponds to.112static size_t heap_map_factor();113114void initialize(G1RegionToSpaceMapper* mapper);115116// Increments the refinement count for the given card.117// Returns the pre-increment count value.118uint add_card_count(CardValue* card_ptr);119120// Returns true if the given count is high enough to be considered121// 'hot'; false otherwise.122bool is_hot(uint count);123124// Clears the card counts for the cards spanned by the region125void clear_region(HeapRegion* hr);126127// Clears the card counts for the cards spanned by the MemRegion128void clear_range(MemRegion mr);129130// Clear the entire card counts table during GC.131void clear_all();132};133134#endif // SHARE_GC_G1_G1CARDCOUNTS_HPP135136137