Path: blob/master/src/hotspot/share/gc/shenandoah/shenandoahBarrierSetClone.inline.hpp
40961 views
/*1* Copyright (c) 2013, 2021, Red Hat, Inc. 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_GC_SHENANDOAH_SHENANDOAHBARRIERSETCLONE_INLINE_HPP25#define SHARE_GC_SHENANDOAH_SHENANDOAHBARRIERSETCLONE_INLINE_HPP2627// No shenandoahBarrierSetClone.hpp2829#include "gc/shenandoah/shenandoahBarrierSet.inline.hpp"30#include "gc/shenandoah/shenandoahCollectionSet.inline.hpp"31#include "gc/shenandoah/shenandoahEvacOOMHandler.hpp"32#include "gc/shenandoah/shenandoahHeap.inline.hpp"33#include "memory/iterator.inline.hpp"34#include "oops/access.hpp"35#include "oops/compressedOops.hpp"3637template <bool HAS_FWD, bool EVAC, bool ENQUEUE>38class ShenandoahUpdateRefsForOopClosure: public BasicOopIterateClosure {39private:40ShenandoahHeap* const _heap;41ShenandoahBarrierSet* const _bs;42const ShenandoahCollectionSet* const _cset;43Thread* const _thread;4445template <class T>46inline void do_oop_work(T* p) {47T o = RawAccess<>::oop_load(p);48if (!CompressedOops::is_null(o)) {49oop obj = CompressedOops::decode_not_null(o);50if (HAS_FWD && _cset->is_in(obj)) {51oop fwd = _bs->resolve_forwarded_not_null(obj);52if (EVAC && obj == fwd) {53fwd = _heap->evacuate_object(obj, _thread);54}55assert(obj != fwd || _heap->cancelled_gc(), "must be forwarded");56ShenandoahHeap::cas_oop(fwd, p, o);57obj = fwd;58}59if (ENQUEUE) {60_bs->enqueue(obj);61}62}63}64public:65ShenandoahUpdateRefsForOopClosure() :66_heap(ShenandoahHeap::heap()),67_bs(ShenandoahBarrierSet::barrier_set()),68_cset(_heap->collection_set()),69_thread(Thread::current()) {70}7172virtual void do_oop(oop* p) { do_oop_work(p); }73virtual void do_oop(narrowOop* p) { do_oop_work(p); }74};7576void ShenandoahBarrierSet::clone_marking(oop obj) {77assert(_heap->is_concurrent_mark_in_progress(), "only during marking");78assert(ShenandoahIUBarrier, "only with incremental-update");79if (!_heap->marking_context()->allocated_after_mark_start(obj)) {80ShenandoahUpdateRefsForOopClosure</* has_fwd = */ false, /* evac = */ false, /* enqueue */ true> cl;81obj->oop_iterate(&cl);82}83}8485void ShenandoahBarrierSet::clone_evacuation(oop obj) {86assert(_heap->is_evacuation_in_progress(), "only during evacuation");87if (need_bulk_update(cast_from_oop<HeapWord*>(obj))) {88ShenandoahEvacOOMScope oom_evac_scope;89ShenandoahUpdateRefsForOopClosure</* has_fwd = */ true, /* evac = */ true, /* enqueue */ false> cl;90obj->oop_iterate(&cl);91}92}9394void ShenandoahBarrierSet::clone_update(oop obj) {95assert(_heap->is_update_refs_in_progress(), "only during update-refs");96if (need_bulk_update(cast_from_oop<HeapWord*>(obj))) {97ShenandoahUpdateRefsForOopClosure</* has_fwd = */ true, /* evac = */ false, /* enqueue */ false> cl;98obj->oop_iterate(&cl);99}100}101102void ShenandoahBarrierSet::clone_barrier(oop obj) {103assert(ShenandoahCloneBarrier, "only get here with clone barriers enabled");104shenandoah_assert_correct(NULL, obj);105106int gc_state = _heap->gc_state();107if ((gc_state & ShenandoahHeap::MARKING) != 0) {108clone_marking(obj);109} else if ((gc_state & ShenandoahHeap::EVACUATION) != 0) {110clone_evacuation(obj);111} else {112clone_update(obj);113}114}115116#endif // SHARE_GC_SHENANDOAH_SHENANDOAHBARRIERSETCLONE_INLINE_HPP117118119