[foreign-memaccess+abi] RFR: 8265751: MemoryAddress should have a scope accessor [v3]
Radoslaw Smogura
github.com+7535718+rsmogura at openjdk.java.net
Fri Apr 23 17:41:40 UTC 2021
On Fri, 23 Apr 2021 17:22:08 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:
>> src/jdk.incubator.foreign/share/classes/jdk/internal/foreign/MemoryAddressImpl.java line 87:
>>
>>> 85: if (segment != null) {
>>> 86: if (segment.base() != null) {
>>> 87: throw new UnsupportedOperationException("Not a native address");
>>
>> Maybe I'm wrong, but if I would like to deregister resource associated with this address here (I.e by calling unmap) during cleanup, will it cause exception?
>
> In general yes. Although I argue that if you get such an exception, the cleanup action is doing something suspicious. If you are referring to your allocator work, I think the trick there is to create entries that are backed by plain addresses (and where the addresses are the ones you obtain from malloc - so they have the global scope, no issue there).
>
> But - if you find yourself in a tight spot during cleanup, you could always do:
>
>
> long rawAddress = address.segmentOffset(MemorySegment.globalNativeScope);
> MemoryAddress addr = MemoryAddress.ofLong(rawAddress);
Yes, I was bit scared about it and one other thing I got in mind, but I think it will work. Thank you.
-------------
PR: https://git.openjdk.java.net/panama-foreign/pull/513
More information about the panama-dev
mailing list