< prev index next >

src/hotspot/share/runtime/mutex.cpp

Print this page
rev 56464 : 8231707: Improve Mutex inlining
Contributed-by: robbin.ehn@oracle.com, claes.redestad@oracle.com

*** 27,37 **** #include "runtime/interfaceSupport.inline.hpp" #include "runtime/mutex.hpp" #include "runtime/osThread.hpp" #include "runtime/safepointMechanism.inline.hpp" #include "runtime/thread.inline.hpp" ! #include "utilities/events.hpp" #include "utilities/macros.hpp" #ifdef ASSERT void Mutex::check_block_state(Thread* thread) { if (!_allow_vm_block && thread->is_VM_thread()) { --- 27,37 ---- #include "runtime/interfaceSupport.inline.hpp" #include "runtime/mutex.hpp" #include "runtime/osThread.hpp" #include "runtime/safepointMechanism.inline.hpp" #include "runtime/thread.inline.hpp" ! #include "utilities/events.inline.hpp" #include "utilities/macros.hpp" #ifdef ASSERT void Mutex::check_block_state(Thread* thread) { if (!_allow_vm_block && thread->is_VM_thread()) {
*** 68,86 **** "This lock should %s have a safepoint check for Java threads: %s", _safepoint_check_required ? "always" : "never", name()); } #endif // ASSERT ! void Mutex::lock(Thread* self) { ! check_safepoint_state(self); ! ! assert(_owner != self, "invariant"); ! Mutex* in_flight_mutex = NULL; DEBUG_ONLY(int retry_cnt = 0;) bool is_active_Java_thread = self->is_active_Java_thread(); ! while (!_lock.try_lock()) { // The lock is contended #ifdef ASSERT if (retry_cnt++ > 3) { log_trace(vmmutex)("JavaThread " INTPTR_FORMAT " on %d attempt trying to acquire vmmutex %s", p2i(self), retry_cnt, _name); --- 68,82 ---- "This lock should %s have a safepoint check for Java threads: %s", _safepoint_check_required ? "always" : "never", name()); } #endif // ASSERT ! void Mutex::lock_slow(Thread* self) { Mutex* in_flight_mutex = NULL; DEBUG_ONLY(int retry_cnt = 0;) bool is_active_Java_thread = self->is_active_Java_thread(); ! do { // The lock is contended #ifdef ASSERT if (retry_cnt++ > 3) { log_trace(vmmutex)("JavaThread " INTPTR_FORMAT " on %d attempt trying to acquire vmmutex %s", p2i(self), retry_cnt, _name);
*** 100,163 **** } } else { _lock.lock(); break; } ! } ! ! assert_owner(NULL); ! set_owner(self); ! } ! ! void Mutex::lock() { ! this->lock(Thread::current()); ! } ! ! // Lock without safepoint check - a degenerate variant of lock() for use by ! // JavaThreads when it is known to be safe to not check for a safepoint when ! // acquiring this lock. If the thread blocks acquiring the lock it is not ! // safepoint-safe and so will prevent a safepoint from being reached. If used ! // in the wrong way this can lead to a deadlock with the safepoint code. ! ! void Mutex::lock_without_safepoint_check(Thread * self) { ! check_no_safepoint_state(self); ! assert(_owner != self, "invariant"); ! _lock.lock(); ! assert_owner(NULL); ! set_owner(self); ! } ! ! void Mutex::lock_without_safepoint_check() { ! lock_without_safepoint_check(Thread::current()); ! } ! ! ! // Returns true if thread succeeds in grabbing the lock, otherwise false. - bool Mutex::try_lock() { - Thread * const self = Thread::current(); - // Some safepoint_check_always locks use try_lock, so cannot check - // safepoint state, but can check blocking state. - check_block_state(self); - if (_lock.try_lock()) { assert_owner(NULL); set_owner(self); - return true; - } - return false; - } - - void Mutex::release_for_safepoint() { - assert_owner(NULL); - _lock.unlock(); } - void Mutex::unlock() { - assert_owner(Thread::current()); - set_owner(NULL); - _lock.unlock(); - } void Monitor::notify() { assert_owner(Thread::current()); _lock.notify(); } --- 96,111 ---- } } else { _lock.lock(); break; } ! } while(!_lock.try_lock()); assert_owner(NULL); set_owner(self); } void Monitor::notify() { assert_owner(Thread::current()); _lock.notify(); }
< prev index next >