RFR: 8328235: GenShen: Robustify ShenandoahGCSession and fix missing use [v22]

William Kemper wkemper at openjdk.org
Mon Jul 1 23:57:37 UTC 2024


On Sat, 29 Jun 2024 06:44:13 GMT, Y. Srinivas Ramakrishna <ysr at openjdk.org> wrote:

>> ShenandoahGCSession is intended to create a scope where the ShenandoahHeap's _gc_cause and _gc_generation field reflect the current gc cycle. We now check that we do not overwrite existing non-default settings (respectively _no_gc and nullptr). The destructor of the scope/stack object also resets these fields to their default settings, ensuring intended uses. This uncovered a situation where the scope was not entered when it should have been, which we have now fixed.
>> 
>> A case of flickering of active_generation() was identified when used concurrently by mutators while it was being modified by the controller thread. To deal with this, we have carefully gone through the setting and use of the field, and found that an expedient fix for the race is to split the field into two:
>> - _gc_generation is set & cleared by the controller thread whenever it enters and exits a GC scope, and services concurrent gc cycles for young or old generations.
>> - _active_generation is set to the value in _gc_generation at the start of each Shenandoah GC safepoint operation so that mutator threads and load barriers always see a consistent value between safepoints.
>> 
>> Asserts check the protocol for setting and clearing these fields.
>> 
>> The protocol for use of the fields is that mutator threads may never use the _gc_generation field since it's subject to asynchronously changing based on actions of the coordinator thread. Mutator threads may only use the _active_generation field which changes synchronously at safepoints. Worker threads will generally use the former, but they may also use the latter as part of the load barrier.
>> 
>> An alternative approach would be to not use a global variable for the _gc_generation indirected through the heap, but rather to pass it into the gc closures that do the work for specific phases of the GC that need to know which generation is currently subject to collector actions. This would work as well, but the changes would potentially touch more code. We would still have to have set the variable that is consulted by the load barriers, viz. _active_generation, in a mutator-safe fashion at a safepoint, like we do today. This or other alternative approaches may be investigated in the future to potentially make this protocol more self-contained and robust rather than leaking as it does today into many places in the code.
>> 
>> *Testing*:
>> - [x] code pipeline
>> - [x] specjbb testing
>> - [x] specjbb performance
>> - [x] jtreg:hotspot_gc and jtreg:hots...
>
> Y. Srinivas Ramakrishna has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Disallow mutator threads from reading the asynchronously updated
>   _gc_generation field of ShHeap.

Marked as reviewed by wkemper (Committer).

-------------

PR Review: https://git.openjdk.org/shenandoah/pull/407#pullrequestreview-2152416786


More information about the shenandoah-dev mailing list