895 // of Mutex-Monitor and instead directly address the underlying design flaw. |
895 // of Mutex-Monitor and instead directly address the underlying design flaw. |
896 |
896 |
897 void Monitor::lock(Thread * Self) { |
897 void Monitor::lock(Thread * Self) { |
898 // Ensure that the Monitor requires/allows safepoint checks. |
898 // Ensure that the Monitor requires/allows safepoint checks. |
899 assert(_safepoint_check_required != Monitor::_safepoint_check_never, |
899 assert(_safepoint_check_required != Monitor::_safepoint_check_never, |
900 err_msg("This lock should never have a safepoint check: %s", |
900 "This lock should never have a safepoint check: %s", name()); |
901 name())); |
|
902 |
901 |
903 #ifdef CHECK_UNHANDLED_OOPS |
902 #ifdef CHECK_UNHANDLED_OOPS |
904 // Clear unhandled oops so we get a crash right away. Only clear for non-vm |
903 // Clear unhandled oops so we get a crash right away. Only clear for non-vm |
905 // or GC threads. |
904 // or GC threads. |
906 if (Self->is_Java_thread()) { |
905 if (Self->is_Java_thread()) { |
958 // thread state set to be in VM, the safepoint synchronization code will deadlock! |
957 // thread state set to be in VM, the safepoint synchronization code will deadlock! |
959 |
958 |
960 void Monitor::lock_without_safepoint_check(Thread * Self) { |
959 void Monitor::lock_without_safepoint_check(Thread * Self) { |
961 // Ensure that the Monitor does not require or allow safepoint checks. |
960 // Ensure that the Monitor does not require or allow safepoint checks. |
962 assert(_safepoint_check_required != Monitor::_safepoint_check_always, |
961 assert(_safepoint_check_required != Monitor::_safepoint_check_always, |
963 err_msg("This lock should always have a safepoint check: %s", |
962 "This lock should always have a safepoint check: %s", name()); |
964 name())); |
|
965 assert(_owner != Self, "invariant"); |
963 assert(_owner != Self, "invariant"); |
966 ILock(Self); |
964 ILock(Self); |
967 assert(_owner == NULL, "invariant"); |
965 assert(_owner == NULL, "invariant"); |
968 set_owner(Self); |
966 set_owner(Self); |
969 } |
967 } |
1091 |
1089 |
1092 bool Monitor::wait(bool no_safepoint_check, long timeout, |
1090 bool Monitor::wait(bool no_safepoint_check, long timeout, |
1093 bool as_suspend_equivalent) { |
1091 bool as_suspend_equivalent) { |
1094 // Make sure safepoint checking is used properly. |
1092 // Make sure safepoint checking is used properly. |
1095 assert(!(_safepoint_check_required == Monitor::_safepoint_check_never && no_safepoint_check == false), |
1093 assert(!(_safepoint_check_required == Monitor::_safepoint_check_never && no_safepoint_check == false), |
1096 err_msg("This lock should never have a safepoint check: %s", name())); |
1094 "This lock should never have a safepoint check: %s", name()); |
1097 assert(!(_safepoint_check_required == Monitor::_safepoint_check_always && no_safepoint_check == true), |
1095 assert(!(_safepoint_check_required == Monitor::_safepoint_check_always && no_safepoint_check == true), |
1098 err_msg("This lock should always have a safepoint check: %s", name())); |
1096 "This lock should always have a safepoint check: %s", name()); |
1099 |
1097 |
1100 Thread * const Self = Thread::current(); |
1098 Thread * const Self = Thread::current(); |
1101 assert(_owner == Self, "invariant"); |
1099 assert(_owner == Self, "invariant"); |
1102 assert(ILocked(), "invariant"); |
1100 assert(ILocked(), "invariant"); |
1103 |
1101 |
1333 !SafepointSynchronize::is_at_safepoint() && |
1331 !SafepointSynchronize::is_at_safepoint() && |
1334 this != Interrupt_lock && this != ProfileVM_lock && |
1332 this != Interrupt_lock && this != ProfileVM_lock && |
1335 !(this == Safepoint_lock && contains(locks, Terminator_lock) && |
1333 !(this == Safepoint_lock && contains(locks, Terminator_lock) && |
1336 SafepointSynchronize::is_synchronizing())) { |
1334 SafepointSynchronize::is_synchronizing())) { |
1337 new_owner->print_owned_locks(); |
1335 new_owner->print_owned_locks(); |
1338 fatal(err_msg("acquiring lock %s/%d out of order with lock %s/%d -- " |
1336 fatal("acquiring lock %s/%d out of order with lock %s/%d -- " |
1339 "possible deadlock", this->name(), this->rank(), |
1337 "possible deadlock", this->name(), this->rank(), |
1340 locks->name(), locks->rank())); |
1338 locks->name(), locks->rank()); |
1341 } |
1339 } |
1342 |
1340 |
1343 this->_next = new_owner->_owned_locks; |
1341 this->_next = new_owner->_owned_locks; |
1344 new_owner->_owned_locks = this; |
1342 new_owner->_owned_locks = this; |
1345 #endif |
1343 #endif |
1384 void Monitor::check_prelock_state(Thread *thread) { |
1382 void Monitor::check_prelock_state(Thread *thread) { |
1385 assert((!thread->is_Java_thread() || ((JavaThread *)thread)->thread_state() == _thread_in_vm) |
1383 assert((!thread->is_Java_thread() || ((JavaThread *)thread)->thread_state() == _thread_in_vm) |
1386 || rank() == Mutex::special, "wrong thread state for using locks"); |
1384 || rank() == Mutex::special, "wrong thread state for using locks"); |
1387 if (StrictSafepointChecks) { |
1385 if (StrictSafepointChecks) { |
1388 if (thread->is_VM_thread() && !allow_vm_block()) { |
1386 if (thread->is_VM_thread() && !allow_vm_block()) { |
1389 fatal(err_msg("VM thread using lock %s (not allowed to block on)", |
1387 fatal("VM thread using lock %s (not allowed to block on)", name()); |
1390 name())); |
|
1391 } |
1388 } |
1392 debug_only(if (rank() != Mutex::special) \ |
1389 debug_only(if (rank() != Mutex::special) \ |
1393 thread->check_for_valid_safepoint_state(false);) |
1390 thread->check_for_valid_safepoint_state(false);) |
1394 } |
1391 } |
1395 if (thread->is_Watcher_thread()) { |
1392 if (thread->is_Watcher_thread()) { |