-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
8326172: Dubious claim on long[]/double[] alignment in MemorySegment javadoc #18007
Conversation
👋 Welcome back jvernee! A progress list of the required criteria for merging this PR into |
@JornVernee The following label will be automatically applied to this pull request:
When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command. |
Webrevs
|
* (1004, 1008, 1012, 1016) are 4-byte aligned. And, the segment can be accessed at | ||
* offsets 0, 2, 4, 6, etc under a 2-byte alignment constraint, because the target | ||
* addresses (e.g. 1000, 1002, 1004, 1006) are 2-byte aligned.</li> | ||
* (e.g. 1000), so that successive long elements occur at 8-byte aligned addresses |
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 believe there might be other changes required. I see the following sentences in the javadoc:
* In other words, heap segments feature a (platform-dependent) <em>maximum</em>
* alignment which is derived from the size of the elements of the Java array backing the
* segment, as shown in the following table:
* In such circumstances, clients have two options. They can use a heap segment backed
* by a different array type (e.g. {@code long[]}), capable of supporting greater maximum
* alignment. More specifically, the maximum alignment associated with {@code long[]} is
* set to {@code ValueLayout.JAVA_LONG.byteAlignment()} which is a platform-dependent
* value (set to {@code ValueLayout.ADDRESS.byteSize()}). That is, {@code long[]}) is
* guaranteed to provide at least 8-byte alignment in 64-bit platforms, but only 4-byte
* alignment in 32-bit platforms:
* In practice, the Java runtime lays out arrays in memory so that each n-byte element
* occurs at an n-byte aligned physical address (except for {@code long[]} and
* {@code double[]}, where alignment is platform-dependent, as explained below).
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 got the second one already. Will modify the 1st and 3rd
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.
Hi @mcimadamore, thanks for making a comment in an OpenJDK project!
All comments and discussions in the OpenJDK Community must be made available under the OpenJDK Terms of Use. If you already are an OpenJDK Author, Committer or Reviewer, please click here to open a new issue so that we can record that fact. Please Use "Add GitHub user mcimadamore" for the summary.
If you are not an OpenJDK Author, Committer or Reviewer, simply check the box below to accept the OpenJDK Terms of Use for your comments.
- I agree to the OpenJDK Terms of Use for all comments I make in a project in the OpenJDK GitHub organization.
Your comment will be automatically restored once you have accepted the OpenJDK Terms of Use.
It is strange to see this comment because @mcimadamore had already been a member in OpenJDK. The SKARA bot may meet a bug. CC'ing @erikj79 and @zhaosongzs .
@@ -161,7 +161,7 @@ public void testStructSizeAndAlign() { | |||
ValueLayout.JAVA_LONG | |||
); | |||
assertEquals(struct.byteSize(), 1 + 1 + 2 + 4 + 8); | |||
assertEquals(struct.byteAlignment(), ADDRESS.byteSize()); | |||
assertEquals(struct.byteAlignment(), 8); |
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.
Looking at this PR:
#18007
This test seemed to cover more case before that PR - e.g. a layout generator was tweaked to exclude long/doubles. I believe revert the test changes now?
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.
That doesn't seem to be the right PR link?
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.
Found the right one: 44218b1
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.
Switched back to using the old generator (and removed the newer one): fad15a6
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.
Sorry, PR number was similar to this and got confused:
#14007
@JornVernee This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be:
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 158 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. ➡️ To integrate this PR with the above commit message to the |
/integrate |
Going to push as commit 2372aba.
Your commit was automatically rebased without conflicts. |
@JornVernee Pushed as commit 2372aba. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
This patch changes the alignment for
JAVA_LONG
andJAVA_DOUBLE
to 8, regardless of the underlying platform. This means that atomic access modes work on memory segments wrappinglong[]
ordouble[]
, as they already do when usingMethodHandless::arrayAccessVarHandle
.After discussion, we came to the conclusion that it is reasonable for the JDK to require the elements of a
long[]
anddouble[]
to be 8 byte aligned. It is ultimately up to the JDK to set these requirements, which are for the VM to implement.I was seeing a stack overflow when running test/jdk/java/foreign/stackwalk/TestReentrantUpcalls.java on x86, so I've lowered the recursion to 50 (which is still more than enough I think).
Testing:
jdk_foreign
on x64 Windows, x64 Windows + fallback linker, and x86 Linux (uses fallback linker)Progress
Issues
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/18007/head:pull/18007
$ git checkout pull/18007
Update a local copy of the PR:
$ git checkout pull/18007
$ git pull https://git.openjdk.org/jdk.git pull/18007/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 18007
View PR using the GUI difftool:
$ git pr show -t 18007
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/18007.diff
Webrev
Link to Webrev Comment