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 #include "precompiled.hpp" 25 26 #include "gc/shared/workerPolicy.hpp" 27 #include "gc/shenandoah/shenandoahWorkerPolicy.hpp" 28 #include "runtime/thread.hpp" 29 30 uint ShenandoahWorkerPolicy::_prev_par_marking = 0; 31 uint ShenandoahWorkerPolicy::_prev_conc_marking = 0; 32 uint ShenandoahWorkerPolicy::_prev_conc_evac = 0; 33 uint ShenandoahWorkerPolicy::_prev_conc_root_proc = 0; 34 uint ShenandoahWorkerPolicy::_prev_fullgc = 0; 35 uint ShenandoahWorkerPolicy::_prev_degengc = 0; 36 uint ShenandoahWorkerPolicy::_prev_stw_traversal = 0; 37 uint ShenandoahWorkerPolicy::_prev_conc_traversal = 0; 38 uint ShenandoahWorkerPolicy::_prev_conc_update_ref = 0; 39 uint ShenandoahWorkerPolicy::_prev_par_update_ref = 0; 40 uint ShenandoahWorkerPolicy::_prev_conc_cleanup = 0; 41 uint ShenandoahWorkerPolicy::_prev_conc_reset = 0; 42 43 uint ShenandoahWorkerPolicy::calc_workers_for_init_marking() { 44 uint active_workers = (_prev_par_marking == 0) ? ParallelGCThreads : _prev_par_marking; 45 46 _prev_par_marking = 47 WorkerPolicy::calc_active_workers(ParallelGCThreads, 48 active_workers, 49 Threads::number_of_non_daemon_threads()); 50 return _prev_par_marking; 51 } 52 53 uint ShenandoahWorkerPolicy::calc_workers_for_conc_marking() { 54 uint active_workers = (_prev_conc_marking == 0) ? ConcGCThreads : _prev_conc_marking; 55 _prev_conc_marking = 56 WorkerPolicy::calc_active_conc_workers(ConcGCThreads, 57 active_workers, 58 Threads::number_of_non_daemon_threads()); 59 return _prev_conc_marking; 60 } 61 62 // Reuse the calculation result from init marking 63 uint ShenandoahWorkerPolicy::calc_workers_for_final_marking() { 64 return _prev_par_marking; 65 } 66 67 // Calculate workers for concurrent root processing 68 uint ShenandoahWorkerPolicy::calc_workers_for_conc_root_processing() { 69 uint active_workers = (_prev_conc_root_proc == 0) ? ConcGCThreads : _prev_conc_root_proc; 70 _prev_conc_root_proc = 71 WorkerPolicy::calc_active_conc_workers(ConcGCThreads, 72 active_workers, 73 Threads::number_of_non_daemon_threads()); 74 return _prev_conc_root_proc; 75 } 76 77 // Calculate workers for concurrent evacuation (concurrent GC) 78 uint ShenandoahWorkerPolicy::calc_workers_for_conc_evac() { 79 uint active_workers = (_prev_conc_evac == 0) ? ConcGCThreads : _prev_conc_evac; 80 _prev_conc_evac = 81 WorkerPolicy::calc_active_conc_workers(ConcGCThreads, 82 active_workers, 83 Threads::number_of_non_daemon_threads()); 84 return _prev_conc_evac; 85 } 86 87 // Calculate workers for parallel fullgc 88 uint ShenandoahWorkerPolicy::calc_workers_for_fullgc() { 89 uint active_workers = (_prev_fullgc == 0) ? ParallelGCThreads : _prev_fullgc; 90 _prev_fullgc = 91 WorkerPolicy::calc_active_workers(ParallelGCThreads, 92 active_workers, 93 Threads::number_of_non_daemon_threads()); 94 return _prev_fullgc; 95 } 96 97 // Calculate workers for parallel degenerated gc 98 uint ShenandoahWorkerPolicy::calc_workers_for_stw_degenerated() { 99 uint active_workers = (_prev_degengc == 0) ? ParallelGCThreads : _prev_degengc; 100 _prev_degengc = 101 WorkerPolicy::calc_active_workers(ParallelGCThreads, 102 active_workers, 103 Threads::number_of_non_daemon_threads()); 104 return _prev_degengc; 105 } 106 107 // Calculate workers for Stop-the-world traversal GC 108 uint ShenandoahWorkerPolicy::calc_workers_for_stw_traversal() { 109 uint active_workers = (_prev_stw_traversal == 0) ? ParallelGCThreads : _prev_stw_traversal; 110 _prev_stw_traversal = 111 WorkerPolicy::calc_active_workers(ParallelGCThreads, 112 active_workers, 113 Threads::number_of_non_daemon_threads()); 114 return _prev_stw_traversal; 115 } 116 117 // Calculate workers for concurent traversal GC 118 uint ShenandoahWorkerPolicy::calc_workers_for_conc_traversal() { 119 uint active_workers = (_prev_conc_traversal == 0) ? ConcGCThreads : _prev_conc_traversal; 120 _prev_conc_traversal = 121 WorkerPolicy::calc_active_conc_workers(ConcGCThreads, 122 active_workers, 123 Threads::number_of_non_daemon_threads()); 124 return _prev_conc_traversal; 125 } 126 127 // Calculate workers for concurrent reference update 128 uint ShenandoahWorkerPolicy::calc_workers_for_conc_update_ref() { 129 uint active_workers = (_prev_conc_update_ref == 0) ? ConcGCThreads : _prev_conc_update_ref; 130 _prev_conc_update_ref = 131 WorkerPolicy::calc_active_conc_workers(ConcGCThreads, 132 active_workers, 133 Threads::number_of_non_daemon_threads()); 134 return _prev_conc_update_ref; 135 } 136 137 // Calculate workers for parallel reference update 138 uint ShenandoahWorkerPolicy::calc_workers_for_final_update_ref() { 139 uint active_workers = (_prev_par_update_ref == 0) ? ParallelGCThreads : _prev_par_update_ref; 140 _prev_par_update_ref = 141 WorkerPolicy::calc_active_workers(ParallelGCThreads, 142 active_workers, 143 Threads::number_of_non_daemon_threads()); 144 return _prev_par_update_ref; 145 } 146 147 uint ShenandoahWorkerPolicy::calc_workers_for_conc_preclean() { 148 // Precleaning is single-threaded 149 return 1; 150 } 151 152 uint ShenandoahWorkerPolicy::calc_workers_for_conc_cleanup() { 153 uint active_workers = (_prev_conc_cleanup == 0) ? ConcGCThreads : _prev_conc_cleanup; 154 _prev_conc_cleanup = 155 WorkerPolicy::calc_active_conc_workers(ConcGCThreads, 156 active_workers, 157 Threads::number_of_non_daemon_threads()); 158 return _prev_conc_cleanup; 159 } 160 161 uint ShenandoahWorkerPolicy::calc_workers_for_conc_reset() { 162 uint active_workers = (_prev_conc_reset == 0) ? ConcGCThreads : _prev_conc_reset; 163 _prev_conc_reset = 164 WorkerPolicy::calc_active_conc_workers(ConcGCThreads, 165 active_workers, 166 Threads::number_of_non_daemon_threads()); 167 return _prev_conc_reset; 168 }