@@ -176,15 +176,30 @@ G1ServiceThread::G1ServiceThread() :
176
176
true ,
177
177
Monitor::_safepoint_check_never),
178
178
_task_queue(),
179
+ _remset_task(new G1RemSetSamplingTask(" Remembered Set Sampling Task" )),
180
+ _periodic_gc_task(new G1PeriodicGCTask(" Periodic GC Task" )),
179
181
_vtime_accum(0 ) {
180
182
set_name (" G1 Service" );
181
183
create_and_start ();
182
184
}
183
185
186
+ G1ServiceThread::~G1ServiceThread () {
187
+ delete _remset_task;
188
+ delete _periodic_gc_task;
189
+ }
190
+
184
191
void G1ServiceThread::register_task (G1ServiceTask* task, jlong delay) {
185
192
guarantee (!task->is_registered (), " Task already registered" );
186
193
guarantee (task->next () == NULL , " Task already in queue" );
187
194
195
+ // Make sure the service thread is still up and running, there is a race
196
+ // during shutdown where the service thread has been stopped, but other
197
+ // GC threads might still be running and trying to add tasks.
198
+ if (has_terminated ()) {
199
+ log_debug (gc, task)(" G1 Service Thread (%s) (terminated)" , task->name ());
200
+ return ;
201
+ }
202
+
188
203
log_debug (gc, task)(" G1 Service Thread (%s) (register)" , task->name ());
189
204
190
205
// Associate the task with the service thread.
@@ -272,13 +287,9 @@ void G1ServiceThread::run_task(G1ServiceTask* task) {
272
287
void G1ServiceThread::run_service () {
273
288
double vtime_start = os::elapsedVTime ();
274
289
275
- // Setup the tasks handeled by the service thread and
276
- // add them to the task list.
277
- G1PeriodicGCTask gc_task (" Periodic GC Task" );
278
- register_task (&gc_task);
279
-
280
- G1RemSetSamplingTask remset_task (" Remembered Set Sampling Task" );
281
- register_task (&remset_task);
290
+ // Register the tasks handled by the service thread.
291
+ register_task (_periodic_gc_task);
292
+ register_task (_remset_task);
282
293
283
294
while (!should_terminate ()) {
284
295
G1ServiceTask* task = pop_due_task ();
@@ -293,6 +304,8 @@ void G1ServiceThread::run_service() {
293
304
}
294
305
sleep_before_next_cycle ();
295
306
}
307
+
308
+ log_debug (gc, task)(" G1 Service Thread (stopping)" );
296
309
}
297
310
298
311
void G1ServiceThread::stop_service () {
0 commit comments