Skip to content

Commit

Permalink
8287805: Shenandoah: consolidate evacuate-update-root closures
Browse files Browse the repository at this point in the history
Reviewed-by: shade
  • Loading branch information
zhengyu123 committed Jul 18, 2022
1 parent ea8b75c commit b2010a7
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 98 deletions.
37 changes: 9 additions & 28 deletions src/hotspot/share/gc/shenandoah/shenandoahClosures.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,42 +89,23 @@ class ShenandoahUpdateRefsClosure: public ShenandoahOopClosureBase {
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;
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 {
Expand Down
98 changes: 32 additions & 66 deletions src/hotspot/share/gc/shenandoah/shenandoahClosures.inline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,53 +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 <DecoratorSet MO>
template <class T>
void ShenandoahEvacuateUpdateMetadataClosure<MO>::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)) {
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, _thread);
}
RawAccess<IS_NOT_NULL | MO>::oop_store(p, resolved);
}
template <bool concurrent, bool stable_thread>
ShenandoahEvacuateUpdateRootClosureBase<concurrent, stable_thread>::ShenandoahEvacuateUpdateRootClosureBase() :
_heap(ShenandoahHeap::heap()), _thread(stable_thread ? Thread::current() : NULL) {
}

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 <DecoratorSet MO>
void ShenandoahEvacuateUpdateMetadataClosure<MO>::do_oop(oop* p) {
do_oop_work(p);
}

template <DecoratorSet MO>
void ShenandoahEvacuateUpdateMetadataClosure<MO>::do_oop(narrowOop* p) {
do_oop_work(p);
}

ShenandoahEvacuateUpdateRootsClosure::ShenandoahEvacuateUpdateRootsClosure() :
_heap(ShenandoahHeap::heap()) {
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 <typename T>
void ShenandoahEvacuateUpdateRootsClosure::do_oop_work(T* p, Thread* t) {
template <bool atomic, bool stable_thread>
template <class T>
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(t == Thread::current(), "Wrong thread");

T o = RawAccess<>::oop_load(p);
if (!CompressedOops::is_null(o)) {
Expand All @@ -165,38 +149,20 @@ void ShenandoahEvacuateUpdateRootsClosure::do_oop_work(T* p, Thread* t) {
shenandoah_assert_marked(p, obj);
oop resolved = ShenandoahBarrierSet::resolve_forwarded_not_null(obj);
if (resolved == obj) {
resolved = _heap->evacuate_object(obj, t);
Thread* thr = stable_thread ? _thread : Thread::current();
assert(thr == Thread::current(), "Wrong thread");

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);
}
ShenandoahHeap::atomic_update_oop(resolved, p, o);
}
}
}

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>
ShenandoahCleanUpdateWeakOopsClosure<CONCURRENT, IsAlive, KeepAlive>::ShenandoahCleanUpdateWeakOopsClosure(IsAlive* is_alive, KeepAlive* keep_alive) :
_is_alive(is_alive), _keep_alive(keep_alive) {
Expand Down
4 changes: 2 additions & 2 deletions src/hotspot/share/gc/shenandoah/shenandoahConcurrentGC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -834,7 +834,7 @@ void ShenandoahConcurrentGC::op_class_unloading() {
class ShenandoahEvacUpdateCodeCacheClosure : public NMethodClosure {
private:
BarrierSetNMethod* const _bs;
ShenandoahEvacuateUpdateMetadataClosure<> _cl;
ShenandoahEvacuateUpdateMetadataClosure _cl;

public:
ShenandoahEvacUpdateCodeCacheClosure() :
Expand Down Expand Up @@ -893,7 +893,7 @@ class ShenandoahConcurrentRootsEvacUpdateTask : public WorkerTask {
}

{
ShenandoahEvacuateUpdateMetadataClosure<> cl;
ShenandoahEvacuateUpdateMetadataClosure cl;
CLDToOopClosure clds(&cl, ClassLoaderData::_claim_strong);
_cld_roots.cld_do(&clds, worker_id);
}
Expand Down
4 changes: 2 additions & 2 deletions src/hotspot/share/gc/shenandoah/shenandoahNMethod.inline.hpp
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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*/);
}

Expand Down

1 comment on commit b2010a7

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.