[foreign-memaccess+abi] RFR: Improve performance of Arena::allocateFrom
Maurizio Cimadamore
mcimadamore at openjdk.org
Thu Aug 3 16:56:54 UTC 2023
On Thu, 3 Aug 2023 16:32:37 GMT, Quan Anh Mai <qamai at openjdk.org> wrote:
> The benchmark methods seem to include arena creation, memory allocation and memory deallocation, is it intended? I think this benchmark should only take into consideration memory allocation, no?
I mean it was intended, as I wanted to measure that too - but you are right that doing so will add noise.
>
> > One caveat: a custom arena does NOT inherit this special behavior. That is, it is the responsibility of the custom arena to define "shortcut" for the `allocateFrom` methods.
>
> This means that the custom arenas have to use another way (e.g `malloc`) to allocate memory without initialization themselves, right? The following sentences give me the impression that there are some kinds of protected methods that can be delegated to.
Say you want to wrap a confined arena in another custom arena. A custom arena is only required to implement a single allocation method (`allocate(long, long)`). But if you do that, then _all_ the default methods the custom arena inherits from `SegmentAllocator` will delegate back to that. Which means no distinction between `allocate` and `allocateFrom`.
So, if a custom arena wants to delegate to the underlying arena, and keep the distinction between zeroing and non-zeroing allocation (e.g. because it doesn't want to use malloc, or something else), it _must_ override all the `allocateFrom` methods, and delegate them to the underlying arena.
Of course if a custom arena implements its single allocation via malloc `malloc`, or if the custom arena recycles memory, then there's no need to override any other methods, as the primary allocation method (the one all the other delegate to) is already avoiding zeroing.
Effectively, what this does is moving the burden of "being efficient" on the implementors of a custom arena (which are developers that, we think, can handle such complexity). But the default arena we return are _already_ optimized as best as we can. Which means less experienced developers, or developers that do not have crazy allocation requirements, can just use them out of the box, while, up to now, the default arenas were all kind of "meh", and the answer always was: to get to better allocation performance, use another custom arena.
>
> Thanks a lot.
-------------
PR Comment: https://git.openjdk.org/panama-foreign/pull/855#issuecomment-1664318342
More information about the panama-dev
mailing list