RFR: 8255980: G1 Service thread register_task can be used after shutdown

Stefan Johansson sjohanss at openjdk.java.net
Mon Nov 9 13:42:59 UTC 2020

On Mon, 9 Nov 2020 11:31:07 GMT, Albert Mingkun Yang <ayang at openjdk.org> wrote:

>> Please review this change to improve the service thread task handling during shutdown.
>> This problem isn't currently visible, but with upcoming changes there is a race where tasks might be added to the service thread after it has been shut down. This becomes problematic because the task queue at that point consists of invalid objects. They are invalid because the tasks are currently stack-allocated on the service thread. This change both allocates the tasks handled by the service thread dynamically and add a check to avoid adding tasks when the service thread has been shut down. Just doing the dynamic allocation would be enough, but there is no reason to add tasks after the thread is shut down.
>> I've tested this fix together with my concurrent uncommit changes which highlight the problem, and also run tier1 and tier2 for sanity.
> src/hotspot/share/gc/g1/g1ServiceThread.hpp line 109:
>> 107: 
>> 108:   G1RemSetSamplingTask* _remset_task;
>> 109:   G1PeriodicGCTask* _periodic_gc_task;
> I would prefer them being embedded directly, `G1RemSetSamplingTask _remset_task;`, since they share the same lifespan with the enclosing object. No strong opinion; up to you.

Me too, but then I would have to move the declaration of the tasks into the header. Now the above forward declaration is enough and I preferred that even more :)


PR: https://git.openjdk.java.net/jdk/pull/1093

More information about the hotspot-gc-dev mailing list