Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Add explanatory bullets after diagrams in "An Example of ObjectMonitor Interference" section.

...

                      ObjectMonitor              T-deflate
T-enter           +-----------------------+  --------------------------------------
----------------  | owner=NULL            |  cmpxchg(DEFLATER_MARKER, &owner, NULL)
                   | count=0               |
                   +-----------------------+
    • The data fields are at their starting values.
    • T-deflate is about to execute cmpxchg()
    • T-enter hasn't done anything yet.

Racing Threads

                      ObjectMonitor              T-deflate
    T-enter           +-----------------------+  --------------------------------------
    ----------------  | owner=DEFLATER_MARKER |  cmpxchg(DEFLATER_MARKER, &owner, NULL)
    owner contended   | count=0               |  :
    atomic inc count  +-----------------------+  prev = cmpxchg(-max_jint, &count, 0)
    • T-deflate

...

    • has executed cmpxchg() and set owner to DEFLATE_MARKER.
    • T-enter

...

    • has observed the contended owner field.
    • T-enter

...

    • and

...

    • T-deflate

...

    • are racing to update the count field.

T-deflate Wins

                               ObjectMonitor              T-deflate
    T-enter                    +-----------------------+  --------------------------------------
    ----------------           | owner=DEFLATER_MARKER |  cmpxchg(DEFLATER_MARKER, &owner, NULL)
    owner contended            | count=-max_jint       |  :
    atomic inc count           +-----------------------+  prev = cmpxchg(-max_jint, &count, 0)
    if (count <= 0 && owner                               if (prev == 0 &&
        == DEFLATER_MARKER) {                                 owner == DEFLATER_MARKER) {
      restore header                                        restore header
      retry enter                                           finish the deflation
    }                                                     }
    • T-enter

...

    • and T-deflate both observe owner == DEFLATER_MARKER and a negative count field

...

    • .
    • T-enter has

...

    • lost the race and it

...

    • retries.
    • T-deflate

...

    • finishes deflation of the ObjectMonitor

T-enter Wins

                      ObjectMonitor              T-deflate
    T-enter           +-----------------------+  --------------------------------------
    ----------------  | owner=DEFLATER_MARKER |  cmpxchg(DEFLATER_MARKER, &owner, NULL)
    owner contended   | count=1               |  :
    atomic inc count  +-----------------------+  prev = cmpxchg(-max_jint, &count, 0)
    if (count > 0)                               if (prev != 0 ||
      do contended                                   owner != DEFLATER_MARKER)
      enter work                                  work                                 bailout on deflation
    • T-enter and T-deflate both observe a count field > 0.
    • T-enter has won the race and it proceeds with the normal contended enter work.
    • T-deflate detects that it has lost the race and bails out on deflating the ObjectMonitor.
    • In this example, T-deflate never reaches the DEFLATER_MARKER check.

An Example of Object Header Interference

...