1 /*
   2  * Copyright (c) 2017, Red Hat, Inc. and/or its affiliates.
   3  *
   4  * This code is free software; you can redistribute it and/or modify it
   5  * under the terms of the GNU General Public License version 2 only, as
   6  * published by the Free Software Foundation.
   7  *
   8  * This code is distributed in the hope that it will be useful, but WITHOUT
   9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  11  * version 2 for more details (a copy is included in the LICENSE file that
  12  * accompanied this code).
  13  *
  14  * You should have received a copy of the GNU General Public License version
  15  * 2 along with this work; if not, write to the Free Software Foundation,
  16  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  17  *
  18  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  19  * or visit www.oracle.com if you need additional information or have any
  20  * questions.
  21  *
  22  */
  23 
  24 #ifndef SHARE_VM_GC_SHENANDOAH_SHENANDOAH_WORKGROUP_HPP
  25 #define SHARE_VM_GC_SHENANDOAH_SHENANDOAH_WORKGROUP_HPP
  26 
  27 #include "gc/shared/workgroup.hpp"
  28 #include "memory/allocation.hpp"
  29 
  30 
  31 class ShenandoahWorkerScope : public StackObj {
  32 private:
  33   uint      _n_workers;
  34   WorkGang* _workers;
  35 public:
  36   ShenandoahWorkerScope(WorkGang* workers, uint nworkers);
  37   ~ShenandoahWorkerScope();
  38 };
  39 
  40 
  41 class ShenandoahPushWorkerScope : StackObj {
  42 private:
  43   uint      _n_workers;
  44   uint      _old_workers;
  45   WorkGang* _workers;
  46 
  47 public:
  48   ShenandoahPushWorkerScope(WorkGang* workers, uint nworkers);
  49   ~ShenandoahPushWorkerScope();
  50 };
  51 
  52 class ShenandoahWorkGang : public WorkGang {
  53 private:
  54   bool     _initialize_gclab;
  55 public:
  56   ShenandoahWorkGang(const char* name,
  57            uint workers,
  58            bool are_GC_task_threads,
  59            bool are_ConcurrentGC_threads) :
  60     WorkGang(name, workers, are_GC_task_threads, are_ConcurrentGC_threads), _initialize_gclab(false) {
  61     }
  62 
  63   // Create a GC worker and install it into the work gang.
  64   // We need to initialize gclab for dynamic allocated workers
  65   AbstractGangWorker* install_worker(uint which);
  66 
  67   // We allow _active_workers < _total_workers when UseDynamicNumberOfGCThreads is off.
  68   // We use the same WorkGang for concurrent and parallel processing, and honor
  69   // ConcGCThreads and ParallelGCThreads settings
  70   virtual uint active_workers() const {
  71     assert(_active_workers > 0, "no active worker");
  72     assert(_active_workers <= _total_workers,
  73            "_active_workers: %u > _total_workers: %u", _active_workers, _total_workers);
  74     return _active_workers;
  75   }
  76 
  77   void set_initialize_gclab() { assert(!_initialize_gclab, "Can only enable once"); _initialize_gclab = true; }
  78 };
  79 
  80 #endif // SHARE_VM_GC_SHENANDOAH_SHENANDOAH_WORKGROUP_HPP