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 conc_update_refs, 116 pre_update_refs, 117 post_update_refs, 118 119 partial_gc, 120 _num_phases 121 }; 122 123 private: 124 struct TimingData { 125 HdrSeq _secs; 126 double _start; 127 size_t _count; 128 }; 129 130 private: 131 TimingData _timing_data[_num_phases]; 132 const char* _phase_names[_num_phases]; 133 134 size_t _user_requested_gcs; 135 size_t _allocation_failure_gcs; 136 size_t _degenerated_cm; 137 size_t _successful_cm; 138 139 ShenandoahHeap* _pgc; 140 ShenandoahHeuristics* _heuristics; 141 ShenandoahTracer* _tracer; 142 STWGCTimer* _stw_timer; 143 ConcurrentGCTimer* _conc_timer; 144 145 bool _conc_gc_aborted; 146 147 size_t _cycle_counter; 148 149 ShenandoahPhaseTimes* _phase_times; 150 151 public: 152 ShenandoahCollectorPolicy(); 153 154 ShenandoahPhaseTimes* phase_times(); 155 156 virtual ShenandoahCollectorPolicy* as_pgc_policy(); 157 158 BarrierSet::Name barrier_set_name(); 159 160 HeapWord* mem_allocate_work(size_t size, 161 bool is_tlab, 162 bool* gc_overhead_limit_was_exceeded); 163 164 HeapWord* satisfy_failed_allocation(size_t size, bool is_tlab); 165 166 void initialize_alignments(); 167 168 void post_heap_initialize(); 169 170 void record_gc_start(); 171 void record_gc_end(); 172 173 void record_phase_start(TimingPhase phase); 174 void record_phase_end(TimingPhase phase); 175 176 void record_workers_start(TimingPhase phase); 177 void record_workers_end(TimingPhase phase); 178 179 void report_concgc_cancelled(); 180 181 void record_user_requested_gc(); 182 void record_allocation_failure_gc(); 183 184 void record_bytes_allocated(size_t bytes); 185 void record_bytes_reclaimed(size_t bytes); 186 void record_bytes_start_CM(size_t bytes); 187 void record_bytes_end_CM(size_t bytes); 188 bool should_start_concurrent_mark(size_t used, size_t capacity); 189 bool should_start_partial_gc(); 190 191 // Returns true when there should be a separate concurrent reference 192 // updating phase after evacuation. 193 bool update_refs_early(); 194 195 bool handover_cancelled_marking(); 196 197 void record_cm_cancelled(); 198 void record_cm_success(); 199 void record_cm_degenerated(); 200 void record_full_gc(); 201 202 void choose_collection_set(ShenandoahCollectionSet* collection_set, int* connections=NULL); 203 void choose_free_set(ShenandoahFreeSet* free_set); 204 205 bool process_references(); 206 bool unload_classes(); 207 208 void print_tracing_info(outputStream* out); 209 210 GCTimer* conc_timer(){return _conc_timer;} 211 GCTimer* stw_timer() {return _stw_timer;} 212 ShenandoahTracer* tracer() {return _tracer;} 213 214 void set_conc_gc_aborted() { _conc_gc_aborted = true;} 215 void clear_conc_gc_aborted() {_conc_gc_aborted = false;} 216 217 void increase_cycle_counter(); 218 size_t cycle_counter() const; 219 220 221 // Calculate the number of workers for initial marking 222 static uint calc_workers_for_init_marking(uint active_workers, 223 uint application_workers); 224 225 // Calculate the number of workers for concurrent marking 226 static uint calc_workers_for_conc_marking(uint active_workers, 227 uint application_workers); 228 229 // Calculate the number of workers for final marking 230 static uint calc_workers_for_final_marking(uint active_workers, 231 uint application_workers); 232 233 // Calculate workers for concurrent evacuation (concurrent GC) 234 static uint calc_workers_for_conc_evacuation(uint active_workers, 235 uint application_workers); 236 237 // Calculate workers for parallel evaculation (full GC) 238 static uint calc_workers_for_parallel_evacuation(uint active_workers, 239 uint application_workers); 240 241 private: 242 static uint calc_workers_for_java_threads(uint application_workers); 243 static uint calc_workers_for_live_set(size_t live_data); 244 245 static uint calc_default_active_workers(uint total_workers, 246 uint min_workers, 247 uint active_workers, 248 uint application_workers, 249 uint workers_by_java_threads, 250 uint workers_by_liveset); 251 252 static uint calc_workers_for_evacuation(bool full_gc, 253 uint total_workers, 254 uint active_workers, 255 uint application_workers); 256 257 void print_summary_sd(outputStream* out, const char* str, const HdrSeq* seq); 258 }; 259 260 261 #endif // SHARE_VM_GC_SHENANDOAH_SHENANDOAH_COLLECTOR_POLICY_HPP