[foreign-memaccess+abi] Integrated: 8287516: Implement fallback Linker
Jorn Vernee
jvernee at openjdk.org
Mon Jan 23 13:00:36 UTC 2023
On Tue, 17 Jan 2023 17:32:41 GMT, Jorn Vernee <jvernee at openjdk.org> wrote:
> 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 (I've tested with version 3.4.2). 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`).
>
> The Java implementation is found in the `jdk.internal.foreign.abi.fallback` package, and consists of the following classes:
> - `FallbackLinker`. The main entry point, an instance of `Linker`. Contains the code for arranging and executing calls.
> - `LibFallback`. A thin wrapper around the native `libfallback` library found in the java.base module, which acts as an interface to the libffi library.
> - `FFIType`. Contains code for creating native `ffi_type` struct instances from memory layouts.
> - The `TypeClass`, `FFIStatus`, and `FFIABI` supporting enums, which should be pretty self-explanatory.
>
> 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`).
This pull request has now been integrated.
Changeset: 850aa09e
Author: Jorn Vernee <jvernee at openjdk.org>
URL: https://git.openjdk.org/panama-foreign/commit/850aa09e5b326c25a706f3eb3b1c13eab1b2968d
Stats: 1359 lines in 35 files changed: 1301 ins; 17 del; 41 mod
8287516: Implement fallback Linker
Reviewed-by: mcimadamore
-------------
PR: https://git.openjdk.org/panama-foreign/pull/770
More information about the panama-dev
mailing list