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 _mixed_gcs;
 44   size_t _abbreviated_concurrent_gcs;
 45   size_t _abbreviated_degenerated_gcs;
 46   size_t _success_old_gcs;
 47   size_t _interrupted_old_gcs;
 48   size_t _success_degenerated_gcs;
 49   // Written by control thread, read by mutators
 50   volatile size_t _success_full_gcs;
 51   volatile size_t _consecutive_young_gcs;
 52   uint _consecutive_degenerated_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 _explicit_concurrent;
 57   size_t _explicit_full;
 58   size_t _implicit_concurrent;
 59   size_t _implicit_full;
 60   size_t _cycle_counter;
 61   size_t _degen_points[ShenandoahGC::_DEGENERATED_LIMIT];
 62 
 63   ShenandoahSharedFlag _in_shutdown;
 64   ShenandoahTracer* _tracer;
 65 
 66 
 67 public:
 68   ShenandoahCollectorPolicy();
 69 
 70   // TODO: This is different from gc_end: that one encompasses one VM operation.
 71   // These two encompass the entire cycle.
 72   void record_cycle_start();
 73 
 74   void record_mixed_cycle();
 75 
 76   void record_success_concurrent(bool is_young, bool is_abbreviated);
 77   void record_success_old();
 78   void record_interrupted_old();
 79   void record_success_degenerated(bool is_young, bool is_abbreviated);
 80   void record_success_full();
 81   void record_alloc_failure_to_degenerated(ShenandoahGC::ShenandoahDegenPoint point);
 82   void record_alloc_failure_to_full();
 83   void record_degenerated_upgrade_to_full();
 84   void record_explicit_to_concurrent();
 85   void record_explicit_to_full();
 86   void record_implicit_to_concurrent();
 87   void record_implicit_to_full();
 88 
 89   void record_shutdown();
 90   bool is_at_shutdown();
 91 
 92   ShenandoahTracer* tracer() {return _tracer;}
 93 
 94   size_t cycle_counter() const;
 95 
 96   void print_gc_stats(outputStream* out) const;
 97 
 98   size_t full_gc_count() const {
 99     return _success_full_gcs + _alloc_failure_degenerated_upgrade_to_full;
100   }
101 
102   inline size_t consecutive_young_gc_count() const {
103     return _consecutive_young_gcs;
104   }
105 
106   inline size_t consecutive_degenerated_gc_count() const {
107     return _consecutive_degenerated_gcs;
108   }
109 
110 private:
111   void update_young(bool is_young);
112 };
113 
114 #endif // SHARE_GC_SHENANDOAH_SHENANDOAHCOLLECTORPOLICY_HPP