Draft JEP: Deprecate Memory-Access Methods in sun.misc.Unsafe for Removal

Ron Pressler ron.pressler at oracle.com
Tue Jan 16 18:00:50 UTC 2024


Hi.

With the FFM API [1] made permanent in JDK 22 (along with VarHandle in JDK 9 [2]), 
the vast majority of methods in sun.misc.Unsafe — those used for memory access 
operations — now have standard, supported replacements. Therefore, it is time 
to begin the process of deprecating and removing those methods from sun.misc.Unsafe. [3][4]

When methods in sun.misc.Unsafe were deprecated and removed in the past after 
standard replacements were introduced, there was little impact on the Java ecosystem. 
However, the memory-access methods are much better known, and we expect that 
removing such a large number of methods (79) will impact libraries. Accordingly, 
we are proposing the deprecation and removal via a JEP, for maximum visibility. 
Furthermore, the removal process we propose is more gradual than the one used for 
other sun.misc.Unsafe methods and follows a process similar to ones we followed for 
some standard APIs: the compile-time warnings for the use of deprecated methods are 
to be followed in later releases by runtime warnings, which are then to be followed by 
errors. A new command-line option will help developers diagnose their reliance on the 
memory-access methods of sun.misc.Unsafe and plan to migrate away from it.

The proposed process is described in this draft JEP [5]. Comments are welcome.

The draft JEP does not propose to remove the sun.misc.Unsafe class itself.
Indeed, a small number of its methods are unaffected by this propsal; their
individual fates will be determined separately.

— Ron

[1]: https://openjdk.org/jeps/454
[2]: https://openjdk.org/jeps/193
[3]: https://youtu.be/4HG0YQVy8UM
[4]: https://cr.openjdk.org/~psandoz/conferences/2015-JavaOne/j1-2015-unsafe-CON7076.pdf
[5]: https://openjdk.org/jeps/8323072




More information about the jdk-dev mailing list