annotate src/share/vm/gc_implementation/g1/g1EvacFailure.hpp @ 5188:5afc5a089c2c

8014555: G1: Memory ordering problem with Conc refinement and card marking Summary: Add a StoreLoad barrier in the G1 post-barrier to fix a race with concurrent refinement. Reviewed-by: brutisso, tschatzl, roland
author mgerdin
date Tue, 08 Oct 2013 17:35:51 +0200
parents eff609af17d7
children
rev   line source
johnc@3276 1 /*
johnc@3276 2 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
johnc@3276 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
johnc@3276 4 *
johnc@3276 5 * This code is free software; you can redistribute it and/or modify it
johnc@3276 6 * under the terms of the GNU General Public License version 2 only, as
johnc@3276 7 * published by the Free Software Foundation.
johnc@3276 8 *
johnc@3276 9 * This code is distributed in the hope that it will be useful, but WITHOUT
johnc@3276 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
johnc@3276 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
johnc@3276 12 * version 2 for more details (a copy is included in the LICENSE file that
johnc@3276 13 * accompanied this code).
johnc@3276 14 *
johnc@3276 15 * You should have received a copy of the GNU General Public License version
johnc@3276 16 * 2 along with this work; if not, write to the Free Software Foundation,
johnc@3276 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
johnc@3276 18 *
johnc@3276 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
johnc@3276 20 * or visit www.oracle.com if you need additional information or have any
johnc@3276 21 * questions.
johnc@3276 22 *
johnc@3276 23 */
johnc@3276 24
johnc@3276 25 #ifndef SHARE_VM_GC_IMPLEMENTATION_G1_G1EVACFAILURE_HPP
johnc@3276 26 #define SHARE_VM_GC_IMPLEMENTATION_G1_G1EVACFAILURE_HPP
johnc@3276 27
johnc@3276 28 #include "gc_implementation/g1/concurrentMark.inline.hpp"
johnc@3276 29 #include "gc_implementation/g1/dirtyCardQueue.hpp"
johnc@3276 30 #include "gc_implementation/g1/g1CollectedHeap.inline.hpp"
johnc@3276 31 #include "gc_implementation/g1/g1_globals.hpp"
johnc@3276 32 #include "gc_implementation/g1/g1OopClosures.inline.hpp"
johnc@3276 33 #include "gc_implementation/g1/heapRegion.hpp"
johnc@3276 34 #include "gc_implementation/g1/heapRegionRemSet.hpp"
johnc@3276 35 #include "utilities/workgroup.hpp"
johnc@3276 36
johnc@3276 37 // Closures and tasks associated with any self-forwarding pointers
johnc@3276 38 // installed as a result of an evacuation failure.
johnc@3276 39
johnc@3276 40 class UpdateRSetDeferred : public OopsInHeapRegionClosure {
johnc@3276 41 private:
johnc@3276 42 G1CollectedHeap* _g1;
johnc@3276 43 DirtyCardQueue *_dcq;
mgerdin@5187 44 G1SATBCardTableModRefBS* _ct_bs;
johnc@3276 45
johnc@3276 46 public:
johnc@3276 47 UpdateRSetDeferred(G1CollectedHeap* g1, DirtyCardQueue* dcq) :
mgerdin@5187 48 _g1(g1), _ct_bs(_g1->g1_barrier_set()), _dcq(dcq) {}
johnc@3276 49
johnc@3276 50 virtual void do_oop(narrowOop* p) { do_oop_work(p); }
johnc@3276 51 virtual void do_oop( oop* p) { do_oop_work(p); }
johnc@3276 52 template <class T> void do_oop_work(T* p) {
johnc@3276 53 assert(_from->is_in_reserved(p), "paranoia");
johnc@3276 54 if (!_from->is_in_reserved(oopDesc::load_decode_heap_oop(p)) &&
johnc@3276 55 !_from->is_survivor()) {
johnc@3276 56 size_t card_index = _ct_bs->index_for(p);
johnc@3276 57 if (_ct_bs->mark_card_deferred(card_index)) {
johnc@3276 58 _dcq->enqueue((jbyte*)_ct_bs->byte_for_index(card_index));
johnc@3276 59 }
johnc@3276 60 }
johnc@3276 61 }
johnc@3276 62 };
johnc@3276 63
johnc@3276 64 class RemoveSelfForwardPtrObjClosure: public ObjectClosure {
johnc@3276 65 private:
johnc@3276 66 G1CollectedHeap* _g1;
johnc@3276 67 ConcurrentMark* _cm;
johnc@3276 68 HeapRegion* _hr;
tonyp@3280 69 size_t _marked_bytes;
johnc@3276 70 OopsInHeapRegionClosure *_update_rset_cl;
tonyp@3280 71 bool _during_initial_mark;
tonyp@3280 72 bool _during_conc_mark;
johnc@3332 73 uint _worker_id;
johnc@3332 74
johnc@3276 75 public:
johnc@3276 76 RemoveSelfForwardPtrObjClosure(G1CollectedHeap* g1, ConcurrentMark* cm,
johnc@3276 77 HeapRegion* hr,
tonyp@3280 78 OopsInHeapRegionClosure* update_rset_cl,
tonyp@3280 79 bool during_initial_mark,
johnc@3332 80 bool during_conc_mark,
johnc@3332 81 uint worker_id) :
tonyp@3280 82 _g1(g1), _cm(cm), _hr(hr), _marked_bytes(0),
johnc@3276 83 _update_rset_cl(update_rset_cl),
tonyp@3280 84 _during_initial_mark(during_initial_mark),
johnc@3332 85 _during_conc_mark(during_conc_mark),
johnc@3332 86 _worker_id(worker_id) { }
johnc@3276 87
tonyp@3280 88 size_t marked_bytes() { return _marked_bytes; }
johnc@3276 89
johnc@3276 90 // <original comment>
johnc@3276 91 // The original idea here was to coalesce evacuated and dead objects.
johnc@3276 92 // However that caused complications with the block offset table (BOT).
johnc@3276 93 // In particular if there were two TLABs, one of them partially refined.
johnc@3276 94 // |----- TLAB_1--------|----TLAB_2-~~~(partially refined part)~~~|
johnc@3276 95 // The BOT entries of the unrefined part of TLAB_2 point to the start
johnc@3276 96 // of TLAB_2. If the last object of the TLAB_1 and the first object
johnc@3276 97 // of TLAB_2 are coalesced, then the cards of the unrefined part
johnc@3276 98 // would point into middle of the filler object.
johnc@3276 99 // The current approach is to not coalesce and leave the BOT contents intact.
johnc@3276 100 // </original comment>
johnc@3276 101 //
johnc@3276 102 // We now reset the BOT when we start the object iteration over the
johnc@3276 103 // region and refine its entries for every object we come across. So
johnc@3276 104 // the above comment is not really relevant and we should be able
johnc@3276 105 // to coalesce dead objects if we want to.
johnc@3276 106 void do_object(oop obj) {
johnc@3276 107 HeapWord* obj_addr = (HeapWord*) obj;
johnc@3276 108 assert(_hr->is_in(obj_addr), "sanity");
johnc@3276 109 size_t obj_size = obj->size();
johnc@3276 110 _hr->update_bot_for_object(obj_addr, obj_size);
johnc@3276 111
johnc@3276 112 if (obj->is_forwarded() && obj->forwardee() == obj) {
johnc@3276 113 // The object failed to move.
tonyp@3280 114
tonyp@3280 115 // We consider all objects that we find self-forwarded to be
tonyp@3280 116 // live. What we'll do is that we'll update the prev marking
tonyp@3280 117 // info so that they are all under PTAMS and explicitly marked.
johnc@3276 118 _cm->markPrev(obj);
tonyp@3280 119 if (_during_initial_mark) {
tonyp@3280 120 // For the next marking info we'll only mark the
tonyp@3280 121 // self-forwarded objects explicitly if we are during
tonyp@3280 122 // initial-mark (since, normally, we only mark objects pointed
tonyp@3280 123 // to by roots if we succeed in copying them). By marking all
tonyp@3280 124 // self-forwarded objects we ensure that we mark any that are
tonyp@3280 125 // still pointed to be roots. During concurrent marking, and
tonyp@3280 126 // after initial-mark, we don't need to mark any objects
tonyp@3280 127 // explicitly and all objects in the CSet are considered
tonyp@3280 128 // (implicitly) live. So, we won't mark them explicitly and
tonyp@3280 129 // we'll leave them over NTAMS.
tonyp@3333 130 _cm->grayRoot(obj, obj_size, _worker_id, _hr);
johnc@3276 131 }
tonyp@3280 132 _marked_bytes += (obj_size * HeapWordSize);
johnc@3276 133 obj->set_mark(markOopDesc::prototype());
johnc@3276 134
johnc@3276 135 // While we were processing RSet buffers during the collection,
johnc@3276 136 // we actually didn't scan any cards on the collection set,
johnc@3276 137 // since we didn't want to update remembered sets with entries
johnc@3276 138 // that point into the collection set, given that live objects
johnc@3276 139 // from the collection set are about to move and such entries
johnc@3276 140 // will be stale very soon.
johnc@3276 141 // This change also dealt with a reliability issue which
johnc@3276 142 // involved scanning a card in the collection set and coming
johnc@3276 143 // across an array that was being chunked and looking malformed.
johnc@3276 144 // The problem is that, if evacuation fails, we might have
johnc@3276 145 // remembered set entries missing given that we skipped cards on
johnc@3276 146 // the collection set. So, we'll recreate such entries now.
johnc@3276 147 obj->oop_iterate(_update_rset_cl);
johnc@3276 148 assert(_cm->isPrevMarked(obj), "Should be marked!");
johnc@3276 149 } else {
johnc@3276 150 // The object has been either evacuated or is dead. Fill it with a
johnc@3276 151 // dummy object.
tonyp@3280 152 MemRegion mr((HeapWord*) obj, obj_size);
johnc@3276 153 CollectedHeap::fill_with_object(mr);
johnc@3276 154 }
johnc@3276 155 }
johnc@3276 156 };
johnc@3276 157
johnc@3276 158 class RemoveSelfForwardPtrHRClosure: public HeapRegionClosure {
johnc@3276 159 G1CollectedHeap* _g1h;
johnc@3276 160 ConcurrentMark* _cm;
johnc@3276 161 OopsInHeapRegionClosure *_update_rset_cl;
johnc@3332 162 uint _worker_id;
johnc@3276 163
johnc@3276 164 public:
johnc@3276 165 RemoveSelfForwardPtrHRClosure(G1CollectedHeap* g1h,
johnc@3332 166 OopsInHeapRegionClosure* update_rset_cl,
johnc@3332 167 uint worker_id) :
johnc@3276 168 _g1h(g1h), _update_rset_cl(update_rset_cl),
johnc@3332 169 _worker_id(worker_id), _cm(_g1h->concurrent_mark()) { }
johnc@3276 170
johnc@3276 171 bool doHeapRegion(HeapRegion *hr) {
tonyp@3280 172 bool during_initial_mark = _g1h->g1_policy()->during_initial_mark_pause();
tonyp@3280 173 bool during_conc_mark = _g1h->mark_in_progress();
tonyp@3280 174
johnc@3276 175 assert(!hr->isHumongous(), "sanity");
johnc@3276 176 assert(hr->in_collection_set(), "bad CS");
johnc@3276 177
johnc@3276 178 if (hr->claimHeapRegion(HeapRegion::ParEvacFailureClaimValue)) {
johnc@3276 179 if (hr->evacuation_failed()) {
tonyp@3280 180 RemoveSelfForwardPtrObjClosure rspc(_g1h, _cm, hr, _update_rset_cl,
tonyp@3280 181 during_initial_mark,
johnc@3332 182 during_conc_mark,
johnc@3332 183 _worker_id);
tonyp@3280 184
tonyp@3280 185 MemRegion mr(hr->bottom(), hr->end());
tonyp@3280 186 // We'll recreate the prev marking info so we'll first clear
tonyp@3280 187 // the prev bitmap range for this region. We never mark any
tonyp@3280 188 // CSet objects explicitly so the next bitmap range should be
tonyp@3280 189 // cleared anyway.
tonyp@3280 190 _cm->clearRangePrevBitmap(mr);
tonyp@3280 191
tonyp@3280 192 hr->note_self_forwarding_removal_start(during_initial_mark,
tonyp@3280 193 during_conc_mark);
johnc@3276 194
johnc@3276 195 // In the common case (i.e. when there is no evacuation
johnc@3276 196 // failure) we make sure that the following is done when
johnc@3276 197 // the region is freed so that it is "ready-to-go" when it's
johnc@3276 198 // re-allocated. However, when evacuation failure happens, a
johnc@3276 199 // region will remain in the heap and might ultimately be added
johnc@3276 200 // to a CSet in the future. So we have to be careful here and
johnc@3276 201 // make sure the region's RSet is ready for parallel iteration
johnc@3276 202 // whenever this might be required in the future.
johnc@3276 203 hr->rem_set()->reset_for_par_iteration();
johnc@3276 204 hr->reset_bot();
johnc@3276 205 _update_rset_cl->set_region(hr);
johnc@3276 206 hr->object_iterate(&rspc);
johnc@3276 207
tonyp@3280 208 hr->note_self_forwarding_removal_end(during_initial_mark,
tonyp@3280 209 during_conc_mark,
tonyp@3280 210 rspc.marked_bytes());
johnc@3276 211 }
johnc@3276 212 }
johnc@3276 213 return false;
johnc@3276 214 }
johnc@3276 215 };
johnc@3276 216
johnc@3276 217 class G1ParRemoveSelfForwardPtrsTask: public AbstractGangTask {
johnc@3276 218 protected:
johnc@3276 219 G1CollectedHeap* _g1h;
johnc@3276 220
johnc@3276 221 public:
johnc@3276 222 G1ParRemoveSelfForwardPtrsTask(G1CollectedHeap* g1h) :
johnc@3276 223 AbstractGangTask("G1 Remove Self-forwarding Pointers"),
johnc@3276 224 _g1h(g1h) { }
johnc@3276 225
johnc@3276 226 void work(uint worker_id) {
johnc@3276 227 UpdateRSetImmediate immediate_update(_g1h->g1_rem_set());
johnc@3276 228 DirtyCardQueue dcq(&_g1h->dirty_card_queue_set());
johnc@3276 229 UpdateRSetDeferred deferred_update(_g1h, &dcq);
johnc@3276 230
johnc@3276 231 OopsInHeapRegionClosure *update_rset_cl = &deferred_update;
johnc@3276 232 if (!G1DeferredRSUpdate) {
johnc@3276 233 update_rset_cl = &immediate_update;
johnc@3276 234 }
johnc@3276 235
johnc@3332 236 RemoveSelfForwardPtrHRClosure rsfp_cl(_g1h, update_rset_cl, worker_id);
johnc@3276 237
johnc@3276 238 HeapRegion* hr = _g1h->start_cset_region_for_worker(worker_id);
johnc@3276 239 _g1h->collection_set_iterate_from(hr, &rsfp_cl);
johnc@3276 240 }
johnc@3276 241 };
johnc@3276 242
johnc@3276 243 #endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1EVACFAILURE_HPP