< prev index next >

src/hotspot/share/runtime/objectMonitor.cpp

Print this page




 899     return;
 900   }
 901 
 902   // Invariant: after setting Responsible=null an thread must execute
 903   // a MEMBAR or other serializing instruction before fetching EntryList|cxq.
 904   _Responsible = NULL;
 905 
 906 #if INCLUDE_JFR
 907   // get the owner's thread id for the MonitorEnter event
 908   // if it is enabled and the thread isn't suspended
 909   if (not_suspended && EventJavaMonitorEnter::is_enabled()) {
 910     _previous_owner_tid = JFR_THREAD_ID(Self);
 911   }
 912 #endif
 913 
 914   for (;;) {
 915     assert(THREAD == _owner, "invariant");
 916 
 917     // release semantics: prior loads and stores from within the critical section
 918     // must not float (reorder) past the following store that drops the lock.
 919     OrderAccess::release_store(&_owner, (void*)NULL);   // drop the lock
 920     OrderAccess::storeload();                        // See if we need to wake a successor
 921     if ((intptr_t(_EntryList)|intptr_t(_cxq)) == 0 || _succ != NULL) {
 922       return;
 923     }
 924     // Other threads are blocked trying to acquire the lock.
 925 
 926     // Normally the exiting thread is responsible for ensuring succession,
 927     // but if other successors are ready or other entering threads are spinning
 928     // then this thread can simply store NULL into _owner and exit without
 929     // waking a successor.  The existence of spinners or ready successors
 930     // guarantees proper succession (liveness).  Responsibility passes to the
 931     // ready or running successors.  The exiting thread delegates the duty.
 932     // More precisely, if a successor already exists this thread is absolved
 933     // of the responsibility of waking (unparking) one.
 934     //
 935     // The _succ variable is critical to reducing futile wakeup frequency.
 936     // _succ identifies the "heir presumptive" thread that has been made
 937     // ready (unparked) but that has not yet run.  We need only one such
 938     // successor thread to guarantee progress.
 939     // See http://www.usenix.org/events/jvm01/full_papers/dice/dice.pdf


1075 
1076 
1077 void ObjectMonitor::ExitEpilog(Thread * Self, ObjectWaiter * Wakee) {
1078   assert(_owner == Self, "invariant");
1079 
1080   // Exit protocol:
1081   // 1. ST _succ = wakee
1082   // 2. membar #loadstore|#storestore;
1083   // 2. ST _owner = NULL
1084   // 3. unpark(wakee)
1085 
1086   _succ = Wakee->_thread;
1087   ParkEvent * Trigger = Wakee->_event;
1088 
1089   // Hygiene -- once we've set _owner = NULL we can't safely dereference Wakee again.
1090   // The thread associated with Wakee may have grabbed the lock and "Wakee" may be
1091   // out-of-scope (non-extant).
1092   Wakee  = NULL;
1093 
1094   // Drop the lock
1095   OrderAccess::release_store(&_owner, (void*)NULL);
1096   OrderAccess::fence();                               // ST _owner vs LD in unpark()
1097 
1098   DTRACE_MONITOR_PROBE(contended__exit, this, object(), Self);
1099   Trigger->unpark();
1100 
1101   // Maintain stats and report events to JVMTI
1102   OM_PERFDATA_OP(Parks, inc());
1103 }
1104 
1105 
1106 // -----------------------------------------------------------------------------
1107 // Class Loader deadlock handling.
1108 //
1109 // complete_exit exits a lock returning recursion count
1110 // complete_exit/reenter operate as a wait without waiting
1111 // complete_exit requires an inflated monitor
1112 // The _owner field is not always the Thread addr even with an
1113 // inflated monitor, e.g. the monitor can be inflated by a non-owning
1114 // thread due to contention.
1115 intx ObjectMonitor::complete_exit(TRAPS) {




 899     return;
 900   }
 901 
 902   // Invariant: after setting Responsible=null an thread must execute
 903   // a MEMBAR or other serializing instruction before fetching EntryList|cxq.
 904   _Responsible = NULL;
 905 
 906 #if INCLUDE_JFR
 907   // get the owner's thread id for the MonitorEnter event
 908   // if it is enabled and the thread isn't suspended
 909   if (not_suspended && EventJavaMonitorEnter::is_enabled()) {
 910     _previous_owner_tid = JFR_THREAD_ID(Self);
 911   }
 912 #endif
 913 
 914   for (;;) {
 915     assert(THREAD == _owner, "invariant");
 916 
 917     // release semantics: prior loads and stores from within the critical section
 918     // must not float (reorder) past the following store that drops the lock.
 919     Atomic::release_store(&_owner, (void*)NULL);   // drop the lock
 920     OrderAccess::storeload();                      // See if we need to wake a successor
 921     if ((intptr_t(_EntryList)|intptr_t(_cxq)) == 0 || _succ != NULL) {
 922       return;
 923     }
 924     // Other threads are blocked trying to acquire the lock.
 925 
 926     // Normally the exiting thread is responsible for ensuring succession,
 927     // but if other successors are ready or other entering threads are spinning
 928     // then this thread can simply store NULL into _owner and exit without
 929     // waking a successor.  The existence of spinners or ready successors
 930     // guarantees proper succession (liveness).  Responsibility passes to the
 931     // ready or running successors.  The exiting thread delegates the duty.
 932     // More precisely, if a successor already exists this thread is absolved
 933     // of the responsibility of waking (unparking) one.
 934     //
 935     // The _succ variable is critical to reducing futile wakeup frequency.
 936     // _succ identifies the "heir presumptive" thread that has been made
 937     // ready (unparked) but that has not yet run.  We need only one such
 938     // successor thread to guarantee progress.
 939     // See http://www.usenix.org/events/jvm01/full_papers/dice/dice.pdf


1075 
1076 
1077 void ObjectMonitor::ExitEpilog(Thread * Self, ObjectWaiter * Wakee) {
1078   assert(_owner == Self, "invariant");
1079 
1080   // Exit protocol:
1081   // 1. ST _succ = wakee
1082   // 2. membar #loadstore|#storestore;
1083   // 2. ST _owner = NULL
1084   // 3. unpark(wakee)
1085 
1086   _succ = Wakee->_thread;
1087   ParkEvent * Trigger = Wakee->_event;
1088 
1089   // Hygiene -- once we've set _owner = NULL we can't safely dereference Wakee again.
1090   // The thread associated with Wakee may have grabbed the lock and "Wakee" may be
1091   // out-of-scope (non-extant).
1092   Wakee  = NULL;
1093 
1094   // Drop the lock
1095   Atomic::release_store(&_owner, (void*)NULL);
1096   OrderAccess::fence();                               // ST _owner vs LD in unpark()
1097 
1098   DTRACE_MONITOR_PROBE(contended__exit, this, object(), Self);
1099   Trigger->unpark();
1100 
1101   // Maintain stats and report events to JVMTI
1102   OM_PERFDATA_OP(Parks, inc());
1103 }
1104 
1105 
1106 // -----------------------------------------------------------------------------
1107 // Class Loader deadlock handling.
1108 //
1109 // complete_exit exits a lock returning recursion count
1110 // complete_exit/reenter operate as a wait without waiting
1111 // complete_exit requires an inflated monitor
1112 // The _owner field is not always the Thread addr even with an
1113 // inflated monitor, e.g. the monitor can be inflated by a non-owning
1114 // thread due to contention.
1115 intx ObjectMonitor::complete_exit(TRAPS) {


< prev index next >