< prev index next >

src/hotspot/share/runtime/objectMonitor.hpp

Print this page
rev 56634 : imported patch 8230876.patch
rev 56635 : v2.00 -> v2.05 (CR5/v2.05/8-for-jdk13) patches combined into one; merge with 8229212.patch; merge with jdk-14+11; merge with 8230184.patch; merge with 8230876.patch; merge with jdk-14+15; merge with jdk-14+18.
rev 56637 : Add OM_CACHE_LINE_SIZE so that ObjectMonitor cache line sizes can be experimented with independently of DEFAULT_CACHE_LINE_SIZE; for SPARC and X64 configs that use 128 for DEFAULT_CACHE_LINE_SIZE, we are experimenting with 64; move _previous_owner_tid and _allocation_state fields to share the cache line with ObjectMonitor::_header; put ObjectMonitor::_ref_count on its own cache line after _owner; add 'int* count_p' parameter to deflate_monitor_list() and deflate_monitor_list_using_JT() and push counter updates down to where the ObjectMonitors are actually removed from the in-use lists; monitors_iterate() async deflation check should use negative ref_count; add 'JavaThread* target' param to deflate_per_thread_idle_monitors_using_JT() add deflate_common_idle_monitors_using_JT() to make it clear which JavaThread* is the target of the work and which is the calling JavaThread* (self); g_free_list, g_om_in_use_list and g_om_in_use_count are now static to synchronizer.cpp (reduce scope); add more diagnostic info to some assert()'s; minor code cleanups and code motion; save_om_ptr() should detect a race with a deflating thread that is bailing out and cause a retry when the ref_count field is not positive; merge with jdk-14+11; add special GC support for TestHumongousClassLoader.java; merge with 8230184.patch; merge with jdk-14+14; merge with jdk-14+18.
rev 56638 : Merge the remainder of the lock-free monitor list changes from v2.06 with v2.06a and v2.06b after running the changes through the edit scripts; merge pieces from dcubed.monitor_deflate_conc.v2.06d in dcubed.monitor_deflate_conc.v2.06[ac]; merge pieces from dcubed.monitor_deflate_conc.v2.06e into dcubed.monitor_deflate_conc.v2.06c; merge with jdk-14+11; test work around for test/jdk/tools/jlink/multireleasejar/JLinkMultiReleaseJarTest.java should not been needed anymore; merge with jdk-14+18.
rev 56639 : loosen a couple more counter checks due to races observed in testing; simplify om_release() extraction of mid since list head or cur_mid_in_use is marked; simplify deflate_monitor_list() extraction of mid since there are no parallel deleters due to the safepoint; simplify deflate_monitor_list_using_JT() extraction of mid since list head or cur_mid_in_use is marked; prepend_block_to_lists() - simplify based on David H's comments; does not need load_acquire() or release_store() because of the cmpxchg(); prepend_to_common() - simplify to use mark_next_loop() for m and use mark_list_head() and release_store() for the non-empty list case; add more debugging for "Non-balanced monitor enter/exit" failure mode; fix race in inflate() in the "CASE: neutral" code path; install_displaced_markword_in_object() does not need to clear the header field since that is handled when the ObjectMonitor is moved from the global free list; LSuccess should clear boxReg to set ICC.ZF=1 to avoid depending on existing boxReg contents; update fast_unlock() to detect when object no longer refers to the same ObjectMonitor and take fast path exit instead; clarify fast_lock() code where we detect when object no longer refers to the same ObjectMonitor; add/update comments for movptr() calls where we move a literal into an Address; remove set_owner(); refactor setting of owner field into set_owner_from(2 versions), set_owner_from_BasicLock(), and try_set_owner_from(); the new functions include monitorinflation+owner logging; extract debug code from v2.06 and v2.07 and move to v2.07.debug; change 'jccb' -> 'jcc' and 'jmpb' -> 'jmp' as needed; checkpoint initial version of MacroAssembler::inc_om_ref_count(); update LP64 MacroAssembler::fast_lock() and fast_unlock() to use inc_om_ref_count(); fast_lock() return flag setting logic can use 'testptr(tmpReg, tmpReg)' instead of 'cmpptr(tmpReg, 0)' since that's more efficient; fast_unlock() LSuccess return flag setting logic can use 'testl (boxReg, 0)' instead of 'xorptr(boxReg, boxReg)' since that's more efficient; cleanup "fast-path" vs "fast path" and "slow-path" vs "slow path"; update MacroAssembler::rtm_inflated_locking() to use inc_om_ref_count(); update MacroAssembler::fast_lock() to preserve the flags before decrementing ref_count and restore the flags afterwards; this is more clean than depending on the contents of rax/tmpReg; coleenp CR - refactor async monitor deflation work from ServiceThread::service_thread_entry() to ObjectSynchronizer::deflate_idle_monitors_using_JT(); rehn,eosterlund CR - add support for HandshakeAfterDeflateIdleMonitors for platforms that don't have ObjectMonitor ref_count support implemented in C2 fast_lock() and fast_unlock().


 174                                       // acting as proxies for Threads.
 175 
 176   ObjectWaiter* volatile _cxq;      // LL of recently-arrived threads blocked on entry.
 177   Thread* volatile _succ;           // Heir presumptive thread - used for futile wakeup throttling
 178   Thread* volatile _Responsible;
 179 
 180   volatile int _Spinner;            // for exit->spinner handoff optimization
 181   volatile int _SpinDuration;
 182 
 183   volatile jint  _contentions;      // Number of active contentions in enter(). It is used by is_busy()
 184                                     // along with other fields to determine if an ObjectMonitor can be
 185                                     // deflated. See ObjectSynchronizer::deflate_monitor() and
 186                                     // ObjectSynchronizer::deflate_monitor_using_JT().
 187  protected:
 188   ObjectWaiter* volatile _WaitSet;  // LL of threads wait()ing on the monitor
 189   volatile jint  _waiters;          // number of waiting threads
 190  private:
 191   volatile int _WaitSetLock;        // protects Wait Queue - simple spinlock
 192 
 193  public:
 194   volatile int visit_marker;
 195   static void Initialize();
 196 
 197   // Only perform a PerfData operation if the PerfData object has been
 198   // allocated and if the PerfDataManager has not freed the PerfData
 199   // objects which can happen at normal VM shutdown.
 200   //
 201   #define OM_PERFDATA_OP(f, op_str)              \
 202     do {                                         \
 203       if (ObjectMonitor::_sync_ ## f != NULL &&  \
 204           PerfDataManager::has_PerfData()) {     \
 205         ObjectMonitor::_sync_ ## f->op_str;      \
 206       }                                          \
 207     } while (0)
 208 
 209   static PerfCounter * _sync_ContendedLockAttempts;
 210   static PerfCounter * _sync_FutileWakeups;
 211   static PerfCounter * _sync_Parks;
 212   static PerfCounter * _sync_Notifications;
 213   static PerfCounter * _sync_Inflations;
 214   static PerfCounter * _sync_Deflations;
 215   static PerfLongVariable * _sync_MonExtant;
 216 
 217   static int Knob_SpinLimit;
 218 
 219   void* operator new (size_t size) throw();
 220   void* operator new[] (size_t size) throw();
 221   void operator delete(void* p);
 222   void operator delete[] (void* p);
 223 
 224   // TODO-FIXME: the "offset" routines should return a type of off_t instead of int ...
 225   // ByteSize would also be an appropriate type.
 226   static int header_offset_in_bytes()      { return offset_of(ObjectMonitor, _header); }
 227   static int object_offset_in_bytes()      { return offset_of(ObjectMonitor, _object); }
 228   static int owner_offset_in_bytes()       { return offset_of(ObjectMonitor, _owner); }

 229   static int recursions_offset_in_bytes()  { return offset_of(ObjectMonitor, _recursions); }
 230   static int cxq_offset_in_bytes()         { return offset_of(ObjectMonitor, _cxq); }
 231   static int succ_offset_in_bytes()        { return offset_of(ObjectMonitor, _succ); }
 232   static int EntryList_offset_in_bytes()   { return offset_of(ObjectMonitor, _EntryList); }
 233 
 234   // ObjectMonitor references can be ORed with markWord::monitor_value
 235   // as part of the ObjectMonitor tagging mechanism. When we combine an
 236   // ObjectMonitor reference with an offset, we need to remove the tag
 237   // value in order to generate the proper address.
 238   //
 239   // We can either adjust the ObjectMonitor reference and then add the
 240   // offset or we can adjust the offset that is added to the ObjectMonitor
 241   // reference. The latter avoids an AGI (Address Generation Interlock)
 242   // stall so the helper macro adjusts the offset value that is returned
 243   // to the ObjectMonitor reference manipulation code:
 244   //
 245   #define OM_OFFSET_NO_MONITOR_VALUE_TAG(f) \
 246     ((ObjectMonitor::f ## _offset_in_bytes()) - markWord::monitor_value)
 247 
 248   markWord           header() const;


 255     // _ref_count is for indicating that the ObjectMonitor* is in
 256     // use which is orthogonal to whether the ObjectMonitor itself
 257     // is in use for a locking operation.
 258     intptr_t ret_code = _contentions | _waiters | intptr_t(_cxq) | intptr_t(_EntryList);
 259     if (!AsyncDeflateIdleMonitors) {
 260       ret_code |= intptr_t(_owner);
 261     } else {
 262       if (_owner != DEFLATER_MARKER) {
 263         ret_code |= intptr_t(_owner);
 264       }
 265     }
 266     return ret_code;
 267   }
 268   const char* is_busy_to_string(stringStream* ss);
 269 
 270   intptr_t  is_entered(Thread* current) const;
 271 
 272   void*     owner() const;  // Returns NULL if DEFLATER_MARKER is observed.
 273   // Returns true if owner field == DEFLATER_MARKER and false otherwise.
 274   bool      owner_is_DEFLATER_MARKER();
 275   void      set_owner(void* owner);








 276 
 277   jint      waiters() const;
 278 
 279   jint      contentions() const;
 280   intptr_t  recursions() const                                         { return _recursions; }
 281 
 282   // JVM/TI GetObjectMonitorUsage() needs this:
 283   ObjectWaiter* first_waiter()                                         { return _WaitSet; }
 284   ObjectWaiter* next_waiter(ObjectWaiter* o)                           { return o->_next; }
 285   Thread* thread_of_waiter(ObjectWaiter* o)                            { return o->_thread; }
 286 
 287  protected:
 288   // We don't typically expect or want the ctors or dtors to run.
 289   // normal ObjectMonitors are type-stable and immortal.
 290   ObjectMonitor() { ::memset((void*)this, 0, sizeof(*this)); }
 291 
 292   ~ObjectMonitor() {
 293     // TODO: Add asserts ...
 294     // _cxq == 0 _succ == NULL _owner == NULL _waiters == 0
 295     // _contentions == 0 _EntryList  == NULL etc


 322   bool      is_active() const;
 323   bool      is_old() const;
 324   bool      is_new() const;
 325   void      dec_ref_count();
 326   void      inc_ref_count();
 327   jint      ref_count() const;
 328 
 329   // Returns true if the specified thread owns the ObjectMonitor. Otherwise
 330   // returns false and throws IllegalMonitorStateException (IMSE).
 331   bool      check_owner(Thread* THREAD);
 332   void      clear();
 333   void      clear_using_JT();
 334 
 335   void      enter(TRAPS);
 336   void      exit(bool not_suspended, TRAPS);
 337   void      wait(jlong millis, bool interruptable, TRAPS);
 338   void      notify(TRAPS);
 339   void      notifyAll(TRAPS);
 340 
 341   void      print() const;

 342   void      print_on(outputStream* st) const;
 343 
 344 // Use the following at your own risk
 345   intptr_t  complete_exit(TRAPS);
 346   void      reenter(intptr_t recursions, TRAPS);
 347 
 348  private:
 349   void      AddWaiter(ObjectWaiter* waiter);
 350   void      INotify(Thread* self);
 351   ObjectWaiter* DequeueWaiter();
 352   void      DequeueSpecificWaiter(ObjectWaiter* waiter);
 353   void      EnterI(TRAPS);
 354   void      ReenterI(Thread* self, ObjectWaiter* self_node);
 355   void      UnlinkAfterAcquire(Thread* self, ObjectWaiter* self_node);
 356   int       TryLock(Thread* self);
 357   int       NotRunnable(Thread* self, Thread* Owner);
 358   int       TrySpin(Thread* self);
 359   void      ExitEpilog(Thread* self, ObjectWaiter* Wakee);
 360   bool      ExitSuspendEquivalent(JavaThread* self);
 361   void      install_displaced_markword_in_object(const oop obj);




 174                                       // acting as proxies for Threads.
 175 
 176   ObjectWaiter* volatile _cxq;      // LL of recently-arrived threads blocked on entry.
 177   Thread* volatile _succ;           // Heir presumptive thread - used for futile wakeup throttling
 178   Thread* volatile _Responsible;
 179 
 180   volatile int _Spinner;            // for exit->spinner handoff optimization
 181   volatile int _SpinDuration;
 182 
 183   volatile jint  _contentions;      // Number of active contentions in enter(). It is used by is_busy()
 184                                     // along with other fields to determine if an ObjectMonitor can be
 185                                     // deflated. See ObjectSynchronizer::deflate_monitor() and
 186                                     // ObjectSynchronizer::deflate_monitor_using_JT().
 187  protected:
 188   ObjectWaiter* volatile _WaitSet;  // LL of threads wait()ing on the monitor
 189   volatile jint  _waiters;          // number of waiting threads
 190  private:
 191   volatile int _WaitSetLock;        // protects Wait Queue - simple spinlock
 192 
 193  public:

 194   static void Initialize();
 195 
 196   // Only perform a PerfData operation if the PerfData object has been
 197   // allocated and if the PerfDataManager has not freed the PerfData
 198   // objects which can happen at normal VM shutdown.
 199   //
 200   #define OM_PERFDATA_OP(f, op_str)              \
 201     do {                                         \
 202       if (ObjectMonitor::_sync_ ## f != NULL &&  \
 203           PerfDataManager::has_PerfData()) {     \
 204         ObjectMonitor::_sync_ ## f->op_str;      \
 205       }                                          \
 206     } while (0)
 207 
 208   static PerfCounter * _sync_ContendedLockAttempts;
 209   static PerfCounter * _sync_FutileWakeups;
 210   static PerfCounter * _sync_Parks;
 211   static PerfCounter * _sync_Notifications;
 212   static PerfCounter * _sync_Inflations;
 213   static PerfCounter * _sync_Deflations;
 214   static PerfLongVariable * _sync_MonExtant;
 215 
 216   static int Knob_SpinLimit;
 217 
 218   void* operator new (size_t size) throw();
 219   void* operator new[] (size_t size) throw();
 220   void operator delete(void* p);
 221   void operator delete[] (void* p);
 222 
 223   // TODO-FIXME: the "offset" routines should return a type of off_t instead of int ...
 224   // ByteSize would also be an appropriate type.
 225   static int header_offset_in_bytes()      { return offset_of(ObjectMonitor, _header); }
 226   static int object_offset_in_bytes()      { return offset_of(ObjectMonitor, _object); }
 227   static int owner_offset_in_bytes()       { return offset_of(ObjectMonitor, _owner); }
 228   static int ref_count_offset_in_bytes()   { return offset_of(ObjectMonitor, _ref_count); }
 229   static int recursions_offset_in_bytes()  { return offset_of(ObjectMonitor, _recursions); }
 230   static int cxq_offset_in_bytes()         { return offset_of(ObjectMonitor, _cxq); }
 231   static int succ_offset_in_bytes()        { return offset_of(ObjectMonitor, _succ); }
 232   static int EntryList_offset_in_bytes()   { return offset_of(ObjectMonitor, _EntryList); }
 233 
 234   // ObjectMonitor references can be ORed with markWord::monitor_value
 235   // as part of the ObjectMonitor tagging mechanism. When we combine an
 236   // ObjectMonitor reference with an offset, we need to remove the tag
 237   // value in order to generate the proper address.
 238   //
 239   // We can either adjust the ObjectMonitor reference and then add the
 240   // offset or we can adjust the offset that is added to the ObjectMonitor
 241   // reference. The latter avoids an AGI (Address Generation Interlock)
 242   // stall so the helper macro adjusts the offset value that is returned
 243   // to the ObjectMonitor reference manipulation code:
 244   //
 245   #define OM_OFFSET_NO_MONITOR_VALUE_TAG(f) \
 246     ((ObjectMonitor::f ## _offset_in_bytes()) - markWord::monitor_value)
 247 
 248   markWord           header() const;


 255     // _ref_count is for indicating that the ObjectMonitor* is in
 256     // use which is orthogonal to whether the ObjectMonitor itself
 257     // is in use for a locking operation.
 258     intptr_t ret_code = _contentions | _waiters | intptr_t(_cxq) | intptr_t(_EntryList);
 259     if (!AsyncDeflateIdleMonitors) {
 260       ret_code |= intptr_t(_owner);
 261     } else {
 262       if (_owner != DEFLATER_MARKER) {
 263         ret_code |= intptr_t(_owner);
 264       }
 265     }
 266     return ret_code;
 267   }
 268   const char* is_busy_to_string(stringStream* ss);
 269 
 270   intptr_t  is_entered(Thread* current) const;
 271 
 272   void*     owner() const;  // Returns NULL if DEFLATER_MARKER is observed.
 273   // Returns true if owner field == DEFLATER_MARKER and false otherwise.
 274   bool      owner_is_DEFLATER_MARKER();
 275   // Set _owner field to new_value; current value must match old_value.
 276   void      set_owner_from(void* new_value, void* old_value);
 277   // Set _owner field to new_value; current value must match old_value1 or old_value2.
 278   void      set_owner_from(void* new_value, void* old_value1, void* old_value2);
 279   // Set _owner field to self; current value must match basic_lock_p.
 280   void      set_owner_from_BasicLock(Thread* self, void* basic_lock_p);
 281   // Try to set _owner field to new_value if the current value matches
 282   // old_value. Otherwise, does not change the _owner field.
 283   void*     try_set_owner_from(void* new_value, void* old_value);
 284 
 285   jint      waiters() const;
 286 
 287   jint      contentions() const;
 288   intptr_t  recursions() const                                         { return _recursions; }
 289 
 290   // JVM/TI GetObjectMonitorUsage() needs this:
 291   ObjectWaiter* first_waiter()                                         { return _WaitSet; }
 292   ObjectWaiter* next_waiter(ObjectWaiter* o)                           { return o->_next; }
 293   Thread* thread_of_waiter(ObjectWaiter* o)                            { return o->_thread; }
 294 
 295  protected:
 296   // We don't typically expect or want the ctors or dtors to run.
 297   // normal ObjectMonitors are type-stable and immortal.
 298   ObjectMonitor() { ::memset((void*)this, 0, sizeof(*this)); }
 299 
 300   ~ObjectMonitor() {
 301     // TODO: Add asserts ...
 302     // _cxq == 0 _succ == NULL _owner == NULL _waiters == 0
 303     // _contentions == 0 _EntryList  == NULL etc


 330   bool      is_active() const;
 331   bool      is_old() const;
 332   bool      is_new() const;
 333   void      dec_ref_count();
 334   void      inc_ref_count();
 335   jint      ref_count() const;
 336 
 337   // Returns true if the specified thread owns the ObjectMonitor. Otherwise
 338   // returns false and throws IllegalMonitorStateException (IMSE).
 339   bool      check_owner(Thread* THREAD);
 340   void      clear();
 341   void      clear_using_JT();
 342 
 343   void      enter(TRAPS);
 344   void      exit(bool not_suspended, TRAPS);
 345   void      wait(jlong millis, bool interruptable, TRAPS);
 346   void      notify(TRAPS);
 347   void      notifyAll(TRAPS);
 348 
 349   void      print() const;
 350   void      print_debug_style_on(outputStream* st) const;
 351   void      print_on(outputStream* st) const;
 352 
 353 // Use the following at your own risk
 354   intptr_t  complete_exit(TRAPS);
 355   void      reenter(intptr_t recursions, TRAPS);
 356 
 357  private:
 358   void      AddWaiter(ObjectWaiter* waiter);
 359   void      INotify(Thread* self);
 360   ObjectWaiter* DequeueWaiter();
 361   void      DequeueSpecificWaiter(ObjectWaiter* waiter);
 362   void      EnterI(TRAPS);
 363   void      ReenterI(Thread* self, ObjectWaiter* self_node);
 364   void      UnlinkAfterAcquire(Thread* self, ObjectWaiter* self_node);
 365   int       TryLock(Thread* self);
 366   int       NotRunnable(Thread* self, Thread* Owner);
 367   int       TrySpin(Thread* self);
 368   void      ExitEpilog(Thread* self, ObjectWaiter* Wakee);
 369   bool      ExitSuspendEquivalent(JavaThread* self);
 370   void      install_displaced_markword_in_object(const oop obj);


< prev index next >