Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ


Choose your language

InfoQ Homepage News Oracle Carving Strategy for Unsafe Library

Oracle Carving Strategy for Unsafe Library


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


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.

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

Community comments

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

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