< prev index next >

src/hotspot/share/runtime/objectMonitor.inline.hpp

Print this page
rev 57587 : imported patch 8236035.patch.cr0
rev 57588 : dholmes CR - rename simply_set_owner_from() -> set_owner_from() and simply_set_owner_from_BasicLock() -> set_owner_from_BasicLock(); rename release_clear_owner_with_barrier() -> release_clear_owner() and refactor barrier code back into the call sites.
rev 57589 : kbarrett CR - rearrange some loads of _owner field to be more efficient; clarify header comment for try_set_owner_from() declaration; make some loads of _owner field DEBUG_ONLY since they only exist for assert()'s; update related logging calls to use the existing function parameter instead.
rev 57590 : dholmes CR - simplify comment for try_set_owner_from(); self-review: add return value comment to try_set_owner_from() definition.
rev 57593 : coleenp CR part1: add ObjectMonitor::next_om(), set_next_om(), and try_set_next_om(); ObjectMonitor::_next_om field is now private; rename ListGlobals -> ObjectMonitorListGlobals, rename LVars -> om_list_globals, and prefix each ObjectMonitorListGlobals field with '_'; delete static set_next() function; clarify comments; coleenp CR part2: delete stale comments about mux*().
rev 57594 : coleenp CR: add comment to explain why _next_om field uses Atomic ops.
rev 57595 : v2.09a with 8235795, 8235931 and 8236035 extracted; rebased to jdk-14+28; merge with 8236035.patch.cr1; merge with 8235795.patch.cr1; merge with 8236035.patch.cr2; merge with 8235795.patch.cr2; merge with 8235795.patch.cr3.


  35   return 0;
  36 }
  37 
  38 inline markWord ObjectMonitor::header() const {
  39   return Atomic::load(&_header);
  40 }
  41 
  42 inline volatile markWord* ObjectMonitor::header_addr() {
  43   assert((intptr_t)this == (intptr_t)&_header, "sync code expects this");
  44   return &_header;
  45 }
  46 
  47 inline void ObjectMonitor::set_header(markWord hdr) {
  48   Atomic::store(&_header, hdr);
  49 }
  50 
  51 inline jint ObjectMonitor::waiters() const {
  52   return _waiters;
  53 }
  54 

  55 inline void* ObjectMonitor::owner() const {
  56   return _owner;








  57 }
  58 
  59 inline void ObjectMonitor::clear() {
  60   assert(Atomic::load(&_header).value() != 0, "must be non-zero");






























  61   assert(_contentions == 0, "must be 0: contentions=%d", _contentions);
  62   assert(_waiters == 0, "must be 0: waiters=%d", _waiters);
  63   assert(_recursions == 0, "must be 0: recursions=" INTX_FORMAT, _recursions);
  64   assert(_object != NULL, "must be non-NULL");
  65   assert(_owner == NULL, "must be NULL: owner=" INTPTR_FORMAT, p2i(_owner));
  66 
  67   Atomic::store(&_header, markWord::zero());
  68   _object = NULL;
  69 }
  70 
  71 inline void* ObjectMonitor::object() const {
  72   return _object;
  73 }
  74 
  75 inline void* ObjectMonitor::object_addr() {
  76   return (void *)(&_object);
  77 }
  78 
  79 inline void ObjectMonitor::set_object(void* obj) {
  80   _object = obj;
  81 }
  82 
  83 // return number of threads contending for this monitor
  84 inline jint ObjectMonitor::contentions() const {
  85   return _contentions;
  86 }
  87 
  88 // Clear _owner field; current value must match old_value.
  89 inline void ObjectMonitor::release_clear_owner(void* old_value) {
  90   DEBUG_ONLY(void* prev = Atomic::load(&_owner);)
  91   assert(prev == old_value, "unexpected prev owner=" INTPTR_FORMAT
  92          ", expected=" INTPTR_FORMAT, p2i(prev), p2i(old_value));
  93   Atomic::release_store(&_owner, (void*)NULL);
  94   log_trace(monitorinflation, owner)("release_clear_owner(): mid="
  95                                      INTPTR_FORMAT ", old_value=" INTPTR_FORMAT,
  96                                      p2i(this), p2i(old_value));
  97 }
  98 
  99 // Simply set _owner field to new_value; current value must match old_value.
 100 // (Simple means no memory sync needed.)
 101 inline void ObjectMonitor::set_owner_from(void* old_value, void* new_value) {
 102   DEBUG_ONLY(void* prev = Atomic::load(&_owner);)
 103   assert(prev == old_value, "unexpected prev owner=" INTPTR_FORMAT
 104          ", expected=" INTPTR_FORMAT, p2i(prev), p2i(old_value));
 105   Atomic::store(&_owner, new_value);
 106   log_trace(monitorinflation, owner)("set_owner_from(): mid="
 107                                      INTPTR_FORMAT ", old_value=" INTPTR_FORMAT
 108                                      ", new_value=" INTPTR_FORMAT, p2i(this),
 109                                      p2i(old_value), p2i(new_value));
 110 }
 111 

















 112 // Simply set _owner field to self; current value must match basic_lock_p.
 113 inline void ObjectMonitor::set_owner_from_BasicLock(void* basic_lock_p, Thread* self) {
 114   DEBUG_ONLY(void* prev = Atomic::load(&_owner);)
 115   assert(prev == basic_lock_p, "unexpected prev owner=" INTPTR_FORMAT
 116          ", expected=" INTPTR_FORMAT, p2i(prev), p2i(basic_lock_p));
 117   // Non-null owner field to non-null owner field is safe without
 118   // cmpxchg() as long as all readers can tolerate either flavor.
 119   Atomic::store(&_owner, self);
 120   log_trace(monitorinflation, owner)("set_owner_from_BasicLock(): mid="
 121                                      INTPTR_FORMAT ", basic_lock_p="
 122                                      INTPTR_FORMAT ", new_value=" INTPTR_FORMAT,
 123                                      p2i(this), p2i(basic_lock_p), p2i(self));
 124 }
 125 
 126 // Try to set _owner field to new_value if the current value matches
 127 // old_value. Otherwise, does not change the _owner field. Returns
 128 // the prior value of the _owner field.
 129 inline void* ObjectMonitor::try_set_owner_from(void* old_value, void* new_value) {
 130   void* prev = Atomic::cmpxchg(&_owner, old_value, new_value);
 131   if (prev == old_value) {
 132     log_trace(monitorinflation, owner)("try_set_owner_from(): mid="
 133                                        INTPTR_FORMAT ", prev=" INTPTR_FORMAT
 134                                        ", new=" INTPTR_FORMAT, p2i(this),
 135                                        p2i(prev), p2i(new_value));
 136   }
 137   return prev;
 138 }
 139 








































 140 // The _next_om field can be concurrently read and modified so we
 141 // use Atomic operations to disable compiler optimizations that
 142 // might try to elide loading and/or storing this field.
 143 
 144 inline ObjectMonitor* ObjectMonitor::next_om() const {
 145   return Atomic::load(&_next_om);
 146 }
 147 
 148 // Simply set _next_om field to new_value.
 149 inline void ObjectMonitor::set_next_om(ObjectMonitor* new_value) {
 150   Atomic::store(&_next_om, new_value);
 151 }
 152 
 153 // Try to set _next_om field to new_value if the current value matches
 154 // old_value. Otherwise, does not change the _next_om field. Returns
 155 // the prior value of the _next_om field.
 156 inline ObjectMonitor* ObjectMonitor::try_set_next_om(ObjectMonitor* old_value, ObjectMonitor* new_value) {
 157   return Atomic::cmpxchg(&_next_om, old_value, new_value);
 158 }
 159 


  35   return 0;
  36 }
  37 
  38 inline markWord ObjectMonitor::header() const {
  39   return Atomic::load(&_header);
  40 }
  41 
  42 inline volatile markWord* ObjectMonitor::header_addr() {
  43   assert((intptr_t)this == (intptr_t)&_header, "sync code expects this");
  44   return &_header;
  45 }
  46 
  47 inline void ObjectMonitor::set_header(markWord hdr) {
  48   Atomic::store(&_header, hdr);
  49 }
  50 
  51 inline jint ObjectMonitor::waiters() const {
  52   return _waiters;
  53 }
  54 
  55 // Returns NULL if DEFLATER_MARKER is observed.
  56 inline void* ObjectMonitor::owner() const {
  57   void* owner = _owner;
  58   return owner != DEFLATER_MARKER ? owner : NULL;
  59 }
  60 
  61 // Returns true if owner field == DEFLATER_MARKER and false otherwise.
  62 // This accessor is called when we really need to know if the owner
  63 // field == DEFLATER_MARKER and any non-NULL value won't do the trick.
  64 inline bool ObjectMonitor::owner_is_DEFLATER_MARKER() {
  65   return _owner == DEFLATER_MARKER;
  66 }
  67 
  68 inline void ObjectMonitor::clear() {
  69   assert(Atomic::load(&_header).value() != 0, "must be non-zero");
  70   assert(_owner == NULL, "must be NULL: owner=" INTPTR_FORMAT, p2i(_owner));
  71 #ifdef ASSERT
  72   jint l_ref_count = ref_count();
  73 #endif
  74   assert(l_ref_count == 0, "must be 0: l_ref_count=%d, ref_count=%d", l_ref_count, ref_count());
  75 
  76   Atomic::store(&_header, markWord::zero());
  77 
  78   clear_using_JT();
  79 }
  80 
  81 inline void ObjectMonitor::clear_using_JT() {
  82   // Unlike other *_using_JT() functions, we cannot assert
  83   // AsyncDeflateIdleMonitors or Thread::current()->is_Java_thread()
  84   // because clear() calls this function for the rest of its checks.
  85 
  86   if (AsyncDeflateIdleMonitors) {
  87     // Async deflation protocol uses the header, owner and ref_count
  88     // fields. While the ObjectMonitor being deflated is on the global free
  89     // list, we leave those three fields alone; owner == DEFLATER_MARKER
  90     // and ref_count < 0 will force any racing threads to retry. The
  91     // header field is used by install_displaced_markword_in_object()
  92     // in the last part of the deflation protocol so we cannot check
  93     // its value here.
  94     guarantee(_owner == NULL || _owner == DEFLATER_MARKER,
  95               "must be NULL or DEFLATER_MARKER: owner=" INTPTR_FORMAT,
  96               p2i(_owner));
  97     jint l_ref_count = ref_count();
  98     guarantee(l_ref_count <= 0, "must be <= 0: l_ref_count=%d, ref_count=%d", l_ref_count, ref_count());
  99   }
 100   assert(_contentions == 0, "must be 0: contentions=%d", _contentions);
 101   assert(_waiters == 0, "must be 0: waiters=%d", _waiters);
 102   assert(_recursions == 0, "must be 0: recursions=" INTX_FORMAT, _recursions);
 103   assert(_object != NULL, "must be non-NULL");

 104 
 105   set_allocation_state(Free);
 106   _object = NULL;
 107 }
 108 
 109 inline void* ObjectMonitor::object() const {
 110   return _object;
 111 }
 112 
 113 inline void* ObjectMonitor::object_addr() {
 114   return (void *)(&_object);
 115 }
 116 
 117 inline void ObjectMonitor::set_object(void* obj) {
 118   _object = obj;
 119 }
 120 
 121 // return number of threads contending for this monitor
 122 inline jint ObjectMonitor::contentions() const {
 123   return _contentions;
 124 }
 125 
 126 // Clear _owner field; current value must match old_value.
 127 inline void ObjectMonitor::release_clear_owner(void* old_value) {
 128   void* prev = Atomic::load(&_owner);
 129   ADIM_guarantee(prev == old_value, "unexpected prev owner=" INTPTR_FORMAT
 130                  ", expected=" INTPTR_FORMAT, p2i(prev), p2i(old_value));
 131   Atomic::release_store(&_owner, (void*)NULL);
 132   log_trace(monitorinflation, owner)("release_clear_owner(): mid="
 133                                      INTPTR_FORMAT ", old_value=" INTPTR_FORMAT,
 134                                      p2i(this), p2i(old_value));
 135 }
 136 
 137 // Simply set _owner field to new_value; current value must match old_value.
 138 // (Simple means no memory sync needed.)
 139 inline void ObjectMonitor::set_owner_from(void* old_value, void* new_value) {
 140   void* prev = Atomic::load(&_owner);
 141   ADIM_guarantee(prev == old_value, "unexpected prev owner=" INTPTR_FORMAT
 142                  ", expected=" INTPTR_FORMAT, p2i(prev), p2i(old_value));
 143   Atomic::store(&_owner, new_value);
 144   log_trace(monitorinflation, owner)("set_owner_from(): mid="
 145                                      INTPTR_FORMAT ", old_value=" INTPTR_FORMAT
 146                                      ", new_value=" INTPTR_FORMAT, p2i(this),
 147                                      p2i(old_value), p2i(new_value));
 148 }
 149 
 150 // Simply set _owner field to new_value; current value must match old_value1 or old_value2.
 151 // (Simple means no memory sync needed.)
 152 inline void ObjectMonitor::set_owner_from(void* old_value1, void* old_value2, void* new_value) {
 153   void* prev = Atomic::load(&_owner);
 154   ADIM_guarantee(prev == old_value1 || prev == old_value2,
 155                  "unexpected prev owner=" INTPTR_FORMAT ", expected1="
 156                  INTPTR_FORMAT " or expected2=" INTPTR_FORMAT, p2i(prev),
 157                  p2i(old_value1), p2i(old_value2));
 158   _owner = new_value;
 159   log_trace(monitorinflation, owner)("set_owner_from(old1=" INTPTR_FORMAT
 160                                      ", old2=" INTPTR_FORMAT "): mid="
 161                                      INTPTR_FORMAT ", prev=" INTPTR_FORMAT
 162                                      ", new=" INTPTR_FORMAT, p2i(old_value1),
 163                                      p2i(old_value2), p2i(this), p2i(prev),
 164                                      p2i(new_value));
 165 }
 166 
 167 // Simply set _owner field to self; current value must match basic_lock_p.
 168 inline void ObjectMonitor::set_owner_from_BasicLock(void* basic_lock_p, Thread* self) {
 169   void* prev = Atomic::load(&_owner);
 170   ADIM_guarantee(prev == basic_lock_p, "unexpected prev owner=" INTPTR_FORMAT
 171                  ", expected=" INTPTR_FORMAT, p2i(prev), p2i(basic_lock_p));
 172   // Non-null owner field to non-null owner field is safe without
 173   // cmpxchg() as long as all readers can tolerate either flavor.
 174   Atomic::store(&_owner, self);
 175   log_trace(monitorinflation, owner)("set_owner_from_BasicLock(): mid="
 176                                      INTPTR_FORMAT ", basic_lock_p="
 177                                      INTPTR_FORMAT ", new_value=" INTPTR_FORMAT,
 178                                      p2i(this), p2i(basic_lock_p), p2i(self));
 179 }
 180 
 181 // Try to set _owner field to new_value if the current value matches
 182 // old_value. Otherwise, does not change the _owner field. Returns
 183 // the prior value of the _owner field.
 184 inline void* ObjectMonitor::try_set_owner_from(void* old_value, void* new_value) {
 185   void* prev = Atomic::cmpxchg(&_owner, old_value, new_value);
 186   if (prev == old_value) {
 187     log_trace(monitorinflation, owner)("try_set_owner_from(): mid="
 188                                        INTPTR_FORMAT ", prev=" INTPTR_FORMAT
 189                                        ", new=" INTPTR_FORMAT, p2i(this),
 190                                        p2i(prev), p2i(new_value));
 191   }
 192   return prev;
 193 }
 194 
 195 inline void ObjectMonitor::set_allocation_state(ObjectMonitor::AllocationState s) {
 196   _allocation_state = s;
 197 }
 198 
 199 inline ObjectMonitor::AllocationState ObjectMonitor::allocation_state() const {
 200   return _allocation_state;
 201 }
 202 
 203 inline bool ObjectMonitor::is_free() const {
 204   return _allocation_state == Free;
 205 }
 206 
 207 inline bool ObjectMonitor::is_old() const {
 208   return _allocation_state == Old;
 209 }
 210 
 211 inline bool ObjectMonitor::is_new() const {
 212   return _allocation_state == New;
 213 }
 214 
 215 inline void ObjectMonitor::dec_ref_count() {
 216   Atomic::dec(&_ref_count);
 217   // Can be negative as part of async deflation protocol.
 218   jint l_ref_count = ref_count();
 219   ADIM_guarantee(AsyncDeflateIdleMonitors || l_ref_count >= 0,
 220                  "sanity check: l_ref_count=%d, ref_count=%d", l_ref_count, ref_count());
 221 }
 222 
 223 inline void ObjectMonitor::inc_ref_count() {
 224   Atomic::inc(&_ref_count);
 225   // Can be negative as part of async deflation protocol.
 226   jint l_ref_count = ref_count();
 227   ADIM_guarantee(AsyncDeflateIdleMonitors || l_ref_count > 0,
 228                  "sanity check: l_ref_count=%d, ref_count=%d", l_ref_count, ref_count());
 229 }
 230 
 231 inline jint ObjectMonitor::ref_count() const {
 232   return Atomic::load(&_ref_count);
 233 }
 234 
 235 // The _next_om field can be concurrently read and modified so we
 236 // use Atomic operations to disable compiler optimizations that
 237 // might try to elide loading and/or storing this field.
 238 
 239 inline ObjectMonitor* ObjectMonitor::next_om() const {
 240   return Atomic::load(&_next_om);
 241 }
 242 
 243 // Simply set _next_om field to new_value.
 244 inline void ObjectMonitor::set_next_om(ObjectMonitor* new_value) {
 245   Atomic::store(&_next_om, new_value);
 246 }
 247 
 248 // Try to set _next_om field to new_value if the current value matches
 249 // old_value. Otherwise, does not change the _next_om field. Returns
 250 // the prior value of the _next_om field.
 251 inline ObjectMonitor* ObjectMonitor::try_set_next_om(ObjectMonitor* old_value, ObjectMonitor* new_value) {
 252   return Atomic::cmpxchg(&_next_om, old_value, new_value);
 253 }
 254 
< prev index next >