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 | 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 class ShenandoahWorkGang; 31 32 class ShenandoahWorkerScope : public StackObj { 33 protected: 34 uint _n_workers; 35 ShenandoahWorkGang* _workers; 36 public: 37 ShenandoahWorkerScope(ShenandoahWorkGang* workers, uint nworkers); 38 ~ShenandoahWorkerScope(); 39 }; 40 41 42 class ShenandoahPushWorkerScope : public StackObj { 43 private: 44 uint _n_workers; 45 uint _old_workers; 46 ShenandoahWorkGang* _workers; 47 48 public: 49 ShenandoahPushWorkerScope(ShenandoahWorkGang* workers, uint nworkers); 50 ~ShenandoahPushWorkerScope(); 51 }; 52 53 class ShenandoahWorkerSessionScope : public ShenandoahWorkerScope { 54 public: 55 enum SessionType { 56 Parallel, 57 Concurrent 58 }; 59 60 private: 61 bool _with_session; 62 63 public: 64 ShenandoahWorkerSessionScope(ShenandoahWorkGang* workers, uint nworkers, 65 SessionType type); 66 ~ShenandoahWorkerSessionScope(); 67 }; 68 69 70 class ShenandoahWorkGang : public WorkGang { 71 friend class ShenandoahWorkerSessionScope; 72 private: 73 bool _initialize_gclab; 74 public: 75 ShenandoahWorkGang(const char* name, 76 uint workers, 77 bool are_GC_task_threads, 78 bool are_ConcurrentGC_threads); 79 80 // Create a GC worker and install it into the work gang. 81 // We need to initialize gclab for dynamic allocated workers 82 AbstractGangWorker* install_worker(uint which); 83 84 // We allow _active_workers < _total_workers when UseDynamicNumberOfGCThreads is off. 85 // We use the same WorkGang for concurrent and parallel processing, and honor 86 // ConcGCThreads and ParallelGCThreads settings 87 virtual uint active_workers() const { 88 assert(_active_workers > 0, "no active worker"); 89 assert(_active_workers <= _total_workers, 90 "_active_workers: %u > _total_workers: %u", _active_workers, _total_workers); 91 return _active_workers; 92 } 93 94 void set_initialize_gclab() { 95 assert(!_initialize_gclab, "Can only enable once"); 96 _initialize_gclab = true; 97 } 98 99 100 bool static allow_session() { 101 return (UseSessionForParallelWorkers || UseSessionForConcWorkers); 102 } 103 104 static void print_stats(); 105 106 private: 107 // Only via ShenandoahWorkerSessionScope 108 void start_session(); 109 void end_session(); 110 111 }; 112 113 114 115 #endif // SHARE_VM_GC_SHENANDOAH_SHENANDOAH_WORKGROUP_HPP |