[foreign-jextract] RFR: MemorySegmentPool + Allocator [v5]

Maurizio Cimadamore mcimadamore at openjdk.java.net
Tue Apr 20 15:36:50 UTC 2021


On Tue, 20 Apr 2021 07:04:47 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:
> 
>   Fix tests (!)
>   Make entries closable, to make API easier to use, and avoid searching for target queue.
>   Replace atomics is var handles

New numbers:


Benchmark                                          (size)  Mode  Cnt   Score   Error  Units
StrLenTest.panama_strlen_memsegmentpool_allocator       5  avgt   30  56.377 ? 1.180  ns/op
StrLenTest.panama_strlen_memsegmentpool_allocator      20  avgt   30  59.849 ? 0.759  ns/op
StrLenTest.panama_strlen_memsegmentpool_allocator     100  avgt   30  83.250 ? 3.614  ns/op
StrLenTest.panama_strlen_memsegmentpool_direct          5  avgt   30  43.117 ? 0.525  ns/op
StrLenTest.panama_strlen_memsegmentpool_direct         20  avgt   30  46.241 ? 0.469  ns/op
StrLenTest.panama_strlen_memsegmentpool_direct        100  avgt   30  63.124 ? 0.708  ns/op


Yes - it seems to match the unsafe case (which does malloc/free).

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

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


More information about the panama-dev mailing list