RFR: 8296139: Make GrowableBitMap the base class of all implementations [v4]
Volker Simonis
simonis at openjdk.org
Wed Nov 9 19:11:46 UTC 2022
On Wed, 9 Nov 2022 18:37:02 GMT, Xin Liu <xliu at openjdk.org> wrote:
>> src/hotspot/share/utilities/bitMap.cpp line 637:
>>
>>> 635: template class GrowableBitMap<ArenaBitMap>;
>>> 636: template class GrowableBitMap<ResourceBitMap>;
>>> 637: template class GrowableBitMap<CHeapBitMap>;
>>
>> Do you really need this explicit template instantiations? I think such code is only required in libraries where you want to be sure to have specific instantiations even though they are not used within the library itself. But here you will get these instantiations anyway whenever `ArenaBitMap`, `ResourceBitMap` or `CHeapBitMap` is used because they are derived from `GrowableBitMap<ArenaBitMap>`, `GrowableBitMap<ResourceBitMap>` and `GrowableBitMap<CHeapBitMap>` respectively.
>
> hi, Volker,
>
> Thank you for reviewing this patch.
>
> The reason we have to explicitly instantiate GrowableBitMap<T> is that we place this member function `GrowableBitMap<BitMapWithAllocator>::reallocate` in CPP file. The cpp file is a compilation unit. Other compilation units which include bitMap.hpp won't trigger template instantiations in the compilation unit of this cpp file. As a result, I will end up with linkage errors.
>
> eg. If I take out those 3 statements, ld/collect2 complains that it can't find definitions.
>
>
> * For target hotspot_variant-server_libjvm_objs_BUILD_LIBJVM_link:
I'll take my comment back :)
It turns out that we need these explicit instantiations, because implicit instantiations do not instantiate unused members (i.e. "*This applies to the members of the class template: unless the member is used in the program, it is not instantiated, and does not require a definition*", see https://en.cppreference.com/w/cpp/language/class_template#Implicit_instantiation).
E.g.:
CHeapBitMap::CHeapBitMap(idx_t size_in_bits, MEMFLAGS flags, bool clear)
: GrowableBitMap<CHeapBitMap>(), _flags(flags) {
initialize(size_in_bits, clear);
}
implicitely instantiates `GrowableBitMap<CHeapBitMap>` but it will not instantiate `GrowableBitMap<CHeapBitMap>::reallocate()` because it is not used in that compilation unit.
-------------
PR: https://git.openjdk.org/jdk/pull/10941
More information about the hotspot-runtime-dev
mailing list