RFR: 8189088: Add intrusive doubly-linked list utility [v3]

Kim Barrett kbarrett at openjdk.org
Sat Oct 7 21:31:16 UTC 2023


On Thu, 5 Oct 2023 10:30:19 GMT, Johan Sjölen <jsjolen at openjdk.org> wrote:

>> Kim Barrett has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   add IntrusiveListEntry::is_attached()
>
> src/hotspot/share/utilities/intrusiveList.hpp line 87:
> 
>> 85:  * iterators and access to const-qualified elements.  A const object cannot be
>> 86:  * added to a list whose value type is not const-qualified, as that would be
>> 87:  * an implicit casting away of the const qualifier.
> 
> Okay, I feel like this can be shortened signifcantly:
> 
>> A const-qualified type can be part of an IntrusiveList, then you only get const iterators and access to const elements. If you use a non-const type, then you can get both const and non-const iterators and access to elements. You can't add const values to a non-const list, as that would be implicitly casting away the const qualifier.

That rewrite isn't correct.

You _can_ add const values to a non-const list. In fact, you can only add
values (const or not) to a non-const list. A const list has type `const
IntrusiveList<T, accessor>`, while a non-const list is similar but without the
`const` qualifier.

What you can't do is add a const value to a (necessarily non-const) list of
non-const elements.  So if T is an unqualified class type, then you can add
const values to an `IntrusiveList<const T, accessor>` but not to an
`IntrusiveList<T, accessor>`.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/15896#discussion_r1349576545


More information about the hotspot-dev mailing list