< prev index next >

src/hotspot/share/runtime/objectMonitor.cpp

Print this page




2071     }
2072   }
2073 
2074  Abort:
2075   if (MaxSpin >= 0) Adjust(&_Spinner, -1);
2076   if (sss && _succ == Self) {
2077     _succ = NULL;
2078     // Invariant: after setting succ=null a contending thread
2079     // must recheck-retry _owner before parking.  This usually happens
2080     // in the normal usage of TrySpin(), but it's safest
2081     // to make TrySpin() as foolproof as possible.
2082     OrderAccess::fence();
2083     if (TryLock(Self) > 0) return 1;
2084   }
2085   return 0;
2086 }
2087 
2088 // NotRunnable() -- informed spinning
2089 //
2090 // Don't bother spinning if the owner is not eligible to drop the lock.
2091 // Peek at the owner's schedctl.sc_state and Thread._thread_values and
2092 // spin only if the owner thread is _thread_in_Java or _thread_in_vm.
2093 // The thread must be runnable in order to drop the lock in timely fashion.
2094 // If the _owner is not runnable then spinning will not likely be
2095 // successful (profitable).
2096 //
2097 // Beware -- the thread referenced by _owner could have died
2098 // so a simply fetch from _owner->_thread_state might trap.
2099 // Instead, we use SafeFetchXX() to safely LD _owner->_thread_state.
2100 // Because of the lifecycle issues the schedctl and _thread_state values
2101 // observed by NotRunnable() might be garbage.  NotRunnable must
2102 // tolerate this and consider the observed _thread_state value
2103 // as advisory.
2104 //
2105 // Beware too, that _owner is sometimes a BasicLock address and sometimes
2106 // a thread pointer.
2107 // Alternately, we might tag the type (thread pointer vs basiclock pointer)
2108 // with the LSB of _owner.  Another option would be to probablistically probe
2109 // the putative _owner->TypeTag value.
2110 //
2111 // Checking _thread_state isn't perfect.  Even if the thread is
2112 // in_java it might be blocked on a page-fault or have been preempted
2113 // and sitting on a ready/dispatch queue.  _thread state in conjunction
2114 // with schedctl.sc_state gives us a good picture of what the
2115 // thread is doing, however.
2116 //
2117 // TODO: check schedctl.sc_state.
2118 // We'll need to use SafeFetch32() to read from the schedctl block.
2119 // See RFE #5004247 and http://sac.sfbay.sun.com/Archives/CaseLog/arc/PSARC/2005/351/
2120 //
2121 // The return value from NotRunnable() is *advisory* -- the
2122 // result is based on sampling and is not necessarily coherent.
2123 // The caller must tolerate false-negative and false-positive errors.
2124 // Spinning, in general, is probabilistic anyway.
2125 
2126 
2127 int ObjectMonitor::NotRunnable(Thread * Self, Thread * ox) {
2128   // Check ox->TypeTag == 2BAD.
2129   if (ox == NULL) return 0;
2130 
2131   // Avoid transitive spinning ...
2132   // Say T1 spins or blocks trying to acquire L.  T1._Stalled is set to L.
2133   // Immediately after T1 acquires L it's possible that T2, also
2134   // spinning on L, will see L.Owner=T1 and T1._Stalled=L.
2135   // This occurs transiently after T1 acquired L but before
2136   // T1 managed to clear T1.Stalled.  T2 does not need to abort
2137   // its spin in this circumstance.
2138   intptr_t BlockedOn = SafeFetchN((intptr_t *) &ox->_Stalled, intptr_t(1));
2139 




2071     }
2072   }
2073 
2074  Abort:
2075   if (MaxSpin >= 0) Adjust(&_Spinner, -1);
2076   if (sss && _succ == Self) {
2077     _succ = NULL;
2078     // Invariant: after setting succ=null a contending thread
2079     // must recheck-retry _owner before parking.  This usually happens
2080     // in the normal usage of TrySpin(), but it's safest
2081     // to make TrySpin() as foolproof as possible.
2082     OrderAccess::fence();
2083     if (TryLock(Self) > 0) return 1;
2084   }
2085   return 0;
2086 }
2087 
2088 // NotRunnable() -- informed spinning
2089 //
2090 // Don't bother spinning if the owner is not eligible to drop the lock.

2091 // spin only if the owner thread is _thread_in_Java or _thread_in_vm.
2092 // The thread must be runnable in order to drop the lock in timely fashion.
2093 // If the _owner is not runnable then spinning will not likely be
2094 // successful (profitable).
2095 //
2096 // Beware -- the thread referenced by _owner could have died
2097 // so a simply fetch from _owner->_thread_state might trap.
2098 // Instead, we use SafeFetchXX() to safely LD _owner->_thread_state.
2099 // Because of the lifecycle issues the schedctl and _thread_state values
2100 // observed by NotRunnable() might be garbage.  NotRunnable must
2101 // tolerate this and consider the observed _thread_state value
2102 // as advisory.
2103 //
2104 // Beware too, that _owner is sometimes a BasicLock address and sometimes
2105 // a thread pointer.
2106 // Alternately, we might tag the type (thread pointer vs basiclock pointer)
2107 // with the LSB of _owner.  Another option would be to probablistically probe
2108 // the putative _owner->TypeTag value.
2109 //
2110 // Checking _thread_state isn't perfect.  Even if the thread is
2111 // in_java it might be blocked on a page-fault or have been preempted
2112 // and sitting on a ready/dispatch queue.






2113 //
2114 // The return value from NotRunnable() is *advisory* -- the
2115 // result is based on sampling and is not necessarily coherent.
2116 // The caller must tolerate false-negative and false-positive errors.
2117 // Spinning, in general, is probabilistic anyway.
2118 
2119 
2120 int ObjectMonitor::NotRunnable(Thread * Self, Thread * ox) {
2121   // Check ox->TypeTag == 2BAD.
2122   if (ox == NULL) return 0;
2123 
2124   // Avoid transitive spinning ...
2125   // Say T1 spins or blocks trying to acquire L.  T1._Stalled is set to L.
2126   // Immediately after T1 acquires L it's possible that T2, also
2127   // spinning on L, will see L.Owner=T1 and T1._Stalled=L.
2128   // This occurs transiently after T1 acquired L but before
2129   // T1 managed to clear T1.Stalled.  T2 does not need to abort
2130   // its spin in this circumstance.
2131   intptr_t BlockedOn = SafeFetchN((intptr_t *) &ox->_Stalled, intptr_t(1));
2132 


< prev index next >