RFR: 8315938: Deprecate for removal Unsafe methods that have standard APIs for many releases

Mandy Chung mchung at openjdk.org
Fri Sep 8 19:24:38 UTC 2023


On Fri, 8 Sep 2023 15:54:05 GMT, Alan Bateman <alanb at openjdk.org> wrote:

> There are several methods defined by sun.misc.Unsafe that have standard API equivalents for many years and releases. The change proposed here is to deprecate, for removal, the park, unpark, getLoadAverage, loadFence, storeFence, and fullFence methods. Code using these methods should move to LockSupport.park/unpark (Java 5), OperatingSystemMXBean.getSystemLoadAverage (Java 6), and VarHandles xxxFence methods (Java 9).
> 
> The following is a summary of a search of 175973022 classes in 484751 artifacts to get a sense of the usage of these methods.
> 
> - 1290 usages of Unsafe.park. 1195 are libraries that have re-packaged some version of ForkJoinPool, maybe from the jsr166 repo, maybe an older JDK release. In the remaining, only Ehcache stands out with 29 matches. It seems to be one usage but the library seems to copied/shaded into other artifacts.
> 
> - 1322 usages of Unsafe.unpark. 1243 are re-packaged ForkJoinPool. 29 occurrences are Encache, again one usage but the library seems to copied/shaded into other artifacts.
> 
> - 22 usages of Unsafe.getLoadAverage. Most of these are one usage in many published versions of Apache HBase.
> 
> - 339 usages of Unsafe.loadFence, 1057 usages of Unsafe.storeFence, 517 usages of Unsafe.fullFence. A handful of these are libraries with copies of j.u.concurrent, the rest seem to be high performance libraries that support older JDK releases or just haven't been updated to use VarHandles yet.

A good set of Unsafe APIs for terminal deprecation and the API replacements exist for some time.

-------------

Marked as reviewed by mchung (Reviewer).

PR Review: https://git.openjdk.org/jdk/pull/15641#pullrequestreview-1618121782


More information about the core-libs-dev mailing list