RFR: 8263551: Provide shared lock-free FIFO queue implementation
Man Cao
manc at openjdk.java.net
Mon Mar 15 20:06:10 UTC 2021
On Sun, 14 Mar 2021 02:25:34 GMT, Kim Barrett <kbarrett at openjdk.org> wrote:
>> Hi all,
>>
>> Could anyone review this change that is mainly code motion? It creates a generalized lock-free queue implementation based on G1DirtyCardQueueSet::Queue, which will be used by JDK-8236485 in the future.
>>
>> The shared LockFreeQueue is similar to the existing LockFreeStack. The notable difference is that the LockFreeQueue has an additional template parameter for whether to use GlobalCounter::CriticalSection to avoid ABA problem.
>>
>> -Man
>
> src/hotspot/share/utilities/lockFreeQueue.hpp line 50:
>
>> 48: NONCOPYABLE(LockFreeQueue);
>> 49:
>> 50: protected:
>
> Protected members (to be accessible from a derived class) are inconsistent with a public non-virtual destructor (that may allow destructor slicing). I dislike classes that try to be both concrete implementation classes and base classes; they are hard to design well (and this class wasn't intended to be such). This was done to allow G1DirtyCardQueueSet to extend it with the `take_all` function; that seems like a useful operation in the generic form, even if it can't be made thread-safe. (The G1 function asserts_at_safepoint(), but that's not really appropriate for a generic form.)
To clarify, do we want to move take_all() to LockFreeQueue, remove assert_at_safepoint() and put a big warning that it is not thread safe? It perhaps also involves adding the "struct HeadTail" to this class.
Another option is to provide two getter methods that returns T** for &_head and &_tail. They are not thread-safe either, but maybe more generic than take_all().
-------------
PR: https://git.openjdk.java.net/jdk/pull/2986
More information about the hotspot-dev
mailing list