changeset 48489:51825789dd89

8194406: Use Atomic::replace_if_null Reviewed-by: coleenp, dholmes
author kbarrett
date Thu, 04 Jan 2018 18:18:18 -0500
parents abf1d797e380
children a5548cf24286
files src/hotspot/share/code/nmethod.cpp src/hotspot/share/gc/parallel/gcTaskThread.cpp src/hotspot/share/oops/method.cpp src/hotspot/share/prims/jvmtiRawMonitor.cpp src/hotspot/share/runtime/mutex.cpp src/hotspot/share/runtime/objectMonitor.cpp src/hotspot/share/runtime/synchronizer.cpp src/hotspot/share/services/mallocSiteTable.cpp src/hotspot/share/utilities/bitMap.cpp
diffstat 9 files changed, 17 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/src/hotspot/share/code/nmethod.cpp	Wed Jan 03 17:29:20 2018 +0000
+++ b/src/hotspot/share/code/nmethod.cpp	Thu Jan 04 18:18:18 2018 -0500
@@ -1625,7 +1625,7 @@
   assert(nmethod::oops_do_marking_is_active(), "oops_do_marking_prologue must be called");
   if (_oops_do_mark_link == NULL) {
     // Claim this nmethod for this thread to mark.
-    if (Atomic::cmpxchg(NMETHOD_SENTINEL, &_oops_do_mark_link, (nmethod*)NULL) == NULL) {
+    if (Atomic::replace_if_null(NMETHOD_SENTINEL, &_oops_do_mark_link)) {
       // Atomically append this nmethod (now claimed) to the head of the list:
       nmethod* observed_mark_nmethods = _oops_do_mark_nmethods;
       for (;;) {
--- a/src/hotspot/share/gc/parallel/gcTaskThread.cpp	Wed Jan 03 17:29:20 2018 +0000
+++ b/src/hotspot/share/gc/parallel/gcTaskThread.cpp	Thu Jan 04 18:18:18 2018 -0500
@@ -77,7 +77,7 @@
   if (_time_stamps == NULL) {
     // We allocate the _time_stamps array lazily since logging can be enabled dynamically
     GCTaskTimeStamp* time_stamps = NEW_C_HEAP_ARRAY(GCTaskTimeStamp, GCTaskTimeStampEntries, mtGC);
-    if (Atomic::cmpxchg(time_stamps, &_time_stamps, (GCTaskTimeStamp*)NULL) != NULL) {
+    if (!Atomic::replace_if_null(time_stamps, &_time_stamps)) {
       // Someone already setup the time stamps
       FREE_C_HEAP_ARRAY(GCTaskTimeStamp, time_stamps);
     }
--- a/src/hotspot/share/oops/method.cpp	Wed Jan 03 17:29:20 2018 +0000
+++ b/src/hotspot/share/oops/method.cpp	Thu Jan 04 18:18:18 2018 -0500
@@ -446,7 +446,7 @@
 
 bool Method::init_method_counters(MethodCounters* counters) {
   // Try to install a pointer to MethodCounters, return true on success.
-  return Atomic::cmpxchg(counters, &_method_counters, (MethodCounters*)NULL) == NULL;
+  return Atomic::replace_if_null(counters, &_method_counters);
 }
 
 void Method::cleanup_inline_caches() {
--- a/src/hotspot/share/prims/jvmtiRawMonitor.cpp	Wed Jan 03 17:29:20 2018 +0000
+++ b/src/hotspot/share/prims/jvmtiRawMonitor.cpp	Thu Jan 04 18:18:18 2018 -0500
@@ -127,7 +127,7 @@
 
 int JvmtiRawMonitor::SimpleEnter (Thread * Self) {
   for (;;) {
-    if (Atomic::cmpxchg(Self, &_owner, (void*)NULL) == NULL) {
+    if (Atomic::replace_if_null(Self, &_owner)) {
        return OS_OK ;
     }
 
@@ -139,7 +139,7 @@
     Node._next  = _EntryList ;
     _EntryList  = &Node ;
     OrderAccess::fence() ;
-    if (_owner == NULL && Atomic::cmpxchg(Self, &_owner, (void*)NULL) == NULL) {
+    if (_owner == NULL && Atomic::replace_if_null(Self, &_owner)) {
         _EntryList = Node._next ;
         RawMonitor_lock->unlock() ;
         return OS_OK ;
--- a/src/hotspot/share/runtime/mutex.cpp	Wed Jan 03 17:29:20 2018 +0000
+++ b/src/hotspot/share/runtime/mutex.cpp	Thu Jan 04 18:18:18 2018 -0500
@@ -467,7 +467,7 @@
   OrderAccess::fence();
 
   // Optional optimization ... try barging on the inner lock
-  if ((NativeMonitorFlags & 32) && Atomic::cmpxchg(ESelf, &_OnDeck, (ParkEvent*)NULL) == NULL) {
+  if ((NativeMonitorFlags & 32) && Atomic::replace_if_null(ESelf, &_OnDeck)) {
     goto OnDeck_LOOP;
   }
 
@@ -574,7 +574,7 @@
   // Unlike a normal lock, however, the exiting thread "locks" OnDeck,
   // picks a successor and marks that thread as OnDeck.  That successor
   // thread will then clear OnDeck once it eventually acquires the outer lock.
-  if (Atomic::cmpxchg((ParkEvent*)_LBIT, &_OnDeck, (ParkEvent*)NULL) != NULL) {
+  if (!Atomic::replace_if_null((ParkEvent*)_LBIT, &_OnDeck)) {
     return;
   }
 
--- a/src/hotspot/share/runtime/objectMonitor.cpp	Wed Jan 03 17:29:20 2018 +0000
+++ b/src/hotspot/share/runtime/objectMonitor.cpp	Thu Jan 04 18:18:18 2018 -0500
@@ -421,7 +421,7 @@
 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");
@@ -529,7 +529,7 @@
   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
@@ -553,7 +553,7 @@
     assert(_owner != Self, "invariant");
 
     if ((SyncFlags & 2) && _Responsible == NULL) {
-      Atomic::cmpxchg(Self, &_Responsible, (Thread*)NULL);
+      Atomic::replace_if_null(Self, &_Responsible);
     }
 
     // park self
@@ -1007,7 +1007,7 @@
       // 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);
@@ -1032,7 +1032,7 @@
         // 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;
         }
@@ -1714,7 +1714,7 @@
         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 {
--- a/src/hotspot/share/runtime/synchronizer.cpp	Wed Jan 03 17:29:20 2018 +0000
+++ b/src/hotspot/share/runtime/synchronizer.cpp	Thu Jan 04 18:18:18 2018 -0500
@@ -238,8 +238,7 @@
     // and last are the inflated Java Monitor (ObjectMonitor) checks.
     lock->set_displaced_header(markOopDesc::unused_mark());
 
-    if (owner == NULL &&
-        Atomic::cmpxchg(Self, &(m->_owner), (void*)NULL) == NULL) {
+    if (owner == NULL && Atomic::replace_if_null(Self, &(m->_owner))) {
       assert(m->_recursions == 0, "invariant");
       assert(m->_owner == Self, "invariant");
       return true;
--- a/src/hotspot/share/services/mallocSiteTable.cpp	Wed Jan 03 17:29:20 2018 +0000
+++ b/src/hotspot/share/services/mallocSiteTable.cpp	Thu Jan 04 18:18:18 2018 -0500
@@ -147,7 +147,7 @@
     if (entry == NULL) return NULL;
 
     // swap in the head
-    if (Atomic::cmpxchg(entry, &_table[index], (MallocSiteHashtableEntry*)NULL) == NULL) {
+    if (Atomic::replace_if_null(entry, &_table[index])) {
       return entry->data();
     }
 
@@ -259,5 +259,5 @@
 }
 
 bool MallocSiteHashtableEntry::atomic_insert(MallocSiteHashtableEntry* entry) {
-  return Atomic::cmpxchg(entry, &_next, (MallocSiteHashtableEntry*)NULL) == NULL;
+  return Atomic::replace_if_null(entry, &_next);
 }
--- a/src/hotspot/share/utilities/bitMap.cpp	Wed Jan 03 17:29:20 2018 +0000
+++ b/src/hotspot/share/utilities/bitMap.cpp	Thu Jan 04 18:18:18 2018 -0500
@@ -628,7 +628,7 @@
       table[i] = num_set_bits(i);
     }
 
-    if (Atomic::cmpxchg(table, &_pop_count_table, (BitMap::idx_t*)NULL) != NULL) {
+    if (!Atomic::replace_if_null(table, &_pop_count_table)) {
       guarantee(_pop_count_table != NULL, "invariant");
       FREE_C_HEAP_ARRAY(idx_t, table);
     }