RFR: 8355013: GrowableArray default constructor should not allocate

Thomas Stuefe stuefe at openjdk.org
Fri Apr 18 07:11:50 UTC 2025


On Fri, 18 Apr 2025 05:35:05 GMT, Quan Anh Mai <qamai at openjdk.org> wrote:

> Hi,
> 
> This patch changes the default constructors of `GrowableArray` so that it does not allocate. This is helpful because sometimes we create a `GrowableArray` and append another into it immediately, or create a `GrowableArray` to merge the value from several branches. In these cases, the default allocation is not needed. This also aligns the behaviour with that of `std::vector`, which does not allocate for default construction.
> 
> Please take a look and leave your reviews, thanks a lot.

Makes sense.

test/hotspot/gtest/utilities/test_growableArray.cpp line 356:

> 354:       ResourceMark rm;
> 355:       GrowableArray<int> a;
> 356:       modify_and_test(&a, modify, test);

Test for zero length before modify_and_test.

test/hotspot/gtest/utilities/test_growableArray.cpp line 446:

> 444: // static empty vector
> 445: const GrowableArray<int> empty_array(mtTest);
> 446: const GrowableArrayCHeap<int, mtTest> empty_cheap_array;

Where are these used?

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

PR Review: https://git.openjdk.org/jdk/pull/24748#pullrequestreview-2777847075
PR Review Comment: https://git.openjdk.org/jdk/pull/24748#discussion_r2050197591
PR Review Comment: https://git.openjdk.org/jdk/pull/24748#discussion_r2050200891


More information about the hotspot-dev mailing list