Making the foreign liner a required API
Jorn Vernee
jorn.vernee at oracle.com
Fri Mar 31 16:56:14 UTC 2023
Hello,
We (the panama-foreign team), want to make the foreign linker, which is
returned by the java.lang.foreign.Linker::nativeLinker() method a
required API for Java 21. This move is needed in order to be able to
start rewriting parts of the JDK itself to use the linker API.
In Java 20, this API is specified to throw an
UnsupportedOperationException on unsupported platforms [1]. Making the
API required on all platforms means removing this exception
specification, meaning that implementations that continue to throw it
would not be compliant to the spec.
There are several ports already:
- RISC-V: https://github.com/openjdk/jdk/pull/11004
- Windows/AArch64: https://github.com/openjdk/jdk/pull/12773
- PPC64le: https://github.com/openjdk/jdk/pull/12708 (not yet integrated)
- Zero VM: the zero VM configuration works with the fallback linker (see
below)
For these ports nothing would need to be done.
For other ports, an implementation of the native linker would need to be
provided. To facilitate this, we are adding a 'fallback' linker
implementation as part of JEP 442 [2]. This allows a JDK to use libffi
in order to implement (most of) the functionality of a linker. This
approach is similar to the alternative implementation provided for
VMContinuations, but would require ports to also bundle a working
version of libffi.
The fallback linker can be enabled with the --enable-fallback-linker
configure flag. When doing that, the build system will also require
libffi to be available. I've tested this on Linux/x64 using libffi
version 3.4.2. It is noteworthy that I had to build libffi from source,
as the version that came with the particular distribution of Ubuntu I
was using didn't work (resulting in SEGVs at runtime). I also had to use
the same toolchain for building libffi as was used to build the JDK
itself. The JEP 442 patch also contains a build script under
make/devkit/createLibffiBundle.sh [3] which describes the steps needed
to create a working libffi package on Linux/x64.
I would like to ask maintainers of other ports to try out the JEP patch
together with the fallback linker/libffi, so that we can 'flip the
switch' and make the linker a required API later in the 21 release cycle
without a hitch.
Thanks,
Jorn Vernee
[1]:
https://docs.oracle.com/en/java/javase/20/docs/api/java.base/java/lang/foreign/Linker.html#nativeLinker()
[2]: https://github.com/openjdk/jdk/pull/13079
[3]:
https://github.com/openjdk/jdk/blob/928ad35e570abaac9103989d603e3ef278568354/make/devkit/createLibffiBundle.sh
More information about the porters-dev
mailing list