[jdk19] RFR: 8291496: Allocating card table before heap causes underflow asserts in CardTable::addr_for()

Kim Barrett kbarrett at openjdk.org
Fri Aug 5 03:57:56 UTC 2022


On Wed, 3 Aug 2022 16:13:50 GMT, Thomas Schatzl <tschatzl at openjdk.org> wrote:

> Hi all,
> 
>   can I have reviews for sidestepping a wrong assert in `CardTable::addr_for`?
> 
> So if `CardTable::_byte_map_base` gets negative (highest bit set) if it is allocated very much below the heap, the used `pointer_delta` method errors out with an assert that (in unsigned comparison) the "left" address is smaller than the "right" address.
> 
> Testing: tier 1-5, failures without change after modifying the code to allocate the card table at very low addresses and using `HeapBaseMinAddress`, no failures afterwards.
> 
> @albertnetymk analyzed this, so I'll add him as contributor of this patch.

Looks good.

src/hotspot/share/gc/shared/cardTable.hpp line 192:

> 190:            " _byte_map: " PTR_FORMAT " _byte_map + _byte_map_size: " PTR_FORMAT,
> 191:            p2i(p), p2i(_byte_map), p2i(_byte_map + _byte_map_size));
> 192:     size_t delta = p - _byte_map_base;

Maybe it's worth a comment that this is specifically NOT using pointer_delta because `_byte_map_base` can be "negative"?  I suspect that situation involves UB, but we've been "getting away" with it so far, so don't try to fix it here.

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

Marked as reviewed by kbarrett (Reviewer).

PR: https://git.openjdk.org/jdk19/pull/160



More information about the hotspot-gc-dev mailing list