-
Notifications
You must be signed in to change notification settings - Fork 63
8307253: Make FunctionDescriptor::toMethodType an instance method of Linker #830
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
8307253: Make FunctionDescriptor::toMethodType an instance method of Linker #830
Conversation
👋 Welcome back mcimadamore! A progress list of the required criteria for merging this PR into |
for (StorageCalculator.StructStorage( | ||
long offset, Class<?> ca, int byteWidth, VMStorage storage | ||
) : structStorages) { | ||
for (StorageCalculator.StructStorage structStorage : structStorages) { |
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 change is not strictly required, but I was getting weird errors when building javadoc from IntelliJ w/o it. Since patterns in for-each are going away anyways, I thought perhaps we could just take care of this.
Webrevs
|
Fix javadoc and impl for FunctionDescriptor::toMethodType to allow sequence layouts.
After some offline discussion, we realized that the current API is actually good enough: FunctionDescriptor::toMethodType defines the "lowest common denominator" for turning a function descriptor into a MethodType. In doing this conversion, we follow the carrier types indicated by value layouts. For structs/unions/sequences we assume the carrier is MemorySegment (it is possible that in the future we will also add a carrier() accessor on composite layouts that can be overridden). Finally, for padding layout we just throw (after all, a padding argument/return doesn't seem to make much sense). Capturing this conversion at the level of FunctionDescription still seems like the right thing to do. However, there is a small detail which this patch fixes: FunctionDescriptor::toMethodType currently rejects sequence layouts. While it is certainly the case that the C ABI does not allow to pass arrays by value. And even if this is the most common choice, this is not the only possible choice (for instance, Pascal has special convention for passing arrays to functions where the size of the array is known). As such, I think we should not bias the conversion with what we know the native linker will and will not support. (sidebar: I've personally always been of the opinion that, even if C ABI do not allow passing arrays by value, since we have a relatively straightforward way to turn a sequence layout into an equivalent struct layout, perhaps the native linker should also be not too biased about which layouts it accepts - after all For this reason, I've tweaked the checks in the conversion, and then made some checks stricter in the linker - so that now sequence layouts are rejected at the level of the linker. |
src/java.base/share/classes/jdk/internal/foreign/abi/AbstractLinker.java
Outdated
Show resolved
Hide resolved
@mcimadamore 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 ➡️ To integrate this PR with the above commit message to the |
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.
Nice! Couple of minor comments.
if (resLayout instanceof PaddingLayout) { | ||
throw new IllegalArgumentException("Unsupported padding layout return in function descriptor: " + resLayout); | ||
} | ||
Optional<MemoryLayout> paddingLayout = argLayouts.stream().filter(l -> l instanceof PaddingLayout).findAny(); |
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 could use Stream::anyMatch
.
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.
Uhm - I thought about that when writing the code, but then I can't print out the problematic 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.
Ok.
/integrate |
Going to push as commit 139a8d2. |
@mcimadamore Pushed as commit 139a8d2. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
This patch moves
FunctionDescriptor::toMethodType
as an instance method ofLinker
. This allows linker implementations to be more opinionated on how the function descriptor -> method type conversion should behave.Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/panama-foreign.git pull/830/head:pull/830
$ git checkout pull/830
Update a local copy of the PR:
$ git checkout pull/830
$ git pull https://git.openjdk.org/panama-foreign.git pull/830/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 830
View PR using the GUI difftool:
$ git pr show -t 830
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/panama-foreign/pull/830.diff
Webrev
Link to Webrev Comment