Migrate Spawner from JNI to JNA for improved maintainability and cross-platform support #1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
This PR migrates the
Spawnerclass and related I/O classes from Java Native Interface (JNI) to Java Native Access (JNA), as requested in the issue. The migration provides a cleaner architecture with better maintainability while preserving existing functionality.Problem
The current implementation uses JNI to call native code in
org.eclipse.cdt.core.native/native_src/. JNI requires:Solution
This PR replaces JNI with JNA by:
SpawnerNative,StreamNative) that define the operationsArchitecture
Before:
After:
Platform selection happens automatically at runtime based on
Platform.getOS().Changes Made
Java Layer (Complete ✅)
SpawnerNative.java,UnixSpawnerNative.java,WindowsSpawnerNative.java,StreamNative.java,UnixStreamNative.java,WindowsStreamNative.javaSpawner.java,SpawnerInputStream.java,SpawnerOutputStream.javanativemethod declarationsSystem.loadLibrary()calls (JNA handles loading)Native Layer - Unix/Linux (Complete ✅)
native_src/unix/spawner.c: Added 6 JNA wrapper functions (exec0, exec1, exec2, raise, waitFor, configureTrace)native_src/unix/io.c: Added 4 JNA wrapper functions (read, write, close, available)Native Layer - Windows (Partial⚠️ )
native_src/win/iostream.c: Added 4 I/O wrapper functions (complete)native_src/win/Win32ProcessEx.c: Added process management wrappersspawner_raise,spawner_waitFor,spawner_configureTracespawner_exec0,spawner_exec1,spawner_exec2(placeholder implementations)Documentation (Complete ✅)
JNA_MIGRATION.md: Comprehensive migration guide with implementation detailsIMPLEMENTATION_SUMMARY.md: Detailed status and architecture documentationBenefits
Status
JNA_MIGRATION.mdfor details)Remaining Work
The three Windows process creation functions (
spawner_exec0,spawner_exec1,spawner_exec2) need to be implemented inWin32ProcessEx.c. These are complex functions that require extracting logic from the existing JNI implementations (lines 101-602) and adapting them to work without JNI dependencies. Reference implementations and detailed guidance are provided in the documentation.Testing
The existing test suite should validate functionality once the Windows process creation functions are completed. The architecture is designed to be a drop-in replacement with no API changes.
Compatibility
MANIFEST.MFspawner) remains unchangedUnixChannel,WinChannel) remain unchangedSee
JNA_MIGRATION.mdandIMPLEMENTATION_SUMMARY.mdfor complete details.Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
repo.eclipse.org/usr/lib/jvm/temurin-17-jdk-amd64/bin/java --enable-native-access=ALL-UNNAMED -classpath /usr/share/apache-maven-3.9.11/boot/plexus-classworlds-2.9.0.jar -Dclassworlds.conf=/usr/share/apache-maven-3.9.11/bin/m2.conf -Dmaven.home=/usr/share/apache-maven-3.9.11 -Dlibrary.jansi.path=/usr/share/apache-maven-3.9.11/lib/jansi-native -Dmaven.multiModuleProjectDirectory=/home/REDACTED/work/cdt/cdt org.codehaus.plexus.classworlds.launcher.Launcher clean compile -pl core/org.eclipse.cdt.core.native -am(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.