[foreign-memaccess+abi] RFR: 8265751: MemoryAddress should have a scope accessor [v3]

Maurizio Cimadamore mcimadamore at openjdk.java.net
Fri Apr 23 17:24:31 UTC 2021


On Fri, 23 Apr 2021 16:32:08 GMT, Radoslaw Smogura <github.com+7535718+rsmogura at openjdk.org> wrote:

>> Maurizio Cimadamore has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   Javadoc of MemoryAddress::equals is still segment-centric
>
> 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);

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

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


More information about the panama-dev mailing list