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