RFR: 8333658: NMT: Use an allocator with 4-byte pointers to save memory in NativeCallStackStorage
Thomas Stuefe
stuefe at openjdk.org
Thu Jun 6 16:01:45 UTC 2024
On Thu, 6 Jun 2024 15:14:33 GMT, Johan Sjölen <jsjolen at openjdk.org> wrote:
>> src/hotspot/share/nmt/indexedFreeListAllocator.hpp line 38:
>>
>>> 36: BackingElement(E& e) {
>>> 37: this->e = e;
>>> 38: }
>>
>> What would be cool is for this data structure to work with any E without requiring E to implement default- and copy-constructors. E.g. an E with a mandatory const member and a single constructor that inits that member.
>>
>> Maybe we could do that by not storing E but making sure there is enough space for E, like this:
>>
>>
>> union BackingElement {
>> I link;
>> char x[sizeof(E)];
>> };
>>
>>
>> Then use x and placement new, which you do already.
>>
>> sizeof(E) would also account for intra-array padding needed to guarantee E alignment. All we need to make sure then is to align the start pointer of the first BackingElement, but since that one is malloced from C-heap, its already aligned.
>>
>> And I think we don't really need any constructors here.
>>
>> Also, please remove unnecessary this->. Please use initializer lists.
>
> That's a good idea. It probably should be:
>
> ```c++
> union alignas(E) BackingElement {
> I link;
> char e[sizeof(E)];
> };
Even better
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/18979#discussion_r1629800717
More information about the hotspot-dev
mailing list