[foreign-memaccess+abi] RFR: 8287516: Implement fallback Linker

Jorn Vernee jvernee at openjdk.org
Wed Jan 18 18:41:15 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. 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`).

src/java.base/share/classes/jdk/internal/foreign/abi/fallback/FFIABI.java line 30:

> 28:     DEFAULT(LibFallback.DEFAULT_ABI);
> 29: 
> 30:     private final int value;

Adding a standalone enum for a single constant might seem a bit overkill right now, but there are many ABIs possible [1], so I expect there to be more constants added in the future (probably at least the stdcall ABI).

Plus, it's a nice bit of civilization compared to passing around `int`.

[1]: https://github.com/libffi/libffi/blob/7611bb4cfe90884b55ad225e0166136a1d2cf22b/src/x86/ffitarget.h#L83

-------------

PR: https://git.openjdk.org/panama-foreign/pull/770


More information about the panama-dev mailing list