RFR: 8139457: Array bases are aligned at HeapWord granularity [v19]

Aleksey Shipilev shade at openjdk.org
Mon Jul 3 18:00:28 UTC 2023


On Mon, 13 Feb 2023 18:05:03 GMT, Roman Kennke <rkennke at openjdk.org> wrote:

>> src/hotspot/share/gc/shared/collectedHeap.cpp line 257:
>> 
>>> 255:   const size_t elements_per_word = HeapWordSize / sizeof(jint);
>>> 256:   int base_offset_in_ints = arrayOopDesc::base_offset_in_ints(T_INT);
>>> 257:   _filler_array_max_size = align_object_size((base_offset_in_ints + max_len) / elements_per_word);
>> 
>> Isn't this expression susceptible to overflow, like the removed comment in `CollectedHeap::max_tlab_size` (below) states? I.e. max_len is probably very close to SIZE_MAX on 32-bit platforms, and adding the base offset gets dangerously close there. Not to mention the positive side of signed `int` domain is lower than SIZE_MAX to beging with? I think you need to keep doing the division `max_len / elements_per_word` first.
>
> As you say, the positive side of int32_t is much smaller than SIZE_MAX and thus we are basically guaranteed to not overflow here. Also, arrayOopDesc::max_array_length() is specifically designed to prevent such overflows (and even the more likely overflowing of size_t when converting. I am going to add corresponding assert there.

All right.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/11044#discussion_r1251006987


More information about the hotspot-dev mailing list