1 /*
2  * Copyright (c) 2017, 2018, Red Hat, Inc. All rights reserved.
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_SHENANDOAHWORKGROUP_HPP
25 #define SHARE_VM_GC_SHENANDOAH_SHENANDOAHWORKGROUP_HPP
26 
27 #include "gc/shared/workgroup.hpp"
28 #include "gc/shenandoah/shenandoahTaskqueue.hpp"
29 #include "memory/allocation.hpp"
30 
31 class ShenandoahObjToScanQueueSet;
32 
33 class ShenandoahWorkerScope : public StackObj {
34 private:
35   uint      _n_workers;
36   WorkGang* _workers;
37 public:
38   ShenandoahWorkerScope(WorkGang* workers, uint nworkers, const char* msg, bool do_check = true);
39   ~ShenandoahWorkerScope();
40 };
41 
42 class ShenandoahPushWorkerScope : StackObj {
43 protected:
44   uint      _n_workers;
45   uint      _old_workers;
46   WorkGang* _workers;
47 
48 public:
49   ShenandoahPushWorkerScope(WorkGang* workers, uint nworkers, bool do_check = true);
50   ~ShenandoahPushWorkerScope();
51 };
52 
53 class ShenandoahPushWorkerQueuesScope : public ShenandoahPushWorkerScope {
54 private:
55   ShenandoahObjToScanQueueSet* _queues;
56 
57 public:
58   ShenandoahPushWorkerQueuesScope(WorkGang* workers, ShenandoahObjToScanQueueSet* queues, uint nworkers, bool do_check = true);
59   ~ShenandoahPushWorkerQueuesScope();
60 };
61 
62 class ShenandoahWorkGang : public WorkGang {
63 private:
64   bool     _initialize_gclab;
65 public:
ShenandoahWorkGang(const char * name,uint workers,bool are_GC_task_threads,bool are_ConcurrentGC_threads)66   ShenandoahWorkGang(const char* name,
67            uint workers,
68            bool are_GC_task_threads,
69            bool are_ConcurrentGC_threads) :
70     WorkGang(name, workers, are_GC_task_threads, are_ConcurrentGC_threads), _initialize_gclab(false) {
71     }
72 
73   // Create a GC worker and install it into the work gang.
74   // We need to initialize gclab for dynamic allocated workers
75   AbstractGangWorker* install_worker(uint which);
76 
77   // We allow _active_workers < _total_workers when UseDynamicNumberOfGCThreads is off.
78   // We use the same WorkGang for concurrent and parallel processing, and honor
79   // ConcGCThreads and ParallelGCThreads settings
active_workers() const80   virtual uint active_workers() const {
81     assert(_active_workers > 0, "no active worker");
82     assert(_active_workers <= _total_workers,
83            "_active_workers: %u > _total_workers: %u", _active_workers, _total_workers);
84     return _active_workers;
85   }
86 
set_initialize_gclab()87   void set_initialize_gclab() { assert(!_initialize_gclab, "Can only enable once"); _initialize_gclab = true; }
88 };
89 
90 #endif // SHARE_VM_GC_SHENANDOAH_SHENANDOAHWORKGROUP_HPP
91