RFR: 8139457: Array bases are aligned at HeapWord granularity [v19]
Roman Kennke
rkennke at openjdk.org
Mon Feb 13 18:07:37 UTC 2023
On Mon, 13 Feb 2023 16:28:14 GMT, Aleksey Shipilev <shade at openjdk.org> wrote:
>> Roman Kennke has updated the pull request incrementally with one additional commit since the last revision:
>>
>> Remove stale method
>
> 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.
-------------
PR: https://git.openjdk.org/jdk/pull/11044
More information about the hotspot-dev
mailing list