src/hotspot/share/runtime/objectMonitor.inline.hpp
branchdatagramsocketimpl-branch
changeset 58678 9cf78a70fa4f
parent 54609 04857e2cd509
child 58679 9c3209ff7550
equal deleted inserted replaced
58677:13588c901957 58678:9cf78a70fa4f
    23  */
    23  */
    24 
    24 
    25 #ifndef SHARE_RUNTIME_OBJECTMONITOR_INLINE_HPP
    25 #ifndef SHARE_RUNTIME_OBJECTMONITOR_INLINE_HPP
    26 #define SHARE_RUNTIME_OBJECTMONITOR_INLINE_HPP
    26 #define SHARE_RUNTIME_OBJECTMONITOR_INLINE_HPP
    27 
    27 
       
    28 #include "runtime/atomic.hpp"
       
    29 
    28 inline intptr_t ObjectMonitor::is_entered(TRAPS) const {
    30 inline intptr_t ObjectMonitor::is_entered(TRAPS) const {
    29   if (THREAD == _owner || THREAD->is_lock_owned((address) _owner)) {
    31   if (THREAD == _owner || THREAD->is_lock_owned((address) _owner)) {
    30     return 1;
    32     return 1;
    31   }
    33   }
    32   return 0;
    34   return 0;
    33 }
    35 }
    34 
    36 
    35 inline markOop ObjectMonitor::header() const {
    37 inline markWord ObjectMonitor::header() const {
    36   return _header;
    38   return Atomic::load(&_header);
    37 }
    39 }
    38 
    40 
    39 inline volatile markOop* ObjectMonitor::header_addr() {
    41 inline volatile markWord* ObjectMonitor::header_addr() {
    40   assert((intptr_t)this == (intptr_t)&_header, "sync code expects this");
    42   assert((intptr_t)this == (intptr_t)&_header, "sync code expects this");
    41   return &_header;
    43   return &_header;
    42 }
    44 }
    43 
    45 
    44 inline void ObjectMonitor::set_header(markOop hdr) {
    46 inline void ObjectMonitor::set_header(markWord hdr) {
    45   _header = hdr;
    47   Atomic::store(hdr, &_header);
    46 }
    48 }
    47 
    49 
    48 inline jint ObjectMonitor::waiters() const {
    50 inline jint ObjectMonitor::waiters() const {
    49   return _waiters;
    51   return _waiters;
    50 }
    52 }
    52 inline void* ObjectMonitor::owner() const {
    54 inline void* ObjectMonitor::owner() const {
    53   return _owner;
    55   return _owner;
    54 }
    56 }
    55 
    57 
    56 inline void ObjectMonitor::clear() {
    58 inline void ObjectMonitor::clear() {
    57   assert(_header != NULL, "must be non-NULL");
    59   assert(Atomic::load(&_header).value() != 0, "must be non-zero");
    58   assert(_contentions == 0, "must be 0: contentions=%d", _contentions);
    60   assert(_contentions == 0, "must be 0: contentions=%d", _contentions);
    59   assert(_waiters == 0, "must be 0: waiters=%d", _waiters);
    61   assert(_waiters == 0, "must be 0: waiters=%d", _waiters);
    60   assert(_recursions == 0, "must be 0: recursions=" INTPTR_FORMAT, _recursions);
    62   assert(_recursions == 0, "must be 0: recursions=" INTPTR_FORMAT, _recursions);
    61   assert(_object != NULL, "must be non-NULL");
    63   assert(_object != NULL, "must be non-NULL");
    62   assert(_owner == NULL, "must be NULL: owner=" INTPTR_FORMAT, p2i(_owner));
    64   assert(_owner == NULL, "must be NULL: owner=" INTPTR_FORMAT, p2i(_owner));
    63 
    65 
    64   _header = NULL;
    66   Atomic::store(markWord::zero(), &_header);
    65   _object = NULL;
    67   _object = NULL;
    66 }
    68 }
    67 
    69 
    68 inline void* ObjectMonitor::object() const {
    70 inline void* ObjectMonitor::object() const {
    69   return _object;
    71   return _object;
    75 
    77 
    76 inline void ObjectMonitor::set_object(void* obj) {
    78 inline void ObjectMonitor::set_object(void* obj) {
    77   _object = obj;
    79   _object = obj;
    78 }
    80 }
    79 
    81 
    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
    82 // return number of threads contending for this monitor
    94 inline jint ObjectMonitor::contentions() const {
    83 inline jint ObjectMonitor::contentions() const {
    95   return _contentions;
    84   return _contentions;
    96 }
    85 }
    97 
    86 
    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) {
    87 inline void ObjectMonitor::set_owner(void* owner) {
   102   _owner = owner;
    88   _owner = owner;
   103   _recursions = 0;
       
   104 }
    89 }
   105 
    90 
   106 #endif // SHARE_RUNTIME_OBJECTMONITOR_INLINE_HPP
    91 #endif // SHARE_RUNTIME_OBJECTMONITOR_INLINE_HPP