Hi all,

Panama's 'foreign' API will be released in JDK 22 [1][2]. It includes
'foreign memory' API for managing off-heap java memory, and 'foreign
function' API for calling native functions. These replace some
sun.misc.unsafe operations and all JNI.

We should start allowing developers to use the new APIs as they greatly
improve many aspects of the code (safer, simpler and possibly more
performant). I have used the foreign function API in other projects since
its incubation period (Java 18 or 19) and I can say that it works well and
causes much less headache than JNI, although I didn't do a performance
comparison in those cases.

We should also think about replacing code with the new API. JavaFX uses
sun.miscs.Unsafe in MarlinFX, and JNI is used extensively. While it's
unreasonable (and at this point undesirable due to manpower constraints) to
replace all of JNI, there are places where this approach should be looked
at. The use of Unsafe also emits warnings, which we are trying to avoid.

I therefore propose that JavaFX 23 bump its Java requirement to 22,
maintaining the "N-1 guarantee". I think that this is a significant enough
addition that merits this version bump, and will also bring with it all the
previous features starting with Java 18, out of which some useful ones are:
* Code Snippets [3] (18)
* Record Patterns [4] (21)
* Pattern Matching for switch [5] (21)
* Unnamed Variables & Patterns [6] (22)

We can start using the new APIs once the jfx 22 branch is split from the
master.

- Nir

[1] https://openjdk.org/jeps/454
[2]
https://download.java.net/java/early_access/jdk22/docs/api/java.base/java/lang/foreign/package-summary.html
[3]  https://openjdk.org/jeps/413
[4] https://openjdk.org/jeps/440
[5] https://openjdk.org/jeps/441
[6] https://openjdk.org/jeps/456

Reply via email to