< prev index next >

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

Print this page

  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_SHENANDOAHHEURISTICS_HPP
 26 #define SHARE_GC_SHENANDOAH_HEURISTICS_SHENANDOAHHEURISTICS_HPP
 27 
 28 #include "gc/shenandoah/shenandoahHeap.hpp"
 29 #include "gc/shenandoah/shenandoahPhaseTimings.hpp"
 30 #include "gc/shenandoah/shenandoahSharedVariables.hpp"
 31 #include "memory/allocation.hpp"
 32 #include "runtime/globals_extension.hpp"
 33 
 34 #define SHENANDOAH_ERGO_DISABLE_FLAG(name)                                  \
 35   do {                                                                      \
 36     if (FLAG_IS_DEFAULT(name) && (name)) {                                  \
 37       log_info(gc)("Heuristics ergonomically sets -XX:-" #name);            \
 38       FLAG_SET_DEFAULT(name, false);                                        \
 39     }                                                                       \
 40   } while (0)
 41 
 42 #define SHENANDOAH_ERGO_ENABLE_FLAG(name)                                   \
 43   do {                                                                      \
 44     if (FLAG_IS_DEFAULT(name) && !(name)) {                                 \
 45       log_info(gc)("Heuristics ergonomically sets -XX:+" #name);            \
 46       FLAG_SET_DEFAULT(name, true);                                         \
 47     }                                                                       \
 48   } while (0)
 49 
 50 #define SHENANDOAH_ERGO_OVERRIDE_DEFAULT(name, value)                       \
 51   do {                                                                      \
 52     if (FLAG_IS_DEFAULT(name)) {                                            \
 53       log_info(gc)("Heuristics ergonomically sets -XX:" #name "=" #value);  \
 54       FLAG_SET_DEFAULT(name, value);                                        \
 55     }                                                                       \
 56   } while (0)
 57 
 58 class ShenandoahCollectionSet;
 59 class ShenandoahHeapRegion;


 60 
 61 class ShenandoahHeuristics : public CHeapObj<mtGC> {
 62   static const intx Concurrent_Adjust   = -1; // recover from penalties
 63   static const intx Degenerated_Penalty = 10; // how much to penalize average GC duration history on Degenerated GC
 64   static const intx Full_Penalty        = 20; // how much to penalize average GC duration history on Full GC
 65 
 66 protected:


 67   typedef struct {
 68     ShenandoahHeapRegion* _region;
 69     size_t _garbage;
 70   } RegionData;
 71 















 72   RegionData* _region_data;
 73 
 74   uint _degenerated_cycles_in_a_row;
 75   uint _successful_cycles_in_a_row;
 76 


 77   double _cycle_start;
 78   double _last_cycle_end;
 79 
 80   size_t _gc_times_learned;
 81   intx _gc_time_penalties;
 82   TruncatedSeq* _gc_time_history;
 83 
 84   // There may be many threads that contend to set this flag
 85   ShenandoahSharedFlag _metaspace_oom;
 86 
 87   static int compare_by_garbage(RegionData a, RegionData b);
 88 




 89   virtual void choose_collection_set_from_regiondata(ShenandoahCollectionSet* set,
 90                                                      RegionData* data, size_t data_size,
 91                                                      size_t free) = 0;
 92 
 93   void adjust_penalty(intx step);
 94 




 95 public:
 96   ShenandoahHeuristics();
 97   virtual ~ShenandoahHeuristics();
 98 
 99   void record_metaspace_oom()     { _metaspace_oom.set(); }
100   void clear_metaspace_oom()      { _metaspace_oom.unset(); }
101   bool has_metaspace_oom() const  { return _metaspace_oom.is_set(); }
102 








103   virtual void record_cycle_start();
104 
105   virtual void record_cycle_end();
106 
107   virtual bool should_start_gc();
108 
109   virtual bool should_degenerate_cycle();
110 
111   virtual void record_success_concurrent();
112 
113   virtual void record_success_degenerated();
114 
115   virtual void record_success_full();
116 
117   virtual void record_allocation_failure_gc();
118 
119   virtual void record_requested_gc();
120 
121   virtual void choose_collection_set(ShenandoahCollectionSet* collection_set);




122 
123   virtual bool can_unload_classes();
124   virtual bool can_unload_classes_normal();
125   virtual bool should_unload_classes();
126 
127   virtual const char* name() = 0;
128   virtual bool is_diagnostic() = 0;
129   virtual bool is_experimental() = 0;
130   virtual void initialize();
131 
132   double time_since_last_gc() const;
133 };
134 
135 #endif // SHARE_GC_SHENANDOAH_HEURISTICS_SHENANDOAHHEURISTICS_HPP

  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_SHENANDOAHHEURISTICS_HPP
 26 #define SHARE_GC_SHENANDOAH_HEURISTICS_SHENANDOAHHEURISTICS_HPP
 27 

 28 #include "gc/shenandoah/shenandoahPhaseTimings.hpp"
 29 #include "gc/shenandoah/shenandoahSharedVariables.hpp"
 30 #include "memory/allocation.hpp"
 31 #include "runtime/globals_extension.hpp"
 32 
 33 #define SHENANDOAH_ERGO_DISABLE_FLAG(name)                                  \
 34   do {                                                                      \
 35     if (FLAG_IS_DEFAULT(name) && (name)) {                                  \
 36       log_info(gc)("Heuristics ergonomically sets -XX:-" #name);            \
 37       FLAG_SET_DEFAULT(name, false);                                        \
 38     }                                                                       \
 39   } while (0)
 40 
 41 #define SHENANDOAH_ERGO_ENABLE_FLAG(name)                                   \
 42   do {                                                                      \
 43     if (FLAG_IS_DEFAULT(name) && !(name)) {                                 \
 44       log_info(gc)("Heuristics ergonomically sets -XX:+" #name);            \
 45       FLAG_SET_DEFAULT(name, true);                                         \
 46     }                                                                       \
 47   } while (0)
 48 
 49 #define SHENANDOAH_ERGO_OVERRIDE_DEFAULT(name, value)                       \
 50   do {                                                                      \
 51     if (FLAG_IS_DEFAULT(name)) {                                            \
 52       log_info(gc)("Heuristics ergonomically sets -XX:" #name "=" #value);  \
 53       FLAG_SET_DEFAULT(name, value);                                        \
 54     }                                                                       \
 55   } while (0)
 56 
 57 class ShenandoahCollectionSet;
 58 class ShenandoahHeapRegion;
 59 class ShenandoahGeneration;
 60 class ShenandoahOldHeuristics;
 61 
 62 class ShenandoahHeuristics : public CHeapObj<mtGC> {
 63   static const intx Concurrent_Adjust   = -1; // recover from penalties
 64   static const intx Degenerated_Penalty = 10; // how much to penalize average GC duration history on Degenerated GC
 65   static const intx Full_Penalty        = 20; // how much to penalize average GC duration history on Full GC
 66 
 67 protected:
 68   static const uint Moving_Average_Samples = 10; // Number of samples to store in moving averages
 69 
 70   typedef struct {
 71     ShenandoahHeapRegion* _region;
 72     size_t _garbage;
 73   } RegionData;
 74 
 75   ShenandoahGeneration* _generation;
 76 
 77   // if (_generation->generation_mode() == GLOBAL) _region_data represents
 78   //  the results of most recently completed global marking pass
 79   // if (_generation->generation_mode() == OLD) _region_data represents
 80   //  the results of most recently completed old-gen marking pass
 81   // if (_generation->generation_mode() == YOUNG) _region_data represents
 82   //  the results of most recently completed young-gen marking pass
 83   //
 84   // Note that there is some redundancy represented in _region_data because
 85   // each instance is an array large enough to hold all regions.  However,
 86   // any region in young-gen is not in old-gen.  And any time we are
 87   // making use of the GLOBAL data, there is no need to maintain the
 88   // YOUNG or OLD data.  Consider this redundancy of data structure to
 89   // have negligible cost unless proven otherwise.
 90   RegionData* _region_data;
 91 
 92   uint _degenerated_cycles_in_a_row;
 93   uint _successful_cycles_in_a_row;
 94 
 95   size_t _guaranteed_gc_interval;
 96 
 97   double _cycle_start;
 98   double _last_cycle_end;
 99 
100   size_t _gc_times_learned;
101   intx _gc_time_penalties;
102   TruncatedSeq* _gc_cycle_time_history;
103 
104   // There may be many threads that contend to set this flag
105   ShenandoahSharedFlag _metaspace_oom;
106 
107   static int compare_by_garbage(RegionData a, RegionData b);
108 
109   // TODO: We need to enhance this API to give visibility to accompanying old-gen evacuation effort.
110   // In the case that the old-gen evacuation effort is small or zero, the young-gen heuristics
111   // should feel free to dedicate increased efforts to young-gen evacuation.
112 
113   virtual void choose_collection_set_from_regiondata(ShenandoahCollectionSet* set,
114                                                      RegionData* data, size_t data_size,
115                                                      size_t free) = 0;
116 
117   void adjust_penalty(intx step);
118 
119   bool in_generation(ShenandoahHeapRegion* region);
120 
121   size_t min_free_threshold();
122 
123 public:
124   ShenandoahHeuristics(ShenandoahGeneration* generation);
125   virtual ~ShenandoahHeuristics();
126 
127   void record_metaspace_oom()     { _metaspace_oom.set(); }
128   void clear_metaspace_oom()      { _metaspace_oom.unset(); }
129   bool has_metaspace_oom() const  { return _metaspace_oom.is_set(); }
130 
131   void set_guaranteed_gc_interval(size_t guaranteed_gc_interval) {
132     _guaranteed_gc_interval = guaranteed_gc_interval;
133   }
134 
135   uint degenerated_cycles_in_a_row() {
136     return _degenerated_cycles_in_a_row;
137   }
138 
139   virtual void record_cycle_start();
140 
141   virtual void record_cycle_end();
142 
143   virtual bool should_start_gc();
144 
145   virtual bool should_degenerate_cycle();
146 
147   virtual void record_success_concurrent(bool abbreviated);
148 
149   virtual void record_success_degenerated();
150 
151   virtual void record_success_full();
152 
153   virtual void record_allocation_failure_gc();
154 
155   virtual void record_requested_gc();
156 
157   virtual void reset_gc_learning();
158 
159   virtual size_t select_aged_regions(size_t old_available, size_t num_regions, bool preselected_regions[]);
160 
161   virtual void choose_collection_set(ShenandoahCollectionSet* collection_set, ShenandoahOldHeuristics* old_heuristics);
162 
163   virtual bool can_unload_classes();
164   virtual bool can_unload_classes_normal();
165   virtual bool should_unload_classes();
166 
167   virtual const char* name() = 0;
168   virtual bool is_diagnostic() = 0;
169   virtual bool is_experimental() = 0;
170   virtual void initialize();
171 
172   double elapsed_cycle_time() const;
173 };
174 
175 #endif // SHARE_GC_SHENANDOAH_HEURISTICS_SHENANDOAHHEURISTICS_HPP
< prev index next >