< prev index next >

src/hotspot/share/runtime/objectMonitor.cpp

Print this page
rev 48406 : 8194406: Use Atomic::replace_if_null
Reviewed-by: coleenp, dholmes

@@ -419,11 +419,11 @@
 // Callers must compensate as needed.
 
 int ObjectMonitor::TryLock(Thread * Self) {
   void * own = _owner;
   if (own != NULL) return 0;
-  if (Atomic::cmpxchg(Self, &_owner, (void*)NULL) == NULL) {
+  if (Atomic::replace_if_null(Self, &_owner)) {
     // Either guarantee _recursions == 0 or set _recursions = 0.
     assert(_recursions == 0, "invariant");
     assert(_owner == Self, "invariant");
     return 1;
   }

@@ -527,11 +527,11 @@
   // -- the checker -- parked on a timer.
 
   if ((SyncFlags & 16) == 0 && nxt == NULL && _EntryList == NULL) {
     // Try to assume the role of responsible thread for the monitor.
     // CONSIDER:  ST vs CAS vs { if (Responsible==null) Responsible=Self }
-    Atomic::cmpxchg(Self, &_Responsible, (Thread*)NULL);
+    Atomic::replace_if_null(Self, &_Responsible);
   }
 
   // The lock might have been released while this thread was occupied queueing
   // itself onto _cxq.  To close the race and avoid "stranding" and
   // progress-liveness failure we must resample-retry _owner before parking.

@@ -551,11 +551,11 @@
 
     if (TryLock(Self) > 0) break;
     assert(_owner != Self, "invariant");
 
     if ((SyncFlags & 2) && _Responsible == NULL) {
-      Atomic::cmpxchg(Self, &_Responsible, (Thread*)NULL);
+      Atomic::replace_if_null(Self, &_Responsible);
     }
 
     // park self
     if (_Responsible == Self || (SyncFlags & 1)) {
       TEVENT(Inflated enter - park TIMED);

@@ -1005,11 +1005,11 @@
       // Only the current lock owner can manipulate the EntryList or
       // drain _cxq, so we need to reacquire the lock.  If we fail
       // to reacquire the lock the responsibility for ensuring succession
       // falls to the new owner.
       //
-      if (Atomic::cmpxchg(THREAD, &_owner, (void*)NULL) != NULL) {
+      if (!Atomic::replace_if_null(THREAD, &_owner)) {
         return;
       }
       TEVENT(Exit - Reacquired);
     } else {
       if ((intptr_t(_EntryList)|intptr_t(_cxq)) == 0 || _succ != NULL) {

@@ -1030,11 +1030,11 @@
         //     we either restart/rerun the exit operation, or simply
         //     fall-through into the code below which wakes a successor.
         // B.  If the elements forming the EntryList|cxq are TSM
         //     we could simply unpark() the lead thread and return
         //     without having set _succ.
-        if (Atomic::cmpxchg(THREAD, &_owner, (void*)NULL) != NULL) {
+        if (!Atomic::replace_if_null(THREAD, &_owner)) {
           TEVENT(Inflated exit - reacquired succeeded);
           return;
         }
         TEVENT(Inflated exit - reacquired failed);
       } else {

@@ -1712,11 +1712,11 @@
       iterator->TState = ObjectWaiter::TS_CXQ;
       for (;;) {
         ObjectWaiter * tail = _cxq;
         if (tail == NULL) {
           iterator->_next = NULL;
-          if (Atomic::cmpxchg(iterator, &_cxq, (ObjectWaiter*)NULL) == NULL) {
+          if (Atomic::replace_if_null(iterator, &_cxq)) {
             break;
           }
         } else {
           while (tail->_next != NULL) tail = tail->_next;
           tail->_next = iterator;
< prev index next >