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

Tue, 17 Oct 2017 12:58:25 +0800

author
aoqi
date
Tue, 17 Oct 2017 12:58:25 +0800
changeset 7994
04ff2f6cd0eb
parent 7535
7ae4e26cb1e0
permissions
-rw-r--r--

merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2012, 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_G1EVACFAILURE_HPP
aoqi@0 26 #define SHARE_VM_GC_IMPLEMENTATION_G1_G1EVACFAILURE_HPP
aoqi@0 27
aoqi@0 28 #include "gc_implementation/g1/concurrentMark.inline.hpp"
aoqi@0 29 #include "gc_implementation/g1/dirtyCardQueue.hpp"
aoqi@0 30 #include "gc_implementation/g1/g1CollectedHeap.inline.hpp"
aoqi@0 31 #include "gc_implementation/g1/g1_globals.hpp"
aoqi@0 32 #include "gc_implementation/g1/g1OopClosures.inline.hpp"
aoqi@0 33 #include "gc_implementation/g1/heapRegion.hpp"
aoqi@0 34 #include "gc_implementation/g1/heapRegionRemSet.hpp"
aoqi@0 35 #include "utilities/workgroup.hpp"
aoqi@0 36
aoqi@0 37 // Closures and tasks associated with any self-forwarding pointers
aoqi@0 38 // installed as a result of an evacuation failure.
aoqi@0 39
aoqi@0 40 class UpdateRSetDeferred : public OopsInHeapRegionClosure {
aoqi@0 41 private:
aoqi@0 42 G1CollectedHeap* _g1;
aoqi@0 43 DirtyCardQueue *_dcq;
aoqi@0 44 G1SATBCardTableModRefBS* _ct_bs;
aoqi@0 45
aoqi@0 46 public:
aoqi@0 47 UpdateRSetDeferred(G1CollectedHeap* g1, DirtyCardQueue* dcq) :
aoqi@0 48 _g1(g1), _ct_bs(_g1->g1_barrier_set()), _dcq(dcq) {}
aoqi@0 49
aoqi@0 50 virtual void do_oop(narrowOop* p) { do_oop_work(p); }
aoqi@0 51 virtual void do_oop( oop* p) { do_oop_work(p); }
aoqi@0 52 template <class T> void do_oop_work(T* p) {
aoqi@0 53 assert(_from->is_in_reserved(p), "paranoia");
aoqi@0 54 if (!_from->is_in_reserved(oopDesc::load_decode_heap_oop(p)) &&
aoqi@0 55 !_from->is_survivor()) {
aoqi@0 56 size_t card_index = _ct_bs->index_for(p);
aoqi@0 57 if (_ct_bs->mark_card_deferred(card_index)) {
aoqi@0 58 _dcq->enqueue((jbyte*)_ct_bs->byte_for_index(card_index));
aoqi@0 59 }
aoqi@0 60 }
aoqi@0 61 }
aoqi@0 62 };
aoqi@0 63
aoqi@0 64 class RemoveSelfForwardPtrObjClosure: public ObjectClosure {
aoqi@0 65 private:
aoqi@0 66 G1CollectedHeap* _g1;
aoqi@0 67 ConcurrentMark* _cm;
aoqi@0 68 HeapRegion* _hr;
aoqi@0 69 size_t _marked_bytes;
aoqi@0 70 OopsInHeapRegionClosure *_update_rset_cl;
aoqi@0 71 bool _during_initial_mark;
aoqi@0 72 bool _during_conc_mark;
aoqi@0 73 uint _worker_id;
stefank@6992 74 HeapWord* _end_of_last_gap;
stefank@6992 75 HeapWord* _last_gap_threshold;
stefank@6992 76 HeapWord* _last_obj_threshold;
aoqi@0 77
aoqi@0 78 public:
aoqi@0 79 RemoveSelfForwardPtrObjClosure(G1CollectedHeap* g1, ConcurrentMark* cm,
aoqi@0 80 HeapRegion* hr,
aoqi@0 81 OopsInHeapRegionClosure* update_rset_cl,
aoqi@0 82 bool during_initial_mark,
aoqi@0 83 bool during_conc_mark,
aoqi@0 84 uint worker_id) :
aoqi@0 85 _g1(g1), _cm(cm), _hr(hr), _marked_bytes(0),
aoqi@0 86 _update_rset_cl(update_rset_cl),
aoqi@0 87 _during_initial_mark(during_initial_mark),
aoqi@0 88 _during_conc_mark(during_conc_mark),
stefank@6992 89 _worker_id(worker_id),
stefank@6992 90 _end_of_last_gap(hr->bottom()),
stefank@6992 91 _last_gap_threshold(hr->bottom()),
stefank@6992 92 _last_obj_threshold(hr->bottom()) { }
aoqi@0 93
aoqi@0 94 size_t marked_bytes() { return _marked_bytes; }
aoqi@0 95
aoqi@0 96 // <original comment>
aoqi@0 97 // The original idea here was to coalesce evacuated and dead objects.
aoqi@0 98 // However that caused complications with the block offset table (BOT).
aoqi@0 99 // In particular if there were two TLABs, one of them partially refined.
aoqi@0 100 // |----- TLAB_1--------|----TLAB_2-~~~(partially refined part)~~~|
aoqi@0 101 // The BOT entries of the unrefined part of TLAB_2 point to the start
aoqi@0 102 // of TLAB_2. If the last object of the TLAB_1 and the first object
aoqi@0 103 // of TLAB_2 are coalesced, then the cards of the unrefined part
aoqi@0 104 // would point into middle of the filler object.
aoqi@0 105 // The current approach is to not coalesce and leave the BOT contents intact.
aoqi@0 106 // </original comment>
aoqi@0 107 //
aoqi@0 108 // We now reset the BOT when we start the object iteration over the
aoqi@0 109 // region and refine its entries for every object we come across. So
aoqi@0 110 // the above comment is not really relevant and we should be able
aoqi@0 111 // to coalesce dead objects if we want to.
aoqi@0 112 void do_object(oop obj) {
aoqi@0 113 HeapWord* obj_addr = (HeapWord*) obj;
aoqi@0 114 assert(_hr->is_in(obj_addr), "sanity");
aoqi@0 115 size_t obj_size = obj->size();
stefank@6992 116 HeapWord* obj_end = obj_addr + obj_size;
stefank@6992 117
stefank@6992 118 if (_end_of_last_gap != obj_addr) {
stefank@6992 119 // there was a gap before obj_addr
stefank@6992 120 _last_gap_threshold = _hr->cross_threshold(_end_of_last_gap, obj_addr);
stefank@6992 121 }
aoqi@0 122
aoqi@0 123 if (obj->is_forwarded() && obj->forwardee() == obj) {
aoqi@0 124 // The object failed to move.
aoqi@0 125
aoqi@0 126 // We consider all objects that we find self-forwarded to be
aoqi@0 127 // live. What we'll do is that we'll update the prev marking
aoqi@0 128 // info so that they are all under PTAMS and explicitly marked.
stefank@6992 129 if (!_cm->isPrevMarked(obj)) {
stefank@6992 130 _cm->markPrev(obj);
stefank@6992 131 }
aoqi@0 132 if (_during_initial_mark) {
aoqi@0 133 // For the next marking info we'll only mark the
aoqi@0 134 // self-forwarded objects explicitly if we are during
aoqi@0 135 // initial-mark (since, normally, we only mark objects pointed
aoqi@0 136 // to by roots if we succeed in copying them). By marking all
aoqi@0 137 // self-forwarded objects we ensure that we mark any that are
aoqi@0 138 // still pointed to be roots. During concurrent marking, and
aoqi@0 139 // after initial-mark, we don't need to mark any objects
aoqi@0 140 // explicitly and all objects in the CSet are considered
aoqi@0 141 // (implicitly) live. So, we won't mark them explicitly and
aoqi@0 142 // we'll leave them over NTAMS.
aoqi@0 143 _cm->grayRoot(obj, obj_size, _worker_id, _hr);
aoqi@0 144 }
aoqi@0 145 _marked_bytes += (obj_size * HeapWordSize);
aoqi@0 146 obj->set_mark(markOopDesc::prototype());
aoqi@0 147
aoqi@0 148 // While we were processing RSet buffers during the collection,
aoqi@0 149 // we actually didn't scan any cards on the collection set,
aoqi@0 150 // since we didn't want to update remembered sets with entries
aoqi@0 151 // that point into the collection set, given that live objects
aoqi@0 152 // from the collection set are about to move and such entries
aoqi@0 153 // will be stale very soon.
aoqi@0 154 // This change also dealt with a reliability issue which
aoqi@0 155 // involved scanning a card in the collection set and coming
aoqi@0 156 // across an array that was being chunked and looking malformed.
aoqi@0 157 // The problem is that, if evacuation fails, we might have
aoqi@0 158 // remembered set entries missing given that we skipped cards on
aoqi@0 159 // the collection set. So, we'll recreate such entries now.
aoqi@0 160 obj->oop_iterate(_update_rset_cl);
aoqi@0 161 } else {
stefank@6992 162
aoqi@0 163 // The object has been either evacuated or is dead. Fill it with a
aoqi@0 164 // dummy object.
stefank@6992 165 MemRegion mr(obj_addr, obj_size);
aoqi@0 166 CollectedHeap::fill_with_object(mr);
stefank@6992 167
stefank@6992 168 // must nuke all dead objects which we skipped when iterating over the region
stefank@6992 169 _cm->clearRangePrevBitmap(MemRegion(_end_of_last_gap, obj_end));
aoqi@0 170 }
stefank@6992 171 _end_of_last_gap = obj_end;
stefank@6992 172 _last_obj_threshold = _hr->cross_threshold(obj_addr, obj_end);
aoqi@0 173 }
aoqi@0 174 };
aoqi@0 175
aoqi@0 176 class RemoveSelfForwardPtrHRClosure: public HeapRegionClosure {
aoqi@0 177 G1CollectedHeap* _g1h;
aoqi@0 178 ConcurrentMark* _cm;
aoqi@0 179 uint _worker_id;
aoqi@0 180
tschatzl@7218 181 DirtyCardQueue _dcq;
tschatzl@7218 182 UpdateRSetDeferred _update_rset_cl;
tschatzl@7218 183
aoqi@0 184 public:
aoqi@0 185 RemoveSelfForwardPtrHRClosure(G1CollectedHeap* g1h,
aoqi@0 186 uint worker_id) :
tschatzl@7218 187 _g1h(g1h), _dcq(&g1h->dirty_card_queue_set()), _update_rset_cl(g1h, &_dcq),
tschatzl@7218 188 _worker_id(worker_id), _cm(_g1h->concurrent_mark()) {
tschatzl@7218 189 }
aoqi@0 190
aoqi@0 191 bool doHeapRegion(HeapRegion *hr) {
aoqi@0 192 bool during_initial_mark = _g1h->g1_policy()->during_initial_mark_pause();
aoqi@0 193 bool during_conc_mark = _g1h->mark_in_progress();
aoqi@0 194
aoqi@0 195 assert(!hr->isHumongous(), "sanity");
aoqi@0 196 assert(hr->in_collection_set(), "bad CS");
aoqi@0 197
aoqi@0 198 if (hr->claimHeapRegion(HeapRegion::ParEvacFailureClaimValue)) {
aoqi@0 199 if (hr->evacuation_failed()) {
tschatzl@7218 200 RemoveSelfForwardPtrObjClosure rspc(_g1h, _cm, hr, &_update_rset_cl,
aoqi@0 201 during_initial_mark,
aoqi@0 202 during_conc_mark,
aoqi@0 203 _worker_id);
aoqi@0 204
aoqi@0 205 hr->note_self_forwarding_removal_start(during_initial_mark,
aoqi@0 206 during_conc_mark);
brutisso@7005 207 _g1h->check_bitmaps("Self-Forwarding Ptr Removal", hr);
aoqi@0 208
aoqi@0 209 // In the common case (i.e. when there is no evacuation
aoqi@0 210 // failure) we make sure that the following is done when
aoqi@0 211 // the region is freed so that it is "ready-to-go" when it's
aoqi@0 212 // re-allocated. However, when evacuation failure happens, a
aoqi@0 213 // region will remain in the heap and might ultimately be added
aoqi@0 214 // to a CSet in the future. So we have to be careful here and
aoqi@0 215 // make sure the region's RSet is ready for parallel iteration
aoqi@0 216 // whenever this might be required in the future.
aoqi@0 217 hr->rem_set()->reset_for_par_iteration();
aoqi@0 218 hr->reset_bot();
tschatzl@7218 219 _update_rset_cl.set_region(hr);
aoqi@0 220 hr->object_iterate(&rspc);
aoqi@0 221
mgerdin@7208 222 hr->rem_set()->clean_strong_code_roots(hr);
mgerdin@7208 223
aoqi@0 224 hr->note_self_forwarding_removal_end(during_initial_mark,
aoqi@0 225 during_conc_mark,
aoqi@0 226 rspc.marked_bytes());
aoqi@0 227 }
aoqi@0 228 }
aoqi@0 229 return false;
aoqi@0 230 }
aoqi@0 231 };
aoqi@0 232
aoqi@0 233 class G1ParRemoveSelfForwardPtrsTask: public AbstractGangTask {
aoqi@0 234 protected:
aoqi@0 235 G1CollectedHeap* _g1h;
aoqi@0 236
aoqi@0 237 public:
aoqi@0 238 G1ParRemoveSelfForwardPtrsTask(G1CollectedHeap* g1h) :
aoqi@0 239 AbstractGangTask("G1 Remove Self-forwarding Pointers"),
aoqi@0 240 _g1h(g1h) { }
aoqi@0 241
aoqi@0 242 void work(uint worker_id) {
tschatzl@7218 243 RemoveSelfForwardPtrHRClosure rsfp_cl(_g1h, worker_id);
aoqi@0 244
aoqi@0 245 HeapRegion* hr = _g1h->start_cset_region_for_worker(worker_id);
aoqi@0 246 _g1h->collection_set_iterate_from(hr, &rsfp_cl);
aoqi@0 247 }
aoqi@0 248 };
aoqi@0 249
aoqi@0 250 #endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1EVACFAILURE_HPP

mercurial