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 #include "precompiled.hpp" 25 26 #include "gc/shared/adaptiveSizePolicy.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_fullgc = 0; 34 uint ShenandoahWorkerPolicy::_prev_degengc = 0; 35 uint ShenandoahWorkerPolicy::_prev_stw_partial = 0; 36 uint ShenandoahWorkerPolicy::_prev_conc_partial = 0; 37 uint ShenandoahWorkerPolicy::_prev_stw_traversal = 0; 38 uint ShenandoahWorkerPolicy::_prev_conc_traversal = 0; 39 uint ShenandoahWorkerPolicy::_prev_conc_update_ref = 0; 40 uint ShenandoahWorkerPolicy::_prev_par_update_ref = 0; 41 uint ShenandoahWorkerPolicy::_prev_conc_cleanup = 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 AdaptiveSizePolicy::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 AdaptiveSizePolicy::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 evacuation (concurrent GC) 68 uint ShenandoahWorkerPolicy::calc_workers_for_conc_evac() { 69 uint active_workers = (_prev_conc_evac == 0) ? ConcGCThreads : _prev_conc_evac; 70 _prev_conc_evac = 71 AdaptiveSizePolicy::calc_active_workers(ConcGCThreads, 72 active_workers, 73 Threads::number_of_non_daemon_threads()); 74 return _prev_conc_evac; 75 } 76 77 // Calculate workers for parallel fullgc 78 uint ShenandoahWorkerPolicy::calc_workers_for_fullgc() { 79 uint active_workers = (_prev_fullgc == 0) ? ParallelGCThreads : _prev_fullgc; 80 _prev_fullgc = 81 AdaptiveSizePolicy::calc_active_workers(ParallelGCThreads, 82 active_workers, 83 Threads::number_of_non_daemon_threads()); 84 return _prev_fullgc; 85 } 86 87 // Calculate workers for parallel degenerated gc 88 uint ShenandoahWorkerPolicy::calc_workers_for_stw_degenerated() { 89 uint active_workers = (_prev_degengc == 0) ? ParallelGCThreads : _prev_degengc; 90 _prev_degengc = 91 AdaptiveSizePolicy::calc_active_workers(ParallelGCThreads, 92 active_workers, 93 Threads::number_of_non_daemon_threads()); 94 return _prev_degengc; 95 } 96 97 // Calculate workers for Stop-the-world partial GC 98 uint ShenandoahWorkerPolicy::calc_workers_for_stw_partial() { 99 uint active_workers = (_prev_stw_partial == 0) ? ParallelGCThreads : _prev_stw_partial; 100 _prev_stw_partial = 101 AdaptiveSizePolicy::calc_active_workers(ParallelGCThreads, 102 active_workers, 103 Threads::number_of_non_daemon_threads()); 104 return _prev_stw_partial; 105 } 106 107 // Calculate workers for concurent partial GC 108 uint ShenandoahWorkerPolicy::calc_workers_for_conc_partial() { 109 uint active_workers = (_prev_conc_partial == 0) ? ConcGCThreads : _prev_conc_partial; 110 _prev_conc_partial = 111 AdaptiveSizePolicy::calc_active_conc_workers(ConcGCThreads, 112 active_workers, 113 Threads::number_of_non_daemon_threads()); 114 return _prev_conc_partial; 115 } 116 117 // Calculate workers for Stop-the-world traversal GC 118 uint ShenandoahWorkerPolicy::calc_workers_for_stw_traversal() { 119 uint active_workers = (_prev_stw_traversal == 0) ? ParallelGCThreads : _prev_stw_traversal; 120 _prev_stw_traversal = 121 AdaptiveSizePolicy::calc_active_workers(ParallelGCThreads, 122 active_workers, 123 Threads::number_of_non_daemon_threads()); 124 return _prev_stw_traversal; 125 } 126 127 // Calculate workers for concurent traversal GC 128 uint ShenandoahWorkerPolicy::calc_workers_for_conc_traversal() { 129 uint active_workers = (_prev_conc_traversal == 0) ? ConcGCThreads : _prev_conc_traversal; 130 _prev_conc_traversal = 131 AdaptiveSizePolicy::calc_active_conc_workers(ConcGCThreads, 132 active_workers, 133 Threads::number_of_non_daemon_threads()); 134 return _prev_conc_traversal; 135 } 136 137 // Calculate workers for concurrent reference update 138 uint ShenandoahWorkerPolicy::calc_workers_for_conc_update_ref() { 139 uint active_workers = (_prev_conc_update_ref == 0) ? ConcGCThreads : _prev_conc_update_ref; 140 _prev_conc_update_ref = 141 AdaptiveSizePolicy::calc_active_workers(ConcGCThreads, 142 active_workers, 143 Threads::number_of_non_daemon_threads()); 144 return _prev_conc_update_ref; 145 } 146 147 // Calculate workers for parallel reference update 148 uint ShenandoahWorkerPolicy::calc_workers_for_final_update_ref() { 149 uint active_workers = (_prev_par_update_ref == 0) ? ParallelGCThreads : _prev_par_update_ref; 150 _prev_par_update_ref = 151 AdaptiveSizePolicy::calc_active_workers(ParallelGCThreads, 152 active_workers, 153 Threads::number_of_non_daemon_threads()); 154 return _prev_par_update_ref; 155 } 156 157 uint ShenandoahWorkerPolicy::calc_workers_for_conc_preclean() { 158 return _prev_conc_marking; 159 } 160 161 uint ShenandoahWorkerPolicy::calc_workers_for_conc_cleanup() { 162 uint active_workers = (_prev_conc_cleanup == 0) ? ConcGCThreads : _prev_conc_cleanup; 163 _prev_conc_cleanup = 164 AdaptiveSizePolicy::calc_active_workers(ConcGCThreads, 165 active_workers, 166 Threads::number_of_non_daemon_threads()); 167 return _prev_conc_cleanup; 168 }