[foreign-jextract] RFR: MemorySegmentPool + Allocator [v8]
Maurizio Cimadamore
mcimadamore at openjdk.java.net
Thu Apr 22 20:33:35 UTC 2021
On Thu, 22 Apr 2021 01:53:10 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:
>
> Tests better distribute sizes for pseudo random allocation - now much larger buffers gets allocated and used.
>
> I'm bit puzzled here, as it looks like, that allocatioin is very fast, only
> reading is extreme slow.
>
> For comparision when processing single allocation:
> Update only first byte: direct pool access - 33ns, malloc / free: 59ns
> Update very 1024th byte: 12980ns, vs malloc: 8400ns
>
> I think simillar results has been spot during test with StringLen.
src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/MemorySegmentPool.java line 199:
> 197: });
> 198:
> 199: return segmentEntry.memoryAddress.asSegment(1L << bitBound, resourceScope);
I wouldn't be surprised if this was the issue - the segment is created with a size that is determined by a long shift. If this segment gets scalarized, I wonder if the VM is able to see that the segment size is actually an int and not a long. Worth a shot.
-------------
PR: https://git.openjdk.java.net/panama-foreign/pull/509
More information about the panama-dev
mailing list