[foreign-preview] RFR: 8281855: Rename ResourceScope to MemorySession
Maurizio Cimadamore
mcimadamore at openjdk.java.net
Tue Feb 15 17:51:46 UTC 2022
On Tue, 15 Feb 2022 17:32:50 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> 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.
I've fixed javadoc references to "scopes" and improved the javadoc text in several places. A link to a javadoc corresponding to these changes can be found here:
http://cr.openjdk.java.net/~mcimadamore/panama/session_preview/javadoc/java.base/java/lang/foreign/package-summary.html
src/java.base/share/classes/jdk/internal/foreign/MemorySessionImpl.java line 330:
> 328: * "root" session implementation, and throws {@link UnsupportedOperationException} on close.
> 329: */
> 330: public final static class NonCloseableView implements MemorySession, Scoped {
This is a simple wrapper class around a session which delegates everything to the session from which it is built - and overrides `close` to throw an exception. I believe the cost for creating these little instances will be negligible - if problems show up, we can always move to more complex approaches (e.g. where `MemorySegment` implements `MemorySession`, or where we use `@Stable` fields to cache a non-closeable view inside the root memory session).
src/java.base/share/classes/jdk/internal/foreign/Scoped.java line 31:
> 29:
> 30: public interface Scoped {
> 31: MemorySessionImpl sessionImpl();
This method is used to retrieve the "root" session associated with either a resource, or a session view. This means that, to simplify the implementation, `MemorySessionImpl` has to implement `Scoped` as well (and return itself).
-------------
PR: https://git.openjdk.java.net/panama-foreign/pull/641
More information about the panama-dev
mailing list