# HG changeset patch # Parent 644b2e8757b23ee3eb62f30994566f792213cded [backport] 8222425: Shenandoah: Move commonly used closures to separate files Reviewed-by: shade diff --git a/src/share/vm/gc_implementation/shenandoah/shenandoahClosures.hpp b/src/share/vm/gc_implementation/shenandoah/shenandoahClosures.hpp new file mode 100644 --- /dev/null +++ b/src/share/vm/gc_implementation/shenandoah/shenandoahClosures.hpp @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2019, Red Hat, Inc. All rights reserved. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ +#ifndef SHARE_GC_SHENANDOAH_SHENANDOAHCLOSURES_HPP +#define SHARE_GC_SHENANDOAH_SHENANDOAHCLOSURES_HPP + +#include "memory/iterator.hpp" + +class ShenandoahHeap; +class ShenandoahMarkingContext; +class Thread; + +class ShenandoahForwardedIsAliveClosure: public BoolObjectClosure { +private: + ShenandoahMarkingContext* const _mark_context; +public: + inline ShenandoahForwardedIsAliveClosure(); + inline bool do_object_b(oop obj); +}; + +class ShenandoahIsAliveClosure: public BoolObjectClosure { +private: + ShenandoahMarkingContext* const _mark_context; +public: + inline ShenandoahIsAliveClosure(); + inline bool do_object_b(oop obj); +}; + +class ShenandoahIsAliveSelector : public StackObj { +private: + ShenandoahIsAliveClosure _alive_cl; + ShenandoahForwardedIsAliveClosure _fwd_alive_cl; +public: + inline BoolObjectClosure* is_alive_closure(); +}; + +class ShenandoahUpdateRefsClosure: public OopClosure { +private: + ShenandoahHeap* _heap; +public: + inline ShenandoahUpdateRefsClosure(); + inline void do_oop(oop* p); + inline void do_oop(narrowOop* p); +private: + template + inline void do_oop_work(T* p); +}; + +class ShenandoahEvacuateUpdateRootsClosure: public ExtendedOopClosure { +private: + ShenandoahHeap* _heap; + Thread* _thread; +public: + inline ShenandoahEvacuateUpdateRootsClosure(); + inline void do_oop(oop* p); + inline void do_oop(narrowOop* p); + +private: + template + inline void do_oop_work(T* p); +}; + +#endif // SHARE_GC_SHENANDOAH_SHENANDOAHCLOSURES_HPP diff --git a/src/share/vm/gc_implementation/shenandoah/shenandoahClosures.inline.hpp b/src/share/vm/gc_implementation/shenandoah/shenandoahClosures.inline.hpp new file mode 100644 --- /dev/null +++ b/src/share/vm/gc_implementation/shenandoah/shenandoahClosures.inline.hpp @@ -0,0 +1,110 @@ +/* + * Copyright (c) 2019, Red Hat, Inc. All rights reserved. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ +#ifndef SHARE_GC_SHENANDOAH_SHENANDOAHCLOSURES_INLINE_HPP +#define SHARE_GC_SHENANDOAH_SHENANDOAHCLOSURES_INLINE_HPP + +#include "gc_implementation/shenandoah/shenandoahAsserts.hpp" +#include "gc_implementation/shenandoah/shenandoahClosures.hpp" +#include "gc_implementation/shenandoah/shenandoahHeap.inline.hpp" +#include "runtime/thread.hpp" + +ShenandoahForwardedIsAliveClosure::ShenandoahForwardedIsAliveClosure() : + _mark_context(ShenandoahHeap::heap()->marking_context()) { +} + +bool ShenandoahForwardedIsAliveClosure::do_object_b(oop obj) { + if (oopDesc::is_null(obj)) { + return false; + } + obj = ShenandoahBarrierSet::resolve_forwarded_not_null(obj); + shenandoah_assert_not_forwarded_if(NULL, obj, + ShenandoahHeap::heap()->is_concurrent_mark_in_progress()); + return _mark_context->is_marked(obj); +} + +ShenandoahIsAliveClosure::ShenandoahIsAliveClosure() : + _mark_context(ShenandoahHeap::heap()->marking_context()) { +} + +bool ShenandoahIsAliveClosure::do_object_b(oop obj) { + if (oopDesc::is_null(obj)) { + return false; + } + shenandoah_assert_not_forwarded(NULL, obj); + return _mark_context->is_marked(obj); +} + +BoolObjectClosure* ShenandoahIsAliveSelector::is_alive_closure() { + return ShenandoahHeap::heap()->has_forwarded_objects() ? + reinterpret_cast(&_fwd_alive_cl) : + reinterpret_cast(&_alive_cl); +} + +ShenandoahUpdateRefsClosure::ShenandoahUpdateRefsClosure() : + _heap(ShenandoahHeap::heap()) { +} + +template +void ShenandoahUpdateRefsClosure::do_oop_work(T* p) { + T o = oopDesc::load_heap_oop(p); + if (!oopDesc::is_null(o)) { + oop obj = oopDesc::decode_heap_oop_not_null(o); + _heap->update_with_forwarded_not_null(p, obj); + } +} + +void ShenandoahUpdateRefsClosure::do_oop(oop* p) { do_oop_work(p); } +void ShenandoahUpdateRefsClosure::do_oop(narrowOop* p) { do_oop_work(p); } + +ShenandoahEvacuateUpdateRootsClosure::ShenandoahEvacuateUpdateRootsClosure() : + _heap(ShenandoahHeap::heap()), _thread(Thread::current()) { +} + +template +void ShenandoahEvacuateUpdateRootsClosure::do_oop_work(T* p) { + assert(_heap->is_evacuation_in_progress(), "Only do this when evacuation is in progress"); + + T o = oopDesc::load_heap_oop(p); + if (! oopDesc::is_null(o)) { + oop obj = oopDesc::decode_heap_oop_not_null(o); + if (_heap->in_collection_set(obj)) { + shenandoah_assert_marked(p, obj); + oop resolved = ShenandoahBarrierSet::resolve_forwarded_not_null(obj); + if (oopDesc::unsafe_equals(resolved, obj)) { + bool evac; + resolved = _heap->evacuate_object(obj, _thread, evac); + } + oopDesc::encode_store_heap_oop(p, resolved); + } + } +} + +void ShenandoahEvacuateUpdateRootsClosure::do_oop(oop* p) { + do_oop_work(p); +} + +void ShenandoahEvacuateUpdateRootsClosure::do_oop(narrowOop* p) { + do_oop_work(p); +} + +#endif // SHARE_GC_SHENANDOAH_SHENANDOAHCLOSURES_HPP diff --git a/src/share/vm/gc_implementation/shenandoah/shenandoahConcurrentMark.cpp b/src/share/vm/gc_implementation/shenandoah/shenandoahConcurrentMark.cpp --- a/src/share/vm/gc_implementation/shenandoah/shenandoahConcurrentMark.cpp +++ b/src/share/vm/gc_implementation/shenandoah/shenandoahConcurrentMark.cpp @@ -30,6 +30,7 @@ #include "gc_implementation/shared/parallelCleaning.hpp" #include "gc_implementation/shenandoah/shenandoahBrooksPointer.hpp" #include "gc_implementation/shenandoah/shenandoahBarrierSet.inline.hpp" +#include "gc_implementation/shenandoah/shenandoahClosures.inline.hpp" #include "gc_implementation/shenandoah/shenandoahConcurrentMark.inline.hpp" #include "gc_implementation/shenandoah/shenandoahOopClosures.inline.hpp" #include "gc_implementation/shenandoah/shenandoahHeap.inline.hpp" diff --git a/src/share/vm/gc_implementation/shenandoah/shenandoahHeap.cpp b/src/share/vm/gc_implementation/shenandoah/shenandoahHeap.cpp --- a/src/share/vm/gc_implementation/shenandoah/shenandoahHeap.cpp +++ b/src/share/vm/gc_implementation/shenandoah/shenandoahHeap.cpp @@ -31,6 +31,7 @@ #include "gc_implementation/shenandoah/shenandoahBrooksPointer.hpp" #include "gc_implementation/shenandoah/shenandoahAllocTracker.hpp" #include "gc_implementation/shenandoah/shenandoahBarrierSet.hpp" +#include "gc_implementation/shenandoah/shenandoahClosures.inline.hpp" #include "gc_implementation/shenandoah/shenandoahCollectionSet.hpp" #include "gc_implementation/shenandoah/shenandoahCollectorPolicy.hpp" #include "gc_implementation/shenandoah/shenandoahConcurrentMark.inline.hpp" @@ -63,8 +64,6 @@ #include "runtime/vmThread.hpp" #include "services/mallocTracker.hpp" -ShenandoahUpdateRefsClosure::ShenandoahUpdateRefsClosure() : _heap(ShenandoahHeap::heap()) {} - #ifdef ASSERT template void ShenandoahAssertToSpaceClosure::do_oop_nv(T* p) { @@ -826,44 +825,6 @@ } } -class ShenandoahEvacuateUpdateRootsClosure: public ExtendedOopClosure { -private: - ShenandoahHeap* _heap; - Thread* _thread; -public: - ShenandoahEvacuateUpdateRootsClosure() : - _heap(ShenandoahHeap::heap()), _thread(Thread::current()) { - } - -private: - template - void do_oop_work(T* p) { - assert(_heap->is_evacuation_in_progress(), "Only do this when evacuation is in progress"); - - T o = oopDesc::load_heap_oop(p); - if (! oopDesc::is_null(o)) { - oop obj = oopDesc::decode_heap_oop_not_null(o); - if (_heap->in_collection_set(obj)) { - shenandoah_assert_marked(p, obj); - oop resolved = ShenandoahBarrierSet::resolve_forwarded_not_null(obj); - if (oopDesc::unsafe_equals(resolved, obj)) { - bool evac; - resolved = _heap->evacuate_object(obj, _thread, evac); - } - oopDesc::encode_store_heap_oop(p, resolved); - } - } - } - -public: - void do_oop(oop* p) { - do_oop_work(p); - } - void do_oop(narrowOop* p) { - do_oop_work(p); - } -}; - class ShenandoahConcurrentEvacuateRegionObjectClosure : public ObjectClosure { private: ShenandoahHeap* const _heap; @@ -1786,31 +1747,6 @@ return ShenandoahBrooksPointer::word_size(); } -ShenandoahForwardedIsAliveClosure::ShenandoahForwardedIsAliveClosure() : - _mark_context(ShenandoahHeap::heap()->marking_context()) { -} - -ShenandoahIsAliveClosure::ShenandoahIsAliveClosure() : - _mark_context(ShenandoahHeap::heap()->marking_context()) { -} - -bool ShenandoahForwardedIsAliveClosure::do_object_b(oop obj) { - if (oopDesc::is_null(obj)) { - return false; - } - obj = ShenandoahBarrierSet::resolve_forwarded_not_null(obj); - shenandoah_assert_not_forwarded_if(NULL, obj, ShenandoahHeap::heap()->is_concurrent_mark_in_progress()); - return _mark_context->is_marked(obj); -} - -bool ShenandoahIsAliveClosure::do_object_b(oop obj) { - if (oopDesc::is_null(obj)) { - return false; - } - shenandoah_assert_not_forwarded(NULL, obj); - return _mark_context->is_marked(obj); -} - void ShenandoahHeap::ref_processing_init() { MemRegion mr = reserved_region(); @@ -2667,8 +2603,3 @@ } } } - -BoolObjectClosure* ShenandoahIsAliveSelector::is_alive_closure() { - return ShenandoahHeap::heap()->has_forwarded_objects() ? reinterpret_cast(&_fwd_alive_cl) - : reinterpret_cast(&_alive_cl); -} diff --git a/src/share/vm/gc_implementation/shenandoah/shenandoahHeap.hpp b/src/share/vm/gc_implementation/shenandoah/shenandoahHeap.hpp --- a/src/share/vm/gc_implementation/shenandoah/shenandoahHeap.hpp +++ b/src/share/vm/gc_implementation/shenandoah/shenandoahHeap.hpp @@ -86,19 +86,6 @@ virtual bool is_thread_safe() { return false; } }; -class ShenandoahUpdateRefsClosure: public OopClosure { -private: - ShenandoahHeap* _heap; - - template - inline void do_oop_work(T* p); - -public: - ShenandoahUpdateRefsClosure(); - inline void do_oop(oop* p); - inline void do_oop(narrowOop* p); -}; - #ifdef ASSERT class ShenandoahAssertToSpaceClosure : public OopClosure { private: @@ -115,30 +102,6 @@ bool do_object_b(oop p) { return true; } }; -class ShenandoahForwardedIsAliveClosure: public BoolObjectClosure { -private: - ShenandoahMarkingContext* const _mark_context; -public: - ShenandoahForwardedIsAliveClosure(); - bool do_object_b(oop obj); -}; - -class ShenandoahIsAliveClosure: public BoolObjectClosure { -private: - ShenandoahMarkingContext* const _mark_context; -public: - ShenandoahIsAliveClosure(); - bool do_object_b(oop obj); -}; - -class ShenandoahIsAliveSelector : public StackObj { -private: - ShenandoahIsAliveClosure _alive_cl; - ShenandoahForwardedIsAliveClosure _fwd_alive_cl; -public: - BoolObjectClosure* is_alive_closure(); -}; - // Shenandoah GC is low-pause concurrent GC that uses Brooks forwarding pointers // to encode forwarding data. See BrooksPointer for details on forwarding data encoding. // See ShenandoahControlThread for GC cycle structure. diff --git a/src/share/vm/gc_implementation/shenandoah/shenandoahHeap.inline.hpp b/src/share/vm/gc_implementation/shenandoah/shenandoahHeap.inline.hpp --- a/src/share/vm/gc_implementation/shenandoah/shenandoahHeap.inline.hpp +++ b/src/share/vm/gc_implementation/shenandoah/shenandoahHeap.inline.hpp @@ -43,17 +43,6 @@ #include "utilities/copy.hpp" #include "utilities/globalDefinitions.hpp" -template -void ShenandoahUpdateRefsClosure::do_oop_work(T* p) { - T o = oopDesc::load_heap_oop(p); - if (! oopDesc::is_null(o)) { - oop obj = oopDesc::decode_heap_oop_not_null(o); - _heap->update_with_forwarded_not_null(p, obj); - } -} - -void ShenandoahUpdateRefsClosure::do_oop(oop* p) { do_oop_work(p); } -void ShenandoahUpdateRefsClosure::do_oop(narrowOop* p) { do_oop_work(p); } inline ShenandoahHeapRegion* ShenandoahRegionIterator::next() { size_t new_index = Atomic::add((size_t) 1, &_index); diff --git a/src/share/vm/gc_implementation/shenandoah/shenandoahRootProcessor.cpp b/src/share/vm/gc_implementation/shenandoah/shenandoahRootProcessor.cpp --- a/src/share/vm/gc_implementation/shenandoah/shenandoahRootProcessor.cpp +++ b/src/share/vm/gc_implementation/shenandoah/shenandoahRootProcessor.cpp @@ -26,6 +26,7 @@ #include "classfile/classLoaderData.hpp" #include "classfile/systemDictionary.hpp" #include "code/codeCache.hpp" +#include "gc_implementation/shenandoah/shenandoahClosures.inline.hpp" #include "gc_implementation/shenandoah/shenandoahRootProcessor.hpp" #include "gc_implementation/shenandoah/shenandoahHeap.hpp" #include "gc_implementation/shenandoah/shenandoahHeap.inline.hpp"