Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8315953

Deprecate for removal Unsafe methods that have standard APIs for many releases

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P4 P4
    • 22
    • core-libs
    • None
    • source
    • minimal
    • Java API
    • JDK

      Summary

      Deprecate for removal the sun.misc.Unsafe park, unpark, getLoadAverage, loadFence, storeFence, and fullFence methods. These methods have standard API equivalents for many years and releases.

      Problem

      sun.misc.Unsafe is an undocumented/unsupported critical internal API. We need to encourage libraries that use this API directly to move to using standard APIs where possible.

      Solution

      Deprecate the 6 methods for removal. The @deprecation text will link to the standard APIs to use.

      Add a release note.

      Specification

      +++ b/src/jdk.unsupported/share/classes/sun/misc/Unsafe.java
      @@ -1089,7 +1089,10 @@ public void putOrderedLong(Object o, long offset, long x) {
            * so when calling from native code.
            *
            * @param thread the thread to unpark.
      +     *
      +     * @deprecated Use {@link java.util.concurrent.locks.LockSupport#unpark(Thread)} instead.
            */
      +    @Deprecated(since="22", forRemoval=true)
           @ForceInline
           public void unpark(Object thread) {
               theInternalUnsafe.unpark(thread);
      @@ -1105,7 +1108,11 @@ public void unpark(Object thread) {
            * "reason"). Note: This operation is in the Unsafe class only
            * because {@code unpark} is, so it would be strange to place it
            * elsewhere.
      +     *
      +     * @deprecated Use {@link java.util.concurrent.locks.LockSupport#parkNanos(long)} or
      +     * {@link java.util.concurrent.locks.LockSupport#parkUntil(long)} instead.
            */
      +    @Deprecated(since="22", forRemoval=true)
           @ForceInline
           public void park(boolean isAbsolute, long time) {
               theInternalUnsafe.park(isAbsolute, time);
      @@ -1125,7 +1132,11 @@ public void park(boolean isAbsolute, long time) {
            *
            * @return the number of samples actually retrieved; or -1
            *         if the load average is unobtainable.
      +     *
      +     * @deprecated Use {@link java.lang.management.OperatingSystemMXBean#getSystemLoadAverage()}
      +     * instead.
            */
      +    @Deprecated(since="22", forRemoval=true)
           @ForceInline
           public int getLoadAverage(double[] loadavg, int nelems) {
               return theInternalUnsafe.getLoadAverage(loadavg, nelems);
      @@ -1225,8 +1235,11 @@ public final Object getAndSetObject(Object o, long offset, Object newValue) {
            * A pure LoadLoad fence is not provided, since the addition of LoadStore
            * is almost always desired, and most current hardware instructions that
            * provide a LoadLoad barrier also provide a LoadStore barrier for free.
      +     *
      +     * @deprecated Use {@link java.lang.invoke.VarHandle#acquireFence()} instead.
            * @since 1.8
            */
      +    @Deprecated(since="22", forRemoval=true)
           @ForceInline
           public void loadFence() {
               theInternalUnsafe.loadFence();
      @@ -1242,8 +1255,11 @@ public void loadFence() {
            * A pure StoreStore fence is not provided, since the addition of LoadStore
            * is almost always desired, and most current hardware instructions that
            * provide a StoreStore barrier also provide a LoadStore barrier for free.
      +     *
      +     * @deprecated Use {@link java.lang.invoke.VarHandle#releaseFence()} instead.
            * @since 1.8
            */
      +    @Deprecated(since="22", forRemoval=true)
           @ForceInline
           public void storeFence() {
               theInternalUnsafe.storeFence();
      @@ -1256,8 +1272,11 @@ public void storeFence() {
            * barrier.
            *
            * Corresponds to C11 atomic_thread_fence(memory_order_seq_cst).
      +     *
      +     * @deprecated Use {@link java.lang.invoke.VarHandle#fullFence()} instead.
            * @since 1.8
            */
      +    @Deprecated(since="22", forRemoval=true)
           @ForceInline
           public void fullFence() {
               theInternalUnsafe.fullFence();

            alanb Alan Bateman
            alanb Alan Bateman
            Iris Clark, Paul Sandoz
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: