RFR: 8345687: Improve the implementation of SegmentFactories::allocateSegment [v3]

Maurizio Cimadamore mcimadamore at openjdk.org
Wed Feb 5 10:21:11 UTC 2025


On Sat, 25 Jan 2025 02:32:56 GMT, Quan Anh Mai <qamai at openjdk.org> wrote:

>> But the address is immediately converted to memory segment using MemorySegment::ofAddress, which is what the linker does anyway?
>
> Only the return value of `CALLOC` is converted to `MemorySegment` in an equivalent way, I believe passing a `MemorySegment` to a downcall involves acquiring the corresponding segment? As a result, `FREE` is made to accept the raw address, and `CALLOC` is changed in the same manner for consistency.

Yes, passing segments to a downcall will acquire -- but if the segment is a wrapper around a long (a zero-length memory segment), its scope is the global scope, and acquire is a no-op. Stepping back what worries me with the changes in this benchmark is that we're replacing idiomatic FFM code with very low-level code which seems less representative of code people would write. Maybe if we need a dedicated benchmark to ensure there's no escaping in the innards of the API impl, we should write one specifically for that?

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

PR Review Comment: https://git.openjdk.org/jdk/pull/22610#discussion_r1942600291


More information about the core-libs-dev mailing list