[foreign-memaccess+abi] RFR: 8265974: ResourceScope code does not handle close vs. add races well
Maurizio Cimadamore
mcimadamore at openjdk.java.net
Mon Apr 26 17:34:19 UTC 2021
This PR is motivated by the discussion in:
https://git.openjdk.java.net/panama-foreign/pull/519
There seems to be an issue (at least conceptually) in that the code which adds a new cleanup can, in principle, replace CLOSED_LIST with a new cleanup action, which then breaks the list invariants.
While some fixes are possible, I believe that this part of the code is too complex and there's really no reason as to why we would want to allow CLOSE and ADD to happen in parallel with as few synchronization as possible.
Since we already have a way to prevent a scope from being closed, it only seems fair that `addCloseAction` should defend against scope closure using acquire. Under this new, simplified world, in the shared case we only have to worry about add vs. add races, as add vs. close is no longer possible.
I've re-ran the benchmark `ResourceScopeClose` and noticed no performance impact of this code simplification. So I think it would be better to make the code "dumber" but more obviously correct, rather than chasing dubious micro optimizations whose correctess we're not 100% sure about.
-------------
Commit messages:
- Further simplify code by moving `ResourceScopeList::cleanup` in a shared superclass method.
- Remove more spurious changes in ResourceScope test
- Remove spurious changes in ResourceScope test
- Initial push
Changes: https://git.openjdk.java.net/panama-foreign/pull/520/files
Webrev: https://webrevs.openjdk.java.net/?repo=panama-foreign&pr=520&range=00
Issue: https://bugs.openjdk.java.net/browse/JDK-8265974
Stats: 80 lines in 4 files changed: 26 ins; 46 del; 8 mod
Patch: https://git.openjdk.java.net/panama-foreign/pull/520.diff
Fetch: git fetch https://git.openjdk.java.net/panama-foreign pull/520/head:pull/520
PR: https://git.openjdk.java.net/panama-foreign/pull/520
More information about the panama-dev
mailing list