8287805: Shenandoah: consolidate evacuate-update-root closures

Reviewed-by: shade
This commit is contained in:
Zhengyu Gu 2022-07-18 16:54:08 +00:00
parent ea8b75cfe4
commit b2010a7481
4 changed files with 44 additions and 97 deletions

View File

@ -89,42 +89,23 @@ private:
inline void do_oop_work(T* p);
};
template <DecoratorSet MO = MO_UNORDERED>
class ShenandoahEvacuateUpdateMetadataClosure: public ShenandoahOopClosureBase {
private:
template <bool concurrent, bool stable_thread>
class ShenandoahEvacuateUpdateRootClosureBase : public ShenandoahOopClosureBase {
protected:
ShenandoahHeap* const _heap;
Thread* const _thread;
public:
inline ShenandoahEvacuateUpdateMetadataClosure();
inline ShenandoahEvacuateUpdateRootClosureBase();
inline void do_oop(oop* p);
inline void do_oop(narrowOop* p);
private:
protected:
template <class T>
inline void do_oop_work(T* p);
};
// Context free version, cannot cache calling thread
class ShenandoahEvacuateUpdateRootsClosure : public ShenandoahOopClosureBase {
private:
ShenandoahHeap* const _heap;
public:
inline ShenandoahEvacuateUpdateRootsClosure();
inline void do_oop(oop* p);
inline void do_oop(narrowOop* p);
protected:
template <typename T>
inline void do_oop_work(T* p, Thread* thr);
};
class ShenandoahContextEvacuateUpdateRootsClosure : public ShenandoahEvacuateUpdateRootsClosure {
private:
Thread* const _thread;
public:
inline ShenandoahContextEvacuateUpdateRootsClosure();
inline void do_oop(oop* p);
inline void do_oop(narrowOop* p);
};
using ShenandoahEvacuateUpdateMetadataClosure = ShenandoahEvacuateUpdateRootClosureBase<false, true>;
using ShenandoahEvacuateUpdateRootsClosure = ShenandoahEvacuateUpdateRootClosureBase<true, false>;
using ShenandoahContextEvacuateUpdateRootsClosure = ShenandoahEvacuateUpdateRootClosureBase<true, true>;
template <bool CONCURRENT, typename IsAlive, typename KeepAlive>
class ShenandoahCleanUpdateWeakOopsClosure : public OopClosure {

View File

@ -109,18 +109,37 @@ void ShenandoahUpdateRefsClosure::do_oop_work(T* p) {
void ShenandoahUpdateRefsClosure::do_oop(oop* p) { do_oop_work(p); }
void ShenandoahUpdateRefsClosure::do_oop(narrowOop* p) { do_oop_work(p); }
template <DecoratorSet MO>
ShenandoahEvacuateUpdateMetadataClosure<MO>::ShenandoahEvacuateUpdateMetadataClosure() :
_heap(ShenandoahHeap::heap()), _thread(Thread::current()) {
template <bool concurrent, bool stable_thread>
ShenandoahEvacuateUpdateRootClosureBase<concurrent, stable_thread>::ShenandoahEvacuateUpdateRootClosureBase() :
_heap(ShenandoahHeap::heap()), _thread(stable_thread ? Thread::current() : NULL) {
}
template <DecoratorSet MO>
template <bool concurrent, bool stable_thread>
void ShenandoahEvacuateUpdateRootClosureBase<concurrent, stable_thread>::do_oop(oop* p) {
if (concurrent) {
ShenandoahEvacOOMScope scope;
do_oop_work(p);
} else {
do_oop_work(p);
}
}
template <bool concurrent, bool stable_thread>
void ShenandoahEvacuateUpdateRootClosureBase<concurrent, stable_thread>::do_oop(narrowOop* p) {
if (concurrent) {
ShenandoahEvacOOMScope scope;
do_oop_work(p);
} else {
do_oop_work(p);
}
}
template <bool atomic, bool stable_thread>
template <class T>
void ShenandoahEvacuateUpdateMetadataClosure<MO>::do_oop_work(T* p) {
void ShenandoahEvacuateUpdateRootClosureBase<atomic, stable_thread>::do_oop_work(T* p) {
assert(_heap->is_concurrent_weak_root_in_progress() ||
_heap->is_concurrent_strong_root_in_progress(),
"Only do this in root processing phase");
assert(_thread == Thread::current(), "Wrong thread");
T o = RawAccess<>::oop_load(p);
if (!CompressedOops::is_null(o)) {
@ -130,71 +149,18 @@ void ShenandoahEvacuateUpdateMetadataClosure<MO>::do_oop_work(T* p) {
shenandoah_assert_marked(p, obj);
oop resolved = ShenandoahBarrierSet::resolve_forwarded_not_null(obj);
if (resolved == obj) {
resolved = _heap->evacuate_object(obj, _thread);
}
RawAccess<IS_NOT_NULL | MO>::oop_store(p, resolved);
}
}
}
template <DecoratorSet MO>
void ShenandoahEvacuateUpdateMetadataClosure<MO>::do_oop(oop* p) {
do_oop_work(p);
}
Thread* thr = stable_thread ? _thread : Thread::current();
assert(thr == Thread::current(), "Wrong thread");
template <DecoratorSet MO>
void ShenandoahEvacuateUpdateMetadataClosure<MO>::do_oop(narrowOop* p) {
do_oop_work(p);
}
ShenandoahEvacuateUpdateRootsClosure::ShenandoahEvacuateUpdateRootsClosure() :
_heap(ShenandoahHeap::heap()) {
}
template <typename T>
void ShenandoahEvacuateUpdateRootsClosure::do_oop_work(T* p, Thread* t) {
assert(_heap->is_concurrent_weak_root_in_progress() ||
_heap->is_concurrent_strong_root_in_progress(),
"Only do this in root processing phase");
assert(t == Thread::current(), "Wrong thread");
T o = RawAccess<>::oop_load(p);
if (!CompressedOops::is_null(o)) {
oop obj = CompressedOops::decode_not_null(o);
if (_heap->in_collection_set(obj)) {
assert(_heap->is_evacuation_in_progress(), "Only do this when evacuation is in progress");
shenandoah_assert_marked(p, obj);
oop resolved = ShenandoahBarrierSet::resolve_forwarded_not_null(obj);
if (resolved == obj) {
resolved = _heap->evacuate_object(obj, t);
resolved = _heap->evacuate_object(obj, thr);
}
if (atomic) {
ShenandoahHeap::atomic_update_oop(resolved, p, o);
} else {
RawAccess<IS_NOT_NULL | MO_UNORDERED>::oop_store(p, resolved);
}
}
}
void ShenandoahEvacuateUpdateRootsClosure::do_oop(oop* p) {
ShenandoahEvacOOMScope scope;
do_oop_work(p, Thread::current());
}
void ShenandoahEvacuateUpdateRootsClosure::do_oop(narrowOop* p) {
ShenandoahEvacOOMScope scope;
do_oop_work(p, Thread::current());
}
ShenandoahContextEvacuateUpdateRootsClosure::ShenandoahContextEvacuateUpdateRootsClosure() :
ShenandoahEvacuateUpdateRootsClosure(),
_thread(Thread::current()) {
}
void ShenandoahContextEvacuateUpdateRootsClosure::do_oop(oop* p) {
ShenandoahEvacOOMScope scope;
do_oop_work(p, _thread);
}
void ShenandoahContextEvacuateUpdateRootsClosure::do_oop(narrowOop* p) {
ShenandoahEvacOOMScope scope;
do_oop_work(p, _thread);
}
template <bool CONCURRENT, typename IsAlive, typename KeepAlive>

View File

@ -834,7 +834,7 @@ void ShenandoahConcurrentGC::op_class_unloading() {
class ShenandoahEvacUpdateCodeCacheClosure : public NMethodClosure {
private:
BarrierSetNMethod* const _bs;
ShenandoahEvacuateUpdateMetadataClosure<> _cl;
ShenandoahEvacuateUpdateMetadataClosure _cl;
public:
ShenandoahEvacUpdateCodeCacheClosure() :
@ -893,7 +893,7 @@ public:
}
{
ShenandoahEvacuateUpdateMetadataClosure<> cl;
ShenandoahEvacuateUpdateMetadataClosure cl;
CLDToOopClosure clds(&cl, ClassLoaderData::_claim_strong);
_cld_roots.cld_do(&clds, worker_id);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2021, Red Hat, Inc. All rights reserved.
* Copyright (c) 2019, 2022, Red Hat, Inc. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -74,7 +74,7 @@ void ShenandoahNMethod::oops_do(OopClosure* oops, bool fix_relocations) {
}
void ShenandoahNMethod::heal_nmethod_metadata(ShenandoahNMethod* nmethod_data) {
ShenandoahEvacuateUpdateMetadataClosure<> cl;
ShenandoahEvacuateUpdateMetadataClosure cl;
nmethod_data->oops_do(&cl, true /*fix relocation*/);
}