Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/memory/cardTableRS.hpp
32285 views
/*1* Copyright (c) 2001, 2013, 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_VM_MEMORY_CARDTABLERS_HPP25#define SHARE_VM_MEMORY_CARDTABLERS_HPP2627#include "memory/cardTableModRefBS.hpp"28#include "memory/genRemSet.hpp"29#include "memory/memRegion.hpp"3031class Space;32class OopsInGenClosure;3334// This kind of "GenRemSet" uses a card table both as shared data structure35// for a mod ref barrier set and for the rem set information.3637class CardTableRS: public GenRemSet {38friend class VMStructs;39// Below are private classes used in impl.40friend class VerifyCTSpaceClosure;41friend class ClearNoncleanCardWrapper;4243static jbyte clean_card_val() {44return CardTableModRefBS::clean_card;45}4647static intptr_t clean_card_row() {48return CardTableModRefBS::clean_card_row;49}5051static bool52card_is_dirty_wrt_gen_iter(jbyte cv) {53return CardTableModRefBS::card_is_dirty_wrt_gen_iter(cv);54}5556CardTableModRefBSForCTRS* _ct_bs;5758virtual void younger_refs_in_space_iterate(Space* sp, OopsInGenClosure* cl);5960void verify_space(Space* s, HeapWord* gen_start);6162enum ExtendedCardValue {63youngergen_card = CardTableModRefBS::CT_MR_BS_last_reserved + 1,64// These are for parallel collection.65// There are three P (parallel) youngergen card values. In general, this66// needs to be more than the number of generations (including the perm67// gen) that might have younger_refs_do invoked on them separately. So68// if we add more gens, we have to add more values.69youngergenP1_card = CardTableModRefBS::CT_MR_BS_last_reserved + 2,70youngergenP2_card = CardTableModRefBS::CT_MR_BS_last_reserved + 3,71youngergenP3_card = CardTableModRefBS::CT_MR_BS_last_reserved + 4,72cur_youngergen_and_prev_nonclean_card =73CardTableModRefBS::CT_MR_BS_last_reserved + 574};7576// An array that contains, for each generation, the card table value last77// used as the current value for a younger_refs_do iteration of that78// portion of the table. (The perm gen is index 0; other gens are at79// their level plus 1. They youngest gen is in the table, but will80// always have the value "clean_card".)81jbyte* _last_cur_val_in_gen;8283jbyte _cur_youngergen_card_val;8485int _regions_to_iterate;8687jbyte cur_youngergen_card_val() {88return _cur_youngergen_card_val;89}90void set_cur_youngergen_card_val(jbyte v) {91_cur_youngergen_card_val = v;92}93bool is_prev_youngergen_card_val(jbyte v) {94return95youngergen_card <= v &&96v < cur_youngergen_and_prev_nonclean_card &&97v != _cur_youngergen_card_val;98}99// Return a youngergen_card_value that is not currently in use.100jbyte find_unused_youngergenP_card_value();101102public:103CardTableRS(MemRegion whole_heap, int max_covered_regions);104~CardTableRS();105106// *** GenRemSet functions.107GenRemSet::Name rs_kind() { return GenRemSet::CardTable; }108109CardTableRS* as_CardTableRS() { return this; }110111CardTableModRefBS* ct_bs() { return _ct_bs; }112113// Override.114void prepare_for_younger_refs_iterate(bool parallel);115116// Card table entries are cleared before application; "blk" is117// responsible for dirtying if the oop is still older-to-younger after118// closure application.119void younger_refs_iterate(Generation* g, OopsInGenClosure* blk);120121void inline_write_ref_field_gc(void* field, oop new_val) {122jbyte* byte = _ct_bs->byte_for(field);123*byte = youngergen_card;124}125void write_ref_field_gc_work(void* field, oop new_val) {126inline_write_ref_field_gc(field, new_val);127}128129// Override. Might want to devirtualize this in the same fashion as130// above. Ensures that the value of the card for field says that it's131// a younger card in the current collection.132virtual void write_ref_field_gc_par(void* field, oop new_val);133134void resize_covered_region(MemRegion new_region);135136bool is_aligned(HeapWord* addr) {137return _ct_bs->is_card_aligned(addr);138}139140void verify();141void verify_aligned_region_empty(MemRegion mr);142143void clear(MemRegion mr) { _ct_bs->clear(mr); }144void clear_into_younger(Generation* old_gen);145146void invalidate(MemRegion mr, bool whole_heap = false) {147_ct_bs->invalidate(mr, whole_heap);148}149void invalidate_or_clear(Generation* old_gen);150151static uintx ct_max_alignment_constraint() {152return CardTableModRefBS::ct_max_alignment_constraint();153}154155jbyte* byte_for(void* p) { return _ct_bs->byte_for(p); }156jbyte* byte_after(void* p) { return _ct_bs->byte_after(p); }157HeapWord* addr_for(jbyte* p) { return _ct_bs->addr_for(p); }158159bool is_prev_nonclean_card_val(jbyte v) {160return161youngergen_card <= v &&162v <= cur_youngergen_and_prev_nonclean_card &&163v != _cur_youngergen_card_val;164}165166static bool youngergen_may_have_been_dirty(jbyte cv) {167return cv == CardTableRS::cur_youngergen_and_prev_nonclean_card;168}169170};171172class ClearNoncleanCardWrapper: public MemRegionClosure {173DirtyCardToOopClosure* _dirty_card_closure;174CardTableRS* _ct;175bool _is_par;176private:177// Clears the given card, return true if the corresponding card should be178// processed.179inline bool clear_card(jbyte* entry);180// Work methods called by the clear_card()181inline bool clear_card_serial(jbyte* entry);182inline bool clear_card_parallel(jbyte* entry);183// check alignment of pointer184bool is_word_aligned(jbyte* entry);185186public:187ClearNoncleanCardWrapper(DirtyCardToOopClosure* dirty_card_closure, CardTableRS* ct);188void do_MemRegion(MemRegion mr);189};190191#endif // SHARE_VM_MEMORY_CARDTABLERS_HPP192193194