< prev index next >

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

Print this page
rev 57232 : v2.00 -> v2.08 (CR8/v2.08/11-for-jdk14) patches combined into one; merge with jdk-14+25 snapshot; merge with jdk-14+26 snapshot.
rev 57233 : See CR8-to-CR9-changes; merge with 8230876.patch (2019.11.15); merge with jdk-14+25 snapshot; fuzzy merge with jdk-14+26 snapshot.


  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   DEBUG_ONLY(jint l_ref_count = ref_count();)


  72   assert(l_ref_count == 0, "must be 0: l_ref_count=%d, ref_count=%d", l_ref_count, ref_count());
  73 
  74   Atomic::store(&_header, markWord::zero());
  75 
  76   clear_using_JT();
  77 }
  78 
  79 inline void ObjectMonitor::clear_using_JT() {
  80   // Unlike other *_using_JT() functions, we cannot assert
  81   // AsyncDeflateIdleMonitors or Thread::current()->is_Java_thread()
  82   // because clear() calls this function for the rest of its checks.
  83 
  84   if (AsyncDeflateIdleMonitors) {
  85     // Async deflation protocol uses the header, owner and ref_count
  86     // fields. While the ObjectMonitor being deflated is on the global free
  87     // list, we leave those three fields alone; owner == DEFLATER_MARKER
  88     // and ref_count < 0 will force any racing threads to retry. The
  89     // header field is used by install_displaced_markword_in_object()
  90     // in the last part of the deflation protocol so we cannot check
  91     // its value here.


 104   _object = NULL;
 105 }
 106 
 107 inline void* ObjectMonitor::object() const {
 108   return _object;
 109 }
 110 
 111 inline void* ObjectMonitor::object_addr() {
 112   return (void *)(&_object);
 113 }
 114 
 115 inline void ObjectMonitor::set_object(void* obj) {
 116   _object = obj;
 117 }
 118 
 119 // return number of threads contending for this monitor
 120 inline jint ObjectMonitor::contentions() const {
 121   return _contentions;
 122 }
 123 
 124 // Set _owner field to new_value; current value must match old_value.
 125 inline void ObjectMonitor::set_owner_from(void* new_value, void* old_value) {
 126   void* prev = Atomic::cmpxchg(&_owner, old_value, new_value);



 127   ADIM_guarantee(prev == old_value, "unexpected prev owner=" INTPTR_FORMAT
 128                  ", expected=" INTPTR_FORMAT, p2i(prev), p2i(old_value));
 129   log_trace(monitorinflation, owner)("set_owner_from(): mid=" INTPTR_FORMAT
 130                                      ", prev=" INTPTR_FORMAT ", new="
 131                                      INTPTR_FORMAT, p2i(this), p2i(prev),
 132                                      p2i(new_value));






 133 }
 134 
 135 // Simply set _owner field to new_value; current value must match old_value.
 136 // (Simple means no memory sync needed.)
 137 inline void ObjectMonitor::simply_set_owner_from(void* new_value, void* old_value) {
 138   void* prev = _owner;
 139   ADIM_guarantee(prev == old_value, "unexpected prev owner=" INTPTR_FORMAT
 140                  ", expected=" INTPTR_FORMAT, p2i(prev), p2i(old_value));
 141   _owner = new_value;
 142   log_trace(monitorinflation, owner)("simply_set_owner_from(): mid="
 143                                      INTPTR_FORMAT ", prev=" INTPTR_FORMAT
 144                                      ", new=" INTPTR_FORMAT, p2i(this),
 145                                      p2i(prev), p2i(new_value));
 146 }
 147 
 148 // Simply set _owner field to new_value; current value must match old_value1 or old_value2.
 149 // (Simple means no memory sync needed.)
 150 inline void ObjectMonitor::simply_set_owner_from(void* new_value, void* old_value1, void* old_value2) {
 151   void* prev = _owner;
 152   ADIM_guarantee(prev == old_value1 || prev == old_value2,


 194   _allocation_state = s;
 195 }
 196 
 197 inline ObjectMonitor::AllocationState ObjectMonitor::allocation_state() const {
 198   return _allocation_state;
 199 }
 200 
 201 inline bool ObjectMonitor::is_free() const {
 202   return _allocation_state == Free;
 203 }
 204 
 205 inline bool ObjectMonitor::is_old() const {
 206   return _allocation_state == Old;
 207 }
 208 
 209 inline bool ObjectMonitor::is_new() const {
 210   return _allocation_state == New;
 211 }
 212 
 213 inline void ObjectMonitor::dec_ref_count() {
 214   // The decrement only needs to be MO_ACQ_REL since the reference
 215   // counter is volatile.
 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   // The increment needs to be MO_SEQ_CST so that the reference
 225   // counter update is seen as soon as possible in a race with the
 226   // async deflation protocol.
 227   Atomic::inc(&_ref_count);
 228   // Can be negative as part of async deflation protocol.
 229   jint l_ref_count = ref_count();
 230   ADIM_guarantee(AsyncDeflateIdleMonitors || l_ref_count > 0,
 231                  "sanity check: l_ref_count=%d, ref_count=%d", l_ref_count, ref_count());
 232 }
 233 
 234 inline jint ObjectMonitor::ref_count() const {
 235   return _ref_count;
 236 }
 237 
 238 #endif // SHARE_RUNTIME_OBJECTMONITOR_INLINE_HPP


  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.


 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 // If needs_fence is true, we issue a fence() after the release_store().
 128 // Otherwise, a storeload() is good enough. See the callers for more info.
 129 inline void ObjectMonitor::release_clear_owner_with_barrier(void* old_value,
 130                                                             bool needs_fence) {
 131   void* prev = _owner;
 132   ADIM_guarantee(prev == old_value, "unexpected prev owner=" INTPTR_FORMAT
 133                  ", expected=" INTPTR_FORMAT, p2i(prev), p2i(old_value));
 134   Atomic::release_store(&_owner, (void*)NULL);
 135   if (needs_fence) {
 136     OrderAccess::fence();
 137   } else {
 138     OrderAccess::storeload();
 139   }
 140   log_trace(monitorinflation, owner)("release_clear_owner_with_barrier(): mid="
 141                                      INTPTR_FORMAT ", prev=" INTPTR_FORMAT
 142                                      ", needs_fence=%d", p2i(this), p2i(prev),
 143                                      needs_fence);
 144 }
 145 
 146 // Simply set _owner field to new_value; current value must match old_value.
 147 // (Simple means no memory sync needed.)
 148 inline void ObjectMonitor::simply_set_owner_from(void* new_value, void* old_value) {
 149   void* prev = _owner;
 150   ADIM_guarantee(prev == old_value, "unexpected prev owner=" INTPTR_FORMAT
 151                  ", expected=" INTPTR_FORMAT, p2i(prev), p2i(old_value));
 152   _owner = new_value;
 153   log_trace(monitorinflation, owner)("simply_set_owner_from(): mid="
 154                                      INTPTR_FORMAT ", prev=" INTPTR_FORMAT
 155                                      ", new=" INTPTR_FORMAT, p2i(this),
 156                                      p2i(prev), p2i(new_value));
 157 }
 158 
 159 // Simply set _owner field to new_value; current value must match old_value1 or old_value2.
 160 // (Simple means no memory sync needed.)
 161 inline void ObjectMonitor::simply_set_owner_from(void* new_value, void* old_value1, void* old_value2) {
 162   void* prev = _owner;
 163   ADIM_guarantee(prev == old_value1 || prev == old_value2,


 205   _allocation_state = s;
 206 }
 207 
 208 inline ObjectMonitor::AllocationState ObjectMonitor::allocation_state() const {
 209   return _allocation_state;
 210 }
 211 
 212 inline bool ObjectMonitor::is_free() const {
 213   return _allocation_state == Free;
 214 }
 215 
 216 inline bool ObjectMonitor::is_old() const {
 217   return _allocation_state == Old;
 218 }
 219 
 220 inline bool ObjectMonitor::is_new() const {
 221   return _allocation_state == New;
 222 }
 223 
 224 inline void ObjectMonitor::dec_ref_count() {


 225   Atomic::dec(&_ref_count);
 226   // Can be negative as part of async deflation protocol.
 227   jint l_ref_count = ref_count();
 228   ADIM_guarantee(AsyncDeflateIdleMonitors || l_ref_count >= 0,
 229                  "sanity check: l_ref_count=%d, ref_count=%d", l_ref_count, ref_count());
 230 }
 231 
 232 inline void ObjectMonitor::inc_ref_count() {



 233   Atomic::inc(&_ref_count);
 234   // Can be negative as part of async deflation protocol.
 235   jint l_ref_count = ref_count();
 236   ADIM_guarantee(AsyncDeflateIdleMonitors || l_ref_count > 0,
 237                  "sanity check: l_ref_count=%d, ref_count=%d", l_ref_count, ref_count());
 238 }
 239 
 240 inline jint ObjectMonitor::ref_count() const {
 241   return Atomic::load(&_ref_count);
 242 }
 243 
 244 #endif // SHARE_RUNTIME_OBJECTMONITOR_INLINE_HPP
< prev index next >