annotate src/share/vm/gc/g1/g1EvacFailure.cpp @ 8677:9690cc21ec74

8129558: Coalesce dead objects during removal of self-forwarded pointers Summary: To improve performance of self-forwarding fixup during evacuation failure, coalesce the work done for dead objects. Reviewed-by: mgerdin, tbenson, tonyp
author tschatzl
date Tue, 07 Jul 2015 14:20:08 +0200
parents 46850a050b8b
children dc9930a04ab0
rev   line source
johnc@2977 1 /*
stefank@7863 2 * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
johnc@2977 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
johnc@2977 4 *
johnc@2977 5 * This code is free software; you can redistribute it and/or modify it
johnc@2977 6 * under the terms of the GNU General Public License version 2 only, as
johnc@2977 7 * published by the Free Software Foundation.
johnc@2977 8 *
johnc@2977 9 * This code is distributed in the hope that it will be useful, but WITHOUT
johnc@2977 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
johnc@2977 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
johnc@2977 12 * version 2 for more details (a copy is included in the LICENSE file that
johnc@2977 13 * accompanied this code).
johnc@2977 14 *
johnc@2977 15 * You should have received a copy of the GNU General Public License version
johnc@2977 16 * 2 along with this work; if not, write to the Free Software Foundation,
johnc@2977 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
johnc@2977 18 *
johnc@2977 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
johnc@2977 20 * or visit www.oracle.com if you need additional information or have any
johnc@2977 21 * questions.
johnc@2977 22 *
johnc@2977 23 */
johnc@2977 24
stefank@7863 25 #include "precompiled.hpp"
pliden@8413 26 #include "gc/g1/concurrentMark.inline.hpp"
pliden@8413 27 #include "gc/g1/dirtyCardQueue.hpp"
pliden@8413 28 #include "gc/g1/g1CollectedHeap.inline.hpp"
drwhite@8529 29 #include "gc/g1/g1CollectorState.hpp"
pliden@8413 30 #include "gc/g1/g1EvacFailure.hpp"
pliden@8413 31 #include "gc/g1/g1OopClosures.inline.hpp"
pliden@8413 32 #include "gc/g1/g1_globals.hpp"
pliden@8413 33 #include "gc/g1/heapRegion.hpp"
pliden@8413 34 #include "gc/g1/heapRegionRemSet.hpp"
johnc@2977 35
johnc@2977 36 class UpdateRSetDeferred : public OopsInHeapRegionClosure {
johnc@2977 37 private:
johnc@2977 38 G1CollectedHeap* _g1;
johnc@2977 39 DirtyCardQueue *_dcq;
mgerdin@5376 40 G1SATBCardTableModRefBS* _ct_bs;
johnc@2977 41
johnc@2977 42 public:
tschatzl@8677 43 UpdateRSetDeferred(DirtyCardQueue* dcq) :
tschatzl@8677 44 _g1(G1CollectedHeap::heap()), _ct_bs(_g1->g1_barrier_set()), _dcq(dcq) {}
johnc@2977 45
johnc@2977 46 virtual void do_oop(narrowOop* p) { do_oop_work(p); }
johnc@2977 47 virtual void do_oop( oop* p) { do_oop_work(p); }
johnc@2977 48 template <class T> void do_oop_work(T* p) {
johnc@2977 49 assert(_from->is_in_reserved(p), "paranoia");
johnc@2977 50 if (!_from->is_in_reserved(oopDesc::load_decode_heap_oop(p)) &&
johnc@2977 51 !_from->is_survivor()) {
johnc@2977 52 size_t card_index = _ct_bs->index_for(p);
johnc@2977 53 if (_ct_bs->mark_card_deferred(card_index)) {
johnc@2977 54 _dcq->enqueue((jbyte*)_ct_bs->byte_for_index(card_index));
johnc@2977 55 }
johnc@2977 56 }
johnc@2977 57 }
johnc@2977 58 };
johnc@2977 59
johnc@2977 60 class RemoveSelfForwardPtrObjClosure: public ObjectClosure {
johnc@2977 61 private:
johnc@2977 62 G1CollectedHeap* _g1;
johnc@2977 63 ConcurrentMark* _cm;
johnc@2977 64 HeapRegion* _hr;
tonyp@2981 65 size_t _marked_bytes;
johnc@2977 66 OopsInHeapRegionClosure *_update_rset_cl;
tonyp@2981 67 bool _during_initial_mark;
johnc@3028 68 uint _worker_id;
tschatzl@8677 69 HeapWord* _last_forwarded_object_end;
johnc@3028 70
johnc@2977 71 public:
tschatzl@8677 72 RemoveSelfForwardPtrObjClosure(HeapRegion* hr,
tonyp@2981 73 OopsInHeapRegionClosure* update_rset_cl,
tonyp@2981 74 bool during_initial_mark,
johnc@3028 75 uint worker_id) :
tschatzl@8677 76 _g1(G1CollectedHeap::heap()),
tschatzl@8677 77 _cm(_g1->concurrent_mark()),
tschatzl@8677 78 _hr(hr),
tschatzl@8677 79 _marked_bytes(0),
johnc@2977 80 _update_rset_cl(update_rset_cl),
tonyp@2981 81 _during_initial_mark(during_initial_mark),
stefank@6707 82 _worker_id(worker_id),
tschatzl@8677 83 _last_forwarded_object_end(hr->bottom()) { }
johnc@2977 84
tonyp@2981 85 size_t marked_bytes() { return _marked_bytes; }
johnc@2977 86
tschatzl@8677 87 // Iterate over the live objects in the region to find self-forwarded objects
tschatzl@8677 88 // that need to be kept live. We need to update the remembered sets of these
tschatzl@8677 89 // objects. Further update the BOT and marks.
tschatzl@8677 90 // We can coalesce and overwrite the remaining heap contents with dummy objects
tschatzl@8677 91 // as they have either been dead or evacuated (which are unreferenced now, i.e.
tschatzl@8677 92 // dead too) already.
johnc@2977 93 void do_object(oop obj) {
johnc@2977 94 HeapWord* obj_addr = (HeapWord*) obj;
johnc@2977 95 assert(_hr->is_in(obj_addr), "sanity");
johnc@2977 96 size_t obj_size = obj->size();
stefank@6707 97 HeapWord* obj_end = obj_addr + obj_size;
stefank@6707 98
johnc@2977 99 if (obj->is_forwarded() && obj->forwardee() == obj) {
johnc@2977 100 // The object failed to move.
tonyp@2981 101
tschatzl@8677 102 zap_dead_objects(_last_forwarded_object_end, obj_addr);
tonyp@2981 103 // We consider all objects that we find self-forwarded to be
tonyp@2981 104 // live. What we'll do is that we'll update the prev marking
tonyp@2981 105 // info so that they are all under PTAMS and explicitly marked.
stefank@6707 106 if (!_cm->isPrevMarked(obj)) {
stefank@6707 107 _cm->markPrev(obj);
stefank@6707 108 }
tonyp@2981 109 if (_during_initial_mark) {
tonyp@2981 110 // For the next marking info we'll only mark the
tonyp@2981 111 // self-forwarded objects explicitly if we are during
tonyp@2981 112 // initial-mark (since, normally, we only mark objects pointed
tonyp@2981 113 // to by roots if we succeed in copying them). By marking all
tonyp@2981 114 // self-forwarded objects we ensure that we mark any that are
tonyp@2981 115 // still pointed to be roots. During concurrent marking, and
tonyp@2981 116 // after initial-mark, we don't need to mark any objects
tonyp@2981 117 // explicitly and all objects in the CSet are considered
tonyp@2981 118 // (implicitly) live. So, we won't mark them explicitly and
tonyp@2981 119 // we'll leave them over NTAMS.
tonyp@3029 120 _cm->grayRoot(obj, obj_size, _worker_id, _hr);
johnc@2977 121 }
tonyp@2981 122 _marked_bytes += (obj_size * HeapWordSize);
johnc@2977 123 obj->set_mark(markOopDesc::prototype());
johnc@2977 124
johnc@2977 125 // While we were processing RSet buffers during the collection,
johnc@2977 126 // we actually didn't scan any cards on the collection set,
johnc@2977 127 // since we didn't want to update remembered sets with entries
johnc@2977 128 // that point into the collection set, given that live objects
johnc@2977 129 // from the collection set are about to move and such entries
johnc@2977 130 // will be stale very soon.
johnc@2977 131 // This change also dealt with a reliability issue which
johnc@2977 132 // involved scanning a card in the collection set and coming
johnc@2977 133 // across an array that was being chunked and looking malformed.
johnc@2977 134 // The problem is that, if evacuation fails, we might have
johnc@2977 135 // remembered set entries missing given that we skipped cards on
johnc@2977 136 // the collection set. So, we'll recreate such entries now.
johnc@2977 137 obj->oop_iterate(_update_rset_cl);
stefank@6707 138
tschatzl@8677 139 _last_forwarded_object_end = obj_end;
tschatzl@8677 140 _hr->cross_threshold(obj_addr, obj_end);
tschatzl@8677 141 }
tschatzl@8677 142 }
stefank@6707 143
tschatzl@8677 144 // Fill the memory area from start to end with filler objects, and update the BOT
tschatzl@8677 145 // and the mark bitmap accordingly.
tschatzl@8677 146 void zap_dead_objects(HeapWord* start, HeapWord* end) {
tschatzl@8677 147 if (start == end) {
tschatzl@8677 148 return;
johnc@2977 149 }
tschatzl@8677 150
tschatzl@8677 151 size_t gap_size = pointer_delta(end, start);
tschatzl@8677 152 MemRegion mr(start, gap_size);
tschatzl@8677 153 if (gap_size >= CollectedHeap::min_fill_size()) {
tschatzl@8677 154 CollectedHeap::fill_with_objects(start, gap_size);
tschatzl@8677 155
tschatzl@8677 156 HeapWord* end_first_obj = start + ((oop)start)->size();
tschatzl@8677 157 _hr->cross_threshold(start, end_first_obj);
tschatzl@8677 158 // Fill_with_objects() may have created multiple (i.e. two)
tschatzl@8677 159 // objects, as the max_fill_size() is half a region.
tschatzl@8677 160 // After updating the BOT for the first object, also update the
tschatzl@8677 161 // BOT for the second object to make the BOT complete.
tschatzl@8677 162 if (end_first_obj != end) {
tschatzl@8677 163 _hr->cross_threshold(end_first_obj, end);
tschatzl@8677 164 #ifdef ASSERT
tschatzl@8677 165 size_t size_second_obj = ((oop)end_first_obj)->size();
tschatzl@8677 166 HeapWord* end_of_second_obj = end_first_obj + size_second_obj;
tschatzl@8677 167 assert(end == end_of_second_obj,
tschatzl@8677 168 err_msg("More than two objects were used to fill the area from " PTR_FORMAT " to " PTR_FORMAT ", "
tschatzl@8677 169 "second objects size " SIZE_FORMAT " ends at " PTR_FORMAT,
tschatzl@8677 170 p2i(start), p2i(end), size_second_obj, p2i(end_of_second_obj)));
tschatzl@8677 171 #endif
tschatzl@8677 172 }
tschatzl@8677 173 }
tschatzl@8677 174 _cm->clearRangePrevBitmap(mr);
tschatzl@8677 175 }
tschatzl@8677 176
tschatzl@8677 177 void zap_remainder() {
tschatzl@8677 178 zap_dead_objects(_last_forwarded_object_end, _hr->top());
johnc@2977 179 }
johnc@2977 180 };
johnc@2977 181
johnc@2977 182 class RemoveSelfForwardPtrHRClosure: public HeapRegionClosure {
johnc@2977 183 G1CollectedHeap* _g1h;
johnc@3028 184 uint _worker_id;
mlarsson@7194 185 HeapRegionClaimer* _hrclaimer;
johnc@2977 186
tschatzl@7068 187 DirtyCardQueue _dcq;
tschatzl@7068 188 UpdateRSetDeferred _update_rset_cl;
tschatzl@7068 189
johnc@2977 190 public:
tschatzl@8677 191 RemoveSelfForwardPtrHRClosure(uint worker_id,
mlarsson@7194 192 HeapRegionClaimer* hrclaimer) :
tschatzl@8677 193 _g1h(G1CollectedHeap::heap()),
tschatzl@8677 194 _dcq(&_g1h->dirty_card_queue_set()),
tschatzl@8677 195 _update_rset_cl(&_dcq),
tschatzl@8677 196 _worker_id(worker_id),
tschatzl@8677 197 _hrclaimer(hrclaimer) {
tschatzl@8677 198 }
tschatzl@8677 199
tschatzl@8677 200 size_t remove_self_forward_ptr_by_walking_hr(HeapRegion* hr,
tschatzl@8677 201 bool during_initial_mark) {
tschatzl@8677 202 RemoveSelfForwardPtrObjClosure rspc(hr,
tschatzl@8677 203 &_update_rset_cl,
tschatzl@8677 204 during_initial_mark,
tschatzl@8677 205 _worker_id);
tschatzl@8677 206 _update_rset_cl.set_region(hr);
tschatzl@8677 207 hr->object_iterate(&rspc);
tschatzl@8677 208 // Need to zap the remainder area of the processed region.
tschatzl@8677 209 rspc.zap_remainder();
tschatzl@8677 210
tschatzl@8677 211 return rspc.marked_bytes();
mlarsson@7194 212 }
johnc@2977 213
johnc@2977 214 bool doHeapRegion(HeapRegion *hr) {
drwhite@8529 215 bool during_initial_mark = _g1h->collector_state()->during_initial_mark_pause();
drwhite@8529 216 bool during_conc_mark = _g1h->collector_state()->mark_in_progress();
tonyp@2981 217
jiangli@8544 218 assert(!hr->is_pinned(), err_msg("Unexpected pinned region at index %u", hr->hrm_index()));
johnc@2977 219 assert(hr->in_collection_set(), "bad CS");
johnc@2977 220
mlarsson@7194 221 if (_hrclaimer->claim_region(hr->hrm_index())) {
johnc@2977 222 if (hr->evacuation_failed()) {
tonyp@2981 223 hr->note_self_forwarding_removal_start(during_initial_mark,
tonyp@2981 224 during_conc_mark);
brutisso@6355 225 _g1h->check_bitmaps("Self-Forwarding Ptr Removal", hr);
johnc@2977 226
johnc@2977 227 // In the common case (i.e. when there is no evacuation
johnc@2977 228 // failure) we make sure that the following is done when
johnc@2977 229 // the region is freed so that it is "ready-to-go" when it's
johnc@2977 230 // re-allocated. However, when evacuation failure happens, a
johnc@2977 231 // region will remain in the heap and might ultimately be added
johnc@2977 232 // to a CSet in the future. So we have to be careful here and
johnc@2977 233 // make sure the region's RSet is ready for parallel iteration
johnc@2977 234 // whenever this might be required in the future.
johnc@2977 235 hr->rem_set()->reset_for_par_iteration();
johnc@2977 236 hr->reset_bot();
tschatzl@8677 237
tschatzl@8677 238 size_t live_bytes = remove_self_forward_ptr_by_walking_hr(hr, during_initial_mark);
johnc@2977 239
mgerdin@6985 240 hr->rem_set()->clean_strong_code_roots(hr);
mgerdin@6985 241
tonyp@2981 242 hr->note_self_forwarding_removal_end(during_initial_mark,
tonyp@2981 243 during_conc_mark,
tschatzl@8677 244 live_bytes);
johnc@2977 245 }
johnc@2977 246 }
johnc@2977 247 return false;
johnc@2977 248 }
johnc@2977 249 };
johnc@2977 250
tschatzl@8677 251 G1ParRemoveSelfForwardPtrsTask::G1ParRemoveSelfForwardPtrsTask() :
tschatzl@8677 252 AbstractGangTask("G1 Remove Self-forwarding Pointers"),
tschatzl@8677 253 _g1h(G1CollectedHeap::heap()),
tschatzl@8677 254 _hrclaimer(_g1h->workers()->active_workers()) { }
johnc@2977 255
stefank@7863 256 void G1ParRemoveSelfForwardPtrsTask::work(uint worker_id) {
tschatzl@8677 257 RemoveSelfForwardPtrHRClosure rsfp_cl(worker_id, &_hrclaimer);
johnc@2977 258
stefank@7863 259 HeapRegion* hr = _g1h->start_cset_region_for_worker(worker_id);
stefank@7863 260 _g1h->collection_set_iterate_from(hr, &rsfp_cl);
stefank@7863 261 }