--- old/src/hotspot/share/runtime/objectMonitor.inline.hpp 2019-12-11 14:56:14.000000000 -0500 +++ new/src/hotspot/share/runtime/objectMonitor.inline.hpp 2019-12-11 14:56:14.000000000 -0500 @@ -68,7 +68,9 @@ 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()); @@ -121,15 +123,24 @@ 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. @@ -211,8 +222,6 @@ } 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(); @@ -221,9 +230,6 @@ } 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(); @@ -232,7 +238,7 @@ } inline jint ObjectMonitor::ref_count() const { - return _ref_count; + return Atomic::load(&_ref_count); } #endif // SHARE_RUNTIME_OBJECTMONITOR_INLINE_HPP