[foreign-jextract] RFR: MemorySegmentPool + Allocator [v6]
Maurizio Cimadamore
mcimadamore at openjdk.java.net
Tue Apr 20 16:50:21 UTC 2021
On Tue, 20 Apr 2021 15:36: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:
>
> Use VH insted of volatile
>
> Replacee
> // while ((int) LOCK.compareAndExchange(this, 0, 1) != 1) { }
> while (!LOCK.compareAndSet(this, 0, 1)) { }
>
> Performane around 34 ns / oop
src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/MemorySegmentPool.java line 133:
> 131: * @return segment of size at least `size`
> 132: */
> 133: @ForceInline
I've tried removing @ForceInline here (and in other places) and I did not notice any regression in the benchmark.
src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/MemorySegmentPool.java line 154:
> 152: private MemorySegment getSegmentForScope(ResourceScope resourceScope, long size, long alignment) {
> 153: final var segmentEntry = getSegmentEntryBySize(size, alignment);
> 154: resourceScope.addOnClose(() -> segmentEntry.close());
There's a potential safety issue here - resourceScope doesn't promise that cleanup actions will be called in a certain order. But I think this should be ok, because the cleanup actions are invoked _after_ the user-provided scope is closed. Meaning that the segments associated with that scope will not be accessible anyway.
-------------
PR: https://git.openjdk.java.net/panama-foreign/pull/509
More information about the panama-dev
mailing list