< prev index next >
src/hotspot/share/runtime/objectMonitor.cpp
Print this page
rev 58110 : v2.09a with 8235795, 8235931 and 8236035 extracted; rebased to jdk-14+28; merge with 8236035.patch.cr1; merge with 8235795.patch.cr1; merge with 8236035.patch.cr2; merge with 8235795.patch.cr2; merge with 8235795.patch.cr3.
rev 58111 : See CR9-to-CR10-changes; merge with jdk-15+11.
*** 269,280 ****
if (AsyncDeflateIdleMonitors &&
try_set_owner_from(DEFLATER_MARKER, Self) == DEFLATER_MARKER) {
// The deflation protocol finished the first part (setting owner),
// but it failed the second part (making ref_count negative) and
! // bailed. Or the ObjectMonitor was async deflated and reused.
! // Acquired the monitor.
assert(_recursions == 0, "invariant");
return;
}
// We've encountered genuine contention.
--- 269,279 ----
if (AsyncDeflateIdleMonitors &&
try_set_owner_from(DEFLATER_MARKER, Self) == DEFLATER_MARKER) {
// The deflation protocol finished the first part (setting owner),
// but it failed the second part (making ref_count negative) and
! // bailed. Acquired the monitor.
assert(_recursions == 0, "invariant");
return;
}
// We've encountered genuine contention.
*** 447,495 ****
// ObjectMonitor's header/dmw has been cleared so the ObjectMonitor
// has been deflated and taken off the global free list.
return;
}
! // A non-NULL dmw has to be either neutral (not locked and not marked)
! // or is already participating in this restoration protocol.
! assert(dmw.is_neutral() || (dmw.is_marked() && dmw.hash() == 0),
! "failed precondition: dmw=" INTPTR_FORMAT, dmw.value());
!
! markWord marked_dmw = markWord::zero();
! if (!dmw.is_marked() && dmw.hash() == 0) {
! // This dmw has not yet started the restoration protocol so we
! // mark a copy of the dmw to begin the protocol.
! // Note: A dmw with a hashcode does not take this code path.
! marked_dmw = dmw.set_marked();
!
! // All of the callers to this function can be racing with each
! // other trying to update the _header field.
! dmw = (markWord) Atomic::cmpxchg(&_header, dmw, marked_dmw);
! if (dmw.value() == 0) {
! // ObjectMonitor's header/dmw has been cleared so the object's
! // header has already been restored.
! return;
! }
! // The _header field is now marked. The winner's 'dmw' variable
! // contains the original, unmarked header/dmw value and any
! // losers have a marked header/dmw value that will be cleaned
! // up below.
! }
!
! if (dmw.is_marked()) {
! // Clear the mark from the header/dmw copy in preparation for
! // possible restoration from this thread.
! assert(dmw.hash() == 0, "hashcode must be 0: dmw=" INTPTR_FORMAT,
! dmw.value());
! dmw = dmw.set_unmarked();
! }
! assert(dmw.is_neutral(), "must be neutral: dmw=" INTPTR_FORMAT, dmw.value());
// Install displaced mark word if the object's header still points
// to this ObjectMonitor. All racing callers to this function will
// reach this point, but only one can win.
! obj->cas_set_mark(dmw, markWord::encode(this));
// Note: It does not matter which thread restored the header/dmw
// into the object's header. The thread deflating the monitor just
// wanted the object's header restored and it is. The threads that
// detected a race with the deflation process also wanted the
--- 446,470 ----
// ObjectMonitor's header/dmw has been cleared so the ObjectMonitor
// has been deflated and taken off the global free list.
return;
}
! // A non-NULL dmw has to be neutral (not locked and not marked).
! ADIM_guarantee(dmw.is_neutral(), "must be neutral: dmw=" INTPTR_FORMAT, dmw.value());
// Install displaced mark word if the object's header still points
// to this ObjectMonitor. All racing callers to this function will
// reach this point, but only one can win.
! markWord res = obj->cas_set_mark(dmw, markWord::encode(this));
! if (res != markWord::encode(this)) {
! // This should be rare so log at the Info level when it happens.
! log_info(monitorinflation)("install_displaced_markword_in_object: "
! "failed cas_set_mark: new_mark=" INTPTR_FORMAT
! ", old_mark=" INTPTR_FORMAT ", res=" INTPTR_FORMAT,
! dmw.value(), markWord::encode(this).value(),
! res.value());
! }
// Note: It does not matter which thread restored the header/dmw
// into the object's header. The thread deflating the monitor just
// wanted the object's header restored and it is. The threads that
// detected a race with the deflation process also wanted the
*** 535,546 ****
if (AsyncDeflateIdleMonitors &&
try_set_owner_from(DEFLATER_MARKER, Self) == DEFLATER_MARKER) {
// The deflation protocol finished the first part (setting owner),
// but it failed the second part (making ref_count negative) and
! // bailed. Or the ObjectMonitor was async deflated and reused.
! // Acquired the monitor.
assert(_succ != Self, "invariant");
assert(_Responsible != Self, "invariant");
return;
}
--- 510,520 ----
if (AsyncDeflateIdleMonitors &&
try_set_owner_from(DEFLATER_MARKER, Self) == DEFLATER_MARKER) {
// The deflation protocol finished the first part (setting owner),
// but it failed the second part (making ref_count negative) and
! // bailed. Acquired the monitor.
assert(_succ != Self, "invariant");
assert(_Responsible != Self, "invariant");
return;
}
*** 662,673 ****
if (AsyncDeflateIdleMonitors &&
try_set_owner_from(DEFLATER_MARKER, Self) == DEFLATER_MARKER) {
// The deflation protocol finished the first part (setting owner),
// but it failed the second part (making ref_count negative) and
! // bailed. Or the ObjectMonitor was async deflated and reused.
! // Acquired the monitor.
break;
}
// The lock is still contested.
// Keep a tally of the # of futile wakeups.
--- 636,646 ----
if (AsyncDeflateIdleMonitors &&
try_set_owner_from(DEFLATER_MARKER, Self) == DEFLATER_MARKER) {
// The deflation protocol finished the first part (setting owner),
// but it failed the second part (making ref_count negative) and
! // bailed. Acquired the monitor.
break;
}
// The lock is still contested.
// Keep a tally of the # of futile wakeups.
*** 795,806 ****
if (AsyncDeflateIdleMonitors &&
try_set_owner_from(DEFLATER_MARKER, Self) == DEFLATER_MARKER) {
// The deflation protocol finished the first part (setting owner),
// but it failed the second part (making ref_count negative) and
! // bailed. Or the ObjectMonitor was async deflated and reused.
! // Acquired the monitor.
break;
}
// State transition wrappers around park() ...
// ReenterI() wisely defers state transitions until
--- 768,778 ----
if (AsyncDeflateIdleMonitors &&
try_set_owner_from(DEFLATER_MARKER, Self) == DEFLATER_MARKER) {
// The deflation protocol finished the first part (setting owner),
// but it failed the second part (making ref_count negative) and
! // bailed. Acquired the monitor.
break;
}
// State transition wrappers around park() ...
// ReenterI() wisely defers state transitions until
*** 2123,2132 ****
--- 2095,2106 ----
return false;
}
// The ObjectMonitor could have been deflated and reused for
// another object before we bumped the ref_count so make sure
// our object still refers to this ObjectMonitor.
+ // Note: With handshakes after deflation is this race even
+ // possible anymore?
const markWord tmp = object->mark();
if (!tmp.has_monitor() || tmp.monitor() != om_ptr) {
// Async deflation and reuse won the race so we have to retry.
// Skip object header restoration since that's already done.
om_ptr->dec_ref_count();
*** 2160,2170 ****
//
// This function returns true if the ObjectMonitor* has been safely
// saved. This function returns false if the specified ObjectMonitor*
// is NULL or if we have lost a race with async deflation; the caller
// can retry as appropriate.
! bool ObjectMonitorHandle::set_om_ptr_if_safe(ObjectMonitor* om_ptr) {
if (om_ptr == NULL) {
return false; // Nothing to save if input is NULL
}
om_ptr->inc_ref_count();
--- 2134,2144 ----
//
// This function returns true if the ObjectMonitor* has been safely
// saved. This function returns false if the specified ObjectMonitor*
// is NULL or if we have lost a race with async deflation; the caller
// can retry as appropriate.
! bool ObjectMonitorHandle::save_om_ptr_if_safe(ObjectMonitor* om_ptr) {
if (om_ptr == NULL) {
return false; // Nothing to save if input is NULL
}
om_ptr->inc_ref_count();
*** 2278,2288 ****
st->print_cr(" }");
st->print_cr(" _ref_count = %d", ref_count());
st->print_cr(" _pad_buf2 = {");
st->print_cr(" [0] = '\\0'");
st->print_cr(" ...");
! st->print_cr(" [%d] = '\\0'", (int)sizeof(_pad_buf1) - 1);
st->print_cr(" }");
st->print_cr(" _next_om = " INTPTR_FORMAT, p2i(next_om()));
st->print_cr(" _recursions = " INTX_FORMAT, _recursions);
st->print_cr(" _EntryList = " INTPTR_FORMAT, p2i(_EntryList));
st->print_cr(" _cxq = " INTPTR_FORMAT, p2i(_cxq));
--- 2252,2262 ----
st->print_cr(" }");
st->print_cr(" _ref_count = %d", ref_count());
st->print_cr(" _pad_buf2 = {");
st->print_cr(" [0] = '\\0'");
st->print_cr(" ...");
! st->print_cr(" [%d] = '\\0'", (int)sizeof(_pad_buf2) - 1);
st->print_cr(" }");
st->print_cr(" _next_om = " INTPTR_FORMAT, p2i(next_om()));
st->print_cr(" _recursions = " INTX_FORMAT, _recursions);
st->print_cr(" _EntryList = " INTPTR_FORMAT, p2i(_EntryList));
st->print_cr(" _cxq = " INTPTR_FORMAT, p2i(_cxq));
< prev index next >