@@ -548,13 +548,12 @@ class G1RemSetSamplingTask : public G1ServiceTask {
548
548
// reevaluates the prediction for the remembered set scanning costs, and potentially
549
549
// G1Policy resizes the young gen. This may do a premature GC or even
550
550
// increase the young gen size to keep pause time length goal.
551
- void sample_young_list_rs_length (){
552
- SuspendibleThreadSetJoiner sts;
551
+ void sample_young_list_rs_length (SuspendibleThreadSetJoiner* sts){
553
552
G1CollectedHeap* g1h = G1CollectedHeap::heap ();
554
553
G1Policy* policy = g1h->policy ();
555
554
556
555
if (policy->use_adaptive_young_list_length ()) {
557
- G1YoungRemSetSamplingClosure cl (& sts);
556
+ G1YoungRemSetSamplingClosure cl (sts);
558
557
559
558
G1CollectionSet* g1cs = g1h->collection_set ();
560
559
g1cs->iterate(&cl);
@@ -565,10 +564,36 @@ class G1RemSetSamplingTask : public G1ServiceTask {
565
564
}
566
565
}
567
566
567
+ // To avoid extensive rescheduling if the task is executed a bit early. The task is
568
+ // only rescheduled if the expected time is more than 1ms away.
569
+ bool should_reschedule () {
570
+ return reschedule_delay_ms () > 1 ;
571
+ }
572
+
573
+ // There is no reason to do the sampling if a GC occurred recently. We use the
574
+ // G1ConcRefinementServiceIntervalMillis as the metric for recently and calculate
575
+ // the diff to the last GC. If the last GC occurred longer ago than the interval
576
+ // 0 is returned.
577
+ jlong reschedule_delay_ms () {
578
+ Tickspan since_last_gc = G1CollectedHeap::heap ()->time_since_last_collection ();
579
+ jlong delay = (jlong) (G1ConcRefinementServiceIntervalMillis - since_last_gc.milliseconds ());
580
+ return MAX2<jlong>(0L , delay);
581
+ }
582
+
568
583
public:
569
584
G1RemSetSamplingTask (const char * name) : G1ServiceTask(name) { }
570
585
virtual void execute () {
571
- sample_young_list_rs_length ();
586
+ SuspendibleThreadSetJoiner sts;
587
+
588
+ // Reschedule if a GC happened too recently.
589
+ if (should_reschedule ()) {
590
+ // Calculate the delay given the last GC and the interval.
591
+ schedule (reschedule_delay_ms ());
592
+ return ;
593
+ }
594
+
595
+ // Do the actual sampling.
596
+ sample_young_list_rs_length (&sts);
572
597
schedule (G1ConcRefinementServiceIntervalMillis);
573
598
}
574
599
};
0 commit comments