[foreign-memaccess+abi] RFR: 8275054: Racy updates when releasing confined scopes
Maurizio Cimadamore
mcimadamore at openjdk.java.net
Mon Oct 11 13:49:32 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.
-------------
Commit messages:
- Handle races between release vs. acquire in confined scopes.
Changes: https://git.openjdk.java.net/panama-foreign/pull/596/files
Webrev: https://webrevs.openjdk.java.net/?repo=panama-foreign&pr=596&range=00
Issue: https://bugs.openjdk.java.net/browse/JDK-8275054
Stats: 85 lines in 2 files changed: 83 ins; 0 del; 2 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