fb64 commented on issue #163:
URL: https://github.com/apache/arrow-java/issues/163#issuecomment-5915335696

   Hi there, the FFM API is final (since JDK 22, [JEP 
454](https://openjdk.org/jeps/454)) and `sun.misc.Unsafe` is on its way out, so 
I prepared an `arrow-memory-ffm` module along the lines of what is suggested 
above. I'd like to open a PR if there's interest.
   Here my branch: https://github.com/fb64/arrow-java/tree/memory-ffm
   
   On the Unsafe side, the memory-access methods were deprecated for removal in 
JDK 23 ([JEP 471](https://openjdk.org/jeps/471)), and since JDK 24 the JVM 
prints a warning on first use ([JEP 498](https://openjdk.org/jeps/498)). The 
next phase, planned for "JDK 26 or later", makes them throw 
`UnsupportedOperationException` by default, followed by removal. You can 
already try that behavior with `--sun-misc-unsafe-memory-access=deny`. Since 
`MemoryUtil` relies on Unsafe whichever allocation manager is used, this will 
affect every Arrow Java user, not only `arrow-memory-unsafe`.
   
   It also covers the original request: no more 
`--add-opens=java.base/java.nio=ALL-UNNAMED`.
   
   What my branch does:
   
   - Moves the low-level operations of `MemoryUtil` behind a small 
`MemoryUtilAccessor` interface. The current Unsafe code becomes 
`UnsafeMemoryAccessor` and stays the default, so nothing changes for existing 
users.
   - Adds `arrow-memory-ffm` (JDK 22+) with an FFM-based accessor and an 
`FfmAllocationManager`. Setting `-Darrow.allocation.manager.type=FFM` switches 
both, so Unsafe is not used at all.
   - Includes a test run without `--add-opens` to prove it isn't needed.
   
   One caveat: wrapping raw addresses goes through `MemorySegment.reinterpret`, 
which is a restricted method, so `--enable-native-access` is needed to avoid a 
warning. That's a supported, documented flag though, unlike opening JDK 
internals.
   
   Full disclosure: I built this with the help of AI (Claude). Happy to walk 
through any part of it.
   
   I can split it into two PRs if that's easier to review: the accessor 
refactoring first, then the new module...


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to