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 #include "precompiled.hpp"
 26 
 27 #include "gc/shenandoah/shenandoahCollectorPolicy.hpp"
 28 #include "gc/shenandoah/shenandoahGC.hpp"
 29 #include "gc/shenandoah/shenandoahHeap.inline.hpp"
 30 #include "runtime/os.hpp"
 31 
 32 ShenandoahCollectorPolicy::ShenandoahCollectorPolicy() :
 33   _success_concurrent_gcs(0),
 34   _success_degenerated_gcs(0),
 35   _success_full_gcs(0),
 36   _alloc_failure_degenerated(0),
 37   _alloc_failure_degenerated_upgrade_to_full(0),
 38   _alloc_failure_full(0),
 39   _explicit_concurrent(0),
 40   _explicit_full(0),
 41   _implicit_concurrent(0),
 42   _implicit_full(0),
 43   _cycle_counter(0) {
 44 
 45   Copy::zero_to_bytes(_degen_points, sizeof(size_t) * ShenandoahGC::_DEGENERATED_LIMIT);
 46 
 47   _tracer = new ShenandoahTracer();
 48 
 49 }
 50 
 51 void ShenandoahCollectorPolicy::record_explicit_to_concurrent() {
 52   _explicit_concurrent++;
 53 }
 54 
 55 void ShenandoahCollectorPolicy::record_explicit_to_full() {
 56   _explicit_full++;
 57 }
 58 
 59 void ShenandoahCollectorPolicy::record_implicit_to_concurrent() {
 60   _implicit_concurrent++;
 61 }
 62 
 63 void ShenandoahCollectorPolicy::record_implicit_to_full() {
 64   _implicit_full++;
 65 }
 66 
 67 void ShenandoahCollectorPolicy::record_alloc_failure_to_full() {
 68   _alloc_failure_full++;
 69 }
 70 
 71 void ShenandoahCollectorPolicy::record_alloc_failure_to_degenerated(ShenandoahGC::ShenandoahDegenPoint point) {
 72   assert(point < ShenandoahGC::_DEGENERATED_LIMIT, "sanity");
 73   _alloc_failure_degenerated++;
 74   _degen_points[point]++;
 75 }
 76 
 77 void ShenandoahCollectorPolicy::record_degenerated_upgrade_to_full() {
 78   _alloc_failure_degenerated_upgrade_to_full++;
 79 }
 80 
 81 void ShenandoahCollectorPolicy::record_success_concurrent() {
 82   _success_concurrent_gcs++;
 83 }
 84 
 85 void ShenandoahCollectorPolicy::record_success_degenerated() {
 86   _success_degenerated_gcs++;
 87 }
 88 
 89 void ShenandoahCollectorPolicy::record_success_full() {
 90   _success_full_gcs++;
 91 }
 92 
 93 size_t ShenandoahCollectorPolicy::cycle_counter() const {
 94   return _cycle_counter;
 95 }
 96 
 97 void ShenandoahCollectorPolicy::record_cycle_start() {
 98   _cycle_counter++;
 99 }
100 
101 void ShenandoahCollectorPolicy::record_shutdown() {
102   _in_shutdown.set();
103 }
104 
105 bool ShenandoahCollectorPolicy::is_at_shutdown() {
106   return _in_shutdown.is_set();
107 }
108 
109 void ShenandoahCollectorPolicy::print_gc_stats(outputStream* out) const {
110   out->print_cr("Under allocation pressure, concurrent cycles may cancel, and either continue cycle");
111   out->print_cr("under stop-the-world pause or result in stop-the-world Full GC. Increase heap size,");
112   out->print_cr("tune GC heuristics, set more aggressive pacing delay, or lower allocation rate");
113   out->print_cr("to avoid Degenerated and Full GC cycles.");
114   out->cr();
115 
116   out->print_cr(SIZE_FORMAT_W(5) " successful concurrent GCs",         _success_concurrent_gcs);
117   out->print_cr("  " SIZE_FORMAT_W(5) " invoked explicitly",           _explicit_concurrent);
118   out->print_cr("  " SIZE_FORMAT_W(5) " invoked implicitly",           _implicit_concurrent);
119   out->cr();
120 
121   out->print_cr(SIZE_FORMAT_W(5) " Degenerated GCs",                   _success_degenerated_gcs);
122   out->print_cr("  " SIZE_FORMAT_W(5) " caused by allocation failure", _alloc_failure_degenerated);
123   for (int c = 0; c < ShenandoahGC::_DEGENERATED_LIMIT; c++) {
124     if (_degen_points[c] > 0) {
125       const char* desc = ShenandoahGC::degen_point_to_string((ShenandoahGC::ShenandoahDegenPoint)c);
126       out->print_cr("    " SIZE_FORMAT_W(5) " happened at %s",         _degen_points[c], desc);
127     }
128   }
129   out->print_cr("  " SIZE_FORMAT_W(5) " upgraded to Full GC",          _alloc_failure_degenerated_upgrade_to_full);
130   out->cr();
131 
132   out->print_cr(SIZE_FORMAT_W(5) " Full GCs",                          _success_full_gcs + _alloc_failure_degenerated_upgrade_to_full);
133   out->print_cr("  " SIZE_FORMAT_W(5) " invoked explicitly",           _explicit_full);
134   out->print_cr("  " SIZE_FORMAT_W(5) " invoked implicitly",           _implicit_full);
135   out->print_cr("  " SIZE_FORMAT_W(5) " caused by allocation failure", _alloc_failure_full);
136   out->print_cr("  " SIZE_FORMAT_W(5) " upgraded from Degenerated GC", _alloc_failure_degenerated_upgrade_to_full);
137 }