RFR: 8365994: ZGC: Incorrect type signature in ZMappedCache comparator
Joel Sikström
jsikstro at openjdk.org
Tue Aug 26 08:57:43 UTC 2025
On Mon, 25 Aug 2025 15:22:21 GMT, Axel Boldt-Christmas <aboldtch at openjdk.org> wrote:
>> src/hotspot/share/gc/z/zMappedCache.hpp line 44:
>>
>>> 42: struct EntryCompare {
>>> 43: static int cmp(zoffset a, const IntrusiveRBNode* b);
>>> 44: static bool cmp(const IntrusiveRBNode* a, const IntrusiveRBNode* b);
>>
>> I'd expect `cmp` to return `int`; otherwise, the `cmp` name is rather misleading. I wonder if rbtree can be changed so that all `cmp` methods return `int` instead.
>
> I tend to agree, or rename it to `less`.
>
> And I think `cmp` should even return a more strongly typed class, rather than `int` to discourage code like `return b - a;` as you have to be very careful to not introduce underflow arithmetic bugs. Maybe even take inspiration from `operator<=>`
I agree with both of you that there is room for improvement here.
I've talked with @caspernorrbin, who is the author of the tree, and we've agreed that he will address this feedback in a follow-up. I'll go ahead and integrate this change so that the comparator we have in ZGC is aligned with the (current) type signature and we verify the tree correctly.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/26904#discussion_r2300289687
More information about the hotspot-gc-dev
mailing list