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