< prev index next >

src/share/vm/runtime/objectMonitor.cpp

Print this page




 290   }
 291 
 292   assert(_owner != Self, "invariant");
 293   assert(_succ != Self, "invariant");
 294   assert(Self->is_Java_thread(), "invariant");
 295   JavaThread * jt = (JavaThread *) Self;
 296   assert(!SafepointSynchronize::is_at_safepoint(), "invariant");
 297   assert(jt->thread_state() != _thread_blocked, "invariant");
 298   assert(this->object() != NULL, "invariant");
 299   assert(_count >= 0, "invariant");
 300 
 301   // Prevent deflation at STW-time.  See deflate_idle_monitors() and is_busy().
 302   // Ensure the object-monitor relationship remains stable while there's contention.
 303   Atomic::inc(&_count);
 304 
 305   EventJavaMonitorEnter event;
 306 
 307   { // Change java thread status to indicate blocked on monitor enter.
 308     JavaThreadBlockedOnMonitorEnterState jtbmes(jt, this);
 309 


 310     DTRACE_MONITOR_PROBE(contended__enter, this, object(), jt);
 311     if (JvmtiExport::should_post_monitor_contended_enter()) {
 312       JvmtiExport::post_monitor_contended_enter(jt, this);
 313 
 314       // The current thread does not yet own the monitor and does not
 315       // yet appear on any queues that would get it made the successor.
 316       // This means that the JVMTI_EVENT_MONITOR_CONTENDED_ENTER event
 317       // handler cannot accidentally consume an unpark() meant for the
 318       // ParkEvent associated with this ObjectMonitor.
 319     }
 320 
 321     OSThreadContendState osts(Self->osthread());
 322     ThreadBlockInVM tbivm(jt);
 323 
 324     Self->set_current_pending_monitor(this);
 325 
 326     // TODO-FIXME: change the following for(;;) loop to straight-line code.
 327     for (;;) {
 328       jt->set_suspend_equivalent();
 329       // cleared by handle_special_suspend_equivalent_condition()
 330       // or java_suspend_self()
 331 
 332       EnterI(THREAD);
 333 
 334       if (!ExitSuspendEquivalent(jt)) break;
 335 
 336       // We have acquired the contended monitor, but while we were
 337       // waiting another thread suspended us. We don't want to enter
 338       // the monitor while suspended because that would surprise the
 339       // thread that suspended us.
 340       //
 341       _recursions = 0;
 342       _succ = NULL;
 343       exit(false, Self);
 344 




 290   }
 291 
 292   assert(_owner != Self, "invariant");
 293   assert(_succ != Self, "invariant");
 294   assert(Self->is_Java_thread(), "invariant");
 295   JavaThread * jt = (JavaThread *) Self;
 296   assert(!SafepointSynchronize::is_at_safepoint(), "invariant");
 297   assert(jt->thread_state() != _thread_blocked, "invariant");
 298   assert(this->object() != NULL, "invariant");
 299   assert(_count >= 0, "invariant");
 300 
 301   // Prevent deflation at STW-time.  See deflate_idle_monitors() and is_busy().
 302   // Ensure the object-monitor relationship remains stable while there's contention.
 303   Atomic::inc(&_count);
 304 
 305   EventJavaMonitorEnter event;
 306 
 307   { // Change java thread status to indicate blocked on monitor enter.
 308     JavaThreadBlockedOnMonitorEnterState jtbmes(jt, this);
 309 
 310     Self->set_current_pending_monitor(this);
 311 
 312     DTRACE_MONITOR_PROBE(contended__enter, this, object(), jt);
 313     if (JvmtiExport::should_post_monitor_contended_enter()) {
 314       JvmtiExport::post_monitor_contended_enter(jt, this);
 315 
 316       // The current thread does not yet own the monitor and does not
 317       // yet appear on any queues that would get it made the successor.
 318       // This means that the JVMTI_EVENT_MONITOR_CONTENDED_ENTER event
 319       // handler cannot accidentally consume an unpark() meant for the
 320       // ParkEvent associated with this ObjectMonitor.
 321     }
 322 
 323     OSThreadContendState osts(Self->osthread());
 324     ThreadBlockInVM tbivm(jt);


 325 
 326     // TODO-FIXME: change the following for(;;) loop to straight-line code.
 327     for (;;) {
 328       jt->set_suspend_equivalent();
 329       // cleared by handle_special_suspend_equivalent_condition()
 330       // or java_suspend_self()
 331 
 332       EnterI(THREAD);
 333 
 334       if (!ExitSuspendEquivalent(jt)) break;
 335 
 336       // We have acquired the contended monitor, but while we were
 337       // waiting another thread suspended us. We don't want to enter
 338       // the monitor while suspended because that would surprise the
 339       // thread that suspended us.
 340       //
 341       _recursions = 0;
 342       _succ = NULL;
 343       exit(false, Self);
 344 


< prev index next >