< prev index next >

src/hotspot/share/runtime/objectMonitor.cpp

Print this page
rev 47413 : Introduce SafepointMechanism
rev 47415 : Add Thread Local handshakes and thread local polling


1266   assert(_owner == Self, "invariant");
1267 
1268   // Exit protocol:
1269   // 1. ST _succ = wakee
1270   // 2. membar #loadstore|#storestore;
1271   // 2. ST _owner = NULL
1272   // 3. unpark(wakee)
1273 
1274   _succ = Knob_SuccEnabled ? Wakee->_thread : NULL;
1275   ParkEvent * Trigger = Wakee->_event;
1276 
1277   // Hygiene -- once we've set _owner = NULL we can't safely dereference Wakee again.
1278   // The thread associated with Wakee may have grabbed the lock and "Wakee" may be
1279   // out-of-scope (non-extant).
1280   Wakee  = NULL;
1281 
1282   // Drop the lock
1283   OrderAccess::release_store_ptr(&_owner, NULL);
1284   OrderAccess::fence();                               // ST _owner vs LD in unpark()
1285 
1286   if (SafepointMechanism::poll()) {
1287     TEVENT(unpark before SAFEPOINT);
1288   }
1289 
1290   DTRACE_MONITOR_PROBE(contended__exit, this, object(), Self);
1291   Trigger->unpark();
1292 
1293   // Maintain stats and report events to JVMTI
1294   OM_PERFDATA_OP(Parks, inc());
1295 }
1296 
1297 
1298 // -----------------------------------------------------------------------------
1299 // Class Loader deadlock handling.
1300 //
1301 // complete_exit exits a lock returning recursion count
1302 // complete_exit/reenter operate as a wait without waiting
1303 // complete_exit requires an inflated monitor
1304 // The _owner field is not always the Thread addr even with an
1305 // inflated monitor, e.g. the monitor can be inflated by a non-owning
1306 // thread due to contention.


1920   if (sss && _succ == NULL) _succ = Self;
1921   Thread * prv = NULL;
1922 
1923   // There are three ways to exit the following loop:
1924   // 1.  A successful spin where this thread has acquired the lock.
1925   // 2.  Spin failure with prejudice
1926   // 3.  Spin failure without prejudice
1927 
1928   while (--ctr >= 0) {
1929 
1930     // Periodic polling -- Check for pending GC
1931     // Threads may spin while they're unsafe.
1932     // We don't want spinning threads to delay the JVM from reaching
1933     // a stop-the-world safepoint or to steal cycles from GC.
1934     // If we detect a pending safepoint we abort in order that
1935     // (a) this thread, if unsafe, doesn't delay the safepoint, and (b)
1936     // this thread, if safe, doesn't steal cycles from GC.
1937     // This is in keeping with the "no loitering in runtime" rule.
1938     // We periodically check to see if there's a safepoint pending.
1939     if ((ctr & 0xFF) == 0) {
1940       if (SafepointMechanism::poll()) {
1941         TEVENT(Spin: safepoint);
1942         goto Abort;           // abrupt spin egress
1943       }
1944       if (Knob_UsePause & 1) SpinPause();
1945     }
1946 
1947     if (Knob_UsePause & 2) SpinPause();
1948 
1949     // Exponential back-off ...  Stay off the bus to reduce coherency traffic.
1950     // This is useful on classic SMP systems, but is of less utility on
1951     // N1-style CMT platforms.
1952     //
1953     // Trade-off: lock acquisition latency vs coherency bandwidth.
1954     // Lock hold times are typically short.  A histogram
1955     // of successful spin attempts shows that we usually acquire
1956     // the lock early in the spin.  That suggests we want to
1957     // sample _owner frequently in the early phase of the spin,
1958     // but then back-off and sample less frequently as the spin
1959     // progresses.  The back-off makes a good citizen on SMP big
1960     // SMP systems.  Oversampling _owner can consume excessive




1266   assert(_owner == Self, "invariant");
1267 
1268   // Exit protocol:
1269   // 1. ST _succ = wakee
1270   // 2. membar #loadstore|#storestore;
1271   // 2. ST _owner = NULL
1272   // 3. unpark(wakee)
1273 
1274   _succ = Knob_SuccEnabled ? Wakee->_thread : NULL;
1275   ParkEvent * Trigger = Wakee->_event;
1276 
1277   // Hygiene -- once we've set _owner = NULL we can't safely dereference Wakee again.
1278   // The thread associated with Wakee may have grabbed the lock and "Wakee" may be
1279   // out-of-scope (non-extant).
1280   Wakee  = NULL;
1281 
1282   // Drop the lock
1283   OrderAccess::release_store_ptr(&_owner, NULL);
1284   OrderAccess::fence();                               // ST _owner vs LD in unpark()
1285 
1286   if (SafepointMechanism::poll(Self)) {
1287     TEVENT(unpark before SAFEPOINT);
1288   }
1289 
1290   DTRACE_MONITOR_PROBE(contended__exit, this, object(), Self);
1291   Trigger->unpark();
1292 
1293   // Maintain stats and report events to JVMTI
1294   OM_PERFDATA_OP(Parks, inc());
1295 }
1296 
1297 
1298 // -----------------------------------------------------------------------------
1299 // Class Loader deadlock handling.
1300 //
1301 // complete_exit exits a lock returning recursion count
1302 // complete_exit/reenter operate as a wait without waiting
1303 // complete_exit requires an inflated monitor
1304 // The _owner field is not always the Thread addr even with an
1305 // inflated monitor, e.g. the monitor can be inflated by a non-owning
1306 // thread due to contention.


1920   if (sss && _succ == NULL) _succ = Self;
1921   Thread * prv = NULL;
1922 
1923   // There are three ways to exit the following loop:
1924   // 1.  A successful spin where this thread has acquired the lock.
1925   // 2.  Spin failure with prejudice
1926   // 3.  Spin failure without prejudice
1927 
1928   while (--ctr >= 0) {
1929 
1930     // Periodic polling -- Check for pending GC
1931     // Threads may spin while they're unsafe.
1932     // We don't want spinning threads to delay the JVM from reaching
1933     // a stop-the-world safepoint or to steal cycles from GC.
1934     // If we detect a pending safepoint we abort in order that
1935     // (a) this thread, if unsafe, doesn't delay the safepoint, and (b)
1936     // this thread, if safe, doesn't steal cycles from GC.
1937     // This is in keeping with the "no loitering in runtime" rule.
1938     // We periodically check to see if there's a safepoint pending.
1939     if ((ctr & 0xFF) == 0) {
1940       if (SafepointMechanism::poll(Self)) {
1941         TEVENT(Spin: safepoint);
1942         goto Abort;           // abrupt spin egress
1943       }
1944       if (Knob_UsePause & 1) SpinPause();
1945     }
1946 
1947     if (Knob_UsePause & 2) SpinPause();
1948 
1949     // Exponential back-off ...  Stay off the bus to reduce coherency traffic.
1950     // This is useful on classic SMP systems, but is of less utility on
1951     // N1-style CMT platforms.
1952     //
1953     // Trade-off: lock acquisition latency vs coherency bandwidth.
1954     // Lock hold times are typically short.  A histogram
1955     // of successful spin attempts shows that we usually acquire
1956     // the lock early in the spin.  That suggests we want to
1957     // sample _owner frequently in the early phase of the spin,
1958     // but then back-off and sample less frequently as the spin
1959     // progresses.  The back-off makes a good citizen on SMP big
1960     // SMP systems.  Oversampling _owner can consume excessive


< prev index next >