aoqi@0: /* aoqi@0: * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: * aoqi@0: */ aoqi@0: aoqi@0: #ifndef SHARE_VM_GC_IMPLEMENTATION_G1_G1EVACFAILURE_HPP aoqi@0: #define SHARE_VM_GC_IMPLEMENTATION_G1_G1EVACFAILURE_HPP aoqi@0: aoqi@0: #include "gc_implementation/g1/concurrentMark.inline.hpp" aoqi@0: #include "gc_implementation/g1/dirtyCardQueue.hpp" aoqi@0: #include "gc_implementation/g1/g1CollectedHeap.inline.hpp" aoqi@0: #include "gc_implementation/g1/g1_globals.hpp" aoqi@0: #include "gc_implementation/g1/g1OopClosures.inline.hpp" aoqi@0: #include "gc_implementation/g1/heapRegion.hpp" aoqi@0: #include "gc_implementation/g1/heapRegionRemSet.hpp" aoqi@0: #include "utilities/workgroup.hpp" aoqi@0: aoqi@0: // Closures and tasks associated with any self-forwarding pointers aoqi@0: // installed as a result of an evacuation failure. aoqi@0: aoqi@0: class UpdateRSetDeferred : public OopsInHeapRegionClosure { aoqi@0: private: aoqi@0: G1CollectedHeap* _g1; aoqi@0: DirtyCardQueue *_dcq; aoqi@0: G1SATBCardTableModRefBS* _ct_bs; aoqi@0: aoqi@0: public: aoqi@0: UpdateRSetDeferred(G1CollectedHeap* g1, DirtyCardQueue* dcq) : aoqi@0: _g1(g1), _ct_bs(_g1->g1_barrier_set()), _dcq(dcq) {} aoqi@0: aoqi@0: virtual void do_oop(narrowOop* p) { do_oop_work(p); } aoqi@0: virtual void do_oop( oop* p) { do_oop_work(p); } aoqi@0: template void do_oop_work(T* p) { aoqi@0: assert(_from->is_in_reserved(p), "paranoia"); aoqi@0: if (!_from->is_in_reserved(oopDesc::load_decode_heap_oop(p)) && aoqi@0: !_from->is_survivor()) { aoqi@0: size_t card_index = _ct_bs->index_for(p); aoqi@0: if (_ct_bs->mark_card_deferred(card_index)) { aoqi@0: _dcq->enqueue((jbyte*)_ct_bs->byte_for_index(card_index)); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: }; aoqi@0: aoqi@0: class RemoveSelfForwardPtrObjClosure: public ObjectClosure { aoqi@0: private: aoqi@0: G1CollectedHeap* _g1; aoqi@0: ConcurrentMark* _cm; aoqi@0: HeapRegion* _hr; aoqi@0: size_t _marked_bytes; aoqi@0: OopsInHeapRegionClosure *_update_rset_cl; aoqi@0: bool _during_initial_mark; aoqi@0: bool _during_conc_mark; aoqi@0: uint _worker_id; aoqi@0: aoqi@0: public: aoqi@0: RemoveSelfForwardPtrObjClosure(G1CollectedHeap* g1, ConcurrentMark* cm, aoqi@0: HeapRegion* hr, aoqi@0: OopsInHeapRegionClosure* update_rset_cl, aoqi@0: bool during_initial_mark, aoqi@0: bool during_conc_mark, aoqi@0: uint worker_id) : aoqi@0: _g1(g1), _cm(cm), _hr(hr), _marked_bytes(0), aoqi@0: _update_rset_cl(update_rset_cl), aoqi@0: _during_initial_mark(during_initial_mark), aoqi@0: _during_conc_mark(during_conc_mark), aoqi@0: _worker_id(worker_id) { } aoqi@0: aoqi@0: size_t marked_bytes() { return _marked_bytes; } aoqi@0: aoqi@0: // aoqi@0: // The original idea here was to coalesce evacuated and dead objects. aoqi@0: // However that caused complications with the block offset table (BOT). aoqi@0: // In particular if there were two TLABs, one of them partially refined. aoqi@0: // |----- TLAB_1--------|----TLAB_2-~~~(partially refined part)~~~| aoqi@0: // The BOT entries of the unrefined part of TLAB_2 point to the start aoqi@0: // of TLAB_2. If the last object of the TLAB_1 and the first object aoqi@0: // of TLAB_2 are coalesced, then the cards of the unrefined part aoqi@0: // would point into middle of the filler object. aoqi@0: // The current approach is to not coalesce and leave the BOT contents intact. aoqi@0: // aoqi@0: // aoqi@0: // We now reset the BOT when we start the object iteration over the aoqi@0: // region and refine its entries for every object we come across. So aoqi@0: // the above comment is not really relevant and we should be able aoqi@0: // to coalesce dead objects if we want to. aoqi@0: void do_object(oop obj) { aoqi@0: HeapWord* obj_addr = (HeapWord*) obj; aoqi@0: assert(_hr->is_in(obj_addr), "sanity"); aoqi@0: size_t obj_size = obj->size(); aoqi@0: _hr->update_bot_for_object(obj_addr, obj_size); aoqi@0: aoqi@0: if (obj->is_forwarded() && obj->forwardee() == obj) { aoqi@0: // The object failed to move. aoqi@0: aoqi@0: // We consider all objects that we find self-forwarded to be aoqi@0: // live. What we'll do is that we'll update the prev marking aoqi@0: // info so that they are all under PTAMS and explicitly marked. aoqi@0: _cm->markPrev(obj); aoqi@0: if (_during_initial_mark) { aoqi@0: // For the next marking info we'll only mark the aoqi@0: // self-forwarded objects explicitly if we are during aoqi@0: // initial-mark (since, normally, we only mark objects pointed aoqi@0: // to by roots if we succeed in copying them). By marking all aoqi@0: // self-forwarded objects we ensure that we mark any that are aoqi@0: // still pointed to be roots. During concurrent marking, and aoqi@0: // after initial-mark, we don't need to mark any objects aoqi@0: // explicitly and all objects in the CSet are considered aoqi@0: // (implicitly) live. So, we won't mark them explicitly and aoqi@0: // we'll leave them over NTAMS. aoqi@0: _cm->grayRoot(obj, obj_size, _worker_id, _hr); aoqi@0: } aoqi@0: _marked_bytes += (obj_size * HeapWordSize); aoqi@0: obj->set_mark(markOopDesc::prototype()); aoqi@0: aoqi@0: // While we were processing RSet buffers during the collection, aoqi@0: // we actually didn't scan any cards on the collection set, aoqi@0: // since we didn't want to update remembered sets with entries aoqi@0: // that point into the collection set, given that live objects aoqi@0: // from the collection set are about to move and such entries aoqi@0: // will be stale very soon. aoqi@0: // This change also dealt with a reliability issue which aoqi@0: // involved scanning a card in the collection set and coming aoqi@0: // across an array that was being chunked and looking malformed. aoqi@0: // The problem is that, if evacuation fails, we might have aoqi@0: // remembered set entries missing given that we skipped cards on aoqi@0: // the collection set. So, we'll recreate such entries now. aoqi@0: obj->oop_iterate(_update_rset_cl); aoqi@0: assert(_cm->isPrevMarked(obj), "Should be marked!"); aoqi@0: } else { aoqi@0: // The object has been either evacuated or is dead. Fill it with a aoqi@0: // dummy object. aoqi@0: MemRegion mr((HeapWord*) obj, obj_size); aoqi@0: CollectedHeap::fill_with_object(mr); aoqi@0: } aoqi@0: } aoqi@0: }; aoqi@0: aoqi@0: class RemoveSelfForwardPtrHRClosure: public HeapRegionClosure { aoqi@0: G1CollectedHeap* _g1h; aoqi@0: ConcurrentMark* _cm; aoqi@0: OopsInHeapRegionClosure *_update_rset_cl; aoqi@0: uint _worker_id; aoqi@0: aoqi@0: public: aoqi@0: RemoveSelfForwardPtrHRClosure(G1CollectedHeap* g1h, aoqi@0: OopsInHeapRegionClosure* update_rset_cl, aoqi@0: uint worker_id) : aoqi@0: _g1h(g1h), _update_rset_cl(update_rset_cl), aoqi@0: _worker_id(worker_id), _cm(_g1h->concurrent_mark()) { } aoqi@0: aoqi@0: bool doHeapRegion(HeapRegion *hr) { aoqi@0: bool during_initial_mark = _g1h->g1_policy()->during_initial_mark_pause(); aoqi@0: bool during_conc_mark = _g1h->mark_in_progress(); aoqi@0: aoqi@0: assert(!hr->isHumongous(), "sanity"); aoqi@0: assert(hr->in_collection_set(), "bad CS"); aoqi@0: aoqi@0: if (hr->claimHeapRegion(HeapRegion::ParEvacFailureClaimValue)) { aoqi@0: if (hr->evacuation_failed()) { aoqi@0: RemoveSelfForwardPtrObjClosure rspc(_g1h, _cm, hr, _update_rset_cl, aoqi@0: during_initial_mark, aoqi@0: during_conc_mark, aoqi@0: _worker_id); aoqi@0: aoqi@0: MemRegion mr(hr->bottom(), hr->end()); aoqi@0: // We'll recreate the prev marking info so we'll first clear aoqi@0: // the prev bitmap range for this region. We never mark any aoqi@0: // CSet objects explicitly so the next bitmap range should be aoqi@0: // cleared anyway. aoqi@0: _cm->clearRangePrevBitmap(mr); aoqi@0: aoqi@0: hr->note_self_forwarding_removal_start(during_initial_mark, aoqi@0: during_conc_mark); aoqi@0: aoqi@0: // In the common case (i.e. when there is no evacuation aoqi@0: // failure) we make sure that the following is done when aoqi@0: // the region is freed so that it is "ready-to-go" when it's aoqi@0: // re-allocated. However, when evacuation failure happens, a aoqi@0: // region will remain in the heap and might ultimately be added aoqi@0: // to a CSet in the future. So we have to be careful here and aoqi@0: // make sure the region's RSet is ready for parallel iteration aoqi@0: // whenever this might be required in the future. aoqi@0: hr->rem_set()->reset_for_par_iteration(); aoqi@0: hr->reset_bot(); aoqi@0: _update_rset_cl->set_region(hr); aoqi@0: hr->object_iterate(&rspc); aoqi@0: aoqi@0: hr->note_self_forwarding_removal_end(during_initial_mark, aoqi@0: during_conc_mark, aoqi@0: rspc.marked_bytes()); aoqi@0: } aoqi@0: } aoqi@0: return false; aoqi@0: } aoqi@0: }; aoqi@0: aoqi@0: class G1ParRemoveSelfForwardPtrsTask: public AbstractGangTask { aoqi@0: protected: aoqi@0: G1CollectedHeap* _g1h; aoqi@0: aoqi@0: public: aoqi@0: G1ParRemoveSelfForwardPtrsTask(G1CollectedHeap* g1h) : aoqi@0: AbstractGangTask("G1 Remove Self-forwarding Pointers"), aoqi@0: _g1h(g1h) { } aoqi@0: aoqi@0: void work(uint worker_id) { aoqi@0: UpdateRSetImmediate immediate_update(_g1h->g1_rem_set()); aoqi@0: DirtyCardQueue dcq(&_g1h->dirty_card_queue_set()); aoqi@0: UpdateRSetDeferred deferred_update(_g1h, &dcq); aoqi@0: aoqi@0: OopsInHeapRegionClosure *update_rset_cl = &deferred_update; aoqi@0: if (!G1DeferredRSUpdate) { aoqi@0: update_rset_cl = &immediate_update; aoqi@0: } aoqi@0: aoqi@0: RemoveSelfForwardPtrHRClosure rsfp_cl(_g1h, update_rset_cl, worker_id); aoqi@0: aoqi@0: HeapRegion* hr = _g1h->start_cset_region_for_worker(worker_id); aoqi@0: _g1h->collection_set_iterate_from(hr, &rsfp_cl); aoqi@0: } aoqi@0: }; aoqi@0: aoqi@0: #endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1EVACFAILURE_HPP