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
8295290: Add Windows ARM64 ABI support to the Foreign Function & Memory API #754
8295290: Add Windows ARM64 ABI support to the Foreign Function & Memory API #754
Conversation
There are 2 primary differences between the Windows ARM64 ABI and the macOS/Linux ARM64 ABI: variadic floating point arguments are passed in general purpose registers on Windows (instead of the vector registers). In addition to this, up to 64 bytes of a struct being passed to a variadic function can be placed in general purpose registers. This happens regardless of the type of struct (HFA or other generic struct). This means that a struct can be split across registers and the stack when invoking a variadic function. This change introduces tests that compute the sum of the fields of structs containing 1-4 ints, floats, and doubles to verify that each field is correctly assigned a register or stack location when invoking a variadic function (both when the struct can be passed entirely in registers as well as when the struct spills onto the stack). For details about the Foreign Function & Memory API, see JEP 434 defined at https://openjdk.org/jeps/434 The Windows ARM64 ABI conventions are documented at https://learn.microsoft.com/en-us/cpp/build/arm64-windows-abi-conventions
👋 Welcome back swesonga! A progress list of the required criteria for merging this PR into |
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.
This looks like a really good start, but there are few things to be done still, I think.
Note also that I'm not able to test this on Windows/AArch64, though I've run jdk_foreign
tests on all the other supported platforms. Some tests having sampling applied, so it is important to run tests with -Dgenerator.sample.factor=1
. When running tests through make
this can be done by using JTREG="JAVA_OPTIONS=-Dgenerator.sample.factor=1"
.
We also have the test java/foreign/TestMatrix.java
which runs several different configurations. It's a manual test that has to be run through jtreg
directly. A comment at the top of that file contains instructions to do that. It's also a good idea to run that test (and it isn't run when using make
). This test also fully runs all the sampled tests at, except for TestVarArgs (we should probably add a cases for that...).
Lastly, eventually this patch will have to be brought over to the mainline JDK repo as well. I suggest you take charge of that as well, since you can do the testing on Windows/AArch64. It might also be easier to straight up integrate things into the mainline JDK repo after the changes for the JDK 20 go into that repo 1, 2 (will likely be somewhere in the next 2 weeks). After that the code is again merged into this repo, and both repos should contain the same code any ways. (There might be some changes needed to the code as well, due to naming changes).
But, we can get started on the review here already.
test/jdk/java/foreign/callarranger/TestAarch64CallArranger.java
Outdated
Show resolved
Hide resolved
src/java.base/share/classes/jdk/internal/foreign/abi/aarch64/CallArranger.java
Outdated
Show resolved
Hide resolved
boolean spillRegistersPartially = forVariadicFunctionArgs && spillsVariadicStructsPartially(); | ||
regs = spillRegistersPartially ? | ||
storageCalculator.regAllocPartial(StorageType.INTEGER, layout) : | ||
storageCalculator.regAlloc(StorageType.INTEGER, layout); |
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 ideally this decision making should be pushed down into StorageCalculator
/BindingCalculator
if possible.
It seems like it should be possible to have a single alloc
method that returns a VMStorage[]
with a mix of register and stack storages that is used by the while loop below.
src/java.base/share/classes/jdk/internal/foreign/abi/aarch64/CallArranger.java
Outdated
Show resolved
Hide resolved
src/java.base/share/classes/jdk/internal/foreign/abi/aarch64/windows/WindowsAArch64VaList.java
Outdated
Show resolved
Hide resolved
src/java.base/share/classes/jdk/internal/foreign/abi/aarch64/windows/WindowsAArch64VaList.java
Outdated
Show resolved
Hide resolved
src/java.base/share/classes/jdk/internal/foreign/abi/aarch64/windows/WindowsAArch64VaList.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.
Few more comments inline.
FWIW, I think CallArranger can be cleaned up further, and I've been playing with a patch 1. But I'll file a followup PR for that.
src/java.base/share/classes/jdk/internal/foreign/abi/LinkerOptions.java
Outdated
Show resolved
Hide resolved
src/java.base/share/classes/jdk/internal/foreign/abi/aarch64/CallArranger.java
Show resolved
Hide resolved
src/java.base/share/classes/jdk/internal/foreign/abi/aarch64/CallArranger.java
Show resolved
Hide resolved
@JornVernee just to clarify, do you expect more refactoring of the CallArranger in this PR or will that be subsumed by your patch? |
@swesonga No, I think this PR is good. I'll file a followup PR myself for the other refactoring I did. |
@swesonga 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 no new commits pushed to the As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@JornVernee) but any other Committer may sponsor as well. ➡️ To flag this PR as ready for integration with the above commit message, type |
/integrate |
/sponsor |
Going to push as commit 08225e4. |
@JornVernee @swesonga Pushed as commit 08225e4. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
@swesonga Hey, just a heads up. It is about that time again where we are looking to put together a PR for the JEP to go into mainline. Since we do not support Windows/AArch64 (e.g. we can not test it), we can not be in charge of a PR that brings this port over to mainline. So, I think it's up to you or another maintainer of Windows/AArch64. I suggest taking the following two commits: And making a PR against openjdk/jdk out of those (since those three are all related to this port). I can approve it again there, since I've already reviewed the changes before. |
@JornVernee I've opened openjdk/jdk#12773 |
There are 2 primary differences between the Windows ARM64 ABI and the macOS/Linux ARM64 ABI: variadic floating point arguments are passed in general purpose registers on Windows (instead of the vector registers). In addition to this, up to 64 bytes of a struct being passed to a variadic function can be placed in general purpose registers. This happens regardless of the type of struct (HFA or other generic struct). This means that a struct can be split across registers and the stack when invoking a variadic function.
This change introduces tests that compute the sum of the fields of structs containing 1-4 ints, floats, and doubles to verify that each field is correctly assigned a register or stack location when invoking a variadic function (both when the struct can be passed entirely in registers as well as when the struct spills onto the stack).
For details about the Foreign Function & Memory API, see JEP 434 defined at https://openjdk.org/jeps/434
The Windows ARM64 ABI conventions are documented at https://learn.microsoft.com/en-us/cpp/build/arm64-windows-abi-conventions
This work builds on @lewurm / Bernhard's branch at https://github.com/lewurm/openjdk/commits/foreign-windows-aarch64
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/panama-foreign pull/754/head:pull/754
$ git checkout pull/754
Update a local copy of the PR:
$ git checkout pull/754
$ git pull https://git.openjdk.org/panama-foreign pull/754/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 754
View PR using the GUI difftool:
$ git pr show -t 754
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/panama-foreign/pull/754.diff