8308293: A linker should expose the layouts it supports#839
8308293: A linker should expose the layouts it supports#839mcimadamore wants to merge 5 commits intoopenjdk:foreign-memaccess+abifrom
Conversation
|
👋 Welcome back mcimadamore! A progress list of the required criteria for merging this PR into |
Webrevs
|
src/java.base/share/classes/jdk/internal/foreign/abi/AbstractLinker.java
Outdated
Show resolved
Hide resolved
|
Maybe we could add a test that ensures basic mapping is in place? |
Good idea. |
src/java.base/share/classes/jdk/internal/foreign/abi/AbstractLinker.java
Outdated
Show resolved
Hide resolved
src/java.base/share/classes/jdk/internal/foreign/abi/AbstractLinker.java
Outdated
Show resolved
Hide resolved
src/java.base/share/classes/jdk/internal/foreign/abi/AbstractLinker.java
Outdated
Show resolved
Hide resolved
Add test Add fallback linker support
| /* | ||
| * @test | ||
| * @enablePreview | ||
| * @requires jdk.foreign.linker != "UNSUPPORTED" |
There was a problem hiding this comment.
This shouldn't be removed I think? (Note that the fallback linker is FALLBACK, so this test was already enabled for it)
There was a problem hiding this comment.
Apologies - I was fighting with jtreg to get the fallback linker enabled (so I could test). This line got in between :-)
|
@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 33 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 |
|
Following some offline discussion, I've also decided to add support for |
| static final MemorySegment FLOAT_TYPE = MemorySegment.ofAddress(ffi_type_float()); | ||
| static final MemorySegment DOUBLE_TYPE = MemorySegment.ofAddress(ffi_type_double()); | ||
| static final MemorySegment POINTER_TYPE = MemorySegment.ofAddress(ffi_type_pointer()); | ||
| static final int SIZEOF_SHORT = ffi_sizeof_short(); |
There was a problem hiding this comment.
Decided to change this a bit - e.g. instead of returning FFI type (which we don't use), I return sizeof instead, which seems more directly usable. This leads to some code simplifications (see definition of SIZE_T in FFIType).
There was a problem hiding this comment.
This looks good. ffi_type also has an alignment field, which we could also theoretically look at, but I think it's fine to assume that we always have naturally aligned types here.
|
So, now that we got the implementation nailed, any further opinion on the API bikeshed? E.g. is a Map enough? Do we want to add other methods? Given this is a rather niche functionality (e.g. mostly for clients that want to dynamically discover layouts), my general feeling is to keep it simple and just expose a map. But I don't have a super strong opinion. |
|
I'm in favor of using a map as well. I don't think there are any issue with doing that? |
|
/integrate |
|
Going to push as commit 7a6fc80.
Your commit was automatically rebased without conflicts. |
|
@mcimadamore Pushed as commit 7a6fc80. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
|
|
||
| @Override | ||
| public Map<String, MemoryLayout> canonicalLayouts() { | ||
| return CANONICAL_LAYOUTS; |
There was a problem hiding this comment.
CANONICAL_LAYOUTS is set to a HashMap, which is not unmodifiable.
| return CANONICAL_LAYOUTS; | |
| return Collections.unmodifiableMap(CANONICAL_LAYOUTS); |
This is another stab at openjdk/jdk#14037
I believe, after some offline discussion, that we have found a more satisfying solution to the problem of JAVA_CHAR being exposed. Jorn suggested that linkers should also provide mappings for JNI types such as
jint,jshortand such (which are aliases for our layout constants anyway). I think that's a great way to bringJAVA_CHARback into the fold.For now, I decided not to specify support for JNI canonical layouts (but I could do so, if that's preferred). I think the highest priority is to provide some stable mappings for C builtin types (+
size_t) as that's what 99% of developers will be struggling with.API-wise, we just expose a map. In the preovious PR there were questions as to whether the map should be split into two methods. In general I see the following options:
Charsetapproach, which has bothavailableCharsetsandforName)My (not so strong) preference would be for either (1) or (2).
Progress
Issues
Reviewers
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/panama-foreign.git pull/839/head:pull/839$ git checkout pull/839Update a local copy of the PR:
$ git checkout pull/839$ git pull https://git.openjdk.org/panama-foreign.git pull/839/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 839View PR using the GUI difftool:
$ git pr show -t 839Using diff file
Download this PR as a diff file:
https://git.openjdk.org/panama-foreign/pull/839.diff
Webrev
Link to Webrev Comment