hotspot/src/share/vm/runtime/objectMonitor.cpp
changeset 22551 9bf46d16dcc6
parent 18025 b7bcf7497f93
child 22753 749328896281
equal deleted inserted replaced
22550:820966182ab9 22551:9bf46d16dcc6
   232 //   More precisely, the CAS-based "push" onto cxq is ABA-oblivious.
   232 //   More precisely, the CAS-based "push" onto cxq is ABA-oblivious.
   233 //
   233 //
   234 // * Taken together, the cxq and the EntryList constitute or form a
   234 // * Taken together, the cxq and the EntryList constitute or form a
   235 //   single logical queue of threads stalled trying to acquire the lock.
   235 //   single logical queue of threads stalled trying to acquire the lock.
   236 //   We use two distinct lists to improve the odds of a constant-time
   236 //   We use two distinct lists to improve the odds of a constant-time
   237 //   dequeue operation after acquisition (in the ::enter() epilog) and
   237 //   dequeue operation after acquisition (in the ::enter() epilogue) and
   238 //   to reduce heat on the list ends.  (c.f. Michael Scott's "2Q" algorithm).
   238 //   to reduce heat on the list ends.  (c.f. Michael Scott's "2Q" algorithm).
   239 //   A key desideratum is to minimize queue & monitor metadata manipulation
   239 //   A key desideratum is to minimize queue & monitor metadata manipulation
   240 //   that occurs while holding the monitor lock -- that is, we want to
   240 //   that occurs while holding the monitor lock -- that is, we want to
   241 //   minimize monitor lock holds times.  Note that even a small amount of
   241 //   minimize monitor lock holds times.  Note that even a small amount of
   242 //   fixed spinning will greatly reduce the # of enqueue-dequeue operations
   242 //   fixed spinning will greatly reduce the # of enqueue-dequeue operations
   675         // by LDing cxq|EntryList.  Newly arrived threads -- that is, threads
   675         // by LDing cxq|EntryList.  Newly arrived threads -- that is, threads
   676         // that arrive on cxq after the ST:MEMBAR, above -- will set Responsible
   676         // that arrive on cxq after the ST:MEMBAR, above -- will set Responsible
   677         // non-null and elect a new "Responsible" timer thread.
   677         // non-null and elect a new "Responsible" timer thread.
   678         //
   678         //
   679         // This thread executes:
   679         // This thread executes:
   680         //    ST Responsible=null; MEMBAR    (in enter epilog - here)
   680         //    ST Responsible=null; MEMBAR    (in enter epilogue - here)
   681         //    LD cxq|EntryList               (in subsequent exit)
   681         //    LD cxq|EntryList               (in subsequent exit)
   682         //
   682         //
   683         // Entering threads in the slow/contended path execute:
   683         // Entering threads in the slow/contended path execute:
   684         //    ST cxq=nonnull; MEMBAR; LD Responsible (in enter prolog)
   684         //    ST cxq=nonnull; MEMBAR; LD Responsible (in enter prolog)
   685         //    The (ST cxq; MEMBAR) is accomplished with CAS().
   685         //    The (ST cxq; MEMBAR) is accomplished with CAS().
  2029     if (MaxSpin >= 0) {
  2029     if (MaxSpin >= 0) {
  2030        if (_Spinner > MaxSpin) {
  2030        if (_Spinner > MaxSpin) {
  2031           TEVENT (Spin abort -- too many spinners) ;
  2031           TEVENT (Spin abort -- too many spinners) ;
  2032           return 0 ;
  2032           return 0 ;
  2033        }
  2033        }
  2034        // Slighty racy, but benign ...
  2034        // Slightly racy, but benign ...
  2035        Adjust (&_Spinner, 1) ;
  2035        Adjust (&_Spinner, 1) ;
  2036     }
  2036     }
  2037 
  2037 
  2038     // We're good to spin ... spin ingress.
  2038     // We're good to spin ... spin ingress.
  2039     // CONSIDER: use Prefetch::write() to avoid RTS->RTO upgrades
  2039     // CONSIDER: use Prefetch::write() to avoid RTS->RTO upgrades