8224664: Parallel GC: Use WorkGang (6: PSRefProcTaskProxy)
authorlkorinth
Fri, 16 Aug 2019 09:18:35 +0200
changeset 57772 2410b04f074f
parent 57771 50c959cc40e8
child 57773 5cbc3bd9fdfd
8224664: Parallel GC: Use WorkGang (6: PSRefProcTaskProxy) Reviewed-by: stefank, kbarrett, tschatzl
src/hotspot/share/gc/parallel/psCardTable.cpp
src/hotspot/share/gc/parallel/psPromotionManager.hpp
src/hotspot/share/gc/parallel/psScavenge.cpp
src/hotspot/share/gc/parallel/psTasks.cpp
src/hotspot/share/gc/parallel/psTasks.hpp
--- a/src/hotspot/share/gc/parallel/psCardTable.cpp	Fri Aug 16 09:18:32 2019 +0200
+++ b/src/hotspot/share/gc/parallel/psCardTable.cpp	Fri Aug 16 09:18:35 2019 +0200
@@ -29,7 +29,6 @@
 #include "gc/parallel/psCardTable.hpp"
 #include "gc/parallel/psPromotionManager.inline.hpp"
 #include "gc/parallel/psScavenge.inline.hpp"
-#include "gc/parallel/psTasks.hpp"
 #include "gc/parallel/psYoungGen.hpp"
 #include "memory/iterator.inline.hpp"
 #include "oops/access.inline.hpp"
--- a/src/hotspot/share/gc/parallel/psPromotionManager.hpp	Fri Aug 16 09:18:32 2019 +0200
+++ b/src/hotspot/share/gc/parallel/psPromotionManager.hpp	Fri Aug 16 09:18:35 2019 +0200
@@ -53,6 +53,8 @@
   friend class PSScavenge;
   friend class ScavengeRootsTask;
   friend class PSRefProcTaskExecutor;
+  friend class PSRefProcTask;
+
  private:
   static PaddedEnd<PSPromotionManager>* _manager_array;
   static OopStarTaskQueueSet*           _stack_array_depth;
--- a/src/hotspot/share/gc/parallel/psScavenge.cpp	Fri Aug 16 09:18:32 2019 +0200
+++ b/src/hotspot/share/gc/parallel/psScavenge.cpp	Fri Aug 16 09:18:35 2019 +0200
@@ -31,12 +31,12 @@
 #include "gc/parallel/parallelScavengeHeap.hpp"
 #include "gc/parallel/psAdaptiveSizePolicy.hpp"
 #include "gc/parallel/psClosure.inline.hpp"
+#include "gc/parallel/psCompactionManager.hpp"
 #include "gc/parallel/psMarkSweepProxy.hpp"
 #include "gc/parallel/psParallelCompact.inline.hpp"
 #include "gc/parallel/psPromotionManager.inline.hpp"
 #include "gc/parallel/psRootType.hpp"
 #include "gc/parallel/psScavenge.inline.hpp"
-#include "gc/parallel/psTasks.hpp"
 #include "gc/shared/gcCause.hpp"
 #include "gc/shared/gcHeapSummary.hpp"
 #include "gc/shared/gcId.hpp"
@@ -213,57 +213,42 @@
   }
 };
 
-class PSRefProcTaskProxy: public GCTask {
-  typedef AbstractRefProcTaskExecutor::ProcessTask ProcessTask;
-  ProcessTask & _rp_task;
-  uint          _work_id;
-public:
-  PSRefProcTaskProxy(ProcessTask & rp_task, uint work_id)
-    : _rp_task(rp_task),
-      _work_id(work_id)
-  { }
-
-private:
-  virtual char* name() { return (char *)"Process referents by policy in parallel"; }
-  virtual void do_it(GCTaskManager* manager, uint which);
+class PSRefProcTaskExecutor: public AbstractRefProcTaskExecutor {
+  virtual void execute(ProcessTask& process_task, uint ergo_workers);
 };
 
-void PSRefProcTaskProxy::do_it(GCTaskManager* manager, uint which)
-{
-  PSPromotionManager* promotion_manager =
-    PSPromotionManager::gc_thread_promotion_manager(which);
-  assert(promotion_manager != NULL, "sanity check");
-  PSKeepAliveClosure keep_alive(promotion_manager);
-  PSEvacuateFollowersClosure evac_followers(promotion_manager);
-  PSIsAliveClosure is_alive;
-  _rp_task.work(_work_id, is_alive, keep_alive, evac_followers);
-}
+class PSRefProcTask : public AbstractGangTask {
+  typedef AbstractRefProcTaskExecutor::ProcessTask ProcessTask;
+  TaskTerminator _terminator;
+  ProcessTask& _task;
+  uint _active_workers;
+
+public:
+  PSRefProcTask(ProcessTask& task, uint active_workers)
+    : AbstractGangTask("PSRefProcTask"),
+      _terminator(active_workers, PSPromotionManager::stack_array_depth()),
+      _task(task),
+      _active_workers(active_workers) {
+  }
 
-class PSRefProcTaskExecutor: public AbstractRefProcTaskExecutor {
-  virtual void execute(ProcessTask& task, uint ergo_workers);
+  virtual void work(uint worker_id) {
+    PSPromotionManager* promotion_manager =
+      PSPromotionManager::gc_thread_promotion_manager(worker_id);
+    assert(promotion_manager != NULL, "sanity check");
+    PSKeepAliveClosure keep_alive(promotion_manager);
+    PSEvacuateFollowersClosure evac_followers(promotion_manager);
+    PSIsAliveClosure is_alive;
+    _task.work(worker_id, is_alive, keep_alive, evac_followers);
+
+    if (_task.marks_oops_alive() && _active_workers > 1) {
+      steal_work(*_terminator.terminator(), worker_id);
+    }
+  }
 };
 
-void PSRefProcTaskExecutor::execute(ProcessTask& task, uint ergo_workers)
-{
-  GCTaskQueue* q = GCTaskQueue::create();
-  GCTaskManager* manager = ParallelScavengeHeap::gc_task_manager();
-  uint active_workers = manager->active_workers();
-
-  assert(active_workers == ergo_workers,
-         "Ergonomically chosen workers (%u) must be equal to active workers (%u)",
-         ergo_workers, active_workers);
-
-  for(uint i=0; i < active_workers; i++) {
-    q->enqueue(new PSRefProcTaskProxy(task, i));
-  }
-  TaskTerminator terminator(active_workers,
-                            (TaskQueueSetSuper*) PSPromotionManager::stack_array_depth());
-  if (task.marks_oops_alive() && active_workers > 1) {
-    for (uint j = 0; j < active_workers; j++) {
-      q->enqueue(new StealTask(terminator.terminator()));
-    }
-  }
-  manager->execute_and_wait(q);
+void PSRefProcTaskExecutor::execute(ProcessTask& process_task, uint ergo_workers) {
+  PSRefProcTask task(process_task, ergo_workers);
+  ParallelScavengeHeap::heap()->workers().run_task(&task);
 }
 
 // This method contains all heap specific policy for invoking scavenge.
--- a/src/hotspot/share/gc/parallel/psTasks.cpp	Fri Aug 16 09:18:32 2019 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,75 +0,0 @@
-/*
- * Copyright (c) 2002, 2019, Oracle and/or its affiliates. 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
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- *
- */
-
-#include "precompiled.hpp"
-#include "classfile/systemDictionary.hpp"
-#include "code/codeCache.hpp"
-#include "gc/parallel/gcTaskManager.hpp"
-#include "gc/parallel/parallelScavengeHeap.inline.hpp"
-#include "gc/parallel/psCardTable.hpp"
-#include "gc/parallel/psClosure.inline.hpp"
-#include "gc/parallel/psPromotionManager.hpp"
-#include "gc/parallel/psPromotionManager.inline.hpp"
-#include "gc/parallel/psScavenge.inline.hpp"
-#include "gc/parallel/psTasks.hpp"
-#include "gc/shared/taskqueue.inline.hpp"
-#include "memory/iterator.hpp"
-#include "memory/resourceArea.hpp"
-#include "memory/universe.hpp"
-#include "oops/oop.inline.hpp"
-#include "runtime/thread.hpp"
-#include "runtime/vmThread.hpp"
-#include "services/management.hpp"
-
-
-//
-// StealTask
-//
-
-StealTask::StealTask(ParallelTaskTerminator* t) :
-  _terminator(t) {}
-
-void StealTask::do_it(GCTaskManager* manager, uint which) {
-  assert(ParallelScavengeHeap::heap()->is_gc_active(), "called outside gc");
-
-  PSPromotionManager* pm =
-    PSPromotionManager::gc_thread_promotion_manager(which);
-  pm->drain_stacks(true);
-  guarantee(pm->stacks_empty(),
-            "stacks should be empty at this point");
-
-  while(true) {
-    StarTask p;
-    if (PSPromotionManager::steal_depth(which, p)) {
-      TASKQUEUE_STATS_ONLY(pm->record_steal(p));
-      pm->process_popped_location_depth(p);
-      pm->drain_stacks_depth(true);
-    } else {
-      if (terminator()->offer_termination()) {
-        break;
-      }
-    }
-  }
-  guarantee(pm->stacks_empty(), "stacks should be empty at this point");
-}
--- a/src/hotspot/share/gc/parallel/psTasks.hpp	Fri Aug 16 09:18:32 2019 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,64 +0,0 @@
-/*
- * Copyright (c) 2002, 2019, Oracle and/or its affiliates. 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
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- *
- */
-
-#ifndef SHARE_GC_PARALLEL_PSTASKS_HPP
-#define SHARE_GC_PARALLEL_PSTASKS_HPP
-
-#include "utilities/growableArray.hpp"
-
-//
-// psTasks.hpp is a collection of GCTasks used by the
-// parallelScavenge collector.
-//
-
-class GCTask;
-class OopClosure;
-class OopStack;
-class ObjectStartArray;
-class ParallelTaskTerminator;
-class MutableSpace;
-class PSOldGen;
-class Thread;
-class VMThread;
-
-//
-// StealTask
-//
-// This task is used to distribute work to idle threads.
-//
-
-class StealTask : public GCTask {
- private:
-   ParallelTaskTerminator* const _terminator;
- public:
-  char* name() { return (char *)"steal-task"; }
-
-  StealTask(ParallelTaskTerminator* t);
-
-  ParallelTaskTerminator* terminator() { return _terminator; }
-
-  virtual void do_it(GCTaskManager* manager, uint which);
-};
-
-#endif // SHARE_GC_PARALLEL_PSTASKS_HPP