RFR: JDK-8312453: GrowableArray should assert for length overflow on append
Thomas Stuefe
stuefe at openjdk.org
Thu Jul 20 16:09:43 UTC 2023
On Thu, 20 Jul 2023 16:04:56 GMT, Thomas Stuefe <stuefe at openjdk.org> wrote:
>> src/hotspot/share/utilities/growableArray.hpp line 390:
>>
>>> 388: public:
>>> 389: int append(const E& elem) {
>>> 390: assert(this->_len != INT_MAX, "Overflow");
>>
>> This isn't needed. `grow` (via `next_power_of_2`) already does the appropriate overflow checking.
>
> Then we rely on the underlying growth algorithm to always work in power-of-2-steps? What if I want to plug in a different allocator with a different growth cadence?
Or, what if we have a simple error? To just accept an overflow here seems dangerous.
That said, I wonder whether we should make the length uintx-sized. As it is now, we are limited to 1G max number of elements.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/14951#discussion_r1269681158
More information about the hotspot-dev
mailing list