< 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   typedef struct {
 69     ShenandoahHeapRegion* _region;
 70     size_t _garbage;
 71   } RegionData;
 72 
 73   ShenandoahGeneration* _generation;
 74 
 75   // if (_generation->generation_mode() == GLOBAL) _region_data represents
 76   //  the results of most recently completed global marking pass
 77   // if (_generation->generation_mode() == OLD) _region_data represents
 78   //  the results of most recently completed old-gen marking pass
 79   // if (_generation->generation_mode() == YOUNG) _region_data represents
 80   //  the resulits of most recently completed young-gen marking pass
 81   //
 82   // Note that there is some redundancy represented in _region_data because
 83   // each instance is an array large enough to hold all regions.  However,
 84   // any region in young-gen is not in old-gen.  And any time we are
 85   // making use of the GLOBAL data, there is no need to maintain the
 86   // YOUNG or OLD data.  Consider this redundancy of data structure to
 87   // have negligible cost unless proven otherwise.
 88   RegionData* _region_data;
 89 
 90   uint _degenerated_cycles_in_a_row;
 91   uint _successful_cycles_in_a_row;
 92 
 93   size_t _guaranteed_gc_interval;
 94 
 95   double _cycle_start;
 96   double _last_cycle_end;
 97 
 98   size_t _gc_times_learned;
 99   intx _gc_time_penalties;
100   TruncatedSeq* _gc_time_history;
101 
102   // There may be many threads that contend to set this flag
103   ShenandoahSharedFlag _metaspace_oom;
104 
105   static int compare_by_garbage(RegionData a, RegionData b);
106 
107   // TODO: We need to enhance this API to give visibility to accompanying old-gen evacuation effort.
108   // In the case that the old-gen evacuation effort is small or zero, the young-gen heuristics
109   // should feel free to dedicate increased efforts to young-gen evacuation.
110 
111   virtual void choose_collection_set_from_regiondata(ShenandoahCollectionSet* set,
112                                                      RegionData* data, size_t data_size,
113                                                      size_t free) = 0;
114 
115   void adjust_penalty(intx step);
116 
117   bool in_generation(ShenandoahHeapRegion* region);
118 
119 public:
120   ShenandoahHeuristics(ShenandoahGeneration* generation);
121   virtual ~ShenandoahHeuristics();
122 
123   void record_metaspace_oom()     { _metaspace_oom.set(); }
124   void clear_metaspace_oom()      { _metaspace_oom.unset(); }
125   bool has_metaspace_oom() const  { return _metaspace_oom.is_set(); }
126 
127   void set_guaranteed_gc_interval(size_t guaranteed_gc_interval) {
128     _guaranteed_gc_interval = guaranteed_gc_interval;
129   }
130 
131   virtual void record_cycle_start();
132 
133   virtual void record_cycle_end();
134 
135   virtual bool should_start_gc();
136 
137   virtual bool should_degenerate_cycle();
138 
139   virtual void record_success_concurrent();
140 
141   virtual void record_success_degenerated();
142 
143   virtual void record_success_full();
144 
145   virtual void record_allocation_failure_gc();
146 
147   virtual void record_requested_gc();
148 
149   // Return true iff the chosen collection set includes at least one old-gen region.
150   virtual bool choose_collection_set(ShenandoahCollectionSet* collection_set, ShenandoahOldHeuristics* old_heuristics);
151 
152   virtual bool can_unload_classes();
153   virtual bool can_unload_classes_normal();
154   virtual bool should_unload_classes();
155 
156   virtual const char* name() = 0;
157   virtual bool is_diagnostic() = 0;
158   virtual bool is_experimental() = 0;
159   virtual void initialize();
160 
161   double time_since_last_gc() const;
162 };
163 
164 #endif // SHARE_GC_SHENANDOAH_HEURISTICS_SHENANDOAHHEURISTICS_HPP
< prev index next >