[foreign-memaccess+abi] RFR: 8317514: Ensure MemorySegment is initialized before touching NativeMemorySegmentImpl [v2]
Jorn Vernee
jvernee at openjdk.org
Mon Oct 9 19:15:59 UTC 2023
> Please review this fix for a class initializer deadlock.
>
> The issue is that `MemorySegment` references `NativeMemorySegmentImpl` in its initializer, through the `NULL` constant. `NativeMemorySegmentImpl` also depends on `MemorySegment` to be initialized, since it's a super interface with default methods. The VM does not drop the initialization monitor of `NativeMemorySegmentImpl` while trying to initialize super classes/interfaces (as mandated by the JVM spec).
>
> When 2 threads try to intialize `MemorySegment` (e.g. through `ofAddress`) and `NativeMemorySegmentImpl` (e.g. through Arena::allocateFrom), at the same time, a deadlock can occur.
>
> This PR fixes this issue by ensuring `MemorySegment` is initialized in all cases where we directly access `NativeMemorySegmentImpl` or `MappedMemorySegmentImpl`.
>
> We might consider a fix that removes the cycle in the future as well.
Jorn Vernee has updated the pull request incrementally with one additional commit since the last revision:
Add test for FileChannel::map
-------------
Changes:
- all: https://git.openjdk.org/panama-foreign/pull/902/files
- new: https://git.openjdk.org/panama-foreign/pull/902/files/22c824d4..cccdebf4
Webrevs:
- full: https://webrevs.openjdk.org/?repo=panama-foreign&pr=902&range=01
- incr: https://webrevs.openjdk.org/?repo=panama-foreign&pr=902&range=00-01
Stats: 46 lines in 1 file changed: 31 ins; 0 del; 15 mod
Patch: https://git.openjdk.org/panama-foreign/pull/902.diff
Fetch: git fetch https://git.openjdk.org/panama-foreign.git pull/902/head:pull/902
PR: https://git.openjdk.org/panama-foreign/pull/902
More information about the panama-dev
mailing list