[foreign-memaccess] RFR: JDK-8243284: Remove Foreign class

Jorn Vernee jvernee at openjdk.java.net
Tue Apr 21 18:17:33 UTC 2020


On Tue, 21 Apr 2020 16:15:46 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.

Looks good, some inline comments.

src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/MemorySegment.java line 517:

> 516:      * @throws NullPointerException if {@code addr == null}.
> 517:      * {@code permit}, {@code warn} or {@code debug} (the default value is set to {@code deny}).
> 518:      */

This last line should be moved up it looks like

src/jdk.incubator.foreign/share/classes/jdk/internal/foreign/Utils.java line 102:

> 101:                 " System property 'jdk.incubator.foreign.Foreign' is set to '" + value + "'");
> 102:     }
> 103: }

The message string here should be updated to talk about the new property/method (they still talk about `Foreign`).
Might also be nice to pass a string for the source of the check to checkRestrictedAccess so that it can be used in the
exception message.

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

Marked as reviewed by jvernee (Committer).

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


More information about the panama-dev mailing list