ysr@777: /* mikael@6198: * Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved. ysr@777: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. ysr@777: * ysr@777: * This code is free software; you can redistribute it and/or modify it ysr@777: * under the terms of the GNU General Public License version 2 only, as ysr@777: * published by the Free Software Foundation. ysr@777: * ysr@777: * This code is distributed in the hope that it will be useful, but WITHOUT ysr@777: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ysr@777: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ysr@777: * version 2 for more details (a copy is included in the LICENSE file that ysr@777: * accompanied this code). ysr@777: * ysr@777: * You should have received a copy of the GNU General Public License version ysr@777: * 2 along with this work; if not, write to the Free Software Foundation, ysr@777: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. ysr@777: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * questions. ysr@777: * ysr@777: */ ysr@777: stefank@2314: #ifndef SHARE_VM_GC_IMPLEMENTATION_G1_G1SATBCARDTABLEMODREFBS_HPP stefank@2314: #define SHARE_VM_GC_IMPLEMENTATION_G1_G1SATBCARDTABLEMODREFBS_HPP stefank@2314: tschatzl@7051: #include "gc_implementation/g1/g1RegionToSpaceMapper.hpp" stefank@2314: #include "memory/cardTableModRefBS.hpp" stefank@2314: #include "memory/memRegion.hpp" stefank@2314: #include "oops/oop.inline.hpp" jprovino@4542: #include "utilities/macros.hpp" stefank@2314: ysr@777: class DirtyCardQueueSet; tschatzl@7051: class G1SATBCardTableLoggingModRefBS; ysr@777: ysr@777: // This barrier is specialized to use a logging barrier to support ysr@777: // snapshot-at-the-beginning marking. ysr@777: ysr@777: class G1SATBCardTableModRefBS: public CardTableModRefBSForCTRS { mgerdin@5860: protected: mgerdin@5860: enum G1CardValues { mgerdin@5860: g1_young_gen = CT_MR_BS_last_reserved << 1 mgerdin@5860: }; mgerdin@5860: johnc@2781: public: mgerdin@5860: static int g1_young_card_val() { return g1_young_gen; } mgerdin@5860: ysr@777: // Add "pre_val" to a set of objects that may have been disconnected from the ysr@777: // pre-marking object graph. ysr@777: static void enqueue(oop pre_val); ysr@777: ysr@777: G1SATBCardTableModRefBS(MemRegion whole_heap, ysr@777: int max_covered_regions); ysr@777: ysr@777: bool is_a(BarrierSet::Name bsn) { ysr@777: return bsn == BarrierSet::G1SATBCT || CardTableModRefBS::is_a(bsn); ysr@777: } ysr@777: ysr@777: virtual bool has_write_ref_pre_barrier() { return true; } ysr@777: ysr@777: // This notes that we don't need to access any BarrierSet data ysr@777: // structures, so this can be called from a static context. ysr@1280: template static void write_ref_field_pre_static(T* field, oop newVal) { ysr@1280: T heap_oop = oopDesc::load_heap_oop(field); ysr@1280: if (!oopDesc::is_null(heap_oop)) { ysr@1280: enqueue(oopDesc::decode_heap_oop(heap_oop)); ysr@777: } ysr@777: } ysr@777: ysr@777: // We export this to make it available in cases where the static ysr@777: // type of the barrier set is known. Note that it is non-virtual. ysr@1280: template inline void inline_write_ref_field_pre(T* field, oop newVal) { ysr@777: write_ref_field_pre_static(field, newVal); ysr@777: } ysr@777: ysr@1280: // These are the more general virtual versions. ysr@1280: virtual void write_ref_field_pre_work(oop* field, oop new_val) { ysr@777: inline_write_ref_field_pre(field, new_val); ysr@777: } ysr@1280: virtual void write_ref_field_pre_work(narrowOop* field, oop new_val) { ysr@1280: inline_write_ref_field_pre(field, new_val); ysr@1280: } ysr@1280: virtual void write_ref_field_pre_work(void* field, oop new_val) { ysr@1280: guarantee(false, "Not needed"); ysr@1280: } ysr@777: ysr@1280: template void write_ref_array_pre_work(T* dst, int count); mgerdin@6989: virtual void write_ref_array_pre(oop* dst, int count, bool dest_uninitialized); mgerdin@6989: virtual void write_ref_array_pre(narrowOop* dst, int count, bool dest_uninitialized); mgerdin@5811: mgerdin@5811: /* mgerdin@5811: Claimed and deferred bits are used together in G1 during the evacuation mgerdin@5811: pause. These bits can have the following state transitions: mgerdin@5811: 1. The claimed bit can be put over any other card state. Except that mgerdin@5811: the "dirty -> dirty and claimed" transition is checked for in mgerdin@5811: G1 code and is not used. mgerdin@5811: 2. Deferred bit can be set only if the previous state of the card mgerdin@5811: was either clean or claimed. mark_card_deferred() is wait-free. mgerdin@5811: We do not care if the operation is be successful because if mgerdin@5811: it does not it will only result in duplicate entry in the update mgerdin@5811: buffer because of the "cache-miss". So it's not worth spinning. mgerdin@5811: */ mgerdin@5811: mgerdin@5811: bool is_card_claimed(size_t card_index) { mgerdin@5811: jbyte val = _byte_map[card_index]; mgerdin@5811: return (val & (clean_card_mask_val() | claimed_card_val())) == claimed_card_val(); mgerdin@5811: } mgerdin@5811: mgerdin@5811: void set_card_claimed(size_t card_index) { mgerdin@5811: jbyte val = _byte_map[card_index]; mgerdin@5811: if (val == clean_card_val()) { mgerdin@5811: val = (jbyte)claimed_card_val(); mgerdin@5811: } else { mgerdin@5811: val |= (jbyte)claimed_card_val(); mgerdin@5811: } mgerdin@5811: _byte_map[card_index] = val; mgerdin@5811: } mgerdin@5811: mgerdin@5860: void verify_g1_young_region(MemRegion mr) PRODUCT_RETURN; mgerdin@5860: void g1_mark_as_young(const MemRegion& mr); mgerdin@5860: mgerdin@5811: bool mark_card_deferred(size_t card_index); mgerdin@5811: mgerdin@5811: bool is_card_deferred(size_t card_index) { mgerdin@5811: jbyte val = _byte_map[card_index]; mgerdin@5811: return (val & (clean_card_mask_val() | deferred_card_val())) == deferred_card_val(); mgerdin@5811: } tschatzl@7051: }; mgerdin@5811: tschatzl@7051: class G1SATBCardTableLoggingModRefBSChangedListener : public G1MappingChangedListener { tschatzl@7051: private: tschatzl@7051: G1SATBCardTableLoggingModRefBS* _card_table; tschatzl@7051: public: tschatzl@7051: G1SATBCardTableLoggingModRefBSChangedListener() : _card_table(NULL) { } tschatzl@7051: tschatzl@7051: void set_card_table(G1SATBCardTableLoggingModRefBS* card_table) { _card_table = card_table; } tschatzl@7051: tschatzl@7257: virtual void on_commit(uint start_idx, size_t num_regions, bool zero_filled); ysr@777: }; ysr@777: ysr@777: // Adds card-table logging to the post-barrier. ysr@777: // Usual invariant: all dirty cards are logged in the DirtyCardQueueSet. ysr@777: class G1SATBCardTableLoggingModRefBS: public G1SATBCardTableModRefBS { tschatzl@7051: friend class G1SATBCardTableLoggingModRefBSChangedListener; ysr@777: private: tschatzl@7051: G1SATBCardTableLoggingModRefBSChangedListener _listener; ysr@777: DirtyCardQueueSet& _dcqs; ysr@777: public: tschatzl@7051: static size_t compute_size(size_t mem_region_size_in_words) { tschatzl@7051: size_t number_of_slots = (mem_region_size_in_words / card_size_in_words); tschatzl@7051: return ReservedSpace::allocation_align_size_up(number_of_slots); tschatzl@7051: } tschatzl@7051: ysr@777: G1SATBCardTableLoggingModRefBS(MemRegion whole_heap, ysr@777: int max_covered_regions); ysr@777: tschatzl@7051: virtual void initialize() { } tschatzl@7051: virtual void initialize(G1RegionToSpaceMapper* mapper); tschatzl@7051: tschatzl@7051: virtual void resize_covered_region(MemRegion new_region) { ShouldNotReachHere(); } tschatzl@7051: ysr@777: bool is_a(BarrierSet::Name bsn) { ysr@777: return bsn == BarrierSet::G1SATBCTLogging || ysr@777: G1SATBCardTableModRefBS::is_a(bsn); ysr@777: } ysr@777: goetz@6493: void write_ref_field_work(void* field, oop new_val, bool release = false); ysr@777: ysr@777: // Can be called from static contexts. ysr@777: static void write_ref_field_static(void* field, oop new_val); ysr@777: ysr@777: // NB: if you do a whole-heap invalidation, the "usual invariant" defined ysr@777: // above no longer applies. ysr@777: void invalidate(MemRegion mr, bool whole_heap = false); ysr@777: ysr@777: void write_region_work(MemRegion mr) { invalidate(mr); } ysr@777: void write_ref_array_work(MemRegion mr) { invalidate(mr); } ysr@777: }; ysr@777: stefank@2314: #endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1SATBCARDTABLEMODREFBS_HPP