< prev index next >

src/hotspot/share/gc/z/zRuntimeWorkers.cpp

Print this page




   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 #include "precompiled.hpp"

  25 #include "gc/shared/workgroup.hpp"
  26 #include "gc/z/zRuntimeWorkers.hpp"
  27 #include "gc/z/zThread.hpp"
  28 #include "runtime/mutexLocker.hpp"
  29 
  30 class ZRuntimeWorkersInitializeTask : public AbstractGangTask {
  31 private:
  32   const uint _nworkers;
  33   uint       _started;
  34   Monitor    _monitor;
  35 
  36 public:
  37   ZRuntimeWorkersInitializeTask(uint nworkers) :
  38       AbstractGangTask("ZRuntimeWorkersInitializeTask"),
  39       _nworkers(nworkers),
  40       _started(0),
  41       _monitor(Monitor::leaf,
  42                "ZRuntimeWorkersInitialize",
  43                false /* allow_vm_block */,
  44                Monitor::_safepoint_check_never) {}


  49 
  50     // Wait for all threads to start
  51     MonitorLocker ml(&_monitor, Monitor::_no_safepoint_check_flag);
  52     if (++_started == _nworkers) {
  53       // All threads started
  54       ml.notify_all();
  55     } else {
  56       while (_started != _nworkers) {
  57         ml.wait();
  58       }
  59     }
  60   }
  61 };
  62 
  63 ZRuntimeWorkers::ZRuntimeWorkers() :
  64     _workers("RuntimeWorker",
  65              nworkers(),
  66              false /* are_GC_task_threads */,
  67              false /* are_ConcurrentGC_threads */) {
  68 
  69   log_info(gc, init)("Runtime Workers: %u parallel", nworkers());
  70 
  71   // Initialize worker threads
  72   _workers.initialize_workers();
  73   _workers.update_active_workers(nworkers());
  74   if (_workers.active_workers() != nworkers()) {
  75     vm_exit_during_initialization("Failed to create ZRuntimeWorkers");
  76   }
  77 
  78   // Execute task to register threads as runtime workers. This also
  79   // helps reduce latency in early safepoints, which otherwise would
  80   // have to take on any warmup costs.
  81   ZRuntimeWorkersInitializeTask task(nworkers());
  82   _workers.run_task(&task);
  83 }
  84 
  85 uint ZRuntimeWorkers::nworkers() const {
  86   return ParallelGCThreads;
  87 }
  88 
  89 WorkGang* ZRuntimeWorkers::workers() {


   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 #include "precompiled.hpp"
  25 #include "gc/shared/gcLogPrecious.hpp"
  26 #include "gc/shared/workgroup.hpp"
  27 #include "gc/z/zRuntimeWorkers.hpp"
  28 #include "gc/z/zThread.hpp"
  29 #include "runtime/mutexLocker.hpp"
  30 
  31 class ZRuntimeWorkersInitializeTask : public AbstractGangTask {
  32 private:
  33   const uint _nworkers;
  34   uint       _started;
  35   Monitor    _monitor;
  36 
  37 public:
  38   ZRuntimeWorkersInitializeTask(uint nworkers) :
  39       AbstractGangTask("ZRuntimeWorkersInitializeTask"),
  40       _nworkers(nworkers),
  41       _started(0),
  42       _monitor(Monitor::leaf,
  43                "ZRuntimeWorkersInitialize",
  44                false /* allow_vm_block */,
  45                Monitor::_safepoint_check_never) {}


  50 
  51     // Wait for all threads to start
  52     MonitorLocker ml(&_monitor, Monitor::_no_safepoint_check_flag);
  53     if (++_started == _nworkers) {
  54       // All threads started
  55       ml.notify_all();
  56     } else {
  57       while (_started != _nworkers) {
  58         ml.wait();
  59       }
  60     }
  61   }
  62 };
  63 
  64 ZRuntimeWorkers::ZRuntimeWorkers() :
  65     _workers("RuntimeWorker",
  66              nworkers(),
  67              false /* are_GC_task_threads */,
  68              false /* are_ConcurrentGC_threads */) {
  69 
  70   log_info_p(gc, init)("Runtime Workers: %u parallel", nworkers());
  71 
  72   // Initialize worker threads
  73   _workers.initialize_workers();
  74   _workers.update_active_workers(nworkers());
  75   if (_workers.active_workers() != nworkers()) {
  76     vm_exit_during_initialization("Failed to create ZRuntimeWorkers");
  77   }
  78 
  79   // Execute task to register threads as runtime workers. This also
  80   // helps reduce latency in early safepoints, which otherwise would
  81   // have to take on any warmup costs.
  82   ZRuntimeWorkersInitializeTask task(nworkers());
  83   _workers.run_task(&task);
  84 }
  85 
  86 uint ZRuntimeWorkers::nworkers() const {
  87   return ParallelGCThreads;
  88 }
  89 
  90 WorkGang* ZRuntimeWorkers::workers() {
< prev index next >