1 /* 2 * Copyright (c) 2013, 2015, 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 #ifndef SHARE_VM_GC_SHENANDOAH_SHENANDOAH_COLLECTOR_POLICY_HPP 25 #define SHARE_VM_GC_SHENANDOAH_SHENANDOAH_COLLECTOR_POLICY_HPP 26 27 #include "gc/shared/gcTrace.hpp" 28 #include "gc/shared/gcTimer.hpp" 29 #include "gc/shared/collectorPolicy.hpp" 30 #include "runtime/arguments.hpp" 31 #include "utilities/numberSeq.hpp" 32 33 class ShenandoahCollectionSet; 34 class ShenandoahFreeSet; 35 class ShenandoahHeap; 36 class ShenandoahHeuristics; 37 class ShenandoahPhaseTimes; 38 39 class ShenandoahCollectorPolicy: public CollectorPolicy { 40 public: 41 enum TimingPhase { 42 total_pause_gross, 43 total_pause, 44 45 init_mark_gross, 46 init_mark, 47 accumulate_stats, 48 make_parsable, 49 clear_liveness, 50 scan_roots, 51 scan_thread_roots, 52 scan_code_roots, 53 scan_string_table_roots, 54 scan_universe_roots, 55 scan_jni_roots, 56 scan_jni_weak_roots, 57 scan_synchronizer_roots, 58 scan_flat_profiler_roots, 59 scan_management_roots, 60 scan_system_dictionary_roots, 61 scan_cldg_roots, 62 scan_jvmti_roots, 63 64 resize_tlabs, 65 66 final_mark_gross, 67 final_mark, 68 update_roots, 69 update_thread_roots, 70 update_code_roots, 71 update_string_table_roots, 72 update_universe_roots, 73 update_jni_roots, 74 update_jni_weak_roots, 75 update_synchronizer_roots, 76 update_flat_profiler_roots, 77 update_management_roots, 78 update_system_dictionary_roots, 79 update_cldg_roots, 80 update_jvmti_roots, 81 drain_satb, 82 weakrefs, 83 class_unloading, 84 prepare_evac, 85 recycle_regions, 86 init_evac, 87 evac_thread_roots, 88 evac_code_roots, 89 evac_string_table_roots, 90 evac_universe_roots, 91 evac_jni_roots, 92 evac_jni_weak_roots, 93 evac_synchronizer_roots, 94 evac_flat_profiler_roots, 95 evac_management_roots, 96 evac_system_dictionary_roots, 97 evac_cldg_roots, 98 evac_jvmti_roots, 99 100 conc_mark, 101 conc_evac, 102 reset_bitmaps, 103 104 full_gc, 105 full_gc_heapdumps, 106 full_gc_prepare, 107 full_gc_mark, 108 full_gc_mark_drain_queues, 109 full_gc_mark_weakrefs, 110 full_gc_mark_class_unloading, 111 full_gc_calculate_addresses, 112 full_gc_adjust_pointers, 113 full_gc_copy_objects, 114 115 partial_gc, 116 _num_phases 117 }; 118 119 private: 120 struct TimingData { 121 HdrSeq _secs; 122 double _start; 123 size_t _count; 124 }; 125 126 private: 127 TimingData _timing_data[_num_phases]; 128 const char* _phase_names[_num_phases]; 129 130 size_t _user_requested_gcs; 131 size_t _allocation_failure_gcs; 132 size_t _degenerated_cm; 133 size_t _successful_cm; 134 135 ShenandoahHeap* _pgc; 136 ShenandoahHeuristics* _heuristics; 137 ShenandoahTracer* _tracer; 138 STWGCTimer* _stw_timer; 139 ConcurrentGCTimer* _conc_timer; 140 141 bool _conc_gc_aborted; 142 143 size_t _cycle_counter; 144 145 ShenandoahPhaseTimes* _phase_times; 146 147 public: 148 ShenandoahCollectorPolicy(); 149 150 ShenandoahPhaseTimes* phase_times(); 151 152 virtual ShenandoahCollectorPolicy* as_pgc_policy(); 153 154 BarrierSet::Name barrier_set_name(); 155 156 HeapWord* mem_allocate_work(size_t size, 157 bool is_tlab, 158 bool* gc_overhead_limit_was_exceeded); 159 160 HeapWord* satisfy_failed_allocation(size_t size, bool is_tlab); 161 162 void initialize_alignments(); 163 164 void post_heap_initialize(); 165 166 void record_gc_start(); 167 void record_gc_end(); 168 169 void record_phase_start(TimingPhase phase); 170 void record_phase_end(TimingPhase phase); 171 172 void record_workers_start(TimingPhase phase); 173 void record_workers_end(TimingPhase phase); 174 175 void report_concgc_cancelled(); 176 177 void record_user_requested_gc(); 178 void record_allocation_failure_gc(); 179 180 void record_bytes_allocated(size_t bytes); 181 void record_bytes_reclaimed(size_t bytes); 182 void record_bytes_start_CM(size_t bytes); 183 void record_bytes_end_CM(size_t bytes); 184 bool should_start_concurrent_mark(size_t used, size_t capacity); 185 bool should_start_partial_gc(); 186 bool handover_cancelled_marking(); 187 188 void record_cm_cancelled(); 189 void record_cm_success(); 190 void record_cm_degenerated(); 191 void record_full_gc(); 192 193 void choose_collection_set(ShenandoahCollectionSet* collection_set, int* connections=NULL); 194 void choose_free_set(ShenandoahFreeSet* free_set); 195 196 bool process_references(); 197 bool unload_classes(); 198 199 void print_tracing_info(outputStream* out); 200 201 GCTimer* conc_timer(){return _conc_timer;} 202 GCTimer* stw_timer() {return _stw_timer;} 203 ShenandoahTracer* tracer() {return _tracer;} 204 205 void set_conc_gc_aborted() { _conc_gc_aborted = true;} 206 void clear_conc_gc_aborted() {_conc_gc_aborted = false;} 207 208 void increase_cycle_counter(); 209 size_t cycle_counter() const; 210 211 212 // Calculate the number of workers for initial marking 213 static uint calc_workers_for_init_marking(uint active_workers, 214 uint application_workers); 215 216 // Calculate the number of workers for concurrent marking 217 static uint calc_workers_for_conc_marking(uint active_workers, 218 uint application_workers); 219 220 // Calculate the number of workers for final marking 221 static uint calc_workers_for_final_marking(uint active_workers, 222 uint application_workers); 223 224 // Calculate workers for concurrent evacuation (concurrent GC) 225 static uint calc_workers_for_conc_evacuation(uint active_workers, 226 uint application_workers); 227 228 // Calculate workers for parallel evaculation (full GC) 229 static uint calc_workers_for_parallel_evacuation(uint active_workers, 230 uint application_workers); 231 232 private: 233 static uint calc_workers_for_java_threads(uint application_workers); 234 static uint calc_workers_for_live_set(size_t live_data); 235 236 static uint calc_default_active_workers(uint total_workers, 237 uint min_workers, 238 uint active_workers, 239 uint application_workers, 240 uint workers_by_java_threads, 241 uint workers_by_liveset); 242 243 static uint calc_workers_for_evacuation(bool full_gc, 244 uint total_workers, 245 uint active_workers, 246 uint application_workers); 247 248 void print_summary_sd(outputStream* out, const char* str, const HdrSeq* seq); 249 }; 250 251 252 #endif // SHARE_VM_GC_SHENANDOAH_SHENANDOAH_COLLECTOR_POLICY_HPP