[foreign-preview] RFR: 8281855: Rename ResourceScope to MemorySession

Maurizio Cimadamore mcimadamore at openjdk.java.net
Fri Feb 18 09:59:14 UTC 2022


On Thu, 17 Feb 2022 23:39:55 GMT, Quan Anh Mai <duke at openjdk.java.net> wrote:

>> This patch implements some of the changes described in [1] and [2]. More specifically, the `ResourceScope` abstraction is renamed into `MemorySession`, and the session accessors in `MemorySegment`, `NativeSymbol` and `VaList` are tweaked to return *non-closeable* session views. To counteract this change, `MemorySession` now supports `equals` and `hashCode`, so that sessions views can be compared to each other in ways that are not identity-sensitive.
>> 
>> [1] - https://mail.openjdk.java.net/pipermail/panama-dev/2022-February/016152.html
>> [2] - https://mail.openjdk.java.net/pipermail/panama-dev/2022-February/016254.html
>
> src/java.base/share/classes/java/lang/foreign/MemorySegment.java line 305:
> 
>> 303:      * {@return a non-closeable view of the memory session associated with this memory segment}
>> 304:      */
>> 305:     MemorySession session();
> 
> Hi, could we take advantage of the type system and return a MemorySessionView which does not have a close method on it. Thanks.

This is a possibility which we have explored. In the end we decided against it because we felt splitting session/scope in two would have had a negative effect on API discoverability. Note that non-closeable sessions are not just used for e.g. `MemorySegment::session`, but they are also returned by `MemorySession::global` and `MemorySession::openImplicit`. If we ever do *structured* sessions (e.g. session that give access to any threads that inherit a given Loom scope local), then it is likely that these sessions will be non-closeable too.

Also, you would need to replace most API methods accepting MemorySession with MemorySessionView - and add a subtyping relationhip between MemorySessionView and MemorySession (so that you can pass a MemorySession where a view is expected). Ultimately that all felt a bit too much.

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

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


More information about the panama-dev mailing list