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