Oracle Carving Strategy for Unsafe Library

| by Victor Grazi Follow 21 Followers on Aug 10, 2015. Estimated reading time: 2 minutes |

The sun.misc.Unsafe Java library class has been the subject of much debate of late, and Oracle's Chief Java Architect and Project Jigsaw owner Mark Reinhold provided some insight about the future of this class in his blog last week.

Reinhold outlines the strategy as follows:

  • If it [i.e. any particular sun.misc.Unsafe feature - Editor] has a supported replacement in JDK 8 then we will encapsulate it in JDK 9;
  • If it does not have a supported replacement in JDK 8 then we will not encapsulate it in JDK 9, so that it remains accessible to outside code; and, further,
  • If it has a supported replacement in JDK 9 then we will deprecate it in JDK 9 and encapsulate it, or possibly even remove it, in JDK 10.

JEP 260, the OpenJDK proposal chartered to "Encapsulate Most Internal APIs", was created to reflect this strategy. Project Jigsaw is Oracle's heavily delayed attempt to modularize the JDK and provide modularization capabilities for Java development.

sun.misc.Unsafe is an unsupported Java class that provides fundamental implementations for performing low-level "unsafe" (by Java sandbox standards) operations. Java creator Sun Microsystems traditionally discouraged the use of "sun" packages since the early days of Java.

At issue is the concern that Unsafe, being a mongrel of sorts, from the unsupported sun.misc package, will have its access severely limited via Project Jigsaw's JDK modularization.

Unsafe operations are divided into several categories:

  • thread locking
  • thread parking and unparking
  • volatile access
  • native compare and swap
  • direct memory access and allocation
  • declarative exceptions

Since these are largely the only access to such features in Java, the library is heavily used in the JDK as well as many third party libraries.

There is an initiative called Variable Handles that addresses some of the memory access and volatile access features, but as yet the remainder of the Unsafe functionality remains to be promoted to a first class citizen.

The high performance community appears to be pleased to have things defined.

Hazelcast's Christoph Engelbert told InfoQ:

The new policy regarding the exposure, removal, or deprecation of sun.misc.Unsafe and other private APIs is very appreciated. We, Hazelcast and myself, think this is the best possible solution to the misery around those heavily used private APIs.

Ben Cotton, an active member of the Mechanical Sympathy low-latency community forum, told InfoQ:

Today's Java application developers need real remedy with regard to coding native "big data" implementations.  Java's current NIO offering, though supported, does not provide an API to allow native allocations greater than 2gb (in a single invoke).   Java 9's replacing sun.misc.Unsafe with a supported API that also empowers big data application development is much welcomed.


InfoQ reached out to Oracle for some clarification but they declined to comment.

Rate this Article

Adoption Stage

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread
Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread


Login to InfoQ to interact with what matters most to you.

Recover your password...


Follow your favorite topics and editors

Quick overview of most important highlights in the industry and on the site.


More signal, less noise

Build your own feed by choosing topics you want to read about and editors you want to hear from.


Stay up-to-date

Set up your notifications and don't miss out on content that matters to you