[foreign-memaccess] RFR: 8253355: Add some overloads to memory access API [v2]

Athijegannathan Sundararajan sundar at openjdk.java.net
Fri Sep 18 12:31:34 UTC 2020


On Fri, 18 Sep 2020 12:28:09 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

>> This patch adds two overload:
>> 
>> * MemoryAddress::asSegmentRestricted which takes an Object attachment
>> * MemorySegment::asSlice which takes a MemoryAddress base and a new length
>> 
>> These overloads make the API slightly more usable.
>
> Maurizio Cimadamore has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Address review comments
>   Fix impl issue with attachment not being propagated

Marked as reviewed by sundar (Committer).

src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/MemoryAddress.java line 136:

> 134:      * a cleanup action to be executed when the returned segment is closed, the {@link
> MemorySegment#withCleanupAction(Runnable)} 135:      * method should be used.
> 136:      * <p>

Do we want to add a warning like native NewDirectByteBuffer method does?

"Native code that calls this function and returns the resulting byte-buffer object to Java-level code should ensure
that the buffer refers to a valid region of memory that is accessible for reading and, if appropriate, writing. An
attempt to access an invalid memory location from Java code will either return an arbitrary value, have no visible
effect, or cause an unspecified exception to be thrown"

src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/MemoryAddress.java line 150:

> 148:      */
> 149:     default MemorySegment asSegmentRestricted(long bytesSize, Object attachment) {
> 150:         Utils.checkRestrictedAccess("MemoryAddress.asSegmentRestricted");

attachment not used?

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

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


More information about the panama-dev mailing list