[foreign-memaccess+abi] RFR: Investigate alternate strategy to acquire resource scopes [v3]
Maurizio Cimadamore
mcimadamore at openjdk.java.net
Wed Apr 21 14:04:02 UTC 2021
> The code in this PR demonstrates a possible, alternate approach to resource scope acquire.
>
> Instead of having `ResourceScope.Handle` be `AutoCloseable` (which is problematic, given that `javac` issues warning when an auto closeable is not used inside the body of the try block) this patch adds a new method on resource scopes, namely `ResourceScope::release(Handle)`.
>
> The semantics of this method is similar to the previous `Handle::close` - one thing that is different is how implicit scopes are handled - instead of trying to keep the implicit scope alive through the handle instance, here we simply return a "dummy" handle, which does nothing.
>
> The idea is that if you write idiomatic code like:
>
>
> var handle = scope.acquire();
> try {
> // critical region
> } finally {
> scope.release(handle);
> }
>
>
> This will work for both explicit scopes (since acquiring actively prevents calls to `ResourceScope::close`) - but also for implicit scopes, since the `release` call inside the finally block will effectively require the scope to be reachable at this stage (see reachability fence inside `ResourceScopeImpl::release`).
Maurizio Cimadamore has updated the pull request with a new target base due to a merge or a rebase. The pull request now contains three commits:
- Merge branch 'foreign-memaccess+abi' into acquire_release_scope
- Add reachability fence on ResourceScope::release
- Initial push
-------------
Changes: https://git.openjdk.java.net/panama-foreign/pull/511/files
Webrev: https://webrevs.openjdk.java.net/?repo=panama-foreign&pr=511&range=02
Stats: 120 lines in 9 files changed: 74 ins; 8 del; 38 mod
Patch: https://git.openjdk.java.net/panama-foreign/pull/511.diff
Fetch: git fetch https://git.openjdk.java.net/panama-foreign pull/511/head:pull/511
PR: https://git.openjdk.java.net/panama-foreign/pull/511
More information about the panama-dev
mailing list