< prev index next >

src/share/vm/gc_implementation/shenandoah/shenandoahHeuristics.cpp

Print this page
rev 10660 : [backport] Refactor bitmap cleaning
rev 10685 : [backport] Rename ShHeap::shenandoahPolicy -> ShHeap::shenandoah_policy
rev 10686 : [backport] Handle ShHeap::time_since_last_millis for RMI users
rev 10690 : [backport] Cleanup header files and forward declarations
rev 10724 : [backport] Add JFR parallel and concurrent events (infrastructure)
rev 10748 : [backport] Handle metadata induced GC
rev 10755 : [backport] Make heuristics tell if we can process references or unload classes
rev 10756 : [backport] Factor out implicit/explicit GC requests
rev 10764 : [backport] Rename BrooksPointer to ShenandoahBrooksPointer
rev 10772 : [backport] Update copyrights

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2018, Red Hat, Inc. and/or its affiliates.
+ * Copyright (c) 2018, Red Hat, Inc. All rights reserved.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.
  *

@@ -20,16 +20,19 @@
  * questions.
  *
  */
 
 #include "precompiled.hpp"
-#include "gc_implementation/shenandoah/brooksPointer.hpp"
+
+#include "gc_interface/gcCause.hpp"
+#include "gc_implementation/shenandoah/shenandoahBrooksPointer.hpp"
 #include "gc_implementation/shenandoah/shenandoahCollectorPolicy.hpp"
 #include "gc_implementation/shenandoah/shenandoahHeap.inline.hpp"
 #include "gc_implementation/shenandoah/shenandoahHeapRegion.hpp"
 #include "gc_implementation/shenandoah/shenandoahHeuristics.hpp"
 #include "gc_implementation/shenandoah/shenandoahMarkingContext.inline.hpp"
+#include "gc_implementation/shenandoah/shenandoahUtils.hpp"
 
 int ShenandoahHeuristics::compare_by_garbage(RegionData a, RegionData b) {
   if (a._garbage > b._garbage)
     return -1;
   else if (a._garbage < b._garbage)

@@ -55,15 +58,16 @@
   _region_data(NULL),
   _region_data_size(0),
   _degenerated_cycles_in_a_row(0),
   _successful_cycles_in_a_row(0),
   _bytes_in_cset(0),
-  _cycle_start(0),
+  _cycle_start(os::elapsedTime()),
   _last_cycle_end(0),
   _gc_times_learned(0),
   _gc_time_penalties(0),
-  _gc_time_history(new TruncatedSeq(5))
+  _gc_time_history(new TruncatedSeq(5)),
+  _metaspace_oom()
 {
   if (strcmp(ShenandoahUpdateRefsEarly, "on") == 0 ||
       strcmp(ShenandoahUpdateRefsEarly, "true") == 0 ) {
     _update_refs_early = true;
   } else if (strcmp(ShenandoahUpdateRefsEarly, "off") == 0 ||

@@ -138,22 +142,22 @@
     } else if (region->is_regular()) {
       if (!region->has_live()) {
         // We can recycle it right away and put it in the free set.
         immediate_regions++;
         immediate_garbage += garbage;
-        region->make_trash();
+        region->make_trash_immediate();
       } else {
         // This is our candidate for later consideration.
         candidates[cand_idx]._region = region;
         candidates[cand_idx]._garbage = garbage;
         cand_idx++;
       }
     } else if (region->is_humongous_start()) {
       // Reclaim humongous regions here, and count them as the immediate garbage
 #ifdef ASSERT
       bool reg_live = region->has_live();
-      bool bm_live = ctx->is_marked(oop(region->bottom() + BrooksPointer::word_size()));
+      bool bm_live = ctx->is_marked(oop(region->bottom() + ShenandoahBrooksPointer::word_size()));
       assert(reg_live == bm_live,
              err_msg("Humongous liveness and marks should agree. Region live: %s; Bitmap live: %s; Region Live Words: " SIZE_FORMAT,
                      BOOL_TO_STR(reg_live), BOOL_TO_STR(bm_live), region->get_live_data_words()));
 #endif
       if (!region->has_live()) {

@@ -223,12 +227,11 @@
 
 void ShenandoahHeuristics::record_success_concurrent() {
   _degenerated_cycles_in_a_row = 0;
   _successful_cycles_in_a_row++;
 
-  double duration = (os::elapsedTime() - _cycle_start);
-  _gc_time_history->add(duration);
+  _gc_time_history->add(time_since_last_gc());
   _gc_times_learned++;
   _gc_time_penalties -= MIN2<size_t>(_gc_time_penalties, Concurrent_Adjust);
 }
 
 void ShenandoahHeuristics::record_success_degenerated() {

@@ -245,28 +248,47 @@
 
 void ShenandoahHeuristics::record_allocation_failure_gc() {
   _bytes_in_cset = 0;
 }
 
-void ShenandoahHeuristics::record_explicit_gc() {
+void ShenandoahHeuristics::record_requested_gc() {
   _bytes_in_cset = 0;
 
   // Assume users call System.gc() when external state changes significantly,
   // which forces us to re-learn the GC timings and allocation rates.
   _gc_times_learned = 0;
 }
 
-bool ShenandoahHeuristics::should_process_references() {
+bool ShenandoahHeuristics::can_process_references() {
   if (ShenandoahRefProcFrequency == 0) return false;
-  size_t cycle = ShenandoahHeap::heap()->shenandoahPolicy()->cycle_counter();
+  return true;
+}
+
+bool ShenandoahHeuristics::should_process_references() {
+  if (!can_process_references()) return false;
+  size_t cycle = ShenandoahHeap::heap()->shenandoah_policy()->cycle_counter();
   // Process references every Nth GC cycle.
   return cycle % ShenandoahRefProcFrequency == 0;
 }
 
-bool ShenandoahHeuristics::should_unload_classes() {
+bool ShenandoahHeuristics::can_unload_classes() {
+  if (!ClassUnloading) return false;
+  return true;
+}
+
+bool ShenandoahHeuristics::can_unload_classes_normal() {
+  if (!can_unload_classes()) return false;
+  if (has_metaspace_oom()) return true;
+  if (!ClassUnloadingWithConcurrentMark) return false;
   if (ShenandoahUnloadClassesFrequency == 0) return false;
-  size_t cycle = ShenandoahHeap::heap()->shenandoahPolicy()->cycle_counter();
+  return true;
+}
+
+bool ShenandoahHeuristics::should_unload_classes() {
+  if (!can_unload_classes_normal()) return false;
+  if (has_metaspace_oom()) return true;
+  size_t cycle = ShenandoahHeap::heap()->shenandoah_policy()->cycle_counter();
   // Unload classes every Nth GC cycle.
   // This should not happen in the same cycle as process_references to amortize costs.
   // Offsetting by one is enough to break the rendezvous when periods are equal.
   // When periods are not equal, offsetting by one is just as good as any other guess.
   return (cycle + 1) % ShenandoahUnloadClassesFrequency == 0;

@@ -274,11 +296,22 @@
 
 void ShenandoahHeuristics::initialize() {
   // Nothing to do by default.
 }
 
+double ShenandoahHeuristics::time_since_last_gc() const {
+  return os::elapsedTime() - _cycle_start;
+}
+
 bool ShenandoahHeuristics::should_start_normal_gc() const {
+  // Perform GC to cleanup metaspace
+  if (has_metaspace_oom()) {
+    // Some of vmTestbase/metaspace tests depend on following line to count GC cycles
+    log_info(gc)("Trigger: %s", GCCause::to_string(GCCause::_metadata_GC_threshold));
+    return true;
+  }
+
   double last_time_ms = (os::elapsedTime() - _last_cycle_end) * 1000;
   bool periodic_gc = (last_time_ms > ShenandoahGuaranteedGCInterval);
   if (periodic_gc) {
     log_info(gc)("Trigger: Time since last GC (%.0f ms) is larger than guaranteed interval (" UINTX_FORMAT " ms)",
                   last_time_ms, ShenandoahGuaranteedGCInterval);
< prev index next >