140 141 bool Mutex::try_lock() { 142 Thread * const self = Thread::current(); 143 // Some safepoint_check_always locks use try_lock, so cannot check 144 // safepoint state, but can check blocking state. 145 check_block_state(self); 146 if (_lock.try_lock()) { 147 assert_owner(NULL); 148 set_owner(self); 149 return true; 150 } 151 return false; 152 } 153 154 void Mutex::release_for_safepoint() { 155 assert_owner(NULL); 156 _lock.unlock(); 157 } 158 159 void Mutex::unlock() { 160 assert_owner(Thread::current()); 161 set_owner(NULL); 162 _lock.unlock(); 163 } 164 165 void Monitor::notify() { 166 assert_owner(Thread::current()); 167 _lock.notify(); 168 } 169 170 void Monitor::notify_all() { 171 assert_owner(Thread::current()); 172 _lock.notify_all(); 173 } 174 175 #ifdef ASSERT 176 void Monitor::assert_wait_lock_state(Thread* self) { 177 Mutex* least = get_least_ranked_lock_besides_this(self->owned_locks()); 178 assert(least != this, "Specification of get_least_... call above"); 179 if (least != NULL && least->rank() <= special) { 180 ::tty->print("Attempting to wait on monitor %s/%d while holding" 181 " lock %s/%d -- possible deadlock", 182 name(), rank(), least->name(), least->rank()); 183 assert(false, "Shouldn't block(wait) while holding a lock of rank special"); 184 } 185 } 186 #endif // ASSERT 187 188 bool Monitor::wait_without_safepoint_check(long timeout) { 189 Thread* const self = Thread::current(); 190 191 // timeout is in milliseconds - with zero meaning never timeout | 140 141 bool Mutex::try_lock() { 142 Thread * const self = Thread::current(); 143 // Some safepoint_check_always locks use try_lock, so cannot check 144 // safepoint state, but can check blocking state. 145 check_block_state(self); 146 if (_lock.try_lock()) { 147 assert_owner(NULL); 148 set_owner(self); 149 return true; 150 } 151 return false; 152 } 153 154 void Mutex::release_for_safepoint() { 155 assert_owner(NULL); 156 _lock.unlock(); 157 } 158 159 void Mutex::unlock() { 160 DEBUG_ONLY(assert_owner(Thread::current())); 161 set_owner(NULL); 162 _lock.unlock(); 163 } 164 165 void Monitor::notify() { 166 DEBUG_ONLY(assert_owner(Thread::current())); 167 _lock.notify(); 168 } 169 170 void Monitor::notify_all() { 171 DEBUG_ONLY(assert_owner(Thread::current())); 172 _lock.notify_all(); 173 } 174 175 #ifdef ASSERT 176 void Monitor::assert_wait_lock_state(Thread* self) { 177 Mutex* least = get_least_ranked_lock_besides_this(self->owned_locks()); 178 assert(least != this, "Specification of get_least_... call above"); 179 if (least != NULL && least->rank() <= special) { 180 ::tty->print("Attempting to wait on monitor %s/%d while holding" 181 " lock %s/%d -- possible deadlock", 182 name(), rank(), least->name(), least->rank()); 183 assert(false, "Shouldn't block(wait) while holding a lock of rank special"); 184 } 185 } 186 #endif // ASSERT 187 188 bool Monitor::wait_without_safepoint_check(long timeout) { 189 Thread* const self = Thread::current(); 190 191 // timeout is in milliseconds - with zero meaning never timeout |