RFR: 8368966: Remove spurious VMStructs friends

Stefan Karlsson stefank at openjdk.org
Thu Oct 2 07:59:48 UTC 2025


On Wed, 1 Oct 2025 14:42:13 GMT, Francesco Andreuzzi <fandreuzzi at openjdk.org> wrote:

>> src/hotspot/share/utilities/growableArray.hpp line 715:
>> 
>>> 713: template <typename E>
>>> 714: class GrowableArray : public GrowableArrayWithAllocator<E, GrowableArray<E>> {
>>> 715:   friend class VMStructs;
>> 
>> I was a bit surprised to see that you added a friend declaration. Was this done because you removed the one in the parent class?
>> 
>> I see that vmStructs.cpp has GrowableArray listed:
>> 
>>   nonstatic_field(GrowableArrayBase,           _len,                                          int)                                   \
>>   nonstatic_field(GrowableArrayBase,           _capacity,                                     int)                                   \
>>   nonstatic_field(GrowableArray<int>,          _data,                                         int*) 
>> 
>> 
>> So, I guess it makes sense to move it here. OTOH, the exposed `_data` field is inside GrowableArrayView, so maybe it would work to put the friend declaration there instead?
>> 
>> I guess either way is fine but there's a risk that there will be some churn about where to put the friend declaration if someone wants add one of the classes between (and including) GrowableArrayView and GrowableArray.
>
>> Was this done because you removed the one in the parent class?
> 
> Yeah that was my reasoning.
> 
>> I guess either way is fine but there's a risk that there will be some churn about where to put the friend declaration if someone wants add one of the classes between (and including) GrowableArrayView and GrowableArray.
> 
> To me it looks less confusing to have the `friend` declaration for the type which is referenced in `vmStructs`. But both are legal, do you think moving the `friend` declaration to the type which declares the referenced field would be more appropriate? If yes, I'll track other similar patterns too.

I don't think such churn is important for VMStructs. Let's keep your change.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/27583#discussion_r2397576465


More information about the hotspot-dev mailing list