Skip to content

Commit 20525d2

Browse files
albertnetymkkstefanj
authored andcommittedNov 27, 2020
8257149: Improve G1 Service thread task scheduling to guarantee task delay
Reviewed-by: sjohanss, iwalulya
1 parent f2f3ba9 commit 20525d2

File tree

3 files changed

+16
-20
lines changed

3 files changed

+16
-20
lines changed
 

‎src/hotspot/share/gc/g1/g1RemSet.cpp

+3-9
Original file line numberDiff line numberDiff line change
@@ -558,12 +558,6 @@ class G1RemSetSamplingTask : public G1ServiceTask {
558558
update_vtime_accum(vtime.duration());
559559
}
560560

561-
// To avoid extensive rescheduling if the task is executed a bit early. The task is
562-
// only rescheduled if the expected time is more than 1ms away.
563-
bool should_reschedule() {
564-
return reschedule_delay_ms() > 1;
565-
}
566-
567561
// There is no reason to do the sampling if a GC occurred recently. We use the
568562
// G1ConcRefinementServiceIntervalMillis as the metric for recently and calculate
569563
// the diff to the last GC. If the last GC occurred longer ago than the interval
@@ -580,9 +574,9 @@ class G1RemSetSamplingTask : public G1ServiceTask {
580574
SuspendibleThreadSetJoiner sts;
581575

582576
// Reschedule if a GC happened too recently.
583-
if (should_reschedule()) {
584-
// Calculate the delay given the last GC and the interval.
585-
schedule(reschedule_delay_ms());
577+
jlong delay_ms = reschedule_delay_ms();
578+
if (delay_ms > 0) {
579+
schedule(delay_ms);
586580
return;
587581
}
588582

‎src/hotspot/share/gc/g1/g1ServiceThread.cpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ G1ServiceThread::~G1ServiceThread() {
111111
delete _periodic_gc_task;
112112
}
113113

114-
void G1ServiceThread::register_task(G1ServiceTask* task, jlong delay) {
114+
void G1ServiceThread::register_task(G1ServiceTask* task, jlong delay_ms) {
115115
guarantee(!task->is_registered(), "Task already registered");
116116
guarantee(task->next() == NULL, "Task already in queue");
117117

@@ -130,7 +130,7 @@ void G1ServiceThread::register_task(G1ServiceTask* task, jlong delay) {
130130

131131
// Schedule the task to run after the given delay. The service will be
132132
// notified to check if this task is first in the queue.
133-
schedule_task(task, delay);
133+
schedule_task(task, delay_ms);
134134
}
135135

136136
void G1ServiceThread::schedule(G1ServiceTask* task, jlong delay_ms) {
@@ -163,8 +163,9 @@ int64_t G1ServiceThread::time_to_next_task_ms() {
163163
return 0;
164164
}
165165

166-
// Return sleep time in milliseconds.
167-
return (int64_t) TimeHelper::counter_to_millis(time_diff);
166+
// Return sleep time in milliseconds. Using ceil to make sure we never
167+
// schedule a task too early.
168+
return (int64_t) ceil(TimeHelper::counter_to_millis(time_diff));
168169
}
169170

170171
void G1ServiceThread::notify() {

‎src/hotspot/share/gc/g1/g1ServiceThread.hpp

+8-7
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,14 @@ class G1ServiceThread: public ConcurrentGCThread {
131131
G1ServiceThread();
132132
~G1ServiceThread();
133133

134-
// Register a task with the service thread and schedule it. If
135-
// no delay is specified the task is scheduled to run directly.
136-
void register_task(G1ServiceTask* task, jlong delay = 0);
137-
138-
// Schedule the task and notify the service thread that a new
139-
// task might be ready to run.
140-
void schedule_task(G1ServiceTask* task, jlong delay);
134+
// Register a task with the service thread. The task is guaranteed not to run
135+
// until at least `delay_ms` has passed. If no delay is specified or the
136+
// delay is 0, the task will run in the earliest time possible.
137+
void register_task(G1ServiceTask* task, jlong delay_ms = 0);
138+
139+
// Schedule an already-registered task to run in at least `delay_ms` time,
140+
// and notify the service thread.
141+
void schedule_task(G1ServiceTask* task, jlong delay_ms);
141142
};
142143

143144
#endif // SHARE_GC_G1_G1SERVICETHREAD_HPP

0 commit comments

Comments
 (0)
Please sign in to comment.