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

Maurizio Cimadamore mcimadamore at openjdk.java.net
Wed Apr 21 23:57:33 UTC 2021


On Wed, 21 Apr 2021 23:37:15 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 two additional commits since the last revision:
> 
>  - Better releasing resources on scopes close
>    New benchamarks for bulk allocations
>  - Minor fixes to SpinLockQueue
>    Remove redundant LOCK release (set to 0) in put entry.
>    Fixed maxSize comparison
>    Removed unused imports
>    
>    Q: Could we reduce setRelease to just set in few places?
>    Q: Should this method be private and moved to Entry.close to prevent accidental adding element from other queue?

test/micro/org/openjdk/bench/jdk/incubator/foreign/AllocatorsForLongRun.java line 149:

> 147:   private void readSegment(MemorySegment s) {
> 148:     final var size = s.byteSize();
> 149:     for (long l = 0; l <  size; l += 256) {

this is a loop on `long` - as thing stands - this is gonna defeat all optimizations. For the time being - replace with an `int` loop (and then cast coordinate back to `long`). Or just use `MemoryAccess.setByteAtIndex`.

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

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


More information about the panama-dev mailing list