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

Wed, 27 Apr 2016 01:25:04 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:25:04 +0800
changeset 0
f90c822e73f8
child 6876
710a3c8b516e
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17

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;
aoqi@0 74
aoqi@0 75 public:
aoqi@0 76 RemoveSelfForwardPtrObjClosure(G1CollectedHeap* g1, ConcurrentMark* cm,
aoqi@0 77 HeapRegion* hr,
aoqi@0 78 OopsInHeapRegionClosure* update_rset_cl,
aoqi@0 79 bool during_initial_mark,
aoqi@0 80 bool during_conc_mark,
aoqi@0 81 uint worker_id) :
aoqi@0 82 _g1(g1), _cm(cm), _hr(hr), _marked_bytes(0),
aoqi@0 83 _update_rset_cl(update_rset_cl),
aoqi@0 84 _during_initial_mark(during_initial_mark),
aoqi@0 85 _during_conc_mark(during_conc_mark),
aoqi@0 86 _worker_id(worker_id) { }
aoqi@0 87
aoqi@0 88 size_t marked_bytes() { return _marked_bytes; }
aoqi@0 89
aoqi@0 90 // <original comment>
aoqi@0 91 // The original idea here was to coalesce evacuated and dead objects.
aoqi@0 92 // However that caused complications with the block offset table (BOT).
aoqi@0 93 // In particular if there were two TLABs, one of them partially refined.
aoqi@0 94 // |----- TLAB_1--------|----TLAB_2-~~~(partially refined part)~~~|
aoqi@0 95 // The BOT entries of the unrefined part of TLAB_2 point to the start
aoqi@0 96 // of TLAB_2. If the last object of the TLAB_1 and the first object
aoqi@0 97 // of TLAB_2 are coalesced, then the cards of the unrefined part
aoqi@0 98 // would point into middle of the filler object.
aoqi@0 99 // The current approach is to not coalesce and leave the BOT contents intact.
aoqi@0 100 // </original comment>
aoqi@0 101 //
aoqi@0 102 // We now reset the BOT when we start the object iteration over the
aoqi@0 103 // region and refine its entries for every object we come across. So
aoqi@0 104 // the above comment is not really relevant and we should be able
aoqi@0 105 // to coalesce dead objects if we want to.
aoqi@0 106 void do_object(oop obj) {
aoqi@0 107 HeapWord* obj_addr = (HeapWord*) obj;
aoqi@0 108 assert(_hr->is_in(obj_addr), "sanity");
aoqi@0 109 size_t obj_size = obj->size();
aoqi@0 110 _hr->update_bot_for_object(obj_addr, obj_size);
aoqi@0 111
aoqi@0 112 if (obj->is_forwarded() && obj->forwardee() == obj) {
aoqi@0 113 // The object failed to move.
aoqi@0 114
aoqi@0 115 // We consider all objects that we find self-forwarded to be
aoqi@0 116 // live. What we'll do is that we'll update the prev marking
aoqi@0 117 // info so that they are all under PTAMS and explicitly marked.
aoqi@0 118 _cm->markPrev(obj);
aoqi@0 119 if (_during_initial_mark) {
aoqi@0 120 // For the next marking info we'll only mark the
aoqi@0 121 // self-forwarded objects explicitly if we are during
aoqi@0 122 // initial-mark (since, normally, we only mark objects pointed
aoqi@0 123 // to by roots if we succeed in copying them). By marking all
aoqi@0 124 // self-forwarded objects we ensure that we mark any that are
aoqi@0 125 // still pointed to be roots. During concurrent marking, and
aoqi@0 126 // after initial-mark, we don't need to mark any objects
aoqi@0 127 // explicitly and all objects in the CSet are considered
aoqi@0 128 // (implicitly) live. So, we won't mark them explicitly and
aoqi@0 129 // we'll leave them over NTAMS.
aoqi@0 130 _cm->grayRoot(obj, obj_size, _worker_id, _hr);
aoqi@0 131 }
aoqi@0 132 _marked_bytes += (obj_size * HeapWordSize);
aoqi@0 133 obj->set_mark(markOopDesc::prototype());
aoqi@0 134
aoqi@0 135 // While we were processing RSet buffers during the collection,
aoqi@0 136 // we actually didn't scan any cards on the collection set,
aoqi@0 137 // since we didn't want to update remembered sets with entries
aoqi@0 138 // that point into the collection set, given that live objects
aoqi@0 139 // from the collection set are about to move and such entries
aoqi@0 140 // will be stale very soon.
aoqi@0 141 // This change also dealt with a reliability issue which
aoqi@0 142 // involved scanning a card in the collection set and coming
aoqi@0 143 // across an array that was being chunked and looking malformed.
aoqi@0 144 // The problem is that, if evacuation fails, we might have
aoqi@0 145 // remembered set entries missing given that we skipped cards on
aoqi@0 146 // the collection set. So, we'll recreate such entries now.
aoqi@0 147 obj->oop_iterate(_update_rset_cl);
aoqi@0 148 assert(_cm->isPrevMarked(obj), "Should be marked!");
aoqi@0 149 } else {
aoqi@0 150 // The object has been either evacuated or is dead. Fill it with a
aoqi@0 151 // dummy object.
aoqi@0 152 MemRegion mr((HeapWord*) obj, obj_size);
aoqi@0 153 CollectedHeap::fill_with_object(mr);
aoqi@0 154 }
aoqi@0 155 }
aoqi@0 156 };
aoqi@0 157
aoqi@0 158 class RemoveSelfForwardPtrHRClosure: public HeapRegionClosure {
aoqi@0 159 G1CollectedHeap* _g1h;
aoqi@0 160 ConcurrentMark* _cm;
aoqi@0 161 OopsInHeapRegionClosure *_update_rset_cl;
aoqi@0 162 uint _worker_id;
aoqi@0 163
aoqi@0 164 public:
aoqi@0 165 RemoveSelfForwardPtrHRClosure(G1CollectedHeap* g1h,
aoqi@0 166 OopsInHeapRegionClosure* update_rset_cl,
aoqi@0 167 uint worker_id) :
aoqi@0 168 _g1h(g1h), _update_rset_cl(update_rset_cl),
aoqi@0 169 _worker_id(worker_id), _cm(_g1h->concurrent_mark()) { }
aoqi@0 170
aoqi@0 171 bool doHeapRegion(HeapRegion *hr) {
aoqi@0 172 bool during_initial_mark = _g1h->g1_policy()->during_initial_mark_pause();
aoqi@0 173 bool during_conc_mark = _g1h->mark_in_progress();
aoqi@0 174
aoqi@0 175 assert(!hr->isHumongous(), "sanity");
aoqi@0 176 assert(hr->in_collection_set(), "bad CS");
aoqi@0 177
aoqi@0 178 if (hr->claimHeapRegion(HeapRegion::ParEvacFailureClaimValue)) {
aoqi@0 179 if (hr->evacuation_failed()) {
aoqi@0 180 RemoveSelfForwardPtrObjClosure rspc(_g1h, _cm, hr, _update_rset_cl,
aoqi@0 181 during_initial_mark,
aoqi@0 182 during_conc_mark,
aoqi@0 183 _worker_id);
aoqi@0 184
aoqi@0 185 MemRegion mr(hr->bottom(), hr->end());
aoqi@0 186 // We'll recreate the prev marking info so we'll first clear
aoqi@0 187 // the prev bitmap range for this region. We never mark any
aoqi@0 188 // CSet objects explicitly so the next bitmap range should be
aoqi@0 189 // cleared anyway.
aoqi@0 190 _cm->clearRangePrevBitmap(mr);
aoqi@0 191
aoqi@0 192 hr->note_self_forwarding_removal_start(during_initial_mark,
aoqi@0 193 during_conc_mark);
aoqi@0 194
aoqi@0 195 // In the common case (i.e. when there is no evacuation
aoqi@0 196 // failure) we make sure that the following is done when
aoqi@0 197 // the region is freed so that it is "ready-to-go" when it's
aoqi@0 198 // re-allocated. However, when evacuation failure happens, a
aoqi@0 199 // region will remain in the heap and might ultimately be added
aoqi@0 200 // to a CSet in the future. So we have to be careful here and
aoqi@0 201 // make sure the region's RSet is ready for parallel iteration
aoqi@0 202 // whenever this might be required in the future.
aoqi@0 203 hr->rem_set()->reset_for_par_iteration();
aoqi@0 204 hr->reset_bot();
aoqi@0 205 _update_rset_cl->set_region(hr);
aoqi@0 206 hr->object_iterate(&rspc);
aoqi@0 207
aoqi@0 208 hr->note_self_forwarding_removal_end(during_initial_mark,
aoqi@0 209 during_conc_mark,
aoqi@0 210 rspc.marked_bytes());
aoqi@0 211 }
aoqi@0 212 }
aoqi@0 213 return false;
aoqi@0 214 }
aoqi@0 215 };
aoqi@0 216
aoqi@0 217 class G1ParRemoveSelfForwardPtrsTask: public AbstractGangTask {
aoqi@0 218 protected:
aoqi@0 219 G1CollectedHeap* _g1h;
aoqi@0 220
aoqi@0 221 public:
aoqi@0 222 G1ParRemoveSelfForwardPtrsTask(G1CollectedHeap* g1h) :
aoqi@0 223 AbstractGangTask("G1 Remove Self-forwarding Pointers"),
aoqi@0 224 _g1h(g1h) { }
aoqi@0 225
aoqi@0 226 void work(uint worker_id) {
aoqi@0 227 UpdateRSetImmediate immediate_update(_g1h->g1_rem_set());
aoqi@0 228 DirtyCardQueue dcq(&_g1h->dirty_card_queue_set());
aoqi@0 229 UpdateRSetDeferred deferred_update(_g1h, &dcq);
aoqi@0 230
aoqi@0 231 OopsInHeapRegionClosure *update_rset_cl = &deferred_update;
aoqi@0 232 if (!G1DeferredRSUpdate) {
aoqi@0 233 update_rset_cl = &immediate_update;
aoqi@0 234 }
aoqi@0 235
aoqi@0 236 RemoveSelfForwardPtrHRClosure rsfp_cl(_g1h, update_rset_cl, worker_id);
aoqi@0 237
aoqi@0 238 HeapRegion* hr = _g1h->start_cset_region_for_worker(worker_id);
aoqi@0 239 _g1h->collection_set_iterate_from(hr, &rsfp_cl);
aoqi@0 240 }
aoqi@0 241 };
aoqi@0 242
aoqi@0 243 #endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1EVACFAILURE_HPP

mercurial