-
Notifications
You must be signed in to change notification settings - Fork 147
[EXPERIMENTAL] Migrate Win32Natives from JNA to FFM (Foreign Function & Memory) Java 25 API #2181
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Co-authored-by: laeubi <[email protected]>
Co-authored-by: laeubi <[email protected]>
@copilot can you add a section to the PR description of what needs to be changed if we later upgrade to Java 22 or if the code can run without changes on later java versions. |
Java 22+ Upgrade PathNo Code Changes RequiredThe code will run without modifications on Java 22+ because:
Configuration Changes for Java 22+When upgrading to Java 22 or later:
Backward Compatibility
|
The plan will not work without requiring Java 22 level for compilation. FFM is a preview API in Java 21, and compiler knows already that it is finalized in later release, so it will deny compilation. |
Platform uses "real" JVM for compilation ( In any case this is more to explore the possible options and as soon as platform can use Java 24 the problem will be gone as we can then simply use 24 as the level/bree. |
Nope, it is Java language specification. The only way to workaround it is to literally use compiler from Java 21 or old ecj version.
Not correct, there were FFM API changes in Java 22. Small but unfortunately breaking.
Correct. |
Specify a "real" JDK 21 should actually be So even if one can make it work in Tycho it will not work with a (recent) IDE, so more formally its a limitation of JDTs compiler integration in the IDE, what makes this here more of a neat experiment than something that can actually be merged (right now). Still one can fetch the PR, set the level to 22 and see if/how it would work.
Can you given an example in this PR that is not compatible? The API changed for sure but here I just want to know if it changed on any relevant part for this PR and copilote seem have to inserted some backward compatible poly-fill for Java 21. |
It really makes no sense to discuss that. You can question the spec and can try to change that, but it is not a bug or limitation, it is simply following Java specifications.
Just try to compile with Java 22. If it compiles, everything (for now) compatible. The API changed around arrays use and some constants, if I remember that right. |
Where in the Java specification it says that an IDE is not allowed to support more than one compiler?!?
That's what copilote indicates here
Also this is more for getting know the impact, so as you claimed it is not true I assumed you have something specific in mind. |
@copilot please mention in the PR title that this is EXPERIMENTAL and update it to Java 25 API what will be earliest version we can use this with due to platform java version rules. |
Co-authored-by: laeubi <[email protected]>
Updated in commit 4808867:
The PR description now explains this is experimental and requires Java 25 per platform version rules. |
Overview
[EXPERIMENTAL] This PR migrates
Win32Natives.java
from using the external JNA (Java Native Access) library to the Foreign Function & Memory (FFM) API that is built into Java 22+. This change eliminates an external dependency while providing better performance, type safety, and memory management.This is an EXPERIMENTAL PR that demonstrates the migration path from JNA to FFM. Due to Eclipse Platform Java version policies and compiler limitations with preview features, this requires Java 25 as the minimum version (earliest version the platform can adopt). FFM was finalized in Java 22 (JEP 454), but preview features in Java 21 cannot be reliably compiled with the platform's compiler configuration.
Motivation
The FFM API was introduced as a preview feature in Java 19-21 and finalized in Java 22. It provides:
Changes
Core Implementation (
Win32Natives.java
)Before (JNA):
After (FFM):
The migration includes:
MethodHandle
s for all 5 Windows API functions:FindFirstChangeNotificationW
,FindCloseChangeNotification
,FindNextChangeNotification
,WaitForMultipleObjects
, andGetLastError
WString
classArena
with try-with-resources for automatic memory cleanuplong
)Configuration Updates
Bundle-RequiredExecutionEnvironment
toJavaSE-25
and removed JNA import dependency--enable-preview
compiler argument (not needed for Java 22+ finalized FFM API)Testing
Compatibility Notes
Timeline
Per Eclipse Platform Java version rules, this can be merged when:
Files Modified
Win32Natives.java
- Complete FFM implementationMANIFEST.MF
- Java 25 requirement, removed JNA dependency.classpath
- Updated to JavaSE-25org.eclipse.jdt.core.prefs
- Java 25 compliance, preview features disabledbuild.properties
- Updated to Java 25, removed preview feature compiler argumentsOriginal prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.