< prev index next >

src/hotspot/share/runtime/objectMonitor.cpp

Print this page

 492 
 493 // Deflate the specified ObjectMonitor if not in-use. Returns true if it
 494 // was deflated and false otherwise.
 495 //
 496 // The async deflation protocol sets owner to DEFLATER_MARKER and
 497 // makes contentions negative as signals to contending threads that
 498 // an async deflation is in progress. There are a number of checks
 499 // as part of the protocol to make sure that the calling thread has
 500 // not lost the race to a contending thread.
 501 //
 502 // The ObjectMonitor has been successfully async deflated when:
 503 //   (contentions < 0)
 504 // Contending threads that see that condition know to retry their operation.
 505 //
 506 bool ObjectMonitor::deflate_monitor() {
 507   if (is_busy()) {
 508     // Easy checks are first - the ObjectMonitor is busy so no deflation.
 509     return false;
 510   }
 511 
 512   if (ObjectSynchronizer::is_final_audit() && owner_is_DEFLATER_MARKER()) {
 513     // The final audit can see an already deflated ObjectMonitor on the
 514     // in-use list because MonitorList::unlink_deflated() might have
 515     // blocked for the final safepoint before unlinking all the deflated
 516     // monitors.
 517     assert(contentions() < 0, "must be negative: contentions=%d", contentions());
 518     // Already returned 'true' when it was originally deflated.
 519     return false;
 520   }
 521 
 522   const oop obj = object_peek();
 523 
 524   if (obj == nullptr) {
 525     // If the object died, we can recycle the monitor without racing with
 526     // Java threads. The GC already broke the association with the object.
 527     set_owner_from(nullptr, DEFLATER_MARKER);
 528     assert(contentions() >= 0, "must be non-negative: contentions=%d", contentions());
 529     _contentions = INT_MIN; // minimum negative int
 530   } else {
 531     // Attempt async deflation protocol.
 532 
 533     // Set a null owner to DEFLATER_MARKER to force any contending thread
 534     // through the slow path. This is just the first part of the async
 535     // deflation dance.
 536     if (try_set_owner_from(nullptr, DEFLATER_MARKER) != nullptr) {
 537       // The owner field is no longer null so we lost the race since the
 538       // ObjectMonitor is now busy.
 539       return false;
 540     }
 541 

 492 
 493 // Deflate the specified ObjectMonitor if not in-use. Returns true if it
 494 // was deflated and false otherwise.
 495 //
 496 // The async deflation protocol sets owner to DEFLATER_MARKER and
 497 // makes contentions negative as signals to contending threads that
 498 // an async deflation is in progress. There are a number of checks
 499 // as part of the protocol to make sure that the calling thread has
 500 // not lost the race to a contending thread.
 501 //
 502 // The ObjectMonitor has been successfully async deflated when:
 503 //   (contentions < 0)
 504 // Contending threads that see that condition know to retry their operation.
 505 //
 506 bool ObjectMonitor::deflate_monitor() {
 507   if (is_busy()) {
 508     // Easy checks are first - the ObjectMonitor is busy so no deflation.
 509     return false;
 510   }
 511 










 512   const oop obj = object_peek();
 513 
 514   if (obj == nullptr) {
 515     // If the object died, we can recycle the monitor without racing with
 516     // Java threads. The GC already broke the association with the object.
 517     set_owner_from(nullptr, DEFLATER_MARKER);
 518     assert(contentions() >= 0, "must be non-negative: contentions=%d", contentions());
 519     _contentions = INT_MIN; // minimum negative int
 520   } else {
 521     // Attempt async deflation protocol.
 522 
 523     // Set a null owner to DEFLATER_MARKER to force any contending thread
 524     // through the slow path. This is just the first part of the async
 525     // deflation dance.
 526     if (try_set_owner_from(nullptr, DEFLATER_MARKER) != nullptr) {
 527       // The owner field is no longer null so we lost the race since the
 528       // ObjectMonitor is now busy.
 529       return false;
 530     }
 531 
< prev index next >