[foreign-abi] RFR: 8254682: Close MemorySegments passed to upcalls after the upcall is done
Maurizio Cimadamore
mcimadamore at openjdk.java.net
Tue Oct 13 17:06:18 UTC 2020
On Tue, 13 Oct 2020 14:58:29 GMT, Jorn Vernee <jvernee at openjdk.org> wrote:
> Hi,
>
> Currently, we don't close MemorySegments that we pass to upcalls. This makes it easier to leak a MemorySegment from an
> upcall, but it also incurs an additional copy on Windows and Aarch64, and forces users to close these segments manually
> instead. (This is mostly so for historical reasons, when it was not as easy to avoid this copy due to the code
> structure/design at that time). We can instead registers these segments with a NativeScope that is closed after the
> upcall completes, to make sure these segments do not leak inadvertently, and we don't need the additional copy on some
> platforms. In this PR I've also fixed 2 minor Javadoc issues in Binding.java that I missed last time around.
> This patch will also break jexract tests, but I have a patch ready to fix (was pretty trivial).
> (https://github.com/openjdk/panama-foreign/pull/380)
> Thanks,
> Jorn
Looks good
src/jdk.incubator.foreign/share/classes/jdk/internal/foreign/AbstractNativeScope.java line 140:
> 138:
> 139: // only for registering
> 140: private static class EmptyScope extends AbstractNativeScope {
could this be your Throwing Allocator?
-------------
Marked as reviewed by mcimadamore (Committer).
PR: https://git.openjdk.java.net/panama-foreign/pull/379
More information about the panama-dev
mailing list