< prev index next >

src/hotspot/share/gc/shenandoah/heuristics/shenandoahAdaptiveHeuristics.hpp

Print this page

  1 /*
  2  * Copyright (c) 2018, 2019, 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_HEURISTICS_SHENANDOAHADAPTIVEHEURISTICS_HPP
 26 #define SHARE_GC_SHENANDOAH_HEURISTICS_SHENANDOAHADAPTIVEHEURISTICS_HPP
 27 

 28 #include "gc/shenandoah/heuristics/shenandoahHeuristics.hpp"
 29 #include "gc/shenandoah/shenandoahPhaseTimings.hpp"

 30 #include "utilities/numberSeq.hpp"
 31 
 32 class ShenandoahAllocationRate : public CHeapObj<mtGC> {
 33  public:
 34   explicit ShenandoahAllocationRate();
 35   void allocation_counter_reset();
 36 
 37   double sample(size_t allocated);
 38 
 39   double upper_bound(double sds) const;
 40   bool is_spiking(double rate, double threshold) const;
 41 
 42  private:
 43 
 44   double instantaneous_rate(double time, size_t allocated) const;
 45 
 46   double _last_sample_time;
 47   size_t _last_sample_value;
 48   double _interval_sec;
 49   TruncatedSeq _rate;
 50   TruncatedSeq _rate_avg;
 51 };
 52 











 53 class ShenandoahAdaptiveHeuristics : public ShenandoahHeuristics {
 54 public:
 55   ShenandoahAdaptiveHeuristics();
 56 
 57   virtual ~ShenandoahAdaptiveHeuristics();
 58 
 59   virtual void choose_collection_set_from_regiondata(ShenandoahCollectionSet* cset,
 60                                                      RegionData* data, size_t size,
 61                                                      size_t actual_free);
 62 
 63   void record_cycle_start();
 64   void record_success_concurrent();
 65   void record_success_degenerated();
 66   void record_success_full();
 67 
 68   virtual bool should_start_gc();
 69 
 70   virtual const char* name()     { return "Adaptive"; }
 71   virtual bool is_diagnostic()   { return false; }
 72   virtual bool is_experimental() { return false; }
 73 
 74  private:
 75   // These are used to adjust the margin of error and the spike threshold

 81   const static double MINIMUM_CONFIDENCE;
 82   const static double MAXIMUM_CONFIDENCE;
 83 
 84   const static double LOWEST_EXPECTED_AVAILABLE_AT_END;
 85   const static double HIGHEST_EXPECTED_AVAILABLE_AT_END;
 86 
 87   friend class ShenandoahAllocationRate;
 88 
 89   // Used to record the last trigger that signaled to start a GC.
 90   // This itself is used to decide whether or not to adjust the margin of
 91   // error for the average cycle time and allocation rate or the allocation
 92   // spike detection threshold.
 93   enum Trigger {
 94     SPIKE, RATE, OTHER
 95   };
 96 
 97   void adjust_last_trigger_parameters(double amount);
 98   void adjust_margin_of_error(double amount);
 99   void adjust_spike_threshold(double amount);
100 

101   ShenandoahAllocationRate _allocation_rate;
102 
103   // The margin of error expressed in standard deviations to add to our
104   // average cycle time and allocation rate. As this value increases we
105   // tend to over estimate the rate at which mutators will deplete the
106   // heap. In other words, erring on the side of caution will trigger more
107   // concurrent GCs.
108   double _margin_of_error_sd;
109 
110   // The allocation spike threshold is expressed in standard deviations.
111   // If the standard deviation of the most recent sample of the allocation
112   // rate exceeds this threshold, a GC cycle is started. As this value
113   // decreases the sensitivity to allocation spikes increases. In other
114   // words, lowering the spike threshold will tend to increase the number
115   // of concurrent GCs.
116   double _spike_threshold_sd;
117 
118   // Remember which trigger is responsible for the last GC cycle. When the
119   // outcome of the cycle is evaluated we will adjust the parameters for the
120   // corresponding triggers. Note that successful outcomes will raise
121   // the spike threshold and lower the margin of error.
122   Trigger _last_trigger;
123 
124   // Keep track of the available memory at the end of a GC cycle. This
125   // establishes what is 'normal' for the application and is used as a
126   // source of feedback to adjust trigger parameters.
127   TruncatedSeq _available;






128 };
129 
130 #endif // SHARE_GC_SHENANDOAH_HEURISTICS_SHENANDOAHADAPTIVEHEURISTICS_HPP

  1 /*
  2  * Copyright (c) 2018, 2019, 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_HEURISTICS_SHENANDOAHADAPTIVEHEURISTICS_HPP
 27 #define SHARE_GC_SHENANDOAH_HEURISTICS_SHENANDOAHADAPTIVEHEURISTICS_HPP
 28 
 29 #include "memory/allocation.hpp"
 30 #include "gc/shenandoah/heuristics/shenandoahHeuristics.hpp"
 31 #include "gc/shenandoah/shenandoahPhaseTimings.hpp"
 32 #include "gc/shenandoah/shenandoahSharedVariables.hpp"
 33 #include "utilities/numberSeq.hpp"
 34 
 35 class ShenandoahAllocationRate : public CHeapObj<mtGC> {
 36  public:
 37   explicit ShenandoahAllocationRate();
 38   void allocation_counter_reset();
 39 
 40   double sample(size_t allocated);
 41 
 42   double upper_bound(double sds) const;
 43   bool is_spiking(double rate, double threshold) const;

 44  private:
 45 
 46   double instantaneous_rate(double time, size_t allocated) const;
 47 
 48   double _last_sample_time;
 49   size_t _last_sample_value;
 50   double _interval_sec;
 51   TruncatedSeq _rate;
 52   TruncatedSeq _rate_avg;
 53 };
 54 
 55 /*
 56  * The adaptive heuristic tracks the allocation behavior and average cycle
 57  * time of the application. It attempts to start a cycle with enough time
 58  * to complete before the available memory is exhausted. It errors on the
 59  * side of starting cycles early to avoid allocation failures (degenerated
 60  * cycles).
 61  *
 62  * This heuristic limits the number of regions for evacuation such that the
 63  * evacuation reserve is respected. This helps it avoid allocation failures
 64  * during evacuation. It preferentially selects regions with the most garbage.
 65  */
 66 class ShenandoahAdaptiveHeuristics : public ShenandoahHeuristics {
 67 public:
 68   ShenandoahAdaptiveHeuristics(ShenandoahSpaceInfo* space_info);
 69 
 70   virtual ~ShenandoahAdaptiveHeuristics();
 71 
 72   virtual void choose_collection_set_from_regiondata(ShenandoahCollectionSet* cset,
 73                                                      RegionData* data, size_t size,
 74                                                      size_t actual_free);
 75 
 76   void record_cycle_start();
 77   void record_success_concurrent();
 78   void record_success_degenerated();
 79   void record_success_full();
 80 
 81   virtual bool should_start_gc();
 82 
 83   virtual const char* name()     { return "Adaptive"; }
 84   virtual bool is_diagnostic()   { return false; }
 85   virtual bool is_experimental() { return false; }
 86 
 87  private:
 88   // These are used to adjust the margin of error and the spike threshold

 94   const static double MINIMUM_CONFIDENCE;
 95   const static double MAXIMUM_CONFIDENCE;
 96 
 97   const static double LOWEST_EXPECTED_AVAILABLE_AT_END;
 98   const static double HIGHEST_EXPECTED_AVAILABLE_AT_END;
 99 
100   friend class ShenandoahAllocationRate;
101 
102   // Used to record the last trigger that signaled to start a GC.
103   // This itself is used to decide whether or not to adjust the margin of
104   // error for the average cycle time and allocation rate or the allocation
105   // spike detection threshold.
106   enum Trigger {
107     SPIKE, RATE, OTHER
108   };
109 
110   void adjust_last_trigger_parameters(double amount);
111   void adjust_margin_of_error(double amount);
112   void adjust_spike_threshold(double amount);
113 
114 protected:
115   ShenandoahAllocationRate _allocation_rate;
116 
117   // The margin of error expressed in standard deviations to add to our
118   // average cycle time and allocation rate. As this value increases we
119   // tend to overestimate the rate at which mutators will deplete the
120   // heap. In other words, erring on the side of caution will trigger more
121   // concurrent GCs.
122   double _margin_of_error_sd;
123 
124   // The allocation spike threshold is expressed in standard deviations.
125   // If the standard deviation of the most recent sample of the allocation
126   // rate exceeds this threshold, a GC cycle is started. As this value
127   // decreases the sensitivity to allocation spikes increases. In other
128   // words, lowering the spike threshold will tend to increase the number
129   // of concurrent GCs.
130   double _spike_threshold_sd;
131 
132   // Remember which trigger is responsible for the last GC cycle. When the
133   // outcome of the cycle is evaluated we will adjust the parameters for the
134   // corresponding triggers. Note that successful outcomes will raise
135   // the spike threshold and lower the margin of error.
136   Trigger _last_trigger;
137 
138   // Keep track of the available memory at the end of a GC cycle. This
139   // establishes what is 'normal' for the application and is used as a
140   // source of feedback to adjust trigger parameters.
141   TruncatedSeq _available;
142 
143   // A conservative minimum threshold of free space that we'll try to maintain when possible.
144   // For example, we might trigger a concurrent gc if we are likely to drop below
145   // this threshold, or we might consider this when dynamically resizing generations
146   // in the generational case. Controlled by global flag ShenandoahMinFreeThreshold.
147   size_t min_free_threshold();
148 };
149 
150 #endif // SHARE_GC_SHENANDOAH_HEURISTICS_SHENANDOAHADAPTIVEHEURISTICS_HPP
< prev index next >