void Mutex::lock(Thread *thread) { debug_only(check_prelock_state(thread)); // lock_implementation is a os-specific method if (lock_implementation()) { // Success, we now own the lock } else { bool is_vm_thread = thread->is_VM_thread(); bool at_safepoint = SafepointSynchronize::is_at_safepoint(); if (is_vm_thread && at_safepoint && _owner == INVALID_THREAD) { // a java thread has locked the lock but has not entered the // critical region -- let's just pretend we've locked the lock // and go on. we note this with _supress_signal so we can also // pretend to unlock when the time comes. _supress_signal = true; } else { check_block_state(thread); if (!thread->is_Java_thread()) { wait_for_lock_implementation(); } else { debug_only(assert(rank() > Mutex::special, "Potential deadlock with special or lesser rank mutex")); wait_for_lock_blocking_implementation((JavaThread*)thread); } } } assert(owner() == Mutex::INVALID_THREAD, "Mutex lock count and owner are inconsistent"); set_owner(thread); trace("locks"); }
void Mutex::lock_without_safepoint_check() { // lock_implementation is platform specific if (lock_implementation()) { // Success, we now own the lock } else { wait_for_lock_implementation(); } assert(_owner == INVALID_THREAD, "Mutex lock count and owner are inconsistent"); set_owner(Thread::current()); }
// Can be called by non-Java threads (JVM_RawMonitorEnter) void Mutex::jvm_raw_lock() { assert(rank() == native, "must be called by non-VM locks"); if (lock_implementation()) { // Success, we now own the lock } else { wait_for_lock_implementation(); } assert(_owner == INVALID_THREAD, "Mutex lock count and owner are inconsistent"); // This can potentially be called by non-java Threads. Thus, the ThreadLocalStorage // might return NULL. Don't call set_owner since it will break on an NULL // owner _owner = ThreadLocalStorage::thread(); }
inline bool Mutex::try_lock_implementation() { // Same on Solaris. return lock_implementation(); }