< prev index next >

src/hotspot/share/gc/shenandoah/shenandoahCollectorPolicy.cpp

Print this page
@@ -1,7 +1,8 @@
  /*
   * Copyright (c) 2013, 2021, Red Hat, Inc. All rights reserved.
+  * Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   *
   * This code is free software; you can redistribute it and/or modify it
   * under the terms of the GNU General Public License version 2 only, as
   * published by the Free Software Foundation.

@@ -29,109 +30,211 @@
  #include "gc/shenandoah/shenandoahHeap.inline.hpp"
  #include "runtime/os.hpp"
  
  ShenandoahCollectorPolicy::ShenandoahCollectorPolicy() :
    _success_concurrent_gcs(0),
+   _abbreviated_concurrent_gcs(0),
    _success_degenerated_gcs(0),
+   _abbreviated_degenerated_gcs(0),
    _success_full_gcs(0),
+   _consecutive_degenerated_gcs(0),
+   _consecutive_young_gcs(0),
+   _mixed_gcs(0),
+   _success_old_gcs(0),
+   _interrupted_old_gcs(0),
    _alloc_failure_degenerated(0),
    _alloc_failure_degenerated_upgrade_to_full(0),
-   _alloc_failure_full(0),
-   _explicit_concurrent(0),
-   _explicit_full(0),
-   _implicit_concurrent(0),
-   _implicit_full(0),
-   _cycle_counter(0) {
+   _alloc_failure_full(0) {
  
-   Copy::zero_to_bytes(_degen_points, sizeof(size_t) * ShenandoahGC::_DEGENERATED_LIMIT);
+   Copy::zero_to_bytes(_degen_point_counts, sizeof(size_t) * ShenandoahGC::_DEGENERATED_LIMIT);
+   Copy::zero_to_bytes(_collection_cause_counts, sizeof(size_t) * GCCause::_last_gc_cause);
  
    _tracer = new ShenandoahTracer();
- 
- }
- 
- void ShenandoahCollectorPolicy::record_explicit_to_concurrent() {
-   _explicit_concurrent++;
- }
- 
- void ShenandoahCollectorPolicy::record_explicit_to_full() {
-   _explicit_full++;
- }
- 
- void ShenandoahCollectorPolicy::record_implicit_to_concurrent() {
-   _implicit_concurrent++;
  }
  
- void ShenandoahCollectorPolicy::record_implicit_to_full() {
-   _implicit_full++;
+ void ShenandoahCollectorPolicy::record_collection_cause(GCCause::Cause cause) {
+   assert(cause < GCCause::_last_gc_cause, "Invalid GCCause");
+   _collection_cause_counts[cause]++;
  }
  
  void ShenandoahCollectorPolicy::record_alloc_failure_to_full() {
    _alloc_failure_full++;
  }
  
  void ShenandoahCollectorPolicy::record_alloc_failure_to_degenerated(ShenandoahGC::ShenandoahDegenPoint point) {
    assert(point < ShenandoahGC::_DEGENERATED_LIMIT, "sanity");
    _alloc_failure_degenerated++;
-   _degen_points[point]++;
+   _degen_point_counts[point]++;
  }
  
  void ShenandoahCollectorPolicy::record_degenerated_upgrade_to_full() {
+   _consecutive_degenerated_gcs = 0;
    _alloc_failure_degenerated_upgrade_to_full++;
  }
  
- void ShenandoahCollectorPolicy::record_success_concurrent() {
+ void ShenandoahCollectorPolicy::record_success_concurrent(bool is_young, bool is_abbreviated) {
+   update_young(is_young);
+ 
+   _consecutive_degenerated_gcs = 0;
    _success_concurrent_gcs++;
+   if (is_abbreviated) {
+     _abbreviated_concurrent_gcs++;
+   }
  }
  
- void ShenandoahCollectorPolicy::record_success_degenerated() {
-   _success_degenerated_gcs++;
+ void ShenandoahCollectorPolicy::record_mixed_cycle() {
+   _mixed_gcs++;
  }
  
- void ShenandoahCollectorPolicy::record_success_full() {
-   _success_full_gcs++;
+ void ShenandoahCollectorPolicy::record_success_old() {
+   _consecutive_young_gcs = 0;
+   _success_old_gcs++;
  }
  
- size_t ShenandoahCollectorPolicy::cycle_counter() const {
-   return _cycle_counter;
+ void ShenandoahCollectorPolicy::record_interrupted_old() {
+   _consecutive_young_gcs = 0;
+   _interrupted_old_gcs++;
  }
  
- void ShenandoahCollectorPolicy::record_cycle_start() {
-   _cycle_counter++;
+ void ShenandoahCollectorPolicy::record_success_degenerated(bool is_young, bool is_abbreviated) {
+   update_young(is_young);
+ 
+   _success_degenerated_gcs++;
+   _consecutive_degenerated_gcs++;
+   if (is_abbreviated) {
+     _abbreviated_degenerated_gcs++;
+   }
+ }
+ 
+ void ShenandoahCollectorPolicy::update_young(bool is_young) {
+   if (is_young) {
+     _consecutive_young_gcs++;
+   } else {
+     _consecutive_young_gcs = 0;
+   }
+ }
+ 
+ void ShenandoahCollectorPolicy::record_success_full() {
+   _consecutive_degenerated_gcs = 0;
+   _consecutive_young_gcs = 0;
+   _success_full_gcs++;
  }
  
  void ShenandoahCollectorPolicy::record_shutdown() {
    _in_shutdown.set();
  }
  
  bool ShenandoahCollectorPolicy::is_at_shutdown() {
    return _in_shutdown.is_set();
  }
  
+ bool is_explicit_gc(GCCause::Cause cause) {
+   return GCCause::is_user_requested_gc(cause)
+       || GCCause::is_serviceability_requested_gc(cause);
+ }
+ 
+ bool is_implicit_gc(GCCause::Cause cause) {
+   return cause != GCCause::_no_gc
+       && cause != GCCause::_shenandoah_concurrent_gc
+       && cause != GCCause::_allocation_failure
+       && !is_explicit_gc(cause);
+ }
+ 
+ #ifdef ASSERT
+ bool is_valid_request(GCCause::Cause cause) {
+   return is_explicit_gc(cause)
+       || cause == GCCause::_metadata_GC_clear_soft_refs
+       || cause == GCCause::_codecache_GC_aggressive
+       || cause == GCCause::_codecache_GC_threshold
+       || cause == GCCause::_full_gc_alot
+       || cause == GCCause::_wb_young_gc
+       || cause == GCCause::_wb_full_gc
+       || cause == GCCause::_wb_breakpoint
+       || cause == GCCause::_scavenge_alot;
+ }
+ #endif
+ 
+ bool ShenandoahCollectorPolicy::is_requested_gc(GCCause::Cause cause) {
+   return is_explicit_gc(cause) || is_implicit_gc(cause);
+ }
+ 
+ bool ShenandoahCollectorPolicy::should_run_full_gc(GCCause::Cause cause) {
+   return is_explicit_gc(cause) ? !ExplicitGCInvokesConcurrent : !ShenandoahImplicitGCInvokesConcurrent;
+ }
+ 
+ bool ShenandoahCollectorPolicy::should_handle_requested_gc(GCCause::Cause cause) {
+   assert(is_valid_request(cause), "only requested GCs here: %s", GCCause::to_string(cause));
+ 
+   if (DisableExplicitGC) {
+     return !is_explicit_gc(cause);
+   }
+   return true;
+ }
+ 
  void ShenandoahCollectorPolicy::print_gc_stats(outputStream* out) const {
    out->print_cr("Under allocation pressure, concurrent cycles may cancel, and either continue cycle");
    out->print_cr("under stop-the-world pause or result in stop-the-world Full GC. Increase heap size,");
    out->print_cr("tune GC heuristics, set more aggressive pacing delay, or lower allocation rate");
-   out->print_cr("to avoid Degenerated and Full GC cycles.");
+   out->print_cr("to avoid Degenerated and Full GC cycles. Abbreviated cycles are those which found");
+   out->print_cr("enough regions with no live objects to skip evacuation.");
    out->cr();
  
-   out->print_cr(SIZE_FORMAT_W(5) " successful concurrent GCs",         _success_concurrent_gcs);
-   out->print_cr("  " SIZE_FORMAT_W(5) " invoked explicitly",           _explicit_concurrent);
-   out->print_cr("  " SIZE_FORMAT_W(5) " invoked implicitly",           _implicit_concurrent);
+   size_t completed_gcs = _success_full_gcs + _success_degenerated_gcs + _success_concurrent_gcs + _success_old_gcs;
+   out->print_cr(SIZE_FORMAT_W(5) " Completed GCs", completed_gcs);
+ 
+   size_t explicit_requests = 0;
+   size_t implicit_requests = 0;
+   for (int c = 0; c < GCCause::_last_gc_cause; c++) {
+     size_t cause_count = _collection_cause_counts[c];
+     if (cause_count > 0) {
+       auto cause = (GCCause::Cause) c;
+       if (is_explicit_gc(cause)) {
+         explicit_requests += cause_count;
+       } else if (is_implicit_gc(cause)) {
+         implicit_requests += cause_count;
+       }
+       const char* desc = GCCause::to_string(cause);
+       out->print_cr("  " SIZE_FORMAT_W(5) " caused by %s (%.2f%%)", cause_count, desc, percent_of(cause_count, completed_gcs));
+     }
+   }
+ 
    out->cr();
+   out->print_cr(SIZE_FORMAT_W(5) " Successful Concurrent GCs (%.2f%%)", _success_concurrent_gcs, percent_of(_success_concurrent_gcs, completed_gcs));
+   if (ExplicitGCInvokesConcurrent) {
+     out->print_cr("  " SIZE_FORMAT_W(5) " invoked explicitly (%.2f%%)", explicit_requests, percent_of(explicit_requests, _success_concurrent_gcs));
+   }
+   if (ShenandoahImplicitGCInvokesConcurrent) {
+     out->print_cr("  " SIZE_FORMAT_W(5) " invoked implicitly (%.2f%%)", implicit_requests, percent_of(implicit_requests, _success_concurrent_gcs));
+   }
+   out->print_cr("  " SIZE_FORMAT_W(5) " abbreviated (%.2f%%)",  _abbreviated_concurrent_gcs, percent_of(_abbreviated_concurrent_gcs, _success_concurrent_gcs));
+   out->cr();
+ 
+   if (ShenandoahHeap::heap()->mode()->is_generational()) {
+     out->print_cr(SIZE_FORMAT_W(5) " Completed Old GCs (%.2f%%)",        _success_old_gcs, percent_of(_success_old_gcs, completed_gcs));
+     out->print_cr("  " SIZE_FORMAT_W(5) " mixed",                        _mixed_gcs);
+     out->print_cr("  " SIZE_FORMAT_W(5) " interruptions",                _interrupted_old_gcs);
+     out->cr();
+   }
  
-   out->print_cr(SIZE_FORMAT_W(5) " Degenerated GCs",                   _success_degenerated_gcs);
-   out->print_cr("  " SIZE_FORMAT_W(5) " caused by allocation failure", _alloc_failure_degenerated);
+   size_t degenerated_gcs = _alloc_failure_degenerated_upgrade_to_full + _success_degenerated_gcs;
+   out->print_cr(SIZE_FORMAT_W(5) " Degenerated GCs (%.2f%%)", degenerated_gcs, percent_of(degenerated_gcs, completed_gcs));
+   out->print_cr("  " SIZE_FORMAT_W(5) " upgraded to Full GC (%.2f%%)",          _alloc_failure_degenerated_upgrade_to_full, percent_of(_alloc_failure_degenerated_upgrade_to_full, degenerated_gcs));
+   out->print_cr("  " SIZE_FORMAT_W(5) " caused by allocation failure (%.2f%%)", _alloc_failure_degenerated, percent_of(_alloc_failure_degenerated, degenerated_gcs));
+   out->print_cr("  " SIZE_FORMAT_W(5) " abbreviated (%.2f%%)",                  _abbreviated_degenerated_gcs, percent_of(_abbreviated_degenerated_gcs, degenerated_gcs));
    for (int c = 0; c < ShenandoahGC::_DEGENERATED_LIMIT; c++) {
-     if (_degen_points[c] > 0) {
+     if (_degen_point_counts[c] > 0) {
        const char* desc = ShenandoahGC::degen_point_to_string((ShenandoahGC::ShenandoahDegenPoint)c);
-       out->print_cr("    " SIZE_FORMAT_W(5) " happened at %s",         _degen_points[c], desc);
+       out->print_cr("    " SIZE_FORMAT_W(5) " happened at %s", _degen_point_counts[c], desc);
      }
    }
-   out->print_cr("  " SIZE_FORMAT_W(5) " upgraded to Full GC",          _alloc_failure_degenerated_upgrade_to_full);
    out->cr();
  
-   out->print_cr(SIZE_FORMAT_W(5) " Full GCs",                          _success_full_gcs + _alloc_failure_degenerated_upgrade_to_full);
-   out->print_cr("  " SIZE_FORMAT_W(5) " invoked explicitly",           _explicit_full);
-   out->print_cr("  " SIZE_FORMAT_W(5) " invoked implicitly",           _implicit_full);
-   out->print_cr("  " SIZE_FORMAT_W(5) " caused by allocation failure", _alloc_failure_full);
-   out->print_cr("  " SIZE_FORMAT_W(5) " upgraded from Degenerated GC", _alloc_failure_degenerated_upgrade_to_full);
+   out->print_cr(SIZE_FORMAT_W(5) " Full GCs (%.2f%%)", _success_full_gcs, percent_of(_success_full_gcs, completed_gcs));
+   if (!ExplicitGCInvokesConcurrent) {
+     out->print_cr("  " SIZE_FORMAT_W(5) " invoked explicitly (%.2f%%)", explicit_requests, percent_of(explicit_requests, _success_concurrent_gcs));
+   }
+   if (!ShenandoahImplicitGCInvokesConcurrent) {
+     out->print_cr("  " SIZE_FORMAT_W(5) " invoked implicitly (%.2f%%)", implicit_requests, percent_of(implicit_requests, _success_concurrent_gcs));
+   }
+   out->print_cr("  " SIZE_FORMAT_W(5) " caused by allocation failure (%.2f%%)", _alloc_failure_full, percent_of(_alloc_failure_full, _success_full_gcs));
+   out->print_cr("  " SIZE_FORMAT_W(5) " upgraded from Degenerated GC (%.2f%%)", _alloc_failure_degenerated_upgrade_to_full, percent_of(_alloc_failure_degenerated_upgrade_to_full, _success_full_gcs));
  }
< prev index next >