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