FlatLaf icon indicating copy to clipboard operation
FlatLaf copied to clipboard

Replace JNI with FFM API

Open beth-soptim opened this issue 9 months ago • 3 comments

JNI should be replaced for JDK22+ with FFM API. This would make it unnecessary to include (unsigned) DLLs in FlatLaF (which some client side security tools etc. don't like).

For backwards compability with older Java versions a modular Jar file could be used.

Example: https://stackoverflow.com/questions/79648661/how-to-use-java-22-ffm-api-to-get-start-menu-and-desktop-location-via-windows-a/

https://openjdk.org/jeps/454 https://github.com/manuelbl/WindowsApiGenerator

beth-soptim avatar Jun 04 '25 05:06 beth-soptim

This would make it unnecessary to include (unsigned) DLLs in FlatLaF

The Windows DLL and macOS dylib are signed. (but not using an Apple certificate) Linux .so libraries are generally not signed.

.. (which some client side security tools etc. don't like).

In this case it is recommended to use the "no-natives" JAR. See https://www.formdev.com/flatlaf/native-libraries/ and https://www.formdev.com/flatlaf/native-libraries/#no_natives_jar

For macOS, sign the dylib using your Apple certificate: https://www.formdev.com/flatlaf/native-libraries/#macOS_signing

Not sure whether it is worth the effort to rewrite (and test) the FlatLaf native code (which becomes much larger with PR #988) and then maintain two versions (JNI and FFM)... There are other ways to make client side security tools happy. See above.

In the last 5-6 years I spent about 3-4 months developing those native libraries. Rewriting this (especially PR #988) is a lot of work... probably several weeks (or months?)...

Invoking macOS Objective C API from FFM is also not trivial.

ATM I have no plans to work on this in the near future. Anyway, if someone wants to finance implementation of issue, I'm open for discussions...

DevCharly avatar Jun 07 '25 17:06 DevCharly

I did some experiments with new FFM API, and on my machine, simple C void function with printf took 0.6 ms to call via JNI, and FFM took 5 ms.

TheEntropyShard avatar Jun 08 '25 19:06 TheEntropyShard

@TheEntropyShard FFM should become faster after it has loaded. There are benchmarks from java team which show that behaviour. @beth-soptim I just manually converted a java function which "just" calls win32 API function SHFileOperationW to FFM and to say the least - it has been very painful. Took a couple of hours to fix padding issues in the structure. If you have a larger JNI code base I would advise against trying to convert to FFM.

derreisende77 avatar Jun 09 '25 16:06 derreisende77