src/hotspot/share/runtime/objectMonitor.cpp
changeset 55345 492b644bb9c2
parent 54807 33fe50b6d707
child 57734 18f4d3d46d54
equal deleted inserted replaced
55344:0c20dbc3d547 55345:492b644bb9c2
   243   // and to reduce RTS->RTO cache line upgrades on SPARC and IA32 processors.
   243   // and to reduce RTS->RTO cache line upgrades on SPARC and IA32 processors.
   244   Thread * const Self = THREAD;
   244   Thread * const Self = THREAD;
   245 
   245 
   246   void * cur = Atomic::cmpxchg(Self, &_owner, (void*)NULL);
   246   void * cur = Atomic::cmpxchg(Self, &_owner, (void*)NULL);
   247   if (cur == NULL) {
   247   if (cur == NULL) {
   248     // Either ASSERT _recursions == 0 or explicitly set _recursions = 0.
       
   249     assert(_recursions == 0, "invariant");
   248     assert(_recursions == 0, "invariant");
   250     assert(_owner == Self, "invariant");
       
   251     return;
   249     return;
   252   }
   250   }
   253 
   251 
   254   if (cur == Self) {
   252   if (cur == Self) {
   255     // TODO-FIXME: check for integer overflow!  BUGID 6557169.
   253     // TODO-FIXME: check for integer overflow!  BUGID 6557169.
   403 
   401 
   404 int ObjectMonitor::TryLock(Thread * Self) {
   402 int ObjectMonitor::TryLock(Thread * Self) {
   405   void * own = _owner;
   403   void * own = _owner;
   406   if (own != NULL) return 0;
   404   if (own != NULL) return 0;
   407   if (Atomic::replace_if_null(Self, &_owner)) {
   405   if (Atomic::replace_if_null(Self, &_owner)) {
   408     // Either guarantee _recursions == 0 or set _recursions = 0.
       
   409     assert(_recursions == 0, "invariant");
   406     assert(_recursions == 0, "invariant");
   410     assert(_owner == Self, "invariant");
       
   411     return 1;
   407     return 1;
   412   }
   408   }
   413   // The lock had been free momentarily, but we lost the race to the lock.
   409   // The lock had been free momentarily, but we lost the race to the lock.
   414   // Interference -- the CAS failed.
   410   // Interference -- the CAS failed.
   415   // We can either return -1 or retry.
   411   // We can either return -1 or retry.
   416   // Retry doesn't make as much sense because the lock was just acquired.
   412   // Retry doesn't make as much sense because the lock was just acquired.
   417   return -1;
   413   return -1;
       
   414 }
       
   415 
       
   416 // Convert the fields used by is_busy() to a string that can be
       
   417 // used for diagnostic output.
       
   418 const char* ObjectMonitor::is_busy_to_string(stringStream* ss) {
       
   419   ss->print("is_busy: contentions=%d, waiters=%d, owner=" INTPTR_FORMAT
       
   420             ", cxq=" INTPTR_FORMAT ", EntryList=" INTPTR_FORMAT, _contentions,
       
   421             _waiters, p2i(_owner), p2i(_cxq), p2i(_EntryList));
       
   422   return ss->base();
   418 }
   423 }
   419 
   424 
   420 #define MAX_RECHECK_INTERVAL 1000
   425 #define MAX_RECHECK_INTERVAL 1000
   421 
   426 
   422 void ObjectMonitor::EnterI(TRAPS) {
   427 void ObjectMonitor::EnterI(TRAPS) {