RFR: 8339242: Fix overflow issues in AdlArena [v2]

Casper Norrbin duke at openjdk.org
Tue Sep 3 14:04:21 UTC 2024


On Tue, 3 Sep 2024 10:01:12 GMT, Kim Barrett <kbarrett at openjdk.org> wrote:

>> Casper Norrbin has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   arena realloc overflow check
>
> src/hotspot/share/adlc/adlArena.cpp line 154:
> 
>> 152:   if( (c_old+old_size == _hwm) &&            // Adjusting recent thing
>> 153:       ((size_t)(_max-c_old) >= new_size) ) { // Still fits where it sits, safe from overflow
>> 154: 
> 
> It appears that this change isn't worrying about bad `old_ptr` or `old_size`
> arguments, which is fine.  But the code can be further improved by replacing
> lines 144-157 with something like
> 
> // Reallocating the most recent allocation?
> if ((c_old + old_size) == _hwm) {
>   assert(_chunk->bottom() <= c_old, "invariant");
>   // Reallocate in place if it fits.  This also handles shrinking.
>   if (pointer_delta(_max, c_old) >= new_size) {
>     _hwm = c_old + new_size;
>     return c_old;
>   }
> }
> 
> Of course, in adlc you can't use HotSpot's pointer_delta utility, so there
> you'll need to use something like what's in the PR for that calculation.
> 
> Any check for an "unreasonable" size should happen in Amalloc, not here.

I believe this would miss the case where we shrink an allocation in place and we are not at the high water mark, where `new_size <= old_size`, but where `c_old + old_size) == _hwm` does not hold.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/20774#discussion_r1742120796


More information about the hotspot-compiler-dev mailing list