GrowableArray<JavaVMOption> - how it works?
Dmitry Samersoff
dms at samersoff.net
Wed Dec 2 14:05:46 UTC 2020
Hello Kim,
Thank you!
As soon as we have c++14 enabled for jdk16, are there any plans to
cleanup template usage in hs - add static_asserts etc?
-Dmitry
On 02/12/2020 04:19, Kim Barrett wrote:
>> On Dec 1, 2020, at 1:31 PM, Dmitry Samersoff <dms at samersoff.net> wrote:
>>
>> Hello Everybody,
>>
>> While experimenting with the use of templates within hotspot in order to reduce VM size, I found a thing that I can't understand.
>>
>> What I'm missing here?
>>
>> arguments.cpp:
>>
>> GrowableArray<JavaVMOption> *options = new (ResourceObj::C_HEAP, mtArguments)
>>
>> Where JavaVMOption is the plain C structure {char*, void*} that comes from jni.h
>>
>> but
>>
>> template<class E>
>> class GrowableArray : public GenericGrowableArray {
>>
>> contains couple of functions like one below:
>>
>> int find_from_end(const E& elem) const {
>> for (int i = _len-1; i >= 0; i--) {
>> if (_data[i] == elem) return i;
>> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>> }
>> return -1;
>> }
>>
>> How it supposed to work?
>>
>> If I instantiate GrowableArray<JavaVMOption> explicitly it can't be compiled at al.
>>
>> Thank you!
>> -Dmitry
>
> Templates have requirements for the template parameters.
>
> Attempting to use a type that doesn't meet the requirements is going
> to fail to compile, sometimes with a really large error dump (the
> so-called error novel). Concepts should eventually help with that, but
> we don't have those in C++14.
>
> GrowableArray doesn't document its requirements (HotSpot templates
> rarely have such documentation, which I think is unfortunate), but
> it's probably similar to the requirements for std::vector; see C++14
> 23.2.1 and 23.2.3.
>
> This is all basic C++ template knowledge.
>
> In the specific example given, E must be EqualityComparable.
> JavaMVOption isn't.
>
More information about the hotspot-dev
mailing list