Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/gc_implementation/g1/g1EvacFailure.hpp
38920 views
/*1* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_VM_GC_IMPLEMENTATION_G1_G1EVACFAILURE_HPP25#define SHARE_VM_GC_IMPLEMENTATION_G1_G1EVACFAILURE_HPP2627#include "gc_implementation/g1/concurrentMark.inline.hpp"28#include "gc_implementation/g1/dirtyCardQueue.hpp"29#include "gc_implementation/g1/g1CollectedHeap.inline.hpp"30#include "gc_implementation/g1/g1_globals.hpp"31#include "gc_implementation/g1/g1OopClosures.inline.hpp"32#include "gc_implementation/g1/heapRegion.hpp"33#include "gc_implementation/g1/heapRegionRemSet.hpp"34#include "utilities/workgroup.hpp"3536// Closures and tasks associated with any self-forwarding pointers37// installed as a result of an evacuation failure.3839class UpdateRSetDeferred : public OopsInHeapRegionClosure {40private:41G1CollectedHeap* _g1;42DirtyCardQueue *_dcq;43G1SATBCardTableModRefBS* _ct_bs;4445public:46UpdateRSetDeferred(G1CollectedHeap* g1, DirtyCardQueue* dcq) :47_g1(g1), _ct_bs(_g1->g1_barrier_set()), _dcq(dcq) {}4849virtual void do_oop(narrowOop* p) { do_oop_work(p); }50virtual void do_oop( oop* p) { do_oop_work(p); }51template <class T> void do_oop_work(T* p) {52assert(_from->is_in_reserved(p), "paranoia");53if (!_from->is_in_reserved(oopDesc::load_decode_heap_oop(p)) &&54!_from->is_survivor()) {55size_t card_index = _ct_bs->index_for(p);56if (_ct_bs->mark_card_deferred(card_index)) {57_dcq->enqueue((jbyte*)_ct_bs->byte_for_index(card_index));58}59}60}61};6263class RemoveSelfForwardPtrObjClosure: public ObjectClosure {64private:65G1CollectedHeap* _g1;66ConcurrentMark* _cm;67HeapRegion* _hr;68size_t _marked_bytes;69OopsInHeapRegionClosure *_update_rset_cl;70bool _during_initial_mark;71bool _during_conc_mark;72uint _worker_id;73HeapWord* _end_of_last_gap;74HeapWord* _last_gap_threshold;75HeapWord* _last_obj_threshold;7677public:78RemoveSelfForwardPtrObjClosure(G1CollectedHeap* g1, ConcurrentMark* cm,79HeapRegion* hr,80OopsInHeapRegionClosure* update_rset_cl,81bool during_initial_mark,82bool during_conc_mark,83uint worker_id) :84_g1(g1), _cm(cm), _hr(hr), _marked_bytes(0),85_update_rset_cl(update_rset_cl),86_during_initial_mark(during_initial_mark),87_during_conc_mark(during_conc_mark),88_worker_id(worker_id),89_end_of_last_gap(hr->bottom()),90_last_gap_threshold(hr->bottom()),91_last_obj_threshold(hr->bottom()) { }9293size_t marked_bytes() { return _marked_bytes; }9495// <original comment>96// The original idea here was to coalesce evacuated and dead objects.97// However that caused complications with the block offset table (BOT).98// In particular if there were two TLABs, one of them partially refined.99// |----- TLAB_1--------|----TLAB_2-~~~(partially refined part)~~~|100// The BOT entries of the unrefined part of TLAB_2 point to the start101// of TLAB_2. If the last object of the TLAB_1 and the first object102// of TLAB_2 are coalesced, then the cards of the unrefined part103// would point into middle of the filler object.104// The current approach is to not coalesce and leave the BOT contents intact.105// </original comment>106//107// We now reset the BOT when we start the object iteration over the108// region and refine its entries for every object we come across. So109// the above comment is not really relevant and we should be able110// to coalesce dead objects if we want to.111void do_object(oop obj) {112HeapWord* obj_addr = (HeapWord*) obj;113assert(_hr->is_in(obj_addr), "sanity");114size_t obj_size = obj->size();115HeapWord* obj_end = obj_addr + obj_size;116117if (_end_of_last_gap != obj_addr) {118// there was a gap before obj_addr119_last_gap_threshold = _hr->cross_threshold(_end_of_last_gap, obj_addr);120}121122if (obj->is_forwarded() && obj->forwardee() == obj) {123// The object failed to move.124125// We consider all objects that we find self-forwarded to be126// live. What we'll do is that we'll update the prev marking127// info so that they are all under PTAMS and explicitly marked.128if (!_cm->isPrevMarked(obj)) {129_cm->markPrev(obj);130}131if (_during_initial_mark) {132// For the next marking info we'll only mark the133// self-forwarded objects explicitly if we are during134// initial-mark (since, normally, we only mark objects pointed135// to by roots if we succeed in copying them). By marking all136// self-forwarded objects we ensure that we mark any that are137// still pointed to be roots. During concurrent marking, and138// after initial-mark, we don't need to mark any objects139// explicitly and all objects in the CSet are considered140// (implicitly) live. So, we won't mark them explicitly and141// we'll leave them over NTAMS.142_cm->grayRoot(obj, obj_size, _worker_id, _hr);143}144_marked_bytes += (obj_size * HeapWordSize);145obj->set_mark(markOopDesc::prototype());146147// While we were processing RSet buffers during the collection,148// we actually didn't scan any cards on the collection set,149// since we didn't want to update remembered sets with entries150// that point into the collection set, given that live objects151// from the collection set are about to move and such entries152// will be stale very soon.153// This change also dealt with a reliability issue which154// involved scanning a card in the collection set and coming155// across an array that was being chunked and looking malformed.156// The problem is that, if evacuation fails, we might have157// remembered set entries missing given that we skipped cards on158// the collection set. So, we'll recreate such entries now.159obj->oop_iterate(_update_rset_cl);160} else {161162// The object has been either evacuated or is dead. Fill it with a163// dummy object.164MemRegion mr(obj_addr, obj_size);165CollectedHeap::fill_with_object(mr);166167// must nuke all dead objects which we skipped when iterating over the region168_cm->clearRangePrevBitmap(MemRegion(_end_of_last_gap, obj_end));169}170_end_of_last_gap = obj_end;171_last_obj_threshold = _hr->cross_threshold(obj_addr, obj_end);172}173};174175class RemoveSelfForwardPtrHRClosure: public HeapRegionClosure {176G1CollectedHeap* _g1h;177ConcurrentMark* _cm;178uint _worker_id;179180DirtyCardQueue _dcq;181UpdateRSetDeferred _update_rset_cl;182183public:184RemoveSelfForwardPtrHRClosure(G1CollectedHeap* g1h,185uint worker_id) :186_g1h(g1h), _dcq(&g1h->dirty_card_queue_set()), _update_rset_cl(g1h, &_dcq),187_worker_id(worker_id), _cm(_g1h->concurrent_mark()) {188}189190bool doHeapRegion(HeapRegion *hr) {191bool during_initial_mark = _g1h->g1_policy()->during_initial_mark_pause();192bool during_conc_mark = _g1h->mark_in_progress();193194assert(!hr->isHumongous(), "sanity");195assert(hr->in_collection_set(), "bad CS");196197if (hr->claimHeapRegion(HeapRegion::ParEvacFailureClaimValue)) {198if (hr->evacuation_failed()) {199RemoveSelfForwardPtrObjClosure rspc(_g1h, _cm, hr, &_update_rset_cl,200during_initial_mark,201during_conc_mark,202_worker_id);203204hr->note_self_forwarding_removal_start(during_initial_mark,205during_conc_mark);206_g1h->check_bitmaps("Self-Forwarding Ptr Removal", hr);207208// In the common case (i.e. when there is no evacuation209// failure) we make sure that the following is done when210// the region is freed so that it is "ready-to-go" when it's211// re-allocated. However, when evacuation failure happens, a212// region will remain in the heap and might ultimately be added213// to a CSet in the future. So we have to be careful here and214// make sure the region's RSet is ready for parallel iteration215// whenever this might be required in the future.216hr->rem_set()->reset_for_par_iteration();217hr->reset_bot();218_update_rset_cl.set_region(hr);219hr->object_iterate(&rspc);220221hr->rem_set()->clean_strong_code_roots(hr);222223hr->note_self_forwarding_removal_end(during_initial_mark,224during_conc_mark,225rspc.marked_bytes());226}227}228return false;229}230};231232class G1ParRemoveSelfForwardPtrsTask: public AbstractGangTask {233protected:234G1CollectedHeap* _g1h;235236public:237G1ParRemoveSelfForwardPtrsTask(G1CollectedHeap* g1h) :238AbstractGangTask("G1 Remove Self-forwarding Pointers"),239_g1h(g1h) { }240241void work(uint worker_id) {242RemoveSelfForwardPtrHRClosure rsfp_cl(_g1h, worker_id);243244HeapRegion* hr = _g1h->start_cset_region_for_worker(worker_id);245_g1h->collection_set_iterate_from(hr, &rsfp_cl);246}247};248249#endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1EVACFAILURE_HPP250251252