JDK-8334137 : Marlin: replace terminally deprecated sun.misc.Unsafe memory access methods
  • Type: Bug
  • Component: javafx
  • Sub-Component: graphics
  • Affected Version: jfx23
  • Priority: P3
  • Status: Open
  • Resolution: Unresolved
  • Submitted: 2024-06-12
  • Updated: 2024-09-27
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
jfx24Unresolved
Related Reports
Relates :  
Relates :  
Relates :  
Relates :  
Description
The Marlin rasterizer uses sun.misc.Unsafe to allocate off-heap memory. All of the memory-access methods in sun.misc.Unsafe have been deprecated for removal by JEP 471 [1] as of JDK 23.

Starting in JDK 24 or 25, using any of these methods will produce a warning. Some time after JDK 25 they will stop working altogether. We need a replacement. There are three options:

1. Use Java arrays, meaning the memory would now be on the heap
2. Use direct NIO buffers for off-heap memory, ByteBuffer.allocateDirect
3. Use FFM as defined in JEP 454 [2]

Option 1 will likely be the least-performant option, and is at least as much work as option 2, so is likely not the best choice.

Option 2 should be pretty straight-forward to implement, at least for the memory allocation and access methods, and should be evaluated for performance.

Option 3 is the best long-term replacement, but will require adopting JDK 22 as the minimum version of JDK for JavaFX. This is something we could consider in the JavaFX 24 or 25 time frame, so this option should also be evaluated.

[1] https://openjdk.org/jeps/471
[2] https://openjdk.org/jeps/454
Comments
NOTE: In JDK-8334161, we will enable warnings-as-errors via "javac -Werror". However, we had to disable it for the javafx.graphics module due to the use of sun.misc.Unsafe, because the warnings generated when using sun.misc.Unsafe cannot be suppressed when building with JDK 22 or later. As part of fixing _this_ bug and removing all uses of sun.misc.Unsafe, we also need to enable "-Werror" for the javafx.graphics module by removing the following block of code from build.gradle: build.gradle: 2270 // FIXME: Remove this setting when JDK-8334137 is fixed 2271 // Disable javac -Werror until we stop using sun.misc.Unsafe 2272 project.ext.disableJavacWerror = true 2273
25-06-2024

[~lbourges] Do you have any thoughts on this?
12-06-2024