RFR: 8296776: Stop using mtNone as marker for CHeap allocations in GrowableArray [v2]

Xin Liu xliu at openjdk.org
Fri Nov 11 07:39:30 UTC 2022


On Thu, 10 Nov 2022 10:15:11 GMT, Stefan Karlsson <stefank at openjdk.org> wrote:

>> Today we use mtNone to denote that a GrowableArray should *NOT* be backed by a CHeap allocated array.
>> 
>> I've gotten feedback that it would probably be good to limit the usage of mtNone, and at some point maybe completely remove it.
>> 
>> This patch takes a small step to remove mtNone from the GrowableArray. What's left is only asserts to forbid that value. Those asserts will be trivial to remove when/if mtNone is removed.
>> 
>> Just like in the proposed patch to make MEMFLAGS non-optional in CHeapBitMap (see JDK-[JDK-8296774](https://bugs.openjdk.org/browse/JDK-8296774)), I have thrown around the parameter order for GrowableArray. When looking at the changes to the usages of CHeap-backed GrowableArrays it becomes apparent that all of these usages where forced to provide a value for the initial capacity. When MEMFLAGS move to the front, we can now skip having to figure an initial capacity.
>
> Stefan Karlsson has updated the pull request with a new target base due to a merge or a rebase. The pull request now contains one commit:
> 
>   8296776: Stop using mtNone as marker for CHeap allocations in GrowableArray

It looks like no one is using mtNone for GrowableArray, but memReporter.cpp and virtualMemoryTracker still accept it. Shall we eliminate mtNone completely?

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

> 732:   }
> 733: 
> 734:   GrowableArray(MEMFLAGS memflags, int initial_capacity = 2) :

I feel it's too dangerous to have two constructors with convertible parameters. 
eg. GrowableArray(int initial_capacity)  and   GrowableArray(MEMFLAGS memflags, int initial_capacity = 2) are very close. what if someone has code like this:

short t = 2;
GrowableArray(2); // it's very vague to me which ctor will be selected.


I think it's a good idea to use 'explicit constructor' for one of them. in case implicit conversation takes place unconsciously.

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

PR: https://git.openjdk.org/jdk/pull/11086


More information about the hotspot-dev mailing list