< prev index next >

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

Print this page
rev 54996 : Checkpoint latest preliminary review patches for full OpenJDK review; merge with 8222295.patch.
rev 54997 : imported patch dcubed.monitor_deflate_conc.v2.01
rev 54998 : imported patch dcubed.monitor_deflate_conc.v2.02
rev 54999 : imported patch dcubed.monitor_deflate_conc.v2.03


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

  52 inline void* ObjectMonitor::owner() const {
  53   return _owner;

  54 }
  55 
  56 inline void ObjectMonitor::clear() {
  57   assert(_header != NULL, "must be non-NULL");


























  58   assert(_contentions == 0, "must be 0: contentions=%d", _contentions);
  59   assert(_waiters == 0, "must be 0: waiters=%d", _waiters);
  60   assert(_recursions == 0, "must be 0: recursions=" INTPTR_FORMAT, _recursions);
  61   assert(_object != NULL, "must be non-NULL");
  62   assert(_owner == NULL, "must be NULL: owner=" INTPTR_FORMAT, p2i(_owner));
  63 
  64   _header = NULL;
  65   _object = NULL;
  66 }
  67 
  68 inline void* ObjectMonitor::object() const {
  69   return _object;
  70 }
  71 
  72 inline void* ObjectMonitor::object_addr() {
  73   return (void *)(&_object);
  74 }
  75 
  76 inline void ObjectMonitor::set_object(void* obj) {
  77   _object = obj;
  78 }
  79 
  80 inline bool ObjectMonitor::check(TRAPS) {
  81   if (THREAD != _owner) {
  82     if (THREAD->is_lock_owned((address) _owner)) {
  83       _owner = THREAD;  // regain ownership of inflated monitor
  84       assert (_recursions == 0, "invariant") ;
  85     } else {
  86       check_slow(THREAD);
  87       return false;
  88     }
  89   }
  90   return true;
  91 }
  92 
  93 // return number of threads contending for this monitor
  94 inline jint ObjectMonitor::contentions() const {
  95   return _contentions;
  96 }
  97 
  98 // Do NOT set _contentions = 0. There is a race such that _contentions could
  99 // be set while inflating prior to setting _owner
 100 // Just use Atomic::inc/dec and assert 0 when monitor put on free list
 101 inline void ObjectMonitor::set_owner(void* owner) {
 102   _owner = owner;
 103   _recursions = 0;















































 104 }
 105 
 106 #endif // SHARE_RUNTIME_OBJECTMONITOR_INLINE_HPP


  32   return 0;
  33 }
  34 
  35 inline markOop ObjectMonitor::header() const {
  36   return _header;
  37 }
  38 
  39 inline volatile markOop* ObjectMonitor::header_addr() {
  40   assert((intptr_t)this == (intptr_t)&_header, "sync code expects this");
  41   return &_header;
  42 }
  43 
  44 inline void ObjectMonitor::set_header(markOop hdr) {
  45   _header = hdr;
  46 }
  47 
  48 inline jint ObjectMonitor::waiters() const {
  49   return _waiters;
  50 }
  51 
  52 // Returns NULL if DEFLATER_MARKER is observed.
  53 inline void* ObjectMonitor::owner() const {
  54   void* owner = _owner;
  55   return owner != DEFLATER_MARKER ? owner : NULL;
  56 }
  57 
  58 inline void ObjectMonitor::clear() {
  59   assert(_header != NULL, "must be non-NULL");
  60   assert(_owner == NULL, "must be NULL: owner=" INTPTR_FORMAT, p2i(_owner));
  61   assert(_ref_count == 0, "must be 0: ref_count=%d", _ref_count);
  62 
  63   _header = NULL;
  64 
  65   clear_using_JT();
  66 }
  67 
  68 inline void ObjectMonitor::clear_using_JT() {
  69   // Unlike other *_using_JT() functions, we cannot assert
  70   // AsyncDeflateIdleMonitors or Thread::current()->is_Java_thread()
  71   // because clear() calls this function for the rest of its checks.
  72 
  73   if (AsyncDeflateIdleMonitors) {
  74     // Async deflation protocol uses the header, owner and ref_count
  75     // fields. While the ObjectMonitor being deflated is on the global free
  76     // list, we leave those three fields alone; owner == DEFLATER_MARKER
  77     // and ref_count < 0 will force any racing threads to retry. The
  78     // header field is used by install_displaced_markword_in_object()
  79     // in the last part of the deflation protocol so we cannot check
  80     // its value here.
  81     guarantee(_owner == NULL || _owner == DEFLATER_MARKER,
  82               "must be NULL or DEFLATER_MARKER: owner=" INTPTR_FORMAT,
  83               p2i(_owner));
  84     guarantee(_ref_count <= 0, "must be <= 0: ref_count=%d", _ref_count);
  85   }
  86   assert(_contentions == 0, "must be 0: contentions=%d", _contentions);
  87   assert(_waiters == 0, "must be 0: waiters=%d", _waiters);
  88   assert(_recursions == 0, "must be 0: recursions=" INTPTR_FORMAT, _recursions);
  89   assert(_object != NULL, "must be non-NULL");

  90 
  91   set_allocation_state(Free);
  92   _object = NULL;
  93 }
  94 
  95 inline void* ObjectMonitor::object() const {
  96   return _object;
  97 }
  98 
  99 inline void* ObjectMonitor::object_addr() {
 100   return (void *)(&_object);
 101 }
 102 
 103 inline void ObjectMonitor::set_object(void* obj) {
 104   _object = obj;
 105 }
 106 
 107 inline bool ObjectMonitor::check(TRAPS) {
 108   if (THREAD != _owner) {
 109     if (THREAD->is_lock_owned((address) _owner)) {
 110       _owner = THREAD;  // regain ownership of inflated monitor
 111       assert (_recursions == 0, "invariant") ;
 112     } else {
 113       check_slow(THREAD);
 114       return false;
 115     }
 116   }
 117   return true;
 118 }
 119 
 120 // return number of threads contending for this monitor
 121 inline jint ObjectMonitor::contentions() const {
 122   return _contentions;
 123 }
 124 
 125 // Do NOT set _contentions = 0. There is a race such that _contentions could
 126 // be set while inflating prior to setting _owner
 127 // Just use Atomic::inc/dec and assert 0 when monitor put on free list
 128 inline void ObjectMonitor::set_owner(void* owner) {
 129   _owner = owner;
 130   _recursions = 0;
 131 }
 132 
 133 inline void ObjectMonitor::set_allocation_state(ObjectMonitor::AllocationState s) {
 134   _allocation_state = s;
 135 }
 136 
 137 inline ObjectMonitor::AllocationState ObjectMonitor::allocation_state() const {
 138   return _allocation_state;
 139 }
 140 
 141 inline bool ObjectMonitor::is_free() const {
 142   return _allocation_state == Free;
 143 }
 144 
 145 inline bool ObjectMonitor::is_active() const {
 146   return !is_free();
 147 }
 148 
 149 inline bool ObjectMonitor::is_old() const {
 150   return _allocation_state == Old;
 151 }
 152 
 153 inline bool ObjectMonitor::is_new() const {
 154   return _allocation_state == New;
 155 }
 156 
 157 inline void ObjectMonitor::dec_ref_count() {
 158   // The decrement only needs to be MO_ACQ_REL since the reference
 159   // counter is volatile.
 160   Atomic::dec(&_ref_count);
 161   // Can be negative as part of async deflation protocol.
 162   guarantee(AsyncDeflateIdleMonitors || _ref_count >= 0,
 163             "sanity check: ref_count=%d", _ref_count);
 164 }
 165 
 166 inline void ObjectMonitor::inc_ref_count() {
 167   // The increment needs to be MO_SEQ_CST so that the reference
 168   // counter update is seen as soon as possible in a race with the
 169   // async deflation protocol.
 170   Atomic::inc(&_ref_count);
 171   // Can be negative as part of async deflation protocol.
 172   guarantee(AsyncDeflateIdleMonitors || _ref_count > 0,
 173             "sanity check: ref_count=%d", _ref_count);
 174 }
 175 
 176 inline jint ObjectMonitor::ref_count() const {
 177   return OrderAccess::load_acquire(&_ref_count);
 178 }
 179 
 180 #endif // SHARE_RUNTIME_OBJECTMONITOR_INLINE_HPP
< prev index next >