[foreign-abi] RFR: 8254682: Close MemorySegments passed to upcalls after the upcall is done
Jorn Vernee
jvernee at openjdk.java.net
Tue Oct 13 17:14:28 UTC 2020
On Tue, 13 Oct 2020 15:07:48 GMT, Maurizio Cimadamore <mcimadamore 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
>
> 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?
No, the throwing allocator has no machinery to do handoffs. The code of EmptyScope looks deceptively simple, but that's
because all the logic we want is actually in the base class.
-------------
PR: https://git.openjdk.java.net/panama-foreign/pull/379
More information about the panama-dev
mailing list