[foreign-memaccess+abi] RFR: 8287516: Implement fallback Linker
Jorn Vernee
jvernee at openjdk.org
Wed Jan 18 18:41:15 UTC 2023
Implement a [libffi](https://github.com/libffi/libffi) based fallback linker. The fallback linker comes with a native library that can be included in the jdk by configuring with `--enable-fallback-linker`. This requires the libffi library to be available as well. On the zero VM configuration the fallback linker is enabled by default.
CABI is refactored a bit. It now supports explicitly setting the CABI using the `jdk.internal.foreign.CABI` system property (which is very handy for testing). Instead of falling back to `null` when the platform is not supported, we instead fall back to checking if the fallback library is supported (`FALLBACK`), and if not, default to the new `UNSUPPORTED` enum constant, which is then mapped to an `UnsupportedOperationException` in the Linker::nativeLinker implementation.
Checking whether the a full port of the foreign linker is available is done through the new jdk.internal.vm.ForeignLinkerSupport class. This follows the precedent set by Loom's jdk.internal.vm.ContinuationSupport class. The implementation simply returns `true` on platforms where we have a port.
The system lookup is changed to be selected based on the platform, rather than CABI. This allows selecting the right library implementation when running on a zero VM configuration as well. The split is now just between Windows and non-Windows platforms.
Finally, I had to slightly modify `globalDefinitions_zero.hpp` to conditionally define `FFI_GO_CLOSURES`, since I was getting a redefinition error using GCC. The macro is also defined in `ffitarget.h` which is included by `ffi.h`. The define in globalDefinitions comes from this PR: https://github.com/openjdk/jdk/pull/8195 which indicates that the define is only needed on Mac Os X. So I switched out the guard to check for `__APPLE__` instead. (the check whether it is already defined doesn't really do anything, since `FFI_GO_CLOSURES` is defined by including `ffi.h`).
I've ran the `jdk_foreign` tests in the following configurations:
- Windows.
- Linux with the fallback linker lib included, but not used.
- Linux with fallback linker and running with `-Djdk.internal.foreign.CABI=FALLBACK` (this uses the fallback implementation).
- Linux zero VM (uses `FALLBACK` as CABI by default, because we don't have a port for `zero`).
-------------
Commit messages:
- polish
- Reorganize impl
- polish
- rebase fixes
- Better port support check
- only define FFI_GO_CLOSURES on apple
- Zero fixes
- Upcalls done
- Improve build
- Downcalls working
- ... and 1 more: https://git.openjdk.org/panama-foreign/compare/cad86458...6a51cde7
Changes: https://git.openjdk.org/panama-foreign/pull/770/files
Webrev: https://webrevs.openjdk.org/?repo=panama-foreign&pr=770&range=00
Issue: https://bugs.openjdk.org/browse/JDK-8287516
Stats: 1254 lines in 34 files changed: 1198 ins; 17 del; 39 mod
Patch: https://git.openjdk.org/panama-foreign/pull/770.diff
Fetch: git fetch https://git.openjdk.org/panama-foreign pull/770/head:pull/770
PR: https://git.openjdk.org/panama-foreign/pull/770
More information about the panama-dev
mailing list