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_implementation/shared/adaptiveSizePolicy.hpp" 27 #include "gc_implementation/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_update_ref = 0; 37 uint ShenandoahWorkerPolicy::_prev_par_update_ref = 0; 38 uint ShenandoahWorkerPolicy::_prev_conc_cleanup = 0; 39 40 uint ShenandoahWorkerPolicy::calc_workers_for_init_marking() { 41 uint active_workers = (_prev_par_marking == 0) ? ParallelGCThreads : _prev_par_marking; 42 43 _prev_par_marking = 44 AdaptiveSizePolicy::calc_active_workers(ParallelGCThreads, 45 active_workers, 46 Threads::number_of_non_daemon_threads()); 47 return _prev_par_marking; 48 } 49 50 uint ShenandoahWorkerPolicy::calc_workers_for_conc_marking() { 51 uint active_workers = (_prev_conc_marking == 0) ? ConcGCThreads : _prev_conc_marking; 52 _prev_conc_marking = 53 AdaptiveSizePolicy::calc_active_conc_workers(ConcGCThreads, 54 active_workers, 55 Threads::number_of_non_daemon_threads()); 56 return _prev_conc_marking; 57 } 58 59 // Reuse the calculation result from init marking 60 uint ShenandoahWorkerPolicy::calc_workers_for_final_marking() { 61 return _prev_par_marking; 62 } 63 64 // Calculate workers for concurrent evacuation (concurrent GC) 65 uint ShenandoahWorkerPolicy::calc_workers_for_conc_evac() { 66 uint active_workers = (_prev_conc_evac == 0) ? ConcGCThreads : _prev_conc_evac; 67 _prev_conc_evac = 68 AdaptiveSizePolicy::calc_active_workers(ConcGCThreads, 69 active_workers, 70 Threads::number_of_non_daemon_threads()); 71 return _prev_conc_evac; 72 } 73 74 // Calculate workers for parallel fullgc 75 uint ShenandoahWorkerPolicy::calc_workers_for_fullgc() { 76 uint active_workers = (_prev_fullgc == 0) ? ParallelGCThreads : _prev_fullgc; 77 _prev_fullgc = 78 AdaptiveSizePolicy::calc_active_workers(ParallelGCThreads, 79 active_workers, 80 Threads::number_of_non_daemon_threads()); 81 return _prev_fullgc; 82 } 83 84 // Calculate workers for Stop-the-world partial GC 85 uint ShenandoahWorkerPolicy::calc_workers_for_stw_partial() { 86 uint active_workers = (_prev_stw_partial == 0) ? ParallelGCThreads : _prev_stw_partial; 87 _prev_stw_partial = 88 AdaptiveSizePolicy::calc_active_workers(ParallelGCThreads, 89 active_workers, 90 Threads::number_of_non_daemon_threads()); 91 return _prev_stw_partial; 92 } 93 94 // Calculate workers for concurrent reference update 95 uint ShenandoahWorkerPolicy::calc_workers_for_conc_update_ref() { 96 uint active_workers = (_prev_conc_update_ref == 0) ? ConcGCThreads : _prev_conc_update_ref; 97 _prev_conc_update_ref = 98 AdaptiveSizePolicy::calc_active_workers(ConcGCThreads, 99 active_workers, 100 Threads::number_of_non_daemon_threads()); 101 return _prev_conc_update_ref; 102 } 103 104 // Calculate workers for parallel reference update 105 uint ShenandoahWorkerPolicy::calc_workers_for_final_update_ref() { 106 uint active_workers = (_prev_par_update_ref == 0) ? ParallelGCThreads : _prev_par_update_ref; 107 _prev_par_update_ref = 108 AdaptiveSizePolicy::calc_active_workers(ParallelGCThreads, 109 active_workers, 110 Threads::number_of_non_daemon_threads()); 111 return _prev_par_update_ref; 112 } 113 114 // Calculate workers for parallel degenerated gc 115 uint ShenandoahWorkerPolicy::calc_workers_for_stw_degenerated() { 116 uint active_workers = (_prev_degengc == 0) ? ParallelGCThreads : _prev_degengc; 117 _prev_degengc = 118 AdaptiveSizePolicy::calc_active_workers(ParallelGCThreads, 119 active_workers, 120 Threads::number_of_non_daemon_threads()); 121 return _prev_degengc; 122 } 123 124 uint ShenandoahWorkerPolicy::calc_workers_for_conc_preclean() { 125 return _prev_conc_marking; 126 } 127 128 uint ShenandoahWorkerPolicy::calc_workers_for_conc_cleanup() { 129 uint active_workers = (_prev_conc_cleanup == 0) ? ConcGCThreads : _prev_conc_cleanup; 130 _prev_conc_cleanup = 131 AdaptiveSizePolicy::calc_active_workers(ConcGCThreads, 132 active_workers, 133 Threads::number_of_non_daemon_threads()); 134 return _prev_conc_cleanup; 135 }