[foreign-preview] RFR: 8281855: Rename ResourceScope to MemorySession [v2]
Maurizio Cimadamore
mcimadamore at openjdk.java.net
Fri Feb 18 11:30:07 UTC 2022
On Fri, 18 Feb 2022 11:10:03 GMT, Quan Anh Mai <duke at openjdk.java.net> wrote:
>>> hat option was also considered, but discarded because it would make `SegmentAllocator` stateful, e.g. more complex than just a functional interface.
>>
>> Note that today there is no contract which says that all segments returned by a `SegmentAllocator` must have the same session. While some allocators might behave like that, I think it would not be ok to force that behavior on _all_ allocators. And, we considered to add, perhaps in the future, some small subinterface, like `ScopedSegmentAllocator` which also has a `session` accessor - this would be a good return type for the arena allocator methods, for instance. But this is a move that is orthogonal to the changes described in this PR (and also not a binding one - we can add the sub-interface even at a later point w/o breaking compatibility).
>
> Thanks a lot for your clarification, I still think that having a scope that throw on `close()` sounds a lot like the problem with `UnmodifiableCollection` but it seems the alternatives have been considered already.
>
Indeed the issues are similar. However, there are some characteristics that are unique to this API. MemorySegment is a lower-level API than, say Collection. Also, while we currently do not generate method handles which require a `MemorySession`, adding intricate subtyping hierarchies always has a cost when interacting with `invokeExact` - so this API often errs on the side of "avoid unnecessary intermediate types, if we can avoid it". Not to dismiss your concern, which is a valid one - just wanted to explain some of the rationale behind some of the API decisions we've been doing.
-------------
PR: https://git.openjdk.java.net/panama-foreign/pull/641
More information about the panama-dev
mailing list