8202649: Move the Parallel GC specific task creation functions out of Threads
authorstefank
Mon, 07 May 2018 16:12:07 +0200
changeset 50058 f7e564cacfbc
parent 50057 f945444fabc3
child 50059 10843c8ecd54
8202649: Move the Parallel GC specific task creation functions out of Threads Reviewed-by: ehelin, pliden
src/hotspot/share/gc/parallel/pcTasks.cpp
src/hotspot/share/gc/parallel/pcTasks.hpp
src/hotspot/share/gc/parallel/psParallelCompact.cpp
src/hotspot/share/gc/parallel/psScavenge.cpp
src/hotspot/share/gc/parallel/psTasks.cpp
src/hotspot/share/gc/parallel/psTasks.hpp
src/hotspot/share/runtime/thread.cpp
src/hotspot/share/runtime/thread.hpp
--- a/src/hotspot/share/gc/parallel/pcTasks.cpp	Mon May 07 14:57:25 2018 +0200
+++ b/src/hotspot/share/gc/parallel/pcTasks.cpp	Mon May 07 16:12:07 2018 +0200
@@ -60,15 +60,7 @@
   ParCompactionManager::MarkAndPushClosure mark_and_push_closure(cm);
   MarkingCodeBlobClosure mark_and_push_in_blobs(&mark_and_push_closure, !CodeBlobToOopClosure::FixRelocations);
 
-  if (_java_thread != NULL)
-    _java_thread->oops_do(
-        &mark_and_push_closure,
-        &mark_and_push_in_blobs);
-
-  if (_vm_thread != NULL)
-    _vm_thread->oops_do(
-        &mark_and_push_closure,
-        &mark_and_push_in_blobs);
+  _thread->oops_do(&mark_and_push_closure, &mark_and_push_in_blobs);
 
   // Do the real work
   cm->follow_marking_stacks();
--- a/src/hotspot/share/gc/parallel/pcTasks.hpp	Mon May 07 14:57:25 2018 +0200
+++ b/src/hotspot/share/gc/parallel/pcTasks.hpp	Mon May 07 16:12:07 2018 +0200
@@ -67,11 +67,10 @@
 
 class ThreadRootsMarkingTask : public GCTask {
  private:
-  JavaThread* _java_thread;
-  VMThread* _vm_thread;
+  Thread* _thread;
+
  public:
-  ThreadRootsMarkingTask(JavaThread* root) : _java_thread(root), _vm_thread(NULL) {}
-  ThreadRootsMarkingTask(VMThread* root) : _java_thread(NULL), _vm_thread(root) {}
+  ThreadRootsMarkingTask(Thread* root) : _thread(root) {}
 
   char* name() { return (char *)"thread-roots-marking-task"; }
 
--- a/src/hotspot/share/gc/parallel/psParallelCompact.cpp	Mon May 07 14:57:25 2018 +0200
+++ b/src/hotspot/share/gc/parallel/psParallelCompact.cpp	Mon May 07 16:12:07 2018 +0200
@@ -2049,6 +2049,17 @@
   return ParallelScavengeHeap::gc_task_manager();
 }
 
+class PCAddThreadRootsMarkingTaskClosure : public ThreadClosure {
+private:
+  GCTaskQueue* _q;
+
+public:
+  PCAddThreadRootsMarkingTaskClosure(GCTaskQueue* q) : _q(q) { }
+  void do_thread(Thread* t) {
+    _q->enqueue(new ThreadRootsMarkingTask(t));
+  }
+};
+
 void PSParallelCompact::marking_phase(ParCompactionManager* cm,
                                       bool maximum_heap_compaction,
                                       ParallelOldTracer *gc_tracer) {
@@ -2077,7 +2088,8 @@
     q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::universe));
     q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::jni_handles));
     // We scan the thread roots in parallel
-    Threads::create_thread_roots_marking_tasks(q);
+    PCAddThreadRootsMarkingTaskClosure cl(q);
+    Threads::java_threads_and_vm_thread_do(&cl);
     q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::object_synchronizer));
     q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::management));
     q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::system_dictionary));
--- a/src/hotspot/share/gc/parallel/psScavenge.cpp	Mon May 07 14:57:25 2018 +0200
+++ b/src/hotspot/share/gc/parallel/psScavenge.cpp	Mon May 07 16:12:07 2018 +0200
@@ -242,6 +242,17 @@
   return full_gc_done;
 }
 
+class PSAddThreadRootsTaskClosure : public ThreadClosure {
+private:
+  GCTaskQueue* _q;
+
+public:
+  PSAddThreadRootsTaskClosure(GCTaskQueue* q) : _q(q) { }
+  void do_thread(Thread* t) {
+    _q->enqueue(new ThreadRootsTask(t));
+  }
+};
+
 // This method contains no policy. You should probably
 // be calling invoke() instead.
 bool PSScavenge::invoke_no_policy() {
@@ -382,7 +393,8 @@
       q->enqueue(new ScavengeRootsTask(ScavengeRootsTask::universe));
       q->enqueue(new ScavengeRootsTask(ScavengeRootsTask::jni_handles));
       // We scan the thread roots in parallel
-      Threads::create_thread_roots_tasks(q);
+      PSAddThreadRootsTaskClosure cl(q);
+      Threads::java_threads_and_vm_thread_do(&cl);
       q->enqueue(new ScavengeRootsTask(ScavengeRootsTask::object_synchronizer));
       q->enqueue(new ScavengeRootsTask(ScavengeRootsTask::management));
       q->enqueue(new ScavengeRootsTask(ScavengeRootsTask::system_dictionary));
--- a/src/hotspot/share/gc/parallel/psTasks.cpp	Mon May 07 14:57:25 2018 +0200
+++ b/src/hotspot/share/gc/parallel/psTasks.cpp	Mon May 07 16:12:07 2018 +0200
@@ -119,11 +119,7 @@
   PSScavengeRootsClosure roots_closure(pm);
   MarkingCodeBlobClosure roots_in_blobs(&roots_closure, CodeBlobToOopClosure::FixRelocations);
 
-  if (_java_thread != NULL)
-    _java_thread->oops_do(&roots_closure, &roots_in_blobs);
-
-  if (_vm_thread != NULL)
-    _vm_thread->oops_do(&roots_closure, &roots_in_blobs);
+  _thread->oops_do(&roots_closure, &roots_in_blobs);
 
   // Do the real work
   pm->drain_stacks(false);
--- a/src/hotspot/share/gc/parallel/psTasks.hpp	Mon May 07 14:57:25 2018 +0200
+++ b/src/hotspot/share/gc/parallel/psTasks.hpp	Mon May 07 16:12:07 2018 +0200
@@ -81,11 +81,10 @@
 
 class ThreadRootsTask : public GCTask {
  private:
-  JavaThread* _java_thread;
-  VMThread* _vm_thread;
+  Thread* _thread;
+
  public:
-  ThreadRootsTask(JavaThread* root) : _java_thread(root), _vm_thread(NULL) {}
-  ThreadRootsTask(VMThread* root) : _java_thread(NULL), _vm_thread(root) {}
+  ThreadRootsTask(Thread* root) : _thread(root) {}
 
   char* name() { return (char *)"thread-roots-task"; }
 
--- a/src/hotspot/share/runtime/thread.cpp	Mon May 07 14:57:25 2018 +0200
+++ b/src/hotspot/share/runtime/thread.cpp	Mon May 07 16:12:07 2018 +0200
@@ -114,9 +114,6 @@
 #include "utilities/macros.hpp"
 #include "utilities/preserveException.hpp"
 #include "utilities/vmError.hpp"
-#if INCLUDE_PARALLELGC
-#include "gc/parallel/pcTasks.hpp"
-#endif
 #if INCLUDE_JVMCI
 #include "jvmci/jvmciCompiler.hpp"
 #include "jvmci/jvmciRuntime.hpp"
@@ -3436,13 +3433,25 @@
   // If CompilerThreads ever become non-JavaThreads, add them here
 }
 
-// All JavaThreads + all non-JavaThreads (i.e., every thread in the system).
-void Threads::threads_do(ThreadClosure* tc) {
+// All JavaThreads
+void Threads::java_threads_do(ThreadClosure* tc) {
   assert_locked_or_safepoint(Threads_lock);
   // ALL_JAVA_THREADS iterates through all JavaThreads.
   ALL_JAVA_THREADS(p) {
     tc->do_thread(p);
   }
+}
+
+void Threads::java_threads_and_vm_thread_do(ThreadClosure* tc) {
+  assert_locked_or_safepoint(Threads_lock);
+  java_threads_do(tc);
+  tc->do_thread(VMThread::vm_thread());
+}
+
+// All JavaThreads + all non-JavaThreads (i.e., every thread in the system).
+void Threads::threads_do(ThreadClosure* tc) {
+  assert_locked_or_safepoint(Threads_lock);
+  java_threads_do(tc);
   non_java_threads_do(tc);
 }
 
@@ -4465,24 +4474,6 @@
   possibly_parallel_threads_do(is_par, &tc);
 }
 
-#if INCLUDE_PARALLELGC
-// Used by ParallelScavenge
-void Threads::create_thread_roots_tasks(GCTaskQueue* q) {
-  ALL_JAVA_THREADS(p) {
-    q->enqueue(new ThreadRootsTask(p));
-  }
-  q->enqueue(new ThreadRootsTask(VMThread::vm_thread()));
-}
-
-// Used by Parallel Old
-void Threads::create_thread_roots_marking_tasks(GCTaskQueue* q) {
-  ALL_JAVA_THREADS(p) {
-    q->enqueue(new ThreadRootsMarkingTask(p));
-  }
-  q->enqueue(new ThreadRootsMarkingTask(VMThread::vm_thread()));
-}
-#endif // INCLUDE_PARALLELGC
-
 void Threads::nmethods_do(CodeBlobClosure* cf) {
   ALL_JAVA_THREADS(p) {
     // This is used by the code cache sweeper to mark nmethods that are active
--- a/src/hotspot/share/runtime/thread.hpp	Mon May 07 14:57:25 2018 +0200
+++ b/src/hotspot/share/runtime/thread.hpp	Mon May 07 16:12:07 2018 +0200
@@ -2104,6 +2104,8 @@
   static void add(JavaThread* p, bool force_daemon = false);
   static void remove(JavaThread* p);
   static void non_java_threads_do(ThreadClosure* tc);
+  static void java_threads_do(ThreadClosure* tc);
+  static void java_threads_and_vm_thread_do(ThreadClosure* tc);
   static void threads_do(ThreadClosure* tc);
   static void possibly_parallel_threads_do(bool is_par, ThreadClosure* tc);
 
@@ -2142,10 +2144,6 @@
   static void oops_do(OopClosure* f, CodeBlobClosure* cf);
   // This version may be called by sequential or parallel code.
   static void possibly_parallel_oops_do(bool is_par, OopClosure* f, CodeBlobClosure* cf);
-  // This creates a list of GCTasks, one per thread.
-  static void create_thread_roots_tasks(GCTaskQueue* q);
-  // This creates a list of GCTasks, one per thread, for marking objects.
-  static void create_thread_roots_marking_tasks(GCTaskQueue* q);
 
   // Apply "f->do_oop" to roots in all threads that
   // are part of compiled frames