aoqi@0: /* aoqi@0: * Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: * aoqi@0: */ aoqi@0: aoqi@0: #ifndef SHARE_VM_MEMORY_CARDTABLERS_HPP aoqi@0: #define SHARE_VM_MEMORY_CARDTABLERS_HPP aoqi@0: aoqi@0: #include "memory/cardTableModRefBS.hpp" aoqi@0: #include "memory/genRemSet.hpp" aoqi@0: #include "memory/memRegion.hpp" aoqi@0: aoqi@0: class Space; aoqi@0: class OopsInGenClosure; aoqi@0: aoqi@0: // This kind of "GenRemSet" uses a card table both as shared data structure aoqi@0: // for a mod ref barrier set and for the rem set information. aoqi@0: aoqi@0: class CardTableRS: public GenRemSet { aoqi@0: friend class VMStructs; aoqi@0: // Below are private classes used in impl. aoqi@0: friend class VerifyCTSpaceClosure; aoqi@0: friend class ClearNoncleanCardWrapper; aoqi@0: aoqi@0: static jbyte clean_card_val() { aoqi@0: return CardTableModRefBS::clean_card; aoqi@0: } aoqi@0: aoqi@0: static intptr_t clean_card_row() { aoqi@0: return CardTableModRefBS::clean_card_row; aoqi@0: } aoqi@0: aoqi@0: static bool aoqi@0: card_is_dirty_wrt_gen_iter(jbyte cv) { aoqi@0: return CardTableModRefBS::card_is_dirty_wrt_gen_iter(cv); aoqi@0: } aoqi@0: aoqi@0: CardTableModRefBSForCTRS* _ct_bs; aoqi@0: aoqi@0: virtual void younger_refs_in_space_iterate(Space* sp, OopsInGenClosure* cl); aoqi@0: aoqi@0: void verify_space(Space* s, HeapWord* gen_start); aoqi@0: aoqi@0: enum ExtendedCardValue { aoqi@0: youngergen_card = CardTableModRefBS::CT_MR_BS_last_reserved + 1, aoqi@0: // These are for parallel collection. aoqi@0: // There are three P (parallel) youngergen card values. In general, this aoqi@0: // needs to be more than the number of generations (including the perm aoqi@0: // gen) that might have younger_refs_do invoked on them separately. So aoqi@0: // if we add more gens, we have to add more values. aoqi@0: youngergenP1_card = CardTableModRefBS::CT_MR_BS_last_reserved + 2, aoqi@0: youngergenP2_card = CardTableModRefBS::CT_MR_BS_last_reserved + 3, aoqi@0: youngergenP3_card = CardTableModRefBS::CT_MR_BS_last_reserved + 4, aoqi@0: cur_youngergen_and_prev_nonclean_card = aoqi@0: CardTableModRefBS::CT_MR_BS_last_reserved + 5 aoqi@0: }; aoqi@0: aoqi@0: // An array that contains, for each generation, the card table value last aoqi@0: // used as the current value for a younger_refs_do iteration of that aoqi@0: // portion of the table. (The perm gen is index 0; other gens are at aoqi@0: // their level plus 1. They youngest gen is in the table, but will aoqi@0: // always have the value "clean_card".) aoqi@0: jbyte* _last_cur_val_in_gen; aoqi@0: aoqi@0: jbyte _cur_youngergen_card_val; aoqi@0: aoqi@0: int _regions_to_iterate; aoqi@0: aoqi@0: jbyte cur_youngergen_card_val() { aoqi@0: return _cur_youngergen_card_val; aoqi@0: } aoqi@0: void set_cur_youngergen_card_val(jbyte v) { aoqi@0: _cur_youngergen_card_val = v; aoqi@0: } aoqi@0: bool is_prev_youngergen_card_val(jbyte v) { aoqi@0: return aoqi@0: youngergen_card <= v && aoqi@0: v < cur_youngergen_and_prev_nonclean_card && aoqi@0: v != _cur_youngergen_card_val; aoqi@0: } aoqi@0: // Return a youngergen_card_value that is not currently in use. aoqi@0: jbyte find_unused_youngergenP_card_value(); aoqi@0: aoqi@0: public: aoqi@0: CardTableRS(MemRegion whole_heap, int max_covered_regions); aoqi@0: ~CardTableRS(); aoqi@0: aoqi@0: // *** GenRemSet functions. aoqi@0: GenRemSet::Name rs_kind() { return GenRemSet::CardTable; } aoqi@0: aoqi@0: CardTableRS* as_CardTableRS() { return this; } aoqi@0: aoqi@0: CardTableModRefBS* ct_bs() { return _ct_bs; } aoqi@0: aoqi@0: // Override. aoqi@0: void prepare_for_younger_refs_iterate(bool parallel); aoqi@0: aoqi@0: // Card table entries are cleared before application; "blk" is aoqi@0: // responsible for dirtying if the oop is still older-to-younger after aoqi@0: // closure application. aoqi@0: void younger_refs_iterate(Generation* g, OopsInGenClosure* blk); aoqi@0: aoqi@0: void inline_write_ref_field_gc(void* field, oop new_val) { aoqi@0: jbyte* byte = _ct_bs->byte_for(field); fujie@116: #ifdef MIPS64 fujie@121: if (Use3A2000) OrderAccess::fence(); fujie@116: #endif fujie@116: *byte = youngergen_card; fujie@116: #ifdef MIPS64 fujie@121: if (Use3A2000) OrderAccess::fence(); fujie@116: #endif fujie@116: aoqi@0: } aoqi@0: void write_ref_field_gc_work(void* field, oop new_val) { aoqi@0: inline_write_ref_field_gc(field, new_val); aoqi@0: } aoqi@0: aoqi@0: // Override. Might want to devirtualize this in the same fashion as aoqi@0: // above. Ensures that the value of the card for field says that it's aoqi@0: // a younger card in the current collection. aoqi@0: virtual void write_ref_field_gc_par(void* field, oop new_val); aoqi@0: aoqi@0: void resize_covered_region(MemRegion new_region); aoqi@0: aoqi@0: bool is_aligned(HeapWord* addr) { aoqi@0: return _ct_bs->is_card_aligned(addr); aoqi@0: } aoqi@0: aoqi@0: void verify(); aoqi@0: void verify_aligned_region_empty(MemRegion mr); aoqi@0: aoqi@0: void clear(MemRegion mr) { _ct_bs->clear(mr); } aoqi@0: void clear_into_younger(Generation* old_gen); aoqi@0: aoqi@0: void invalidate(MemRegion mr, bool whole_heap = false) { aoqi@0: _ct_bs->invalidate(mr, whole_heap); aoqi@0: } aoqi@0: void invalidate_or_clear(Generation* old_gen); aoqi@0: aoqi@0: static uintx ct_max_alignment_constraint() { aoqi@0: return CardTableModRefBS::ct_max_alignment_constraint(); aoqi@0: } aoqi@0: aoqi@0: jbyte* byte_for(void* p) { return _ct_bs->byte_for(p); } aoqi@0: jbyte* byte_after(void* p) { return _ct_bs->byte_after(p); } aoqi@0: HeapWord* addr_for(jbyte* p) { return _ct_bs->addr_for(p); } aoqi@0: aoqi@0: bool is_prev_nonclean_card_val(jbyte v) { aoqi@0: return aoqi@0: youngergen_card <= v && aoqi@0: v <= cur_youngergen_and_prev_nonclean_card && aoqi@0: v != _cur_youngergen_card_val; aoqi@0: } aoqi@0: aoqi@0: static bool youngergen_may_have_been_dirty(jbyte cv) { aoqi@0: return cv == CardTableRS::cur_youngergen_and_prev_nonclean_card; aoqi@0: } aoqi@0: aoqi@0: }; aoqi@0: aoqi@0: class ClearNoncleanCardWrapper: public MemRegionClosure { aoqi@0: DirtyCardToOopClosure* _dirty_card_closure; aoqi@0: CardTableRS* _ct; aoqi@0: bool _is_par; aoqi@0: private: aoqi@0: // Clears the given card, return true if the corresponding card should be aoqi@0: // processed. aoqi@0: inline bool clear_card(jbyte* entry); aoqi@0: // Work methods called by the clear_card() aoqi@0: inline bool clear_card_serial(jbyte* entry); aoqi@0: inline bool clear_card_parallel(jbyte* entry); aoqi@0: // check alignment of pointer aoqi@0: bool is_word_aligned(jbyte* entry); aoqi@0: aoqi@0: public: aoqi@0: ClearNoncleanCardWrapper(DirtyCardToOopClosure* dirty_card_closure, CardTableRS* ct); aoqi@0: void do_MemRegion(MemRegion mr); aoqi@0: }; aoqi@0: aoqi@0: #endif // SHARE_VM_MEMORY_CARDTABLERS_HPP