[foreign-memaccess] [Rev 01] RFR: JDK-8243284: Remove Foreign class
Jorn Vernee
jvernee at openjdk.java.net
Wed Apr 22 09:26:27 UTC 2020
On Tue, 21 Apr 2020 21:19:06 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:
>> The Foreign class is currently used for 3 methods:
>>
>> * withSize, which takes an unchecked address and gives it a size
>> * asUnconfined, which takes an existing segment and turns it into an unconfined segment
>> * asMallocSegment, which takes an unchecked address and converts that into a segment which can be closed, and where
>> closed is mapped into "free"
>>
>> This patch replaces all these with this method:
>>
>> static MemorySegment ofNativeUnsafe(MemoryAddress addr, long bytesSize, Thread owner, AutoCloseable cleanup, Object
>> attachment)
>> Which is then moved directly into MemorySegment - so that we can garbage-collect the Foreign class.
>>
>> I've also made some changes on the JDK property - new name is simply "jdk.foreign" and I now made sure that it cannot
>> be bypassed with a simple static initializer.
>
> Maurizio Cimadamore has updated the pull request incrementally with one additional commit since the last revision:
>
> * simplified API to take Runnable instead of AutoCloseable
> * renamed all occurrences of "unsafe" with "restricted" (e.g. as in "restricted foreign")
> * cleaned up the code which performs the restricted access check
Marked as reviewed by jvernee (Committer).
src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/MemorySegment.java line 509:
> 508: }
> 509: Utils.checkRestrictedAccess("MemorySegment.ofNativeUnsafe");
> 510: return NativeMemorySegmentImpl.makeNativeSegmentUnchecked(addr, bytesSize, owner, cleanup, attachment);
Suggestion:
Utils.checkRestrictedAccess("MemorySegment.ofNativeRestricted");
-------------
PR: https://git.openjdk.java.net/panama-foreign/pull/122
More information about the panama-dev
mailing list