src/share/vm/gc_implementation/g1/g1SATBCardTableModRefBS.hpp

Thu, 12 Oct 2017 21:27:07 +0800

author
aoqi
date
Thu, 12 Oct 2017 21:27:07 +0800
changeset 7535
7ae4e26cb1e0
parent 7257
e7d0505c8a30
parent 6876
710a3c8b516e
permissions
-rw-r--r--

merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #ifndef SHARE_VM_GC_IMPLEMENTATION_G1_G1SATBCARDTABLEMODREFBS_HPP
aoqi@0 26 #define SHARE_VM_GC_IMPLEMENTATION_G1_G1SATBCARDTABLEMODREFBS_HPP
aoqi@0 27
tschatzl@7051 28 #include "gc_implementation/g1/g1RegionToSpaceMapper.hpp"
aoqi@0 29 #include "memory/cardTableModRefBS.hpp"
aoqi@0 30 #include "memory/memRegion.hpp"
aoqi@0 31 #include "oops/oop.inline.hpp"
aoqi@0 32 #include "utilities/macros.hpp"
aoqi@0 33
aoqi@0 34 class DirtyCardQueueSet;
tschatzl@7051 35 class G1SATBCardTableLoggingModRefBS;
aoqi@0 36
aoqi@0 37 // This barrier is specialized to use a logging barrier to support
aoqi@0 38 // snapshot-at-the-beginning marking.
aoqi@0 39
aoqi@0 40 class G1SATBCardTableModRefBS: public CardTableModRefBSForCTRS {
aoqi@0 41 protected:
aoqi@0 42 enum G1CardValues {
aoqi@0 43 g1_young_gen = CT_MR_BS_last_reserved << 1
aoqi@0 44 };
aoqi@0 45
aoqi@0 46 public:
aoqi@0 47 static int g1_young_card_val() { return g1_young_gen; }
aoqi@0 48
aoqi@0 49 // Add "pre_val" to a set of objects that may have been disconnected from the
aoqi@0 50 // pre-marking object graph.
aoqi@0 51 static void enqueue(oop pre_val);
aoqi@0 52
aoqi@0 53 G1SATBCardTableModRefBS(MemRegion whole_heap,
aoqi@0 54 int max_covered_regions);
aoqi@0 55
aoqi@0 56 bool is_a(BarrierSet::Name bsn) {
aoqi@0 57 return bsn == BarrierSet::G1SATBCT || CardTableModRefBS::is_a(bsn);
aoqi@0 58 }
aoqi@0 59
aoqi@0 60 virtual bool has_write_ref_pre_barrier() { return true; }
aoqi@0 61
aoqi@0 62 // This notes that we don't need to access any BarrierSet data
aoqi@0 63 // structures, so this can be called from a static context.
aoqi@0 64 template <class T> static void write_ref_field_pre_static(T* field, oop newVal) {
aoqi@0 65 T heap_oop = oopDesc::load_heap_oop(field);
aoqi@0 66 if (!oopDesc::is_null(heap_oop)) {
aoqi@0 67 enqueue(oopDesc::decode_heap_oop(heap_oop));
aoqi@0 68 }
aoqi@0 69 }
aoqi@0 70
aoqi@0 71 // We export this to make it available in cases where the static
aoqi@0 72 // type of the barrier set is known. Note that it is non-virtual.
aoqi@0 73 template <class T> inline void inline_write_ref_field_pre(T* field, oop newVal) {
aoqi@0 74 write_ref_field_pre_static(field, newVal);
aoqi@0 75 }
aoqi@0 76
aoqi@0 77 // These are the more general virtual versions.
aoqi@0 78 virtual void write_ref_field_pre_work(oop* field, oop new_val) {
aoqi@0 79 inline_write_ref_field_pre(field, new_val);
aoqi@0 80 }
aoqi@0 81 virtual void write_ref_field_pre_work(narrowOop* field, oop new_val) {
aoqi@0 82 inline_write_ref_field_pre(field, new_val);
aoqi@0 83 }
aoqi@0 84 virtual void write_ref_field_pre_work(void* field, oop new_val) {
aoqi@0 85 guarantee(false, "Not needed");
aoqi@0 86 }
aoqi@0 87
aoqi@0 88 template <class T> void write_ref_array_pre_work(T* dst, int count);
mgerdin@6989 89 virtual void write_ref_array_pre(oop* dst, int count, bool dest_uninitialized);
mgerdin@6989 90 virtual void write_ref_array_pre(narrowOop* dst, int count, bool dest_uninitialized);
aoqi@0 91
aoqi@0 92 /*
aoqi@0 93 Claimed and deferred bits are used together in G1 during the evacuation
aoqi@0 94 pause. These bits can have the following state transitions:
aoqi@0 95 1. The claimed bit can be put over any other card state. Except that
aoqi@0 96 the "dirty -> dirty and claimed" transition is checked for in
aoqi@0 97 G1 code and is not used.
aoqi@0 98 2. Deferred bit can be set only if the previous state of the card
aoqi@0 99 was either clean or claimed. mark_card_deferred() is wait-free.
aoqi@0 100 We do not care if the operation is be successful because if
aoqi@0 101 it does not it will only result in duplicate entry in the update
aoqi@0 102 buffer because of the "cache-miss". So it's not worth spinning.
aoqi@0 103 */
aoqi@0 104
aoqi@0 105 bool is_card_claimed(size_t card_index) {
aoqi@0 106 jbyte val = _byte_map[card_index];
aoqi@0 107 return (val & (clean_card_mask_val() | claimed_card_val())) == claimed_card_val();
aoqi@0 108 }
aoqi@0 109
aoqi@0 110 void set_card_claimed(size_t card_index) {
aoqi@0 111 jbyte val = _byte_map[card_index];
aoqi@0 112 if (val == clean_card_val()) {
aoqi@0 113 val = (jbyte)claimed_card_val();
aoqi@0 114 } else {
aoqi@0 115 val |= (jbyte)claimed_card_val();
aoqi@0 116 }
aoqi@0 117 _byte_map[card_index] = val;
aoqi@0 118 }
aoqi@0 119
aoqi@0 120 void verify_g1_young_region(MemRegion mr) PRODUCT_RETURN;
aoqi@0 121 void g1_mark_as_young(const MemRegion& mr);
aoqi@0 122
aoqi@0 123 bool mark_card_deferred(size_t card_index);
aoqi@0 124
aoqi@0 125 bool is_card_deferred(size_t card_index) {
aoqi@0 126 jbyte val = _byte_map[card_index];
aoqi@0 127 return (val & (clean_card_mask_val() | deferred_card_val())) == deferred_card_val();
aoqi@0 128 }
tschatzl@7051 129 };
aoqi@0 130
tschatzl@7051 131 class G1SATBCardTableLoggingModRefBSChangedListener : public G1MappingChangedListener {
tschatzl@7051 132 private:
tschatzl@7051 133 G1SATBCardTableLoggingModRefBS* _card_table;
tschatzl@7051 134 public:
tschatzl@7051 135 G1SATBCardTableLoggingModRefBSChangedListener() : _card_table(NULL) { }
tschatzl@7051 136
tschatzl@7051 137 void set_card_table(G1SATBCardTableLoggingModRefBS* card_table) { _card_table = card_table; }
tschatzl@7051 138
tschatzl@7257 139 virtual void on_commit(uint start_idx, size_t num_regions, bool zero_filled);
aoqi@0 140 };
aoqi@0 141
aoqi@0 142 // Adds card-table logging to the post-barrier.
aoqi@0 143 // Usual invariant: all dirty cards are logged in the DirtyCardQueueSet.
aoqi@0 144 class G1SATBCardTableLoggingModRefBS: public G1SATBCardTableModRefBS {
tschatzl@7051 145 friend class G1SATBCardTableLoggingModRefBSChangedListener;
aoqi@0 146 private:
tschatzl@7051 147 G1SATBCardTableLoggingModRefBSChangedListener _listener;
aoqi@0 148 DirtyCardQueueSet& _dcqs;
aoqi@0 149 public:
tschatzl@7051 150 static size_t compute_size(size_t mem_region_size_in_words) {
tschatzl@7051 151 size_t number_of_slots = (mem_region_size_in_words / card_size_in_words);
tschatzl@7051 152 return ReservedSpace::allocation_align_size_up(number_of_slots);
tschatzl@7051 153 }
tschatzl@7051 154
aoqi@0 155 G1SATBCardTableLoggingModRefBS(MemRegion whole_heap,
aoqi@0 156 int max_covered_regions);
aoqi@0 157
tschatzl@7051 158 virtual void initialize() { }
tschatzl@7051 159 virtual void initialize(G1RegionToSpaceMapper* mapper);
tschatzl@7051 160
tschatzl@7051 161 virtual void resize_covered_region(MemRegion new_region) { ShouldNotReachHere(); }
tschatzl@7051 162
aoqi@0 163 bool is_a(BarrierSet::Name bsn) {
aoqi@0 164 return bsn == BarrierSet::G1SATBCTLogging ||
aoqi@0 165 G1SATBCardTableModRefBS::is_a(bsn);
aoqi@0 166 }
aoqi@0 167
aoqi@0 168 void write_ref_field_work(void* field, oop new_val, bool release = false);
aoqi@0 169
aoqi@0 170 // Can be called from static contexts.
aoqi@0 171 static void write_ref_field_static(void* field, oop new_val);
aoqi@0 172
aoqi@0 173 // NB: if you do a whole-heap invalidation, the "usual invariant" defined
aoqi@0 174 // above no longer applies.
aoqi@0 175 void invalidate(MemRegion mr, bool whole_heap = false);
aoqi@0 176
aoqi@0 177 void write_region_work(MemRegion mr) { invalidate(mr); }
aoqi@0 178 void write_ref_array_work(MemRegion mr) { invalidate(mr); }
aoqi@0 179 };
aoqi@0 180
aoqi@0 181 #endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1SATBCARDTABLEMODREFBS_HPP

mercurial