Path: blob/master/src/hotspot/share/gc/g1/g1CardTable.hpp
40957 views
/*1* Copyright (c) 2001, 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_G1CARDTABLE_HPP25#define SHARE_GC_G1_G1CARDTABLE_HPP2627#include "gc/g1/g1RegionToSpaceMapper.hpp"28#include "gc/shared/cardTable.hpp"29#include "oops/oopsHierarchy.hpp"30#include "utilities/macros.hpp"3132class G1CardTable;33class G1RegionToSpaceMapper;3435class G1CardTableChangedListener : public G1MappingChangedListener {36private:37G1CardTable* _card_table;38public:39G1CardTableChangedListener() : _card_table(NULL) { }4041void set_card_table(G1CardTable* card_table) { _card_table = card_table; }4243virtual void on_commit(uint start_idx, size_t num_regions, bool zero_filled);44};4546class G1CardTable : public CardTable {47friend class VMStructs;48friend class G1CardTableChangedListener;4950G1CardTableChangedListener _listener;5152public:53enum G1CardValues {54g1_young_gen = CT_MR_BS_last_reserved << 1,5556// During evacuation we use the card table to consolidate the cards we need to57// scan for roots onto the card table from the various sources. Further it is58// used to record already completely scanned cards to avoid re-scanning them59// when incrementally evacuating the old gen regions of a collection set.60// This means that already scanned cards should be preserved.61//62// The merge at the start of each evacuation round simply sets cards to dirty63// that are clean; scanned cards are set to 0x1.64//65// This means that the LSB determines what to do with the card during evacuation66// given the following possible values:67//68// 11111111 - clean, do not scan69// 00000001 - already scanned, do not scan70// 00000000 - dirty, needs to be scanned.71//72g1_card_already_scanned = 0x173};7475static const size_t WordAllClean = SIZE_MAX;76static const size_t WordAllDirty = 0;7778STATIC_ASSERT(BitsPerByte == 8);79static const size_t WordAlreadyScanned = (SIZE_MAX / 255) * g1_card_already_scanned;8081G1CardTable(MemRegion whole_heap): CardTable(whole_heap), _listener() {82_listener.set_card_table(this);83}8485static CardValue g1_young_card_val() { return g1_young_gen; }86static CardValue g1_scanned_card_val() { return g1_card_already_scanned; }8788void verify_g1_young_region(MemRegion mr) PRODUCT_RETURN;89void g1_mark_as_young(const MemRegion& mr);9091size_t index_for_cardvalue(CardValue const* p) const {92return pointer_delta(p, _byte_map, sizeof(CardValue));93}9495// Mark the given card as Dirty if it is Clean. Returns whether the card was96// Clean before this operation. This result may be inaccurate as it does not97// perform the dirtying atomically.98inline bool mark_clean_as_dirty(CardValue* card);99100// Change Clean cards in a (large) area on the card table as Dirty, preserving101// already scanned cards. Assumes that most cards in that area are Clean.102// Returns the number of dirtied cards that were not yet dirty. This result may103// be inaccurate as it does not perform the dirtying atomically.104inline size_t mark_region_dirty(size_t start_card_index, size_t num_cards);105106// Change the given range of dirty cards to "which". All of these cards must be Dirty.107inline void change_dirty_cards_to(size_t start_card_index, size_t num_cards, CardValue which);108109inline uint region_idx_for(CardValue* p);110111static size_t compute_size(size_t mem_region_size_in_words) {112size_t number_of_slots = (mem_region_size_in_words / card_size_in_words);113return ReservedSpace::allocation_align_size_up(number_of_slots);114}115116// Returns how many bytes of the heap a single byte of the Card Table corresponds to.117static size_t heap_map_factor() { return card_size; }118119void initialize() {}120void initialize(G1RegionToSpaceMapper* mapper);121122virtual void resize_covered_region(MemRegion new_region) { ShouldNotReachHere(); }123124virtual bool is_in_young(oop obj) const;125};126127#endif // SHARE_GC_G1_G1CARDTABLE_HPP128129130