< prev index next >

src/hotspot/share/gc/shenandoah/heuristics/shenandoahTraversalHeuristics.cpp

Print this page




  24 #include "precompiled.hpp"
  25 
  26 #include "gc/shenandoah/heuristics/shenandoahTraversalHeuristics.hpp"
  27 #include "gc/shenandoah/shenandoahCollectionSet.hpp"
  28 #include "gc/shenandoah/shenandoahFreeSet.hpp"
  29 #include "gc/shenandoah/shenandoahHeap.inline.hpp"
  30 #include "gc/shenandoah/shenandoahHeuristics.hpp"
  31 #include "gc/shenandoah/shenandoahTraversalGC.hpp"
  32 #include "logging/log.hpp"
  33 #include "logging/logTag.hpp"
  34 #include "utilities/quickSort.hpp"
  35 
  36 ShenandoahTraversalHeuristics::ShenandoahTraversalHeuristics() : ShenandoahHeuristics(),
  37   _last_cset_select(0)
  38  {
  39   FLAG_SET_DEFAULT(ShenandoahSATBBarrier,            false);
  40   FLAG_SET_DEFAULT(ShenandoahStoreValEnqueueBarrier, true);
  41   FLAG_SET_DEFAULT(ShenandoahKeepAliveBarrier,       false);
  42   FLAG_SET_DEFAULT(ShenandoahAllowMixedAllocs,       false);
  43 







  44   SHENANDOAH_ERGO_ENABLE_FLAG(ExplicitGCInvokesConcurrent);
  45   SHENANDOAH_ERGO_ENABLE_FLAG(ShenandoahImplicitGCInvokesConcurrent);
  46 
  47   // Final configuration checks
  48   SHENANDOAH_CHECK_FLAG_SET(ShenandoahLoadRefBarrier);
  49   SHENANDOAH_CHECK_FLAG_SET(ShenandoahStoreValEnqueueBarrier);
  50   SHENANDOAH_CHECK_FLAG_SET(ShenandoahCASBarrier);
  51   SHENANDOAH_CHECK_FLAG_SET(ShenandoahCloneBarrier);
  52 }
  53 
  54 bool ShenandoahTraversalHeuristics::should_start_normal_gc() const {
  55   return false;
  56 }
  57 
  58 bool ShenandoahTraversalHeuristics::is_experimental() {
  59   return true;
  60 }
  61 
  62 bool ShenandoahTraversalHeuristics::is_diagnostic() {
  63   return false;


 100   // The logic for cset selection is similar to that of adaptive:
 101   //
 102   //   1. We cannot get cset larger than available free space. Otherwise we guarantee OOME
 103   //      during evacuation, and thus guarantee full GC. In practice, we also want to let
 104   //      application to allocate something. This is why we limit CSet to some fraction of
 105   //      available space. In non-overloaded heap, max_cset would contain all plausible candidates
 106   //      over garbage threshold.
 107   //
 108   //   2. We should not get cset too low so that free threshold would not be met right
 109   //      after the cycle. Otherwise we get back-to-back cycles for no reason if heap is
 110   //      too fragmented. In non-overloaded non-fragmented heap min_garbage would be around zero.
 111   //
 112   // Therefore, we start by sorting the regions by garbage. Then we unconditionally add the best candidates
 113   // before we meet min_garbage. Then we add all candidates that fit with a garbage threshold before
 114   // we hit max_cset. When max_cset is hit, we terminate the cset selection. Note that in this scheme,
 115   // ShenandoahGarbageThreshold is the soft threshold which would be ignored until min_garbage is hit.
 116   //
 117   // The significant complication is that liveness data was collected at the previous cycle, and only
 118   // for those regions that were allocated before previous cycle started.
 119 
 120   size_t capacity    = heap->max_capacity();
 121   size_t actual_free = heap->free_set()->available();
 122   size_t free_target = capacity / 100 * ShenandoahMinFreeThreshold;
 123   size_t min_garbage = free_target > actual_free ? (free_target - actual_free) : 0;
 124   size_t max_cset    = (size_t)((1.0 * capacity / 100 * ShenandoahEvacReserve) / ShenandoahEvacWaste);
 125 
 126   log_info(gc, ergo)("Adaptive CSet Selection. Target Free: " SIZE_FORMAT "M, Actual Free: "
 127                      SIZE_FORMAT "M, Max CSet: " SIZE_FORMAT "M, Min Garbage: " SIZE_FORMAT "M",
 128                      free_target / M, actual_free / M, max_cset / M, min_garbage / M);
 129 
 130   // Better select garbage-first regions, and then older ones
 131   QuickSort::sort<RegionData>(data, (int) cnt, compare_by_garbage_then_alloc_seq_ascending, false);
 132 
 133   size_t cur_cset = 0;
 134   size_t cur_garbage = 0;
 135 
 136   size_t garbage_threshold = ShenandoahHeapRegion::region_size_bytes() / 100 * ShenandoahGarbageThreshold;
 137 
 138   // Step 1. Add trustworthy regions to collection set.
 139   //
 140   // We can trust live/garbage data from regions that were fully traversed during
 141   // previous cycle. Even if actual liveness is different now, we can only have _less_
 142   // live objects, because dead objects are not resurrected. Which means we can undershoot
 143   // the collection set, but not overshoot it.
 144 


 189   }
 190 
 191   // Step 3. Clear liveness data
 192   // TODO: Merge it with step 0, but save live data in RegionData before.
 193   for (size_t i = 0; i < heap->num_regions(); i++) {
 194     ShenandoahHeapRegion* r = heap->get_region(i);
 195     if (r->used() > 0) {
 196       r->clear_live_data();
 197     }
 198   }
 199 
 200   collection_set->update_region_status();
 201 
 202   _last_cset_select = ShenandoahHeapRegion::seqnum_current_alloc();
 203 }
 204 
 205 bool ShenandoahTraversalHeuristics::should_start_traversal_gc() {
 206   ShenandoahHeap* heap = ShenandoahHeap::heap();
 207   assert(!heap->has_forwarded_objects(), "no forwarded objects here");
 208 
 209   size_t capacity = heap->max_capacity();
 210   size_t available = heap->free_set()->available();
 211 
 212   // Check if we are falling below the worst limit, time to trigger the GC, regardless of
 213   // anything else.
 214   size_t min_threshold = capacity / 100 * ShenandoahMinFreeThreshold;
 215   if (available < min_threshold) {
 216     log_info(gc)("Trigger: Free (" SIZE_FORMAT "M) is below minimum threshold (" SIZE_FORMAT "M)",
 217                  available / M, min_threshold / M);
 218     return true;
 219   }
 220 
 221   // Check if are need to learn a bit about the application
 222   const size_t max_learn = ShenandoahLearningSteps;
 223   if (_gc_times_learned < max_learn) {
 224     size_t init_threshold = capacity / 100 * ShenandoahInitFreeThreshold;
 225     if (available < init_threshold) {
 226       log_info(gc)("Trigger: Learning " SIZE_FORMAT " of " SIZE_FORMAT ". Free (" SIZE_FORMAT "M) is below initial threshold (" SIZE_FORMAT "M)",
 227                    _gc_times_learned + 1, max_learn, available / M, init_threshold / M);
 228       return true;
 229     }
 230   }
 231 
 232   // Check if allocation headroom is still okay. This also factors in:
 233   //   1. Some space to absorb allocation spikes
 234   //   2. Accumulated penalties from Degenerated and Full GC
 235 
 236   size_t allocation_headroom = available;
 237 
 238   size_t spike_headroom = capacity / 100 * ShenandoahAllocSpikeFactor;
 239   size_t penalties      = capacity / 100 * _gc_time_penalties;
 240 
 241   allocation_headroom -= MIN2(allocation_headroom, spike_headroom);
 242   allocation_headroom -= MIN2(allocation_headroom, penalties);
 243 
 244   double average_gc = _gc_time_history->avg();
 245   double time_since_last = time_since_last_gc();
 246   double allocation_rate = heap->bytes_allocated_since_gc_start() / time_since_last;
 247 
 248   if (average_gc > allocation_headroom / allocation_rate) {
 249     log_info(gc)("Trigger: Average GC time (%.2f ms) is above the time for allocation rate (%.2f MB/s) to deplete free headroom (" SIZE_FORMAT "M)",
 250                  average_gc * 1000, allocation_rate / M, allocation_headroom / M);
 251     log_info(gc, ergo)("Free headroom: " SIZE_FORMAT "M (free) - " SIZE_FORMAT "M (spike) - " SIZE_FORMAT "M (penalties) = " SIZE_FORMAT "M",
 252                        available / M, spike_headroom / M, penalties / M, allocation_headroom / M);
 253     return true;
 254   } else if (ShenandoahHeuristics::should_start_normal_gc()) {
 255     return true;
 256   }
 257 
 258   return false;
 259 }


  24 #include "precompiled.hpp"
  25 
  26 #include "gc/shenandoah/heuristics/shenandoahTraversalHeuristics.hpp"
  27 #include "gc/shenandoah/shenandoahCollectionSet.hpp"
  28 #include "gc/shenandoah/shenandoahFreeSet.hpp"
  29 #include "gc/shenandoah/shenandoahHeap.inline.hpp"
  30 #include "gc/shenandoah/shenandoahHeuristics.hpp"
  31 #include "gc/shenandoah/shenandoahTraversalGC.hpp"
  32 #include "logging/log.hpp"
  33 #include "logging/logTag.hpp"
  34 #include "utilities/quickSort.hpp"
  35 
  36 ShenandoahTraversalHeuristics::ShenandoahTraversalHeuristics() : ShenandoahHeuristics(),
  37   _last_cset_select(0)
  38  {
  39   FLAG_SET_DEFAULT(ShenandoahSATBBarrier,            false);
  40   FLAG_SET_DEFAULT(ShenandoahStoreValEnqueueBarrier, true);
  41   FLAG_SET_DEFAULT(ShenandoahKeepAliveBarrier,       false);
  42   FLAG_SET_DEFAULT(ShenandoahAllowMixedAllocs,       false);
  43 
  44   SHENANDOAH_ERGO_OVERRIDE_DEFAULT(ShenandoahRefProcFrequency, 1);
  45 
  46   // Adjust class unloading settings only if globally enabled.
  47   if (ClassUnloadingWithConcurrentMark) {
  48     SHENANDOAH_ERGO_OVERRIDE_DEFAULT(ShenandoahUnloadClassesFrequency, 1);
  49   }
  50 
  51   SHENANDOAH_ERGO_ENABLE_FLAG(ExplicitGCInvokesConcurrent);
  52   SHENANDOAH_ERGO_ENABLE_FLAG(ShenandoahImplicitGCInvokesConcurrent);
  53 
  54   // Final configuration checks
  55   SHENANDOAH_CHECK_FLAG_SET(ShenandoahLoadRefBarrier);
  56   SHENANDOAH_CHECK_FLAG_SET(ShenandoahStoreValEnqueueBarrier);
  57   SHENANDOAH_CHECK_FLAG_SET(ShenandoahCASBarrier);
  58   SHENANDOAH_CHECK_FLAG_SET(ShenandoahCloneBarrier);
  59 }
  60 
  61 bool ShenandoahTraversalHeuristics::should_start_normal_gc() const {
  62   return false;
  63 }
  64 
  65 bool ShenandoahTraversalHeuristics::is_experimental() {
  66   return true;
  67 }
  68 
  69 bool ShenandoahTraversalHeuristics::is_diagnostic() {
  70   return false;


 107   // The logic for cset selection is similar to that of adaptive:
 108   //
 109   //   1. We cannot get cset larger than available free space. Otherwise we guarantee OOME
 110   //      during evacuation, and thus guarantee full GC. In practice, we also want to let
 111   //      application to allocate something. This is why we limit CSet to some fraction of
 112   //      available space. In non-overloaded heap, max_cset would contain all plausible candidates
 113   //      over garbage threshold.
 114   //
 115   //   2. We should not get cset too low so that free threshold would not be met right
 116   //      after the cycle. Otherwise we get back-to-back cycles for no reason if heap is
 117   //      too fragmented. In non-overloaded non-fragmented heap min_garbage would be around zero.
 118   //
 119   // Therefore, we start by sorting the regions by garbage. Then we unconditionally add the best candidates
 120   // before we meet min_garbage. Then we add all candidates that fit with a garbage threshold before
 121   // we hit max_cset. When max_cset is hit, we terminate the cset selection. Note that in this scheme,
 122   // ShenandoahGarbageThreshold is the soft threshold which would be ignored until min_garbage is hit.
 123   //
 124   // The significant complication is that liveness data was collected at the previous cycle, and only
 125   // for those regions that were allocated before previous cycle started.
 126 
 127   size_t capacity    = heap->capacity();
 128   size_t actual_free = heap->free_set()->available();
 129   size_t free_target = ShenandoahMinFreeThreshold * capacity / 100;
 130   size_t min_garbage = free_target > actual_free ? (free_target - actual_free) : 0;
 131   size_t max_cset    = (size_t)(1.0 * ShenandoahEvacReserve * capacity / 100 / ShenandoahEvacWaste);
 132 
 133   log_info(gc, ergo)("Adaptive CSet Selection. Target Free: " SIZE_FORMAT "M, Actual Free: "
 134                      SIZE_FORMAT "M, Max CSet: " SIZE_FORMAT "M, Min Garbage: " SIZE_FORMAT "M",
 135                      free_target / M, actual_free / M, max_cset / M, min_garbage / M);
 136 
 137   // Better select garbage-first regions, and then older ones
 138   QuickSort::sort<RegionData>(data, (int) cnt, compare_by_garbage_then_alloc_seq_ascending, false);
 139 
 140   size_t cur_cset = 0;
 141   size_t cur_garbage = 0;
 142 
 143   size_t garbage_threshold = ShenandoahHeapRegion::region_size_bytes() / 100 * ShenandoahGarbageThreshold;
 144 
 145   // Step 1. Add trustworthy regions to collection set.
 146   //
 147   // We can trust live/garbage data from regions that were fully traversed during
 148   // previous cycle. Even if actual liveness is different now, we can only have _less_
 149   // live objects, because dead objects are not resurrected. Which means we can undershoot
 150   // the collection set, but not overshoot it.
 151 


 196   }
 197 
 198   // Step 3. Clear liveness data
 199   // TODO: Merge it with step 0, but save live data in RegionData before.
 200   for (size_t i = 0; i < heap->num_regions(); i++) {
 201     ShenandoahHeapRegion* r = heap->get_region(i);
 202     if (r->used() > 0) {
 203       r->clear_live_data();
 204     }
 205   }
 206 
 207   collection_set->update_region_status();
 208 
 209   _last_cset_select = ShenandoahHeapRegion::seqnum_current_alloc();
 210 }
 211 
 212 bool ShenandoahTraversalHeuristics::should_start_traversal_gc() {
 213   ShenandoahHeap* heap = ShenandoahHeap::heap();
 214   assert(!heap->has_forwarded_objects(), "no forwarded objects here");
 215 
 216   size_t capacity = heap->capacity();
 217   size_t available = heap->free_set()->available();
 218 
 219   // Check if we are falling below the worst limit, time to trigger the GC, regardless of
 220   // anything else.
 221   size_t min_threshold = ShenandoahMinFreeThreshold * heap->capacity() / 100;
 222   if (available < min_threshold) {
 223     log_info(gc)("Trigger: Free (" SIZE_FORMAT "M) is below minimum threshold (" SIZE_FORMAT "M)",
 224                  available / M, min_threshold / M);
 225     return true;
 226   }
 227 
 228   // Check if are need to learn a bit about the application
 229   const size_t max_learn = ShenandoahLearningSteps;
 230   if (_gc_times_learned < max_learn) {
 231     size_t init_threshold = ShenandoahInitFreeThreshold * heap->capacity() / 100;
 232     if (available < init_threshold) {
 233       log_info(gc)("Trigger: Learning " SIZE_FORMAT " of " SIZE_FORMAT ". Free (" SIZE_FORMAT "M) is below initial threshold (" SIZE_FORMAT "M)",
 234                    _gc_times_learned + 1, max_learn, available / M, init_threshold / M);
 235       return true;
 236     }
 237   }
 238 
 239   // Check if allocation headroom is still okay. This also factors in:
 240   //   1. Some space to absorb allocation spikes
 241   //   2. Accumulated penalties from Degenerated and Full GC
 242 
 243   size_t allocation_headroom = available;
 244 
 245   size_t spike_headroom = ShenandoahAllocSpikeFactor * capacity / 100;
 246   size_t penalties      = _gc_time_penalties         * capacity / 100;
 247 
 248   allocation_headroom -= MIN2(allocation_headroom, spike_headroom);
 249   allocation_headroom -= MIN2(allocation_headroom, penalties);
 250 
 251   double average_gc = _gc_time_history->avg();
 252   double time_since_last = time_since_last_gc();
 253   double allocation_rate = heap->bytes_allocated_since_gc_start() / time_since_last;
 254 
 255   if (average_gc > allocation_headroom / allocation_rate) {
 256     log_info(gc)("Trigger: Average GC time (%.2f ms) is above the time for allocation rate (%.2f MB/s) to deplete free headroom (" SIZE_FORMAT "M)",
 257                  average_gc * 1000, allocation_rate / M, allocation_headroom / M);
 258     log_info(gc, ergo)("Free headroom: " SIZE_FORMAT "M (free) - " SIZE_FORMAT "M (spike) - " SIZE_FORMAT "M (penalties) = " SIZE_FORMAT "M",
 259                        available / M, spike_headroom / M, penalties / M, allocation_headroom / M);
 260     return true;
 261   } else if (ShenandoahHeuristics::should_start_normal_gc()) {
 262     return true;
 263   }
 264 
 265   return false;
 266 }
< prev index next >