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