src/share/vm/runtime/synchronizer.cpp

Print this page
rev 4773 : 8005849: JEP 167: Event-Based JVM Tracing
Reviewed-by: acorn, coleenp, sla
Contributed-by: Karen Kinnear <karen.kinnear@oracle.com>, Bengt Rutisson <bengt.rutisson@oracle.com>, Calvin Cheung <calvin.cheung@oracle.com>, Erik Gahlin <erik.gahlin@oracle.com>, Erik Helin <erik.helin@oracle.com>, Jesper Wilhelmsson <jesper.wilhelmsson@oracle.com>, Keith McGuigan <keith.mcguigan@oracle.com>, Mattias Tobiasson <mattias.tobiasson@oracle.com>, Markus Gronlund <markus.gronlund@oracle.com>, Mikael Auno <mikael.auno@oracle.com>, Nils Eliasson <nils.eliasson@oracle.com>, Nils Loodin <nils.loodin@oracle.com>, Rickard Backman <rickard.backman@oracle.com>, Staffan Larsen <staffan.larsen@oracle.com>, Stefan Karlsson <stefan.karlsson@oracle.com>, Yekaterina Kantserova <yekaterina.kantserova@oracle.com>


 196      if (mark->has_monitor()) {
 197         ObjectMonitor * m = mark->monitor() ;
 198         assert(((oop)(m->object()))->mark() == mark, "invariant") ;
 199         assert(m->is_entered(THREAD), "invariant") ;
 200      }
 201      return ;
 202   }
 203 
 204   mark = object->mark() ;
 205 
 206   // If the object is stack-locked by the current thread, try to
 207   // swing the displaced header from the box back to the mark.
 208   if (mark == (markOop) lock) {
 209      assert (dhw->is_neutral(), "invariant") ;
 210      if ((markOop) Atomic::cmpxchg_ptr (dhw, object->mark_addr(), mark) == mark) {
 211         TEVENT (fast_exit: release stacklock) ;
 212         return;
 213      }
 214   }
 215 
 216   ObjectSynchronizer::inflate(THREAD, object)->exit (THREAD) ;
 217 }
 218 
 219 // -----------------------------------------------------------------------------
 220 // Interpreter/Compiler Slow Case
 221 // This routine is used to handle interpreter/compiler slow case
 222 // We don't need to use fast path here, because it must have been
 223 // failed in the interpreter/compiler code.
 224 void ObjectSynchronizer::slow_enter(Handle obj, BasicLock* lock, TRAPS) {
 225   markOop mark = obj->mark();
 226   assert(!mark->has_bias_pattern(), "should not see bias pattern here");
 227 
 228   if (mark->is_neutral()) {
 229     // Anticipate successful CAS -- the ST of the displaced mark must
 230     // be visible <= the ST performed by the CAS.
 231     lock->set_displaced_header(mark);
 232     if (mark == (markOop) Atomic::cmpxchg_ptr(lock, obj()->mark_addr(), mark)) {
 233       TEVENT (slow_enter: release stacklock) ;
 234       return ;
 235     }
 236     // Fall through to inflate() ...


 326 
 327   ObjectMonitor* monitor = ObjectSynchronizer::inflate_helper(obj());
 328   return monitor->try_enter(THREAD);
 329 }
 330 
 331 
 332 // NOTE: must use heavy weight monitor to handle jni monitor exit
 333 void ObjectSynchronizer::jni_exit(oop obj, Thread* THREAD) {
 334   TEVENT (jni_exit) ;
 335   if (UseBiasedLocking) {
 336     Handle h_obj(THREAD, obj);
 337     BiasedLocking::revoke_and_rebias(h_obj, false, THREAD);
 338     obj = h_obj();
 339   }
 340   assert(!obj->mark()->has_bias_pattern(), "biases should be revoked by now");
 341 
 342   ObjectMonitor* monitor = ObjectSynchronizer::inflate(THREAD, obj);
 343   // If this thread has locked the object, exit the monitor.  Note:  can't use
 344   // monitor->check(CHECK); must exit even if an exception is pending.
 345   if (monitor->check(THREAD)) {
 346      monitor->exit(THREAD);
 347   }
 348 }
 349 
 350 // -----------------------------------------------------------------------------
 351 // Internal VM locks on java objects
 352 // standard constructor, allows locking failures
 353 ObjectLocker::ObjectLocker(Handle obj, Thread* thread, bool doLock) {
 354   _dolock = doLock;
 355   _thread = thread;
 356   debug_only(if (StrictSafepointChecks) _thread->check_for_valid_safepoint_state(false);)
 357   _obj = obj;
 358 
 359   if (_dolock) {
 360     TEVENT (ObjectLocker) ;
 361 
 362     ObjectSynchronizer::fast_enter(_obj, &_lock, false, _thread);
 363   }
 364 }
 365 
 366 ObjectLocker::~ObjectLocker() {




 196      if (mark->has_monitor()) {
 197         ObjectMonitor * m = mark->monitor() ;
 198         assert(((oop)(m->object()))->mark() == mark, "invariant") ;
 199         assert(m->is_entered(THREAD), "invariant") ;
 200      }
 201      return ;
 202   }
 203 
 204   mark = object->mark() ;
 205 
 206   // If the object is stack-locked by the current thread, try to
 207   // swing the displaced header from the box back to the mark.
 208   if (mark == (markOop) lock) {
 209      assert (dhw->is_neutral(), "invariant") ;
 210      if ((markOop) Atomic::cmpxchg_ptr (dhw, object->mark_addr(), mark) == mark) {
 211         TEVENT (fast_exit: release stacklock) ;
 212         return;
 213      }
 214   }
 215 
 216   ObjectSynchronizer::inflate(THREAD, object)->exit (true, THREAD) ;
 217 }
 218 
 219 // -----------------------------------------------------------------------------
 220 // Interpreter/Compiler Slow Case
 221 // This routine is used to handle interpreter/compiler slow case
 222 // We don't need to use fast path here, because it must have been
 223 // failed in the interpreter/compiler code.
 224 void ObjectSynchronizer::slow_enter(Handle obj, BasicLock* lock, TRAPS) {
 225   markOop mark = obj->mark();
 226   assert(!mark->has_bias_pattern(), "should not see bias pattern here");
 227 
 228   if (mark->is_neutral()) {
 229     // Anticipate successful CAS -- the ST of the displaced mark must
 230     // be visible <= the ST performed by the CAS.
 231     lock->set_displaced_header(mark);
 232     if (mark == (markOop) Atomic::cmpxchg_ptr(lock, obj()->mark_addr(), mark)) {
 233       TEVENT (slow_enter: release stacklock) ;
 234       return ;
 235     }
 236     // Fall through to inflate() ...


 326 
 327   ObjectMonitor* monitor = ObjectSynchronizer::inflate_helper(obj());
 328   return monitor->try_enter(THREAD);
 329 }
 330 
 331 
 332 // NOTE: must use heavy weight monitor to handle jni monitor exit
 333 void ObjectSynchronizer::jni_exit(oop obj, Thread* THREAD) {
 334   TEVENT (jni_exit) ;
 335   if (UseBiasedLocking) {
 336     Handle h_obj(THREAD, obj);
 337     BiasedLocking::revoke_and_rebias(h_obj, false, THREAD);
 338     obj = h_obj();
 339   }
 340   assert(!obj->mark()->has_bias_pattern(), "biases should be revoked by now");
 341 
 342   ObjectMonitor* monitor = ObjectSynchronizer::inflate(THREAD, obj);
 343   // If this thread has locked the object, exit the monitor.  Note:  can't use
 344   // monitor->check(CHECK); must exit even if an exception is pending.
 345   if (monitor->check(THREAD)) {
 346      monitor->exit(true, THREAD);
 347   }
 348 }
 349 
 350 // -----------------------------------------------------------------------------
 351 // Internal VM locks on java objects
 352 // standard constructor, allows locking failures
 353 ObjectLocker::ObjectLocker(Handle obj, Thread* thread, bool doLock) {
 354   _dolock = doLock;
 355   _thread = thread;
 356   debug_only(if (StrictSafepointChecks) _thread->check_for_valid_safepoint_state(false);)
 357   _obj = obj;
 358 
 359   if (_dolock) {
 360     TEVENT (ObjectLocker) ;
 361 
 362     ObjectSynchronizer::fast_enter(_obj, &_lock, false, _thread);
 363   }
 364 }
 365 
 366 ObjectLocker::~ObjectLocker() {