Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Fix intro sentence for "T-hash Wins Scenario 2" subsection.

...

    • T-hash has incremented ref_count before T-deflate made it past that check.
    • The first ObjectMonitor box is showing the fields at this point and the "1>" markers are showing where each thread is at for that ObjectMonitor box.
    • T-deflate bails out on deflation, but first it tries to restore the owner field:
      • The return value of cmpxchg() is not checked here.
      • If T-deflate cannot restore the owner field to NULL, then another thread has managed to enter the monitor (or enter and exit the monitor) and we don't want to overwrite that information.
    • T-hash observes:
      • "owner == DEFLATER_MARKER && contentions == 0" or
      • "owner == NULL && contentions == 0" so it does not cause a retry.
    • T-hash verifies that the object still has a monitor and that monitor still refers to our current ObjectMonitor.
    • The second ObjectMonitor box is showing the fields at this point and the "2>" markers are showing where each thread is at for that ObjectMonitor box.
    • if save_om_ptr() returns true ObjectMonitor is safe:
      • if ObjectMonitor's 'header/dmw' field does not have a hash, then generate a hash and merge it with the 'header/dmw' field.
      • extract the hash from the ObjectMonitor's 'header/dmw' field.
    • The third ObjectMonitor box is showing the fields at this point and the "3>" marker is showing where T-hash is at for that ObjectMonitor box.
    • T-hash decrements the ref_count field.
    • T-hash returns the hash value.

T-hash Wins Scenario 2

If In this T-hash wins the race, then the ref_count will cause T-deflate to bail out on deflating the monitor. Note: header is not mentioned in any of the previous sections for simplicityscenario, the need for the "ref_count == 0" check in the third phase of the protocol is illustrated.

    T-hash                     ObjectMonitor              T-deflate
    ------------------------  +-----------------------+  ------------------------------------------
    save_om_ptr() {           | header=dmw_no_hash | deflate_monitor_using_JT() {
      atomic inc ref_count    | owner=DEFLATER_MARKER |   cmpxchg(DEFLATER_MARKER, &owner, NULL)
   if (owner ==            | contentions=0      | if (waiters != 0 || ref_count != 0) {
          DEFLATER_MARKER && | ref_count=1 |   }
         contentions <= 0) {  +-----------------------+ 1> prev = cmpxchg(-max_jint, &contentions, 0)
      }                 ||             2> if (prev == 0 &&
   1> if (object no longer \/   owner == DEFLATER_MARKER &&
          has a monitor or +-----------------------+ ref_count == 0) {
          is a different | header=dmw_no_hash | cmpxchg(NULL, &owner, DEFLATER_MARKER)
        monitor) { | owner=DEFLATER_MARKER | atomic add max_jint to contentions
        atomic dec ref_count | contentions=-max_jint | 3> bailout on deflation
        return false to | ref_count=1 | }
      cause a retry +-----------------------+
      } ||
   2> save om_ptr in the \/
    ObjectMonitorHandle +-----------------------+
} | header=dmw_hash |
if save_om_ptr() { | owner=NULL |
if no hash | contentions=0 |
gen hash & merge | ref_count=1 |
hash = hash(header) +-----------------------+
}
3> atomic dec ref_count
return hash

...