< prev index next >

src/hotspot/share/runtime/objectMonitor.inline.hpp

Print this page
rev 57232 : v2.00 -> v2.08 (CR8/v2.08/11-for-jdk14) patches combined into one; merge with jdk-14+25 snapshot; merge with jdk-14+26 snapshot.
rev 57233 : See CR8-to-CR9-changes; merge with 8230876.patch (2019.11.15); merge with jdk-14+25 snapshot; fuzzy merge with jdk-14+26 snapshot.

@@ -66,11 +66,13 @@
 }
 
 inline void ObjectMonitor::clear() {
   assert(Atomic::load(&_header).value() != 0, "must be non-zero");
   assert(_owner == NULL, "must be NULL: owner=" INTPTR_FORMAT, p2i(_owner));
-  DEBUG_ONLY(jint l_ref_count = ref_count();)
+#ifdef ASSERT
+  jint l_ref_count = ref_count();
+#endif
   assert(l_ref_count == 0, "must be 0: l_ref_count=%d, ref_count=%d", l_ref_count, ref_count());
 
   Atomic::store(&_header, markWord::zero());
 
   clear_using_JT();

@@ -119,19 +121,28 @@
 // return number of threads contending for this monitor
 inline jint ObjectMonitor::contentions() const {
   return _contentions;
 }
 
-// Set _owner field to new_value; current value must match old_value.
-inline void ObjectMonitor::set_owner_from(void* new_value, void* old_value) {
-  void* prev = Atomic::cmpxchg(&_owner, old_value, new_value);
+// Clear _owner field; current value must match old_value.
+// If needs_fence is true, we issue a fence() after the release_store().
+// Otherwise, a storeload() is good enough. See the callers for more info.
+inline void ObjectMonitor::release_clear_owner_with_barrier(void* old_value,
+                                                            bool needs_fence) {
+  void* prev = _owner;
   ADIM_guarantee(prev == old_value, "unexpected prev owner=" INTPTR_FORMAT
                  ", expected=" INTPTR_FORMAT, p2i(prev), p2i(old_value));
-  log_trace(monitorinflation, owner)("set_owner_from(): mid=" INTPTR_FORMAT
-                                     ", prev=" INTPTR_FORMAT ", new="
-                                     INTPTR_FORMAT, p2i(this), p2i(prev),
-                                     p2i(new_value));
+  Atomic::release_store(&_owner, (void*)NULL);
+  if (needs_fence) {
+    OrderAccess::fence();
+  } else {
+    OrderAccess::storeload();
+  }
+  log_trace(monitorinflation, owner)("release_clear_owner_with_barrier(): mid="
+                                     INTPTR_FORMAT ", prev=" INTPTR_FORMAT
+                                     ", needs_fence=%d", p2i(this), p2i(prev),
+                                     needs_fence);
 }
 
 // Simply set _owner field to new_value; current value must match old_value.
 // (Simple means no memory sync needed.)
 inline void ObjectMonitor::simply_set_owner_from(void* new_value, void* old_value) {

@@ -209,30 +220,25 @@
 inline bool ObjectMonitor::is_new() const {
   return _allocation_state == New;
 }
 
 inline void ObjectMonitor::dec_ref_count() {
-  // The decrement only needs to be MO_ACQ_REL since the reference
-  // counter is volatile.
   Atomic::dec(&_ref_count);
   // Can be negative as part of async deflation protocol.
   jint l_ref_count = ref_count();
   ADIM_guarantee(AsyncDeflateIdleMonitors || l_ref_count >= 0,
                  "sanity check: l_ref_count=%d, ref_count=%d", l_ref_count, ref_count());
 }
 
 inline void ObjectMonitor::inc_ref_count() {
-  // The increment needs to be MO_SEQ_CST so that the reference
-  // counter update is seen as soon as possible in a race with the
-  // async deflation protocol.
   Atomic::inc(&_ref_count);
   // Can be negative as part of async deflation protocol.
   jint l_ref_count = ref_count();
   ADIM_guarantee(AsyncDeflateIdleMonitors || l_ref_count > 0,
                  "sanity check: l_ref_count=%d, ref_count=%d", l_ref_count, ref_count());
 }
 
 inline jint ObjectMonitor::ref_count() const {
-  return _ref_count;
+  return Atomic::load(&_ref_count);
 }
 
 #endif // SHARE_RUNTIME_OBJECTMONITOR_INLINE_HPP
< prev index next >