8222425: Shenandoah: Move commonly used closures to separate files

Reviewed-by: shade
This commit is contained in:
Zhengyu Gu 2019-04-15 13:07:06 -04:00
parent a652f593f2
commit 826c03330b
8 changed files with 196 additions and 116 deletions

View File

@ -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 <class T>
inline void do_oop_work(T* p);
};
class ShenandoahEvacuateUpdateRootsClosure: public BasicOopIterateClosure {
private:
ShenandoahHeap* _heap;
Thread* _thread;
public:
inline ShenandoahEvacuateUpdateRootsClosure();
inline void do_oop(oop* p);
inline void do_oop(narrowOop* p);
private:
template <class T>
inline void do_oop_work(T* p);
};
#endif // SHARE_GC_SHENANDOAH_SHENANDOAHCLOSURES_HPP

View File

@ -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/shenandoah/shenandoahAsserts.hpp"
#include "gc/shenandoah/shenandoahClosures.hpp"
#include "gc/shenandoah/shenandoahHeap.inline.hpp"
#include "oops/compressedOops.inline.hpp"
#include "runtime/thread.hpp"
ShenandoahForwardedIsAliveClosure::ShenandoahForwardedIsAliveClosure() :
_mark_context(ShenandoahHeap::heap()->marking_context()) {
}
bool ShenandoahForwardedIsAliveClosure::do_object_b(oop obj) {
if (CompressedOops::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() ||
ShenandoahHeap::heap()->is_concurrent_traversal_in_progress()));
return _mark_context->is_marked(obj);
}
ShenandoahIsAliveClosure::ShenandoahIsAliveClosure() :
_mark_context(ShenandoahHeap::heap()->marking_context()) {
}
bool ShenandoahIsAliveClosure::do_object_b(oop obj) {
if (CompressedOops::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<BoolObjectClosure*>(&_fwd_alive_cl) :
reinterpret_cast<BoolObjectClosure*>(&_alive_cl);
}
ShenandoahUpdateRefsClosure::ShenandoahUpdateRefsClosure() :
_heap(ShenandoahHeap::heap()) {
}
template <class T>
void ShenandoahUpdateRefsClosure::do_oop_work(T* p) {
T o = RawAccess<>::oop_load(p);
if (!CompressedOops::is_null(o)) {
oop obj = CompressedOops::decode_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 <class T>
void ShenandoahEvacuateUpdateRootsClosure::do_oop_work(T* p) {
assert(_heap->is_evacuation_in_progress(), "Only do this when evacuation is in progress");
T o = RawAccess<>::oop_load(p);
if (! CompressedOops::is_null(o)) {
oop obj = CompressedOops::decode_not_null(o);
if (_heap->in_collection_set(obj)) {
shenandoah_assert_marked(p, obj);
oop resolved = ShenandoahBarrierSet::resolve_forwarded_not_null(obj);
if (oopDesc::equals_raw(resolved, obj)) {
resolved = _heap->evacuate_object(obj, _thread);
}
RawAccess<IS_NOT_NULL>::oop_store(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

View File

@ -33,6 +33,7 @@
#include "gc/shared/referenceProcessorPhaseTimes.hpp"
#include "gc/shenandoah/shenandoahBarrierSet.inline.hpp"
#include "gc/shenandoah/shenandoahClosures.inline.hpp"
#include "gc/shenandoah/shenandoahConcurrentMark.inline.hpp"
#include "gc/shenandoah/shenandoahMarkCompact.hpp"
#include "gc/shenandoah/shenandoahHeap.inline.hpp"

View File

@ -33,6 +33,7 @@
#include "gc/shenandoah/shenandoahAllocTracker.hpp"
#include "gc/shenandoah/shenandoahBarrierSet.hpp"
#include "gc/shenandoah/shenandoahBrooksPointer.hpp"
#include "gc/shenandoah/shenandoahClosures.inline.hpp"
#include "gc/shenandoah/shenandoahCollectionSet.hpp"
#include "gc/shenandoah/shenandoahCollectorPolicy.hpp"
#include "gc/shenandoah/shenandoahConcurrentMark.inline.hpp"
@ -70,8 +71,6 @@
#include "runtime/vmThread.hpp"
#include "services/mallocTracker.hpp"
ShenandoahUpdateRefsClosure::ShenandoahUpdateRefsClosure() : _heap(ShenandoahHeap::heap()) {}
#ifdef ASSERT
template <class T>
void ShenandoahAssertToSpaceClosure::do_oop_work(T* p) {
@ -940,43 +939,6 @@ size_t ShenandoahHeap::min_dummy_object_size() const {
return CollectedHeap::min_dummy_object_size() + ShenandoahBrooksPointer::word_size();
}
class ShenandoahEvacuateUpdateRootsClosure: public BasicOopIterateClosure {
private:
ShenandoahHeap* _heap;
Thread* _thread;
public:
ShenandoahEvacuateUpdateRootsClosure() :
_heap(ShenandoahHeap::heap()), _thread(Thread::current()) {
}
private:
template <class T>
void do_oop_work(T* p) {
assert(_heap->is_evacuation_in_progress(), "Only do this when evacuation is in progress");
T o = RawAccess<>::oop_load(p);
if (! CompressedOops::is_null(o)) {
oop obj = CompressedOops::decode_not_null(o);
if (_heap->in_collection_set(obj)) {
shenandoah_assert_marked(p, obj);
oop resolved = ShenandoahBarrierSet::resolve_forwarded_not_null(obj);
if (oopDesc::equals_raw(resolved, obj)) {
resolved = _heap->evacuate_object(obj, _thread);
}
RawAccess<IS_NOT_NULL>::oop_store(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;
@ -1884,31 +1846,6 @@ HeapWord* ShenandoahHeap::tlab_post_allocation_setup(HeapWord* obj) {
return result;
}
ShenandoahForwardedIsAliveClosure::ShenandoahForwardedIsAliveClosure() :
_mark_context(ShenandoahHeap::heap()->marking_context()) {
}
ShenandoahIsAliveClosure::ShenandoahIsAliveClosure() :
_mark_context(ShenandoahHeap::heap()->marking_context()) {
}
bool ShenandoahForwardedIsAliveClosure::do_object_b(oop obj) {
if (CompressedOops::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() || ShenandoahHeap::heap()->is_concurrent_traversal_in_progress());
return _mark_context->is_marked(obj);
}
bool ShenandoahIsAliveClosure::do_object_b(oop obj) {
if (CompressedOops::is_null(obj)) {
return false;
}
shenandoah_assert_not_forwarded(NULL, obj);
return _mark_context->is_marked(obj);
}
void ShenandoahHeap::ref_processing_init() {
assert(_max_workers > 0, "Sanity");
@ -2879,8 +2816,3 @@ size_t ShenandoahHeap::obj_size(oop obj) const {
ptrdiff_t ShenandoahHeap::cell_header_size() const {
return ShenandoahBrooksPointer::byte_size();
}
BoolObjectClosure* ShenandoahIsAliveSelector::is_alive_closure() {
return ShenandoahHeap::heap()->has_forwarded_objects() ? reinterpret_cast<BoolObjectClosure*>(&_fwd_alive_cl)
: reinterpret_cast<BoolObjectClosure*>(&_alive_cl);
}

View File

@ -91,19 +91,6 @@ public:
virtual bool is_thread_safe() { return false; }
};
class ShenandoahUpdateRefsClosure: public OopClosure {
private:
ShenandoahHeap* _heap;
template <class T>
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,29 +102,6 @@ public:
};
#endif
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.

View File

@ -46,17 +46,6 @@
#include "utilities/copy.hpp"
#include "utilities/globalDefinitions.hpp"
template <class T>
void ShenandoahUpdateRefsClosure::do_oop_work(T* p) {
T o = RawAccess<>::oop_load(p);
if (!CompressedOops::is_null(o)) {
oop obj = CompressedOops::decode_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);

View File

@ -27,6 +27,7 @@
#include "classfile/stringTable.hpp"
#include "classfile/systemDictionary.hpp"
#include "code/codeCache.hpp"
#include "gc/shenandoah/shenandoahClosures.inline.hpp"
#include "gc/shenandoah/shenandoahRootProcessor.hpp"
#include "gc/shenandoah/shenandoahHeap.hpp"
#include "gc/shenandoah/shenandoahPhaseTimings.hpp"

View File

@ -30,6 +30,7 @@
#include "gc/shared/workgroup.hpp"
#include "gc/shared/weakProcessor.inline.hpp"
#include "gc/shenandoah/shenandoahBarrierSet.hpp"
#include "gc/shenandoah/shenandoahClosures.inline.hpp"
#include "gc/shenandoah/shenandoahCodeRoots.hpp"
#include "gc/shenandoah/shenandoahCollectionSet.hpp"
#include "gc/shenandoah/shenandoahCollectorPolicy.hpp"