# HG changeset patch # User pliden # Date 1550666582 -3600 # Node ID b38d76fc48357969730fa2e807d1d986769b70c3 # Parent c459deff5939f40433cbf86f032d97c9b16479cc 8219332: ZGC: Improve ZRootsIteratorClosure abstraction Reviewed-by: stefank diff -r c459deff5939 -r b38d76fc4835 src/hotspot/share/gc/z/zMark.cpp --- a/src/hotspot/share/gc/z/zMark.cpp Wed Feb 20 13:43:01 2019 +0100 +++ b/src/hotspot/share/gc/z/zMark.cpp Wed Feb 20 13:43:02 2019 +0100 @@ -129,8 +129,6 @@ } virtual void do_thread(Thread* thread) { - ZRootsIteratorClosure::do_thread(thread); - // Update thread local address bad mask ZThreadLocalData::set_address_bad_mask(thread, ZAddressBadMask); diff -r c459deff5939 -r b38d76fc4835 src/hotspot/share/gc/z/zRelocate.cpp --- a/src/hotspot/share/gc/z/zRelocate.cpp Wed Feb 20 13:43:01 2019 +0100 +++ b/src/hotspot/share/gc/z/zRelocate.cpp Wed Feb 20 13:43:02 2019 +0100 @@ -40,8 +40,6 @@ class ZRelocateRootsIteratorClosure : public ZRootsIteratorClosure { public: virtual void do_thread(Thread* thread) { - ZRootsIteratorClosure::do_thread(thread); - // Update thread local address bad mask ZThreadLocalData::set_address_bad_mask(thread, ZAddressBadMask); diff -r c459deff5939 -r b38d76fc4835 src/hotspot/share/gc/z/zRootsIterator.cpp --- a/src/hotspot/share/gc/z/zRootsIterator.cpp Wed Feb 20 13:43:01 2019 +0100 +++ b/src/hotspot/share/gc/z/zRootsIterator.cpp Wed Feb 20 13:43:02 2019 +0100 @@ -135,29 +135,38 @@ } } -class ZCodeBlobClosure : public CodeBlobToOopClosure { +class ZRootsIteratorCodeBlobClosure : public CodeBlobToOopClosure { private: BarrierSetNMethod* _bs; public: - ZCodeBlobClosure(OopClosure* cl) : + ZRootsIteratorCodeBlobClosure(OopClosure* cl) : CodeBlobToOopClosure(cl, true /* fix_relocations */), _bs(BarrierSet::barrier_set()->barrier_set_nmethod()) {} virtual void do_code_blob(CodeBlob* cb) { nmethod* const nm = cb->as_nmethod_or_null(); - if (nm == NULL || nm->test_set_oops_do_mark()) { - return; + if (nm != NULL && !nm->test_set_oops_do_mark()) { + CodeBlobToOopClosure::do_code_blob(cb); + _bs->disarm(nm); } - CodeBlobToOopClosure::do_code_blob(cb); - _bs->disarm(nm); } }; -void ZRootsIteratorClosure::do_thread(Thread* thread) { - ZCodeBlobClosure code_cl(this); - thread->oops_do(this, ClassUnloading ? &code_cl : NULL); -} +class ZRootsIteratorThreadClosure : public ThreadClosure { +private: + ZRootsIteratorClosure* _cl; + +public: + ZRootsIteratorThreadClosure(ZRootsIteratorClosure* cl) : + _cl(cl) {} + + virtual void do_thread(Thread* thread) { + ZRootsIteratorCodeBlobClosure code_cl(_cl); + thread->oops_do(_cl, ClassUnloading ? &code_cl : NULL); + _cl->do_thread(thread); + } +}; ZRootsIterator::ZRootsIterator() : _universe(this), @@ -227,7 +236,8 @@ void ZRootsIterator::do_threads(ZRootsIteratorClosure* cl) { ZStatTimer timer(ZSubPhasePauseRootsThreads); ResourceMark rm; - Threads::possibly_parallel_threads_do(true, cl); + ZRootsIteratorThreadClosure thread_cl(cl); + Threads::possibly_parallel_threads_do(true, &thread_cl); } void ZRootsIterator::do_code_cache(ZRootsIteratorClosure* cl) { diff -r c459deff5939 -r b38d76fc4835 src/hotspot/share/gc/z/zRootsIterator.hpp --- a/src/hotspot/share/gc/z/zRootsIterator.hpp Wed Feb 20 13:43:01 2019 +0100 +++ b/src/hotspot/share/gc/z/zRootsIterator.hpp Wed Feb 20 13:43:02 2019 +0100 @@ -31,9 +31,9 @@ #include "runtime/thread.hpp" #include "utilities/globalDefinitions.hpp" -class ZRootsIteratorClosure : public OopClosure, public ThreadClosure { +class ZRootsIteratorClosure : public OopClosure { public: - virtual void do_thread(Thread* thread); + virtual void do_thread(Thread* thread) {} }; typedef OopStorage::ParState ZOopStorageIterator;