[foreign-memaccess+abi] RFR: 8275054: Racy updates when releasing confined scopes [v2]
Maurizio Cimadamore
mcimadamore at openjdk.java.net
Mon Oct 11 14:08:51 UTC 2021
> As the subject says, there are cases where a close dependency on a confined parent scope can occur from an unrelated thread:
>
> 1. the confined scope is acquired by another confined scope featuring implicit cleanup - in which case the cleaner thread will do the release
>
> 2. the confined scope is acquired, in the same thread, by a shared scope. Since a shared scope can be closed by any other thread, it follows that release can also be done by any thread.
>
> In such cases we can have races (either between release/release or between acquire/release) and the `lockCount` variable of the updated scope becomes garbage.
>
> The solution is to add an extra variable `asyncReleaseCount`. If a release request occur from the same thread that owns the confined scope, we proceed as usual, otherwise we atomically increment the `asyncReleaseCount`. When the confined scope is later closed, if `lockCount == 0`, nothing needs to be done, so we can just close. Otherwise, we need to check that `lockCount - asyncReleaseCount == 0`. This works because a confined segment can only be acquired by the same thread owning it. So, if `lockCount == 0` there can be no other pending release.
Maurizio Cimadamore has updated the pull request incrementally with two additional commits since the last revision:
- Fix javadoc in ConfinedScope
- Fix javadoc in test
-------------
Changes:
- all: https://git.openjdk.java.net/panama-foreign/pull/596/files
- new: https://git.openjdk.java.net/panama-foreign/pull/596/files/0befcbe5..e807618c
Webrevs:
- full: https://webrevs.openjdk.java.net/?repo=panama-foreign&pr=596&range=01
- incr: https://webrevs.openjdk.java.net/?repo=panama-foreign&pr=596&range=00-01
Stats: 5 lines in 2 files changed: 0 ins; 1 del; 4 mod
Patch: https://git.openjdk.java.net/panama-foreign/pull/596.diff
Fetch: git fetch https://git.openjdk.java.net/panama-foreign pull/596/head:pull/596
PR: https://git.openjdk.java.net/panama-foreign/pull/596
More information about the panama-dev
mailing list