[foreign-memaccess+abi] RFR: 8315096: Allowed access modes in memory segment should depend on layout alignment
Paul Sandoz
psandoz at openjdk.org
Mon Aug 28 18:05:25 UTC 2023
On Mon, 28 Aug 2023 11:47:27 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:
> There are some issues with the way memory segment var handle are specified and implemented: if an access mode is not supported, then using such access mode should result in an `UnsupportedOperationException`. But in our implementation, all alignment issues result in `IllegalArgumentException`.
>
> This means that clients can get the same exception if:
>
> * they try to read a 4-byte aligned int at a physical address that is not multiple of 4 (use-site error, IAE is good)
> * they try to do a compareAndSwap on a var handle obtained using an unaligned int layout (decl-site error, IAE is not good, and UOE should be used instead).
>
> This PR rectifies this issue: now a var handle is either *aligned* (meaning it is constructed with a value layout which respects the *size* of the accessed carrier type), or *unaligned*. Aligned var handles enjoy more access modes. Unaligned var handle only support `get`/`set`. Trying to use any other access mode on an unaligned var handle will now result in `UOE` regardless of the address being accessed - which makes the code more robust and portable.
>
> This PR also clarifies the javadoc, by avoiding using the term "atomic access" to mean "absence of tearing". This is confusing because we then refer to terms such as "atomic updates" also to refer to operations such as CAS.
>
> The proposed javadoc now uses the term "Word Tearing" which is taken from the memory model section of the JLS (and even has a link to it).
Marked as reviewed by psandoz (Committer).
-------------
PR Review: https://git.openjdk.org/panama-foreign/pull/876#pullrequestreview-1598788235
More information about the panama-dev
mailing list