# HG changeset patch # User shade # Date 1582617759 -3600 # Tue Feb 25 09:02:39 2020 +0100 # Node ID 647fd0e9762f142f5981eafdb0bde47e9019648a # Parent d33754052039af3923b24932c4bb830a7fb7ffc5 8239904: Shenandoah: accumulated penalties should not be over 100% of capacity Reviewed-by: XXX diff --git a/src/hotspot/share/gc/shenandoah/shenandoahHeuristics.cpp b/src/hotspot/share/gc/shenandoah/shenandoahHeuristics.cpp --- a/src/hotspot/share/gc/shenandoah/shenandoahHeuristics.cpp +++ b/src/hotspot/share/gc/shenandoah/shenandoahHeuristics.cpp @@ -261,25 +261,45 @@ return _degenerated_cycles_in_a_row <= ShenandoahFullGCThreshold; } +void ShenandoahHeuristics::adjust_penalty(intx step) { + assert(0 <= _gc_time_penalties && _gc_time_penalties <= 100, + "In range before adjustment: " INTX_FORMAT, _gc_time_penalties); + + intx new_val = _gc_time_penalties + step; + if (new_val < 0) { + new_val = 0; + } + if (new_val > 100) { + new_val = 100; + } + _gc_time_penalties = new_val; + + assert(0 <= _gc_time_penalties && _gc_time_penalties <= 100, + "In range after adjustment: " INTX_FORMAT, _gc_time_penalties); +} + void ShenandoahHeuristics::record_success_concurrent() { _degenerated_cycles_in_a_row = 0; _successful_cycles_in_a_row++; _gc_time_history->add(time_since_last_gc()); _gc_times_learned++; - _gc_time_penalties -= MIN2(_gc_time_penalties, Concurrent_Adjust); + + adjust_penalty(Concurrent_Adjust); } void ShenandoahHeuristics::record_success_degenerated() { _degenerated_cycles_in_a_row++; _successful_cycles_in_a_row = 0; - _gc_time_penalties += Degenerated_Penalty; + + adjust_penalty(Degenerated_Penalty); } void ShenandoahHeuristics::record_success_full() { _degenerated_cycles_in_a_row = 0; _successful_cycles_in_a_row++; - _gc_time_penalties += Full_Penalty; + + adjust_penalty(Full_Penalty); } void ShenandoahHeuristics::record_allocation_failure_gc() { diff --git a/src/hotspot/share/gc/shenandoah/shenandoahHeuristics.hpp b/src/hotspot/share/gc/shenandoah/shenandoahHeuristics.hpp --- a/src/hotspot/share/gc/shenandoah/shenandoahHeuristics.hpp +++ b/src/hotspot/share/gc/shenandoah/shenandoahHeuristics.hpp @@ -67,7 +67,7 @@ class ShenandoahHeapRegion; class ShenandoahHeuristics : public CHeapObj { - static const intx Concurrent_Adjust = 1; // recover from penalties + static const intx Concurrent_Adjust = -1; // recover from penalties static const intx Degenerated_Penalty = 10; // how much to penalize average GC duration history on Degenerated GC static const intx Full_Penalty = 20; // how much to penalize average GC duration history on Full GC @@ -93,7 +93,7 @@ double _last_cycle_end; size_t _gc_times_learned; - size_t _gc_time_penalties; + intx _gc_time_penalties; TruncatedSeq* _gc_time_history; // There may be many threads that contend to set this flag @@ -110,6 +110,8 @@ RegionData* data, size_t data_size, size_t free) = 0; + void adjust_penalty(intx step); + public: ShenandoahHeuristics(); virtual ~ShenandoahHeuristics();