8219332: ZGC: Improve ZRootsIteratorClosure abstraction
authorpliden
Wed, 20 Feb 2019 13:43:02 +0100
changeset 53843 b38d76fc4835
parent 53842 c459deff5939
child 53844 8323fdac6da5
8219332: ZGC: Improve ZRootsIteratorClosure abstraction Reviewed-by: stefank
src/hotspot/share/gc/z/zMark.cpp
src/hotspot/share/gc/z/zRelocate.cpp
src/hotspot/share/gc/z/zRootsIterator.cpp
src/hotspot/share/gc/z/zRootsIterator.hpp
--- 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);
 
--- 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);
 
--- 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) {
--- 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<true /* concurrent */, false /* is_const */> ZOopStorageIterator;