< prev index next >

src/share/vm/gc_implementation/shenandoah/heuristics/shenandoahCompactHeuristics.cpp

Print this page
rev 10584 : [backport] Move periodic GC decision making to GC heuristics base class
rev 10604 : [backport] Comprehensible GC trigger logging
rev 10625 : [backport] Soft refs should be purged reliably on allocation failure, or with compact heuristics


  13  *
  14  * You should have received a copy of the GNU General Public License version
  15  * 2 along with this work; if not, write to the Free Software Foundation,
  16  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  17  *
  18  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  19  * or visit www.oracle.com if you need additional information or have any
  20  * questions.
  21  *
  22  */
  23 
  24 #include "precompiled.hpp"
  25 #include "gc_implementation/shenandoah/shenandoahCollectionSet.hpp"
  26 #include "gc_implementation/shenandoah/heuristics/shenandoahCompactHeuristics.hpp"
  27 #include "gc_implementation/shenandoah/shenandoahFreeSet.hpp"
  28 #include "gc_implementation/shenandoah/shenandoahHeapRegion.hpp"
  29 #include "gc_implementation/shenandoah/shenandoahLogging.hpp"
  30 
  31 ShenandoahCompactHeuristics::ShenandoahCompactHeuristics() : ShenandoahHeuristics() {
  32   SHENANDOAH_ERGO_ENABLE_FLAG(ShenandoahUncommit);

  33   SHENANDOAH_ERGO_OVERRIDE_DEFAULT(ShenandoahAllocationThreshold,  10);
  34   SHENANDOAH_ERGO_OVERRIDE_DEFAULT(ShenandoahImmediateThreshold,   100);
  35   SHENANDOAH_ERGO_OVERRIDE_DEFAULT(ShenandoahUncommitDelay,        5000);
  36   SHENANDOAH_ERGO_OVERRIDE_DEFAULT(ShenandoahGuaranteedGCInterval, 30000);
  37   SHENANDOAH_ERGO_OVERRIDE_DEFAULT(ShenandoahGarbageThreshold,     20);
  38 }
  39 
  40 bool ShenandoahCompactHeuristics::should_start_normal_gc() const {
  41   ShenandoahHeap* heap = ShenandoahHeap::heap();
  42 
  43   size_t available = heap->free_set()->available();
  44   double last_time_ms = (os::elapsedTime() - _last_cycle_end) * 1000;
  45   bool periodic_gc = (last_time_ms > ShenandoahGuaranteedGCInterval);
  46   size_t bytes_allocated = heap->bytes_allocated_since_gc_start();
  47   size_t threshold_bytes_allocated = heap->capacity() * ShenandoahAllocationThreshold / 100;
  48 
  49   if (available < threshold_bytes_allocated || bytes_allocated > threshold_bytes_allocated) {
  50     log_info(gc,ergo)("Concurrent marking triggered. Free: " SIZE_FORMAT "M, Allocated: " SIZE_FORMAT "M, Alloc Threshold: " SIZE_FORMAT "M",
  51                       available / M, bytes_allocated / M, threshold_bytes_allocated / M);
  52     return true;
  53   } else if (periodic_gc) {
  54     log_info(gc,ergo)("Periodic GC triggered. Time since last GC: %.0f ms, Guaranteed Interval: " UINTX_FORMAT " ms",
  55                       last_time_ms, ShenandoahGuaranteedGCInterval);



  56     return true;
  57   }
  58 
  59   return false;
  60 }
  61 
  62 void ShenandoahCompactHeuristics::choose_collection_set_from_regiondata(ShenandoahCollectionSet* cset,
  63                                                                         RegionData* data, size_t size,
  64                                                                         size_t actual_free) {
  65 
  66   // Do not select too large CSet that would overflow the available free space
  67   size_t max_cset = actual_free * 3 / 4;
  68 
  69   log_info(gc, ergo)("CSet Selection. Actual Free: " SIZE_FORMAT "M, Max CSet: " SIZE_FORMAT "M",
  70                      actual_free / M, max_cset / M);
  71 
  72   size_t threshold = ShenandoahHeapRegion::region_size_bytes() * ShenandoahGarbageThreshold / 100;
  73 
  74   size_t live_cset = 0;
  75   for (size_t idx = 0; idx < size; idx++) {
  76     ShenandoahHeapRegion* r = data[idx]._region;
  77     size_t new_cset = live_cset + r->get_live_data_bytes();
  78     if (new_cset < max_cset && r->garbage() > threshold) {
  79       live_cset = new_cset;


  13  *
  14  * You should have received a copy of the GNU General Public License version
  15  * 2 along with this work; if not, write to the Free Software Foundation,
  16  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  17  *
  18  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  19  * or visit www.oracle.com if you need additional information or have any
  20  * questions.
  21  *
  22  */
  23 
  24 #include "precompiled.hpp"
  25 #include "gc_implementation/shenandoah/shenandoahCollectionSet.hpp"
  26 #include "gc_implementation/shenandoah/heuristics/shenandoahCompactHeuristics.hpp"
  27 #include "gc_implementation/shenandoah/shenandoahFreeSet.hpp"
  28 #include "gc_implementation/shenandoah/shenandoahHeapRegion.hpp"
  29 #include "gc_implementation/shenandoah/shenandoahLogging.hpp"
  30 
  31 ShenandoahCompactHeuristics::ShenandoahCompactHeuristics() : ShenandoahHeuristics() {
  32   SHENANDOAH_ERGO_ENABLE_FLAG(ShenandoahUncommit);
  33   SHENANDOAH_ERGO_ENABLE_FLAG(ShenandoahAlwaysClearSoftRefs);
  34   SHENANDOAH_ERGO_OVERRIDE_DEFAULT(ShenandoahAllocationThreshold,  10);
  35   SHENANDOAH_ERGO_OVERRIDE_DEFAULT(ShenandoahImmediateThreshold,   100);
  36   SHENANDOAH_ERGO_OVERRIDE_DEFAULT(ShenandoahUncommitDelay,        5000);
  37   SHENANDOAH_ERGO_OVERRIDE_DEFAULT(ShenandoahGuaranteedGCInterval, 30000);
  38   SHENANDOAH_ERGO_OVERRIDE_DEFAULT(ShenandoahGarbageThreshold,     20);
  39 }
  40 
  41 bool ShenandoahCompactHeuristics::should_start_normal_gc() const {
  42   ShenandoahHeap* heap = ShenandoahHeap::heap();
  43 
  44   size_t available = heap->free_set()->available();



  45   size_t threshold_bytes_allocated = heap->capacity() * ShenandoahAllocationThreshold / 100;
  46 
  47   if (available < threshold_bytes_allocated) {
  48     log_info(gc)("Trigger: Free (" SIZE_FORMAT "M) is lower than allocated recently (" SIZE_FORMAT "M)",
  49                  available / M, threshold_bytes_allocated / M);
  50     return true;
  51   }
  52 
  53   size_t bytes_allocated = heap->bytes_allocated_since_gc_start();
  54   if (bytes_allocated > threshold_bytes_allocated) {
  55     log_info(gc)("Trigger: Allocated since last cycle (" SIZE_FORMAT "M) is larger than allocation threshold (" SIZE_FORMAT "M)",
  56                  bytes_allocated / M, threshold_bytes_allocated / M);
  57     return true;
  58   }
  59 
  60   return ShenandoahHeuristics::should_start_normal_gc();
  61 }
  62 
  63 void ShenandoahCompactHeuristics::choose_collection_set_from_regiondata(ShenandoahCollectionSet* cset,
  64                                                                         RegionData* data, size_t size,
  65                                                                         size_t actual_free) {
  66 
  67   // Do not select too large CSet that would overflow the available free space
  68   size_t max_cset = actual_free * 3 / 4;
  69 
  70   log_info(gc, ergo)("CSet Selection. Actual Free: " SIZE_FORMAT "M, Max CSet: " SIZE_FORMAT "M",
  71                      actual_free / M, max_cset / M);
  72 
  73   size_t threshold = ShenandoahHeapRegion::region_size_bytes() * ShenandoahGarbageThreshold / 100;
  74 
  75   size_t live_cset = 0;
  76   for (size_t idx = 0; idx < size; idx++) {
  77     ShenandoahHeapRegion* r = data[idx]._region;
  78     size_t new_cset = live_cset + r->get_live_data_bytes();
  79     if (new_cset < max_cset && r->garbage() > threshold) {
  80       live_cset = new_cset;
< prev index next >