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

Use Unsafe.weakCompareAndSet in java.util.concurrent

XMLWordPrintable

      With VarHandles integrated into JDK 9, we now have the opportunity to use the actual Unsafe.weakCompareAndSet entry points in java.util.concurrent, not delegate them to stronger forms.

      E.g.:

      diff -r 195c39d24602 src/java.base/share/classes/java/util/concurrent/atomic/AtomicBoolean.java
      --- a/src/java.base/share/classes/java/util/concurrent/atomic/AtomicBoolean.java Thu Apr 07 15:09:03 2016 +0800
      +++ b/src/java.base/share/classes/java/util/concurrent/atomic/AtomicBoolean.java Thu Apr 07 11:10:51 2016 +0300
      @@ -115,9 +115,9 @@
            * @return {@code true} if successful
            */
           public boolean weakCompareAndSet(boolean expect, boolean update) {
      - return U.compareAndSwapInt(this, VALUE,
      - (expect ? 1 : 0),
      - (update ? 1 : 0));
      + return U.weakCompareAndSwapInt(this, VALUE,
      + (expect ? 1 : 0),
      + (update ? 1 : 0));
           }

            martin Martin Buchholz
            shade Aleksey Shipilev
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: