[foreign-memaccess+abi] RFR: MemorySegmentPool + Allocator [v12]

Radoslaw Smogura github.com+7535718+rsmogura at openjdk.java.net
Mon Apr 26 23:46:51 UTC 2021


On Mon, 26 Apr 2021 23:24:13 GMT, Radoslaw Smogura <github.com+7535718+rsmogura at openjdk.org> wrote:

>> (Preview)
>> 
>> The MemorySegmentPool is a pool maintaining memory segments, optionally can expose allocator which can be bound to other scope, and which will return allocated segments back to pool.
>> 
>> However the best results has been achieved by using getSegmentEntry & putSegmentEntry methods.
>> 
>> The pool is intended to be used by long running applications (i.e. like global shared pool), where fast allocation and de-allocation of segments is critical (was designed during implementation of I/O subsystem with Panama, as a pool for temporary buffers between system I/O methods and Java byte arrays from InputStreams).
>> 
>> The pool uses hand-made SpinLockQueue as the Deque from JDK offers too much functionality and overhead.
>
> Radoslaw Smogura has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Drop internal API.
>   Use fields access instead of VarHandler in poll & put entry (small performance gain,
>   hope fences will work normally)
>   
>   Replace scope close handler with ResourceCleanup to get additional performance
>   
>   Dropped registering cleaners per allocated item, and moved freeing entries to cleaner (thanks Maurizio)

With the latest changes I could go down from 61ns to 54ns per operation.

I hope I didn't mess with dropping VarHandles but it gave 1ns.

Clearing MemoryPoolItem helped a bit, too.

Most important, replacing cleaner from public API by ResourceCleaner gave big win.

I still, think having a good indicator if cleaner was added or not is a good idea (it can be a Boolean return or concrete exception). For clients wanting to use public API, IllegalStateException is not 100% sure indicator. 

Once again I would like to thank you @mcimadamore for a good review! You helped a lot!

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

PR: https://git.openjdk.java.net/panama-foreign/pull/509


More information about the panama-dev mailing list