18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "classfile/vmSymbols.hpp"
27 #include "memory/resourceArea.hpp"
28 #include "oops/markOop.hpp"
29 #include "oops/oop.inline.hpp"
30 #include "runtime/atomic.hpp"
31 #include "runtime/handles.inline.hpp"
32 #include "runtime/interfaceSupport.hpp"
33 #include "runtime/mutexLocker.hpp"
34 #include "runtime/objectMonitor.hpp"
35 #include "runtime/objectMonitor.inline.hpp"
36 #include "runtime/orderAccess.inline.hpp"
37 #include "runtime/osThread.hpp"
38 #include "runtime/stubRoutines.hpp"
39 #include "runtime/thread.inline.hpp"
40 #include "services/threadService.hpp"
41 #include "trace/tracing.hpp"
42 #include "trace/traceMacros.hpp"
43 #include "utilities/dtrace.hpp"
44 #include "utilities/macros.hpp"
45 #include "utilities/preserveException.hpp"
46
47 #ifdef DTRACE_ENABLED
48
49 // Only bother with this argument setup if dtrace is available
50 // TODO-FIXME: probes should not fire when caller is _blocked. assert() accordingly.
51
52
53 #define DTRACE_MONITOR_PROBE_COMMON(obj, thread) \
54 char* bytes = NULL; \
55 int len = 0; \
56 jlong jtid = SharedRuntime::get_java_tid(thread); \
57 Symbol* klassname = ((oop)obj)->klass()->name(); \
1265 assert(_owner == Self, "invariant");
1266
1267 // Exit protocol:
1268 // 1. ST _succ = wakee
1269 // 2. membar #loadstore|#storestore;
1270 // 2. ST _owner = NULL
1271 // 3. unpark(wakee)
1272
1273 _succ = Knob_SuccEnabled ? Wakee->_thread : NULL;
1274 ParkEvent * Trigger = Wakee->_event;
1275
1276 // Hygiene -- once we've set _owner = NULL we can't safely dereference Wakee again.
1277 // The thread associated with Wakee may have grabbed the lock and "Wakee" may be
1278 // out-of-scope (non-extant).
1279 Wakee = NULL;
1280
1281 // Drop the lock
1282 OrderAccess::release_store_ptr(&_owner, NULL);
1283 OrderAccess::fence(); // ST _owner vs LD in unpark()
1284
1285 if (SafepointSynchronize::do_call_back()) {
1286 TEVENT(unpark before SAFEPOINT);
1287 }
1288
1289 DTRACE_MONITOR_PROBE(contended__exit, this, object(), Self);
1290 Trigger->unpark();
1291
1292 // Maintain stats and report events to JVMTI
1293 OM_PERFDATA_OP(Parks, inc());
1294 }
1295
1296
1297 // -----------------------------------------------------------------------------
1298 // Class Loader deadlock handling.
1299 //
1300 // complete_exit exits a lock returning recursion count
1301 // complete_exit/reenter operate as a wait without waiting
1302 // complete_exit requires an inflated monitor
1303 // The _owner field is not always the Thread addr even with an
1304 // inflated monitor, e.g. the monitor can be inflated by a non-owning
1305 // thread due to contention.
1919 if (sss && _succ == NULL) _succ = Self;
1920 Thread * prv = NULL;
1921
1922 // There are three ways to exit the following loop:
1923 // 1. A successful spin where this thread has acquired the lock.
1924 // 2. Spin failure with prejudice
1925 // 3. Spin failure without prejudice
1926
1927 while (--ctr >= 0) {
1928
1929 // Periodic polling -- Check for pending GC
1930 // Threads may spin while they're unsafe.
1931 // We don't want spinning threads to delay the JVM from reaching
1932 // a stop-the-world safepoint or to steal cycles from GC.
1933 // If we detect a pending safepoint we abort in order that
1934 // (a) this thread, if unsafe, doesn't delay the safepoint, and (b)
1935 // this thread, if safe, doesn't steal cycles from GC.
1936 // This is in keeping with the "no loitering in runtime" rule.
1937 // We periodically check to see if there's a safepoint pending.
1938 if ((ctr & 0xFF) == 0) {
1939 if (SafepointSynchronize::do_call_back()) {
1940 TEVENT(Spin: safepoint);
1941 goto Abort; // abrupt spin egress
1942 }
1943 if (Knob_UsePause & 1) SpinPause();
1944 }
1945
1946 if (Knob_UsePause & 2) SpinPause();
1947
1948 // Exponential back-off ... Stay off the bus to reduce coherency traffic.
1949 // This is useful on classic SMP systems, but is of less utility on
1950 // N1-style CMT platforms.
1951 //
1952 // Trade-off: lock acquisition latency vs coherency bandwidth.
1953 // Lock hold times are typically short. A histogram
1954 // of successful spin attempts shows that we usually acquire
1955 // the lock early in the spin. That suggests we want to
1956 // sample _owner frequently in the early phase of the spin,
1957 // but then back-off and sample less frequently as the spin
1958 // progresses. The back-off makes a good citizen on SMP big
1959 // SMP systems. Oversampling _owner can consume excessive
|
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "classfile/vmSymbols.hpp"
27 #include "memory/resourceArea.hpp"
28 #include "oops/markOop.hpp"
29 #include "oops/oop.inline.hpp"
30 #include "runtime/atomic.hpp"
31 #include "runtime/handles.inline.hpp"
32 #include "runtime/interfaceSupport.hpp"
33 #include "runtime/mutexLocker.hpp"
34 #include "runtime/objectMonitor.hpp"
35 #include "runtime/objectMonitor.inline.hpp"
36 #include "runtime/orderAccess.inline.hpp"
37 #include "runtime/osThread.hpp"
38 #include "runtime/safepointMechanism.inline.hpp"
39 #include "runtime/stubRoutines.hpp"
40 #include "runtime/thread.inline.hpp"
41 #include "services/threadService.hpp"
42 #include "trace/tracing.hpp"
43 #include "trace/traceMacros.hpp"
44 #include "utilities/dtrace.hpp"
45 #include "utilities/macros.hpp"
46 #include "utilities/preserveException.hpp"
47
48 #ifdef DTRACE_ENABLED
49
50 // Only bother with this argument setup if dtrace is available
51 // TODO-FIXME: probes should not fire when caller is _blocked. assert() accordingly.
52
53
54 #define DTRACE_MONITOR_PROBE_COMMON(obj, thread) \
55 char* bytes = NULL; \
56 int len = 0; \
57 jlong jtid = SharedRuntime::get_java_tid(thread); \
58 Symbol* klassname = ((oop)obj)->klass()->name(); \
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
|