[foreign-abi] RFR: JDK-8241998: Revisit Foreign::ofNativeUnchecked
Maurizio Cimadamore
mcimadamore at openjdk.java.net
Wed Apr 1 13:31:12 UTC 2020
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
-------------
Commit messages:
- Remove overloads
- First sketch of unsafe API
- Initial API sketch
Changes: https://git.openjdk.java.net/panama-foreign/pull/81/files
Webrev: https://webrevs.openjdk.java.net/panama-foreign/81/webrev.00
Issue: https://bugs.openjdk.java.net/browse/JDK-JDK-8241998
Stats: 96 lines in 9 files changed: 37 ins; 18 del; 41 mod
Patch: https://git.openjdk.java.net/panama-foreign/pull/81.diff
Fetch: git fetch https://git.openjdk.java.net/panama-foreign pull/81/head:pull/81
PR: https://git.openjdk.java.net/panama-foreign/pull/81
More information about the panama-dev
mailing list