> The methods `load()`, `unload()`, `isLoaded()`, and `force()` in 
> `MemorySegment` currently delegate to `ScopedMemoryAccess` through a set of 
> `@Scoped` methods, after which the implementation calls into 
> `java.nio.MappedMemoryUtils`. This means that, when a shared scope is closed 
> during a call to one of these methods, an exception can be installed at any 
> point during the execution of the util method.
> 
> The problem is that some parts of these methods are not able to handle such 
> exceptions being installed.
> 
> We've had some previous discussion about these methods not really needing to 
> be `@Scoped` in the first place, but instead being able to rely on paired 
> acquire/release of the session being accessed. This code is not as 
> performance critical compared to a scoped memory access, since we're doing a 
> native call any way.
> 
> To avoid issues with exceptions being installed in surprising places, this 
> patch switches the named methods to use acquire/release instead of being 
> `@Scoped`. This changes the behavior of these methods slightly: they now keep 
> the scope alive during the execution of the method. I've updated the doc, 
> borrowing from existing text in the `Linked::downcallHandle` docs, to explain 
> that a scope closure may now fail during the execution of one of these 
> methods.
> 
> Does this seem like the right tradeoff?
> 
> ---------
> - [x] I confirm that I make this contribution in accordance with the [OpenJDK 
> Interim AI Policy](https://openjdk.org/legal/ai).

Jorn Vernee has updated the pull request with a new target base due to a merge 
or a rebase. The incremental webrev excludes the unrelated changes brought in 
by the merge/rebase. The pull request contains eight additional commits since 
the last revision:

 - Propagate uncaught exception in forked thread
 - Merge branch 'master' into MappeNoScoped
 - tweak comment
 - Fix issue where release is called even when acquire completes abnormally
 - Missed one link
 - Fix links
 - Add keep-alive docs
 - Use acquire/release for memory mapped segment operations

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

Changes:
  - all: https://git.openjdk.org/jdk/pull/31918/files
  - new: https://git.openjdk.org/jdk/pull/31918/files/5ee9830b..9e6d648c

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk&pr=31918&range=02
 - incr: https://webrevs.openjdk.org/?repo=jdk&pr=31918&range=01-02

  Stats: 322501 lines in 3937 files changed: 270967 ins; 27497 del; 24037 mod
  Patch: https://git.openjdk.org/jdk/pull/31918.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/31918/head:pull/31918

PR: https://git.openjdk.org/jdk/pull/31918

Reply via email to