< prev index next >

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

Print this page
rev 57560 : imported patch 8236035.patch.cr0
rev 57561 : 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 57562 : 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.


  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   void* prev = _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 ", prev=" INTPTR_FORMAT,
  96                                      p2i(this), p2i(prev));
  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   void* prev = _owner;
 103   assert(prev == old_value, "unexpected prev owner=" INTPTR_FORMAT
 104          ", expected=" INTPTR_FORMAT, p2i(prev), p2i(old_value));
 105   _owner = new_value;
 106   log_trace(monitorinflation, owner)("set_owner_from(): mid="
 107                                      INTPTR_FORMAT ", prev=" INTPTR_FORMAT
 108                                      ", new=" INTPTR_FORMAT, p2i(this),
 109                                      p2i(prev), 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   void* prev = _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   _owner = self;
 120   log_trace(monitorinflation, owner)("set_owner_from_BasicLock(): mid="
 121                                      INTPTR_FORMAT ", prev=" INTPTR_FORMAT
 122                                      ", new=" INTPTR_FORMAT ", basic_lock_p="
 123                                      INTPTR_FORMAT, p2i(this), p2i(prev),
 124                                      p2i(self), p2i(basic_lock_p));
 125 }
 126 
 127 // Try to set _owner field to new_value if the current value matches
 128 // old_value. Otherwise, does not change 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 #endif // SHARE_RUNTIME_OBJECTMONITOR_INLINE_HPP


  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.
 128 inline void* ObjectMonitor::try_set_owner_from(void* old_value, void* new_value) {
 129   void* prev = Atomic::cmpxchg(&_owner, old_value, new_value);
 130   if (prev == old_value) {
 131     log_trace(monitorinflation, owner)("try_set_owner_from(): mid="
 132                                        INTPTR_FORMAT ", prev=" INTPTR_FORMAT
 133                                        ", new=" INTPTR_FORMAT, p2i(this),
 134                                        p2i(prev), p2i(new_value));
 135   }
 136   return prev;
 137 }
 138 
 139 #endif // SHARE_RUNTIME_OBJECTMONITOR_INLINE_HPP
< prev index next >