< prev index next >

src/hotspot/share/gc/g1/g1YoungRemSetSamplingThread.cpp

Print this page




  93       if (!G1CollectedHeap::heap()->try_collect(GCCause::_g1_periodic_collection,
  94                                                     false /* retry_on_vmop_failure */)) {
  95         log_debug(gc, periodic)("GC request denied. Skipping.");
  96       }
  97     }
  98     _last_periodic_gc_attempt_s = os::elapsedTime();
  99   }
 100 }
 101 
 102 void G1YoungRemSetSamplingThread::run_service() {
 103   double vtime_start = os::elapsedVTime();
 104 
 105   // Print a message about periodic GC configuration.
 106   if (G1PeriodicGCInterval != 0) {
 107     log_info(gc)("Periodic GC enabled with interval " UINTX_FORMAT "ms", G1PeriodicGCInterval);
 108   } else {
 109     log_info(gc)("Periodic GC disabled");
 110   }
 111 
 112   while (!should_terminate()) {
 113     sample_young_list_rs_length();
 114 
 115     if (os::supports_vtime()) {
 116       _vtime_accum = (os::elapsedVTime() - vtime_start);
 117     } else {
 118       _vtime_accum = 0.0;
 119     }
 120 
 121     check_for_periodic_gc();
 122 
 123     sleep_before_next_cycle();
 124   }
 125 }
 126 
 127 void G1YoungRemSetSamplingThread::stop_service() {
 128   MutexLocker x(&_monitor, Mutex::_no_safepoint_check_flag);
 129   _monitor.notify();
 130 }
 131 
 132 class G1YoungRemSetSamplingClosure : public HeapRegionClosure {
 133   SuspendibleThreadSetJoiner* _sts;
 134   size_t _regions_visited;
 135   size_t _sampled_rs_length;
 136 public:
 137   G1YoungRemSetSamplingClosure(SuspendibleThreadSetJoiner* sts) :
 138     HeapRegionClosure(), _sts(sts), _regions_visited(0), _sampled_rs_length(0) { }
 139 
 140   virtual bool do_heap_region(HeapRegion* r) {
 141     size_t rs_length = r->rem_set()->occupied();
 142     _sampled_rs_length += rs_length;
 143 
 144     // Update the collection set policy information for this region
 145     G1CollectedHeap::heap()->collection_set()->update_young_region_prediction(r, rs_length);
 146 
 147     _regions_visited++;
 148 
 149     if (_regions_visited == 10) {
 150       if (_sts->should_yield()) {
 151         _sts->yield();
 152         // A gc may have occurred and our sampling data is stale and further
 153         // traversal of the collection set is unsafe
 154         return true;
 155       }
 156       _regions_visited = 0;
 157     }
 158     return false;
 159   }
 160 
 161   size_t sampled_rs_length() const { return _sampled_rs_length; }
 162 };
 163 
 164 void G1YoungRemSetSamplingThread::sample_young_list_rs_length() {
 165   SuspendibleThreadSetJoiner sts;
 166   G1CollectedHeap* g1h = G1CollectedHeap::heap();
 167   G1Policy* policy = g1h->policy();
 168 
 169   if (policy->use_adaptive_young_list_length()) {
 170     G1YoungRemSetSamplingClosure cl(&sts);
 171 
 172     G1CollectionSet* g1cs = g1h->collection_set();
 173     g1cs->iterate(&cl);
 174 
 175     if (cl.is_complete()) {
 176       policy->revise_young_list_target_length_if_necessary(cl.sampled_rs_length());
 177     }
 178   }
 179 }


  93       if (!G1CollectedHeap::heap()->try_collect(GCCause::_g1_periodic_collection,
  94                                                     false /* retry_on_vmop_failure */)) {
  95         log_debug(gc, periodic)("GC request denied. Skipping.");
  96       }
  97     }
  98     _last_periodic_gc_attempt_s = os::elapsedTime();
  99   }
 100 }
 101 
 102 void G1YoungRemSetSamplingThread::run_service() {
 103   double vtime_start = os::elapsedVTime();
 104 
 105   // Print a message about periodic GC configuration.
 106   if (G1PeriodicGCInterval != 0) {
 107     log_info(gc)("Periodic GC enabled with interval " UINTX_FORMAT "ms", G1PeriodicGCInterval);
 108   } else {
 109     log_info(gc)("Periodic GC disabled");
 110   }
 111 
 112   while (!should_terminate()) {
 113     sample_young_list_rs_lengths();
 114 
 115     if (os::supports_vtime()) {
 116       _vtime_accum = (os::elapsedVTime() - vtime_start);
 117     } else {
 118       _vtime_accum = 0.0;
 119     }
 120 
 121     check_for_periodic_gc();
 122 
 123     sleep_before_next_cycle();
 124   }
 125 }
 126 
 127 void G1YoungRemSetSamplingThread::stop_service() {
 128   MutexLocker x(&_monitor, Mutex::_no_safepoint_check_flag);
 129   _monitor.notify();
 130 }
 131 
 132 class G1YoungRemSetSamplingClosure : public HeapRegionClosure {
 133   SuspendibleThreadSetJoiner* _sts;
 134   size_t _regions_visited;
 135   size_t _sampled_rs_lengths;
 136 public:
 137   G1YoungRemSetSamplingClosure(SuspendibleThreadSetJoiner* sts) :
 138     HeapRegionClosure(), _sts(sts), _regions_visited(0), _sampled_rs_lengths(0) { }
 139 
 140   virtual bool do_heap_region(HeapRegion* r) {
 141     size_t rs_length = r->rem_set()->occupied();
 142     _sampled_rs_lengths += rs_length;
 143 
 144     // Update the collection set policy information for this region
 145     G1CollectedHeap::heap()->collection_set()->update_young_region_prediction(r, rs_length);
 146 
 147     _regions_visited++;
 148 
 149     if (_regions_visited == 10) {
 150       if (_sts->should_yield()) {
 151         _sts->yield();
 152         // A gc may have occurred and our sampling data is stale and further
 153         // traversal of the collection set is unsafe
 154         return true;
 155       }
 156       _regions_visited = 0;
 157     }
 158     return false;
 159   }
 160 
 161   size_t sampled_rs_lengths() const { return _sampled_rs_lengths; }
 162 };
 163 
 164 void G1YoungRemSetSamplingThread::sample_young_list_rs_lengths() {
 165   SuspendibleThreadSetJoiner sts;
 166   G1CollectedHeap* g1h = G1CollectedHeap::heap();
 167   G1Policy* policy = g1h->policy();
 168 
 169   if (policy->use_adaptive_young_list_length()) {
 170     G1YoungRemSetSamplingClosure cl(&sts);
 171 
 172     G1CollectionSet* g1cs = g1h->collection_set();
 173     g1cs->iterate(&cl);
 174 
 175     if (cl.is_complete()) {
 176       policy->revise_young_list_target_length_if_necessary(cl.sampled_rs_lengths());
 177     }
 178   }
 179 }
< prev index next >