[foreign-abi] RFR: JDK-8241998: Revisit Foreign::ofNativeUnchecked

Athijegannathan Sundararajan sundar at openjdk.java.net
Wed Apr 1 13:57:43 UTC 2020


On Wed, 1 Apr 2020 13:25:23 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

> The current Foreign::ofNativeUnchecked can be a bit clunky too use in idiomatic native interop code. So far we have
> isolated two common use cases:
> * attach a size to an otherwise unchecked address
> * create a segment from an address that comes from a malloc - in cases where user is responsible for cleanup
> 
> The current ofNativeUnchecked is too clunky for the first use case, and not powerful enough for the latter. Rather than
> exposing a very complex, builder-like factory to create any kind of segment, let's add ad-hoc capabilities to create
> segments that native interop actually needs.   This patch replaces Foreign::ofNativeUnchecked with two routines:
> 
> * withSize, which takes a MemoryAddress and returns a MemoryAddress (with a sized segment attached)
> * asMallocSegment, which takes a MemoryAddress and create a closeable, confined segment of given size; calling close will
>   free the address

Marked as reviewed by sundar (Committer).

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

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


More information about the panama-dev mailing list