RFR: 8345687: Improve the implementation of SegmentFactories::allocateSegment [v3]
Maurizio Cimadamore
mcimadamore at openjdk.org
Fri Jan 24 11:59:47 UTC 2025
On Wed, 22 Jan 2025 16:45:39 GMT, Quan Anh Mai <qamai at openjdk.org> wrote:
>> test/micro/org/openjdk/bench/java/lang/foreign/AllocTest.java line 77:
>>
>>> 75: var freeAddr = lookup.findOrThrow("free");
>>> 76: CALLOC = linker.downcallHandle(callocAddr, FunctionDescriptor.of(ValueLayout.JAVA_LONG, ValueLayout.JAVA_LONG, ValueLayout.JAVA_LONG));
>>> 77: FREE = linker.downcallHandle(freeAddr, FunctionDescriptor.ofVoid(ValueLayout.JAVA_LONG));
>>
>> I'm not sure these changes are needed. It seems the main goal here is to avoid the cost of the capture associated with `CLayouts::freeMemory` ? If so, can't we just store that consumer into a static final and call it a day? I think then we could avoid the `static` init, and leave most of the code unchanged, except for the additional static field?
>
> The main goal here is that passing/receiving raw addresses as longs is cheaper than as `MemorySegment`s.
But the address is immediately converted to memory segment using MemorySegment::ofAddress, which is what the linker does anyway?
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/22610#discussion_r1928571827
More information about the core-libs-dev
mailing list