RFR: 8367536: Change RBTree to use C++17 features [v3]

Casper Norrbin cnorrbin at openjdk.org
Wed Sep 17 08:48:21 UTC 2025


On Wed, 17 Sep 2025 08:41:43 GMT, Casper Norrbin <cnorrbin at openjdk.org> wrote:

>> Hi everyone,
>> 
>> C++17 lets us tidy up som of the ugly templating done in the red-black tree. We can replace the `std::false_type`/`std::true_type` tricks used to discover comparator and verifier signatures with the new `std::is_invocable(_r_v)`, and most of the overload/SFINAE noise can disappear thanks to `if constexpr`.
>> 
>> We can now write one-liners such as:
>> ```c++
>> static constexpr bool HasKeyComparator = std::is_invocable_r_v<RBTreeOrdering, decltype(&CMP::cmp), K, K>;
>> 
>> 
>> and then select the right branch with
>> ```c++
>> if constexpr (HasKeyComparator<CMP>) { }
>> 
>> inside a single function instead of having several `ENABLE_IF` overloads.
>> 
>> This results in fewer lines, clearer intent, and more readable errors, while keeping behaviour identical.
>> 
>> Testing:
>> - Oracle tiers 1-3
>
> Casper Norrbin has updated the pull request incrementally with one additional commit since the last revision:
> 
>   change HasNodeVerifier back to struct

Thank you both for reviewing!

There seems to be a [bug](https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71954) in older versions of gcc with partial template specialization of constexpr inside classes. This makes GHA fail on linux since it uses that older version, but works fine on newer versions or other platforms. I think the correct solutions is to make some changes to `HasNodeVerifier` to make GHA pass.

I have turned that back into a struct with `std::false_type`/`std::true_type`, similar in style to what it was before. It is still cleaner than the previous solutions, since we can still use `std::is_invocable_r_v`, and now also use `std::bool_constant`. With this we can get rid of the templated constexpr variables.

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

PR Comment: https://git.openjdk.org/jdk/pull/27260#issuecomment-3301975221


More information about the hotspot-dev mailing list