src/hotspot/share/gc/z/zRuntimeWorkers.cpp
changeset 53072 82d3f0820d37
parent 50525 767cdb97f103
child 54623 1126f0607c70
equal deleted inserted replaced
53071:281c85f43f79 53072:82d3f0820d37
    20  * or visit www.oracle.com if you need additional information or have any
    20  * or visit www.oracle.com if you need additional information or have any
    21  * questions.
    21  * questions.
    22  */
    22  */
    23 
    23 
    24 #include "precompiled.hpp"
    24 #include "precompiled.hpp"
       
    25 #include "gc/shared/workgroup.hpp"
    25 #include "gc/z/zRuntimeWorkers.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) {}
       
    45 
       
    46   virtual void work(uint worker_id) {
       
    47     // Register as runtime worker
       
    48     ZThread::set_runtime_worker();
       
    49 
       
    50     // Wait for all threads to start
       
    51     MonitorLockerEx 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(Monitor::_no_safepoint_check_flag);
       
    58       }
       
    59     }
       
    60   }
       
    61 };
    26 
    62 
    27 ZRuntimeWorkers::ZRuntimeWorkers() :
    63 ZRuntimeWorkers::ZRuntimeWorkers() :
    28     _workers("RuntimeWorker",
    64     _workers("RuntimeWorker",
    29              nworkers(),
    65              nworkers(),
    30              false /* are_GC_task_threads */,
    66              false /* are_GC_task_threads */,
    33   log_info(gc, init)("Runtime Workers: %u parallel", nworkers());
    69   log_info(gc, init)("Runtime Workers: %u parallel", nworkers());
    34 
    70 
    35   // Initialize worker threads
    71   // Initialize worker threads
    36   _workers.initialize_workers();
    72   _workers.initialize_workers();
    37   _workers.update_active_workers(nworkers());
    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);
    38 }
    83 }
    39 
    84 
    40 uint ZRuntimeWorkers::nworkers() const {
    85 uint ZRuntimeWorkers::nworkers() const {
    41   return ParallelGCThreads;
    86   return ParallelGCThreads;
    42 }
    87 }