[foreign-memaccess+abi] Integrated: 8275054: Racy updates when releasing confined scopes

Maurizio Cimadamore mcimadamore at openjdk.java.net
Mon Oct 11 16:50:21 UTC 2021


On Mon, 11 Oct 2021 13:28:15 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

> 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.

This pull request has now been integrated.

Changeset: b0cf974b
Author:    Maurizio Cimadamore <mcimadamore at openjdk.org>
URL:       https://git.openjdk.java.net/panama-foreign/commit/b0cf974bdb0afcd736909128f940ce8c3f6d4285
Stats:     84 lines in 2 files changed: 82 ins; 0 del; 2 mod

8275054: Racy updates when releasing confined scopes

Reviewed-by: jvernee

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

PR: https://git.openjdk.java.net/panama-foreign/pull/596


More information about the panama-dev mailing list