RFR: 8274286: Skip null for make_referent_alive in referenceProcessor

Kim Barrett kbarrett at openjdk.java.net
Tue Sep 28 05:35:03 UTC 2021


On Sat, 25 Sep 2021 20:46:31 GMT, Kim Barrett <kbarrett at openjdk.org> wrote:

>> src/hotspot/share/gc/shared/referenceProcessor.cpp line 267:
>> 
>>> 265: 
>>> 266: void DiscoveredListIterator::make_referent_alive() {
>>> 267:   assert(referent() != nullptr, "precondition");
>> 
>> This assert is not correct.  Preclean runs concurrently with the mutator.  The mutator could clear the reference between the time it is accessed by the list iterator and the call to make_referent_alive.  Looking at this also makes me wonder if the keep-alive function is safe against a racing clear by the mutator.
>
> Answering my own question. Only G1 currently uses precleaning, and it looks fine wrto a concurrent clear. Indeed, I think it's an expensive nop. I suspect (though haven't thought about it carefully yet) that any GC that uses ReferenceProcessor would do nothing there, and I'm not sure preclean actually needs the keep-alive and complete-gc closures.

@albertnetymk  pointed out that I was confused about what referent access we're dealing with in the assert.  That's the referent that was previously loaded and cached in the iterator.  But that just makes the assert confusing in my opinion.  There is nothing about make_referent_alive that depends on that precondition, and indeed the keep-alive function must *not* depend on it.  So I still think the assert should not be added.

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

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



More information about the hotspot-gc-dev mailing list