-
Notifications
You must be signed in to change notification settings - Fork 6.1k
8315131: Clarify VarHandle set/get access on 32-bit platforms #26258
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
👋 Welcome back liach! A progress list of the required criteria for merging this PR into |
@liach This change is no longer ready for integration - check the PR body for details. |
Webrevs
|
src/java.base/share/classes/java/lang/invoke/MethodHandles.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it looks okay. But I am not spec expert, you need someone else to look at this carefully.
To be super-pedantic, JLS 17.7 does not guarantee atomic access of |
@@ -278,7 +278,7 @@ | |||
* <ul> | |||
* <li>read write access modes for all {@code T}. On 32-bit platforms, access modes | |||
* {@code get} and {@code set} for {@code long}, {@code double} and {@code MemorySegment} | |||
* are supported but might lead to word tearing, as described in Section {@jls 17.7}. | |||
* are supported but not atomic, as described in Section {@jls 17.7} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pedantically it is "... but are not guaranteed to be atomic, ...", since IIUC some 32-bit CPU architectures support 64-bit loads and stores (e.g., the ARM A32 LDREXD instruction) so the JVM can do something stronger than what is prescribed by the JMM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, updated to be "but may be non-atomic". Please review the CSR as well.
You are right. I should use "may be non-atomic", as the implementation can make these operations atomic. Also re JLS 17.7 for 64-bit platforms: this phrase is qualified to be on 32-bit platforms, and we are already under aligned access, so I assume we have sufficient preconditions to ignore this aspect. |
I think @mcimadamore and @JornVernee still disagree with this - they think "atomic" can mean a CAS operation as a whole is atomic, or an individual memory access (read, write) in the CAS is. This atomicity here is lacking for the individual memory access, which is the weaker form of atomicity. On another look, I think another way to address this problem could be to move this "potential lack of atomicity in memory access" to "get" and "set" themselves - which also applies to unaligned access and other var handles. Then, for aligned access through VH, the VH just specify it implements all access modes and upholds all atomicity guarantees of those modes (with respect to other threads) |
@@ -278,7 +278,7 @@ | |||
* <ul> | |||
* <li>read write access modes for all {@code T}. On 32-bit platforms, access modes | |||
* {@code get} and {@code set} for {@code long}, {@code double} and {@code MemorySegment} | |||
* are supported but might lead to word tearing, as described in Section {@jls 17.7}. | |||
* are supported but may be non-atomic, as described in Section {@jls 17.7} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* are supported but may be non-atomic, as described in Section {@jls 17.7} | |
* are supported but may be non-atomic in the sense of Section {@jls 17.7} |
A useful taxonomy has atomic read-modify-write operations (atomic updates, numeric atomic updates, bitwise atomic updates, like CASes, etc.), and atomic access operations, that is, atomic loads and stores (atomic reads and writes).
But the reference to the JLS section here should clarify what is meant in this specific context, namely access operation, not read-modify-write operations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, to distinguish access and the encapsulated read-modify-write atomicity, I decided to avoid using "atomic"/"non-atomic" altogether - now it is just "make no atomicity guarantee"
* {@code double} on 32-bit platforms. | ||
* <li>read write access modes for all {@code T}. On 32-bit platforms, | ||
* access modes {@code get} and {@code set} for {@code long}, {@code | ||
* double} are supported but may be non-atomic, as described in Section |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* double} are supported but may be non-atomic, as described in Section | |
* double} are supported but may be non-atomic in the sense of Section |
src/java.base/share/classes/java/lang/foreign/MemoryLayout.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good
On 32 bit platforms, when an access to long/double is aligned, it is supported but not atomic. The original wording in
MethodHandles::byteBufferViewVarHandle
sounds as if it is not supported at all. We can fix that by borrowing the improved specification fromMemoryLayout::varHandle
.Note: This doc is copied from
jdk/src/java.base/share/classes/java/lang/foreign/MemoryLayout.java
Lines 279 to 282 in ee0d309
Progress
Issues
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/26258/head:pull/26258
$ git checkout pull/26258
Update a local copy of the PR:
$ git checkout pull/26258
$ git pull https://git.openjdk.org/jdk.git pull/26258/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 26258
View PR using the GUI difftool:
$ git pr show -t 26258
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/26258.diff
Using Webrev
Link to Webrev Comment