1 /* 2 * Copyright (c) 2013, 2021, Red Hat, Inc. All rights reserved. 3 * Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5 * 6 * This code is free software; you can redistribute it and/or modify it 7 * under the terms of the GNU General Public License version 2 only, as 8 * published by the Free Software Foundation. 9 * 10 * This code is distributed in the hope that it will be useful, but WITHOUT 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 * version 2 for more details (a copy is included in the LICENSE file that 14 * accompanied this code). 15 * 16 * You should have received a copy of the GNU General Public License version 17 * 2 along with this work; if not, write to the Free Software Foundation, 18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 19 * 20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 21 * or visit www.oracle.com if you need additional information or have any 22 * questions. 23 * 24 */ 25 26 #ifndef SHARE_GC_SHENANDOAH_SHENANDOAHCOLLECTORPOLICY_HPP 27 #define SHARE_GC_SHENANDOAH_SHENANDOAHCOLLECTORPOLICY_HPP 28 29 #include "gc/shared/gcTrace.hpp" 30 #include "gc/shenandoah/shenandoahGC.hpp" 31 #include "gc/shenandoah/shenandoahSharedVariables.hpp" 32 #include "memory/allocation.hpp" 33 #include "utilities/ostream.hpp" 34 35 class ShenandoahTracer : public GCTracer, public CHeapObj<mtGC> { 36 public: 37 ShenandoahTracer() : GCTracer(Shenandoah) {} 38 }; 39 40 class ShenandoahCollectorPolicy : public CHeapObj<mtGC> { 41 private: 42 size_t _success_concurrent_gcs; 43 size_t _abbreviated_concurrent_gcs; 44 size_t _success_degenerated_gcs; 45 size_t _abbreviated_degenerated_gcs; 46 // Written by control thread, read by mutators 47 volatile size_t _success_full_gcs; 48 uint _consecutive_degenerated_gcs; 49 volatile size_t _consecutive_young_gcs; 50 size_t _mixed_gcs; 51 size_t _success_old_gcs; 52 size_t _interrupted_old_gcs; 53 size_t _alloc_failure_degenerated; 54 size_t _alloc_failure_degenerated_upgrade_to_full; 55 size_t _alloc_failure_full; 56 size_t _collection_cause_counts[GCCause::_last_gc_cause]; 57 size_t _degen_point_counts[ShenandoahGC::_DEGENERATED_LIMIT]; 58 59 ShenandoahSharedFlag _in_shutdown; 60 ShenandoahTracer* _tracer; 61 62 63 public: 64 ShenandoahCollectorPolicy(); 65 66 void record_mixed_cycle(); 67 void record_success_old(); 68 void record_interrupted_old(); 69 70 // A collection cycle may be "abbreviated" if Shenandoah finds a sufficient percentage 71 // of regions that contain no live objects (ShenandoahImmediateThreshold). These cycles 72 // end after final mark, skipping the evacuation and reference-updating phases. Such 73 // cycles are very efficient and are worth tracking. Note that both degenerated and 74 // concurrent cycles can be abbreviated. 75 void record_success_concurrent(bool is_young, bool is_abbreviated); 76 void record_success_degenerated(bool is_young, bool is_abbreviated); 77 void record_success_full(); 78 void record_alloc_failure_to_degenerated(ShenandoahGC::ShenandoahDegenPoint point); 79 void record_alloc_failure_to_full(); 80 void record_degenerated_upgrade_to_full(); 81 void record_collection_cause(GCCause::Cause cause); 82 83 void record_shutdown(); 84 bool is_at_shutdown(); 85 86 ShenandoahTracer* tracer() {return _tracer;} 87 88 void print_gc_stats(outputStream* out) const; 89 90 size_t full_gc_count() const { 91 return _success_full_gcs + _alloc_failure_degenerated_upgrade_to_full; 92 } 93 94 // If the heuristics find that the number of consecutive degenerated cycles is above 95 // ShenandoahFullGCThreshold, then they will initiate a Full GC upon an allocation 96 // failure. 97 inline size_t consecutive_degenerated_gc_count() const { 98 return _consecutive_degenerated_gcs; 99 } 100 101 static bool is_requested_gc(GCCause::Cause cause); 102 static bool should_run_full_gc(GCCause::Cause cause); 103 static bool should_handle_requested_gc(GCCause::Cause cause); 104 105 inline size_t consecutive_young_gc_count() const { 106 return _consecutive_young_gcs; 107 } 108 109 private: 110 void update_young(bool is_young); 111 }; 112 113 #endif // SHARE_GC_SHENANDOAH_SHENANDOAHCOLLECTORPOLICY_HPP --- EOF ---