RFR (M): 7023898: Intrinsify AtomicLongFieldUpdater.getAndIncrement()

Vladimir Kozlov vladimir.kozlov at oracle.com
Tue May 15 11:23:32 PDT 2012


In c1_LIRAssembler_sparc.cpp move assert(code == lir_xchg) to the beginning of method since on sparc we have only swap 
for all types and change "xadd for oops" --> "no xadd on sparc".

In c1_LIR.cpp fix comment:

+        // destroy inputs. On the other platform that implements those
+        // (x86, sparc), the extra constrainsts are armless.
----
+        // destroy inputs. On other platforms that implement those
+        // (x86, sparc), the extra constraints are harmless.

In escape.cpp move add_obload_* call up with cases for GetAndSet and then fallthrough:

+    case Op_GetAndSetP:
+    case Op_GetAndSetN: {
+      add_objload_to_connection_graph(n, delayed_worklist);
+      // fallthrough
+    }
      case Op_StoreP:
      case Op_StoreN:
      case Op_StorePConditional:
      case Op_CompareAndSwapP:
      case Op_CompareAndSwapN: {

The rest looks good.

Vladimir


On 5/15/12 9:10 AM, Roland Westrelin wrote:
> http://cr.openjdk.java.net/~roland/7023898/
>
> This change provides intrinsics when optimized instruction sequences for the new Unsafe methods below exist (the change to the libraries will get in as a separate piece of work).
>
> Roland.
>
>     /**
>      * Atomically update Java variable by<tt>delta</tt>  returning
>      * the previous value.
>      * @return the previous value
>      */
>     public int getAndAddInt(Object o, long offset, int delta) {
>         for (;;) {
>             int current = getInt(obj, offset);
>             int next = current + delta;
>             if (compareAndSwapInt(obj, offset, current, next)) {
>                 return current;
>             }
>         }
>     }
>
>     /**
>      * Atomically update Java variable by<tt>delta</tt>  returning
>      * the previous value.
>      * @return the previous value
>      */
>     public long getAndAddLong(Object o, long offset, long delta) {
>         for (;;) {
>             long current = getLongVolatile(obj, offset);
>             long next = current + delta;
>             if (compareAndSwapLong(obj, offset, current, next)) {
>                 return current;
>             }
>         }
>     }
>
>     /**
>      * Atomically sets the field of the given object at the given offset
>      * to the given value and returns the old value.
>      *
>      * @param obj An object whose field to get and set
>      * @param newValue the new value
>      * @return the previous value
>      */
>     int getAndSet(Object o, long offset, int newValue) {
>         for (;;) {
>             int current = getInt(obj, offset);
>             if (compareAndSwapInt(obj, offset, current, newValue)) {
>                 return current;
>             }
>         }
>     }
>     /**
>      * Atomically sets the field of the given object at the given offset
>      * to the given value and returns the old value.
>      *
>      * @param obj An object whose field to get and set
>      * @param newValue the new value
>      * @return the previous value
>      */
>     long getAndSet(Object o, long offset, long newValue) {
>         for (;;) {
>             long current = getLongVolatile(obj, offset);
>             if (compareAndSwapLong(obj, offset, current, newValue)) {
>                 return current;
>             }
>         }
>     }
>     /**
>      * Atomically sets the field of the given object at the given offset
>      * to the given value and returns the old value.
>      *
>      * @param obj An object whose field to get and set
>      * @param newValue the new value
>      * @return the previous value
>      */
>     Object getAndSet(Object o, long offset, Object newValue) {
>         for (;;) {
>             Object current = getObject(obj, offset);
>             if (compareAndSwapObject(obj, offset, current, newValue)) {
>                 return current;
>             }
>         }
>     }


More information about the hotspot-compiler-dev mailing list