RFR: 8319117: GrowableArray: Allow for custom initializer instead of copy constructor [v15]

Leo Korinth lkorinth at openjdk.org
Mon Nov 13 08:47:00 UTC 2023


On Tue, 7 Nov 2023 15:24:49 GMT, Johan Sjölen <jsjolen at openjdk.org> wrote:

>> Hi, 
>> 
>> When using at_put and at_put_grow you can provide a value which will be supplied to the constructor of each element. In other words, you can intialize each element through a copy constructor.
>> 
>> I suggest that we also provide a function equivalent where the function is provided a pointer to the memory to be initialized. This can be used for `NONCOPYABLE` classes, for example.
>> 
>> This is implemented using a SFINAE pattern because `nullptr` introduces ambiguity if you use static overload.
>> 
>> Currently running tier1-tier4.
>
> Johan Sjölen has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Fix bug and style issues

src/hotspot/share/utilities/growableArray.hpp line 434:

> 432:     assert(0 <= i, "negative index %d", i);
> 433:     if (i < this->_len) {
> 434:       this->_data[i] = E(elem);

This is not good if we want to remove dependency on having an assignment operator. Maybe change the assignment and the return statement to a destructor call, and let the code path below initialize the value in the destructed memory?

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

PR Review Comment: https://git.openjdk.org/jdk/pull/16409#discussion_r1390768906


More information about the hotspot-dev mailing list