Lines Matching full:monitor
38 #include "monitor-inl.h"
57 * Every Object has a monitor associated with it, but not every Object is actually locked. Even
58 * the ones that are locked do not need a full-fledged monitor until a) there is actual contention
79 * Only one thread can own the monitor at any time. There may be several threads waiting on it
84 uint32_t Monitor::lock_profiling_threshold_ = 0;
85 uint32_t Monitor::stack_dump_lock_profiling_threshold_ = 0;
87 void Monitor::Init(uint32_t lock_profiling_threshold, in Init()
97 Monitor::Monitor(Thread* self, Thread* owner, ObjPtr<mirror::Object> obj, int32_t hash_code) in Monitor() function in art::Monitor
98 : monitor_lock_("a monitor lock", kMonitorLock), in Monitor()
119 // The identity hash code is set for the life time of the monitor. in Monitor()
127 Monitor::Monitor(Thread* self, in Monitor() function in art::Monitor
132 : monitor_lock_("a monitor lock", kMonitorLock), in Monitor()
152 // The identity hash code is set for the life time of the monitor. in Monitor()
160 int32_t Monitor::GetHashCode() { in GetHashCode()
172 void Monitor::SetLockingMethod(Thread* owner) { in SetLockingMethod()
218 void Monitor::SetLockingMethodNoProxy(Thread *owner) { in SetLockingMethodNoProxy()
227 bool Monitor::Install(Thread* self) NO_THREAD_SAFETY_ANALYSIS { in Install()
230 // Monitor is not yet public. in Install()
264 // The owner_ is suspended but another thread beat us to install a monitor. in Install()
272 LOG(FATAL) << "Invalid monitor state " << lw.GetState(); in Install()
278 Monitor::~Monitor() { in ~Monitor()
282 void Monitor::AppendToWaitSet(Thread* thread) { in AppendToWaitSet()
284 // the monitor by the time this method is called. in AppendToWaitSet()
300 void Monitor::RemoveFromWaitSet(Thread *thread) { in RemoveFromWaitSet()
328 void Monitor::SetObject(ObjPtr<mirror::Object> object) { in SetObject()
334 void Monitor::AtraceMonitorLock(Thread* self, ObjPtr<mirror::Object> obj, bool is_wait) { in AtraceMonitorLock()
340 void Monitor::AtraceMonitorLockImpl(Thread* self, ObjPtr<mirror::Object> obj, bool is_wait) { in AtraceMonitorLockImpl()
386 // Because of thin-locks we also cannot use the monitor id (as there is no monitor). Monitor ids in AtraceMonitorLockImpl()
387 // also do not have to be stable, as the monitor may be deflated. in AtraceMonitorLockImpl()
396 void Monitor::AtraceMonitorUnlock() { in AtraceMonitorUnlock()
402 std::string Monitor::PrettyContentionInfo(const std::string& owner_name, in PrettyContentionInfo()
414 oss << "monitor contention with owner " << owner_name << " (" << owner_tid << ")"; in PrettyContentionInfo()
423 bool Monitor::TryLock(Thread* self, bool spin) { in TryLock()
447 void Monitor::Lock(Thread* self) { in Lock()
627 // We avoided touching monitor fields while suspended, so set owner_ here. in Lock()
648 template void Monitor::Lock<LockReason::kForLock>(Thread* self);
649 template void Monitor::Lock<LockReason::kForWait>(Thread* self);
660 if (!Runtime::Current()->IsStarted() || VLOG_IS_ON(monitor)) { in ThrowIllegalMonitorStateExceptionF()
679 void Monitor::FailedUnlock(ObjPtr<mirror::Object> o, in FailedUnlock()
682 Monitor* monitor) { in FailedUnlock() argument
694 Thread* current_owner = (monitor != nullptr) ? monitor->GetOwner() : nullptr; in FailedUnlock()
706 ThrowIllegalMonitorStateExceptionF("unlock of unowned monitor on object of type '%s'" in FailedUnlock()
712 ThrowIllegalMonitorStateExceptionF("unlock of monitor owned by '%s' on object of type '%s'" in FailedUnlock()
713 " (where now the monitor appears unowned) on thread '%s'", in FailedUnlock()
721 ThrowIllegalMonitorStateExceptionF("unlock of monitor owned by '%s' on object of type '%s'" in FailedUnlock()
729 ThrowIllegalMonitorStateExceptionF("unlock of monitor originally owned by '%s' (now" in FailedUnlock()
736 ThrowIllegalMonitorStateExceptionF("unlock of monitor owned by '%s' on object of type '%s'" in FailedUnlock()
746 bool Monitor::Unlock(Thread* self) { in Unlock()
750 // We own the monitor, so nobody else can be in here. in Unlock()
781 void Monitor::SignalWaiterAndReleaseMonitorLock(Thread* self) { in SignalWaiterAndReleaseMonitorLock()
782 // We want to release the monitor and signal up to one thread that was waiting in SignalWaiterAndReleaseMonitorLock()
828 void Monitor::Wait(Thread* self, int64_t ms, int32_t ns, in Wait()
870 // Update monitor state now; it's not safe once we're "suspended". in Wait()
879 // Pseudo-atomically wait on self's wait_cond_ and release the monitor lock. in Wait()
883 * Add ourselves to the set of threads waiting on this monitor. in Wait()
887 * until we've signalled contenders on this monitor. in Wait()
891 // Set wait_monitor_ to the monitor object we will be waiting on. When wait_monitor_ is in Wait()
897 // Release the monitor lock. in Wait()
926 // Allocate the interrupted exception not holding the monitor lock since it may cause a GC. in Wait()
927 // If the GC requires acquiring the monitor for enqueuing cleared references, this would in Wait()
928 // cause a deadlock if the monitor is held. in Wait()
946 // Re-acquire the monitor and lock. in Wait()
956 void Monitor::Notify(Thread* self) { in Notify()
972 void Monitor::NotifyAll(Thread* self) { in NotifyAll()
996 bool Monitor::Deflate(Thread* self, ObjPtr<mirror::Object> obj) { in Deflate()
1002 // If the lock isn't an inflated monitor, then we don't need to deflate anything. in Deflate()
1004 Monitor* monitor = lw.FatLockMonitor(); in Deflate() local
1005 DCHECK(monitor != nullptr); in Deflate()
1006 // Can't deflate if we have anybody waiting on the CV or trying to acquire the monitor. in Deflate()
1007 if (monitor->num_waiters_.load(std::memory_order_relaxed) > 0) { in Deflate()
1010 if (!monitor->monitor_lock_.ExclusiveTryLock</* check= */ false>(self)) { in Deflate()
1011 // We cannot deflate a monitor that's currently held. It's unclear whether we should if in Deflate()
1015 DCHECK_EQ(monitor->lock_count_, 0u); in Deflate()
1016 DCHECK_EQ(monitor->owner_.load(std::memory_order_relaxed), static_cast<Thread*>(nullptr)); in Deflate()
1017 if (monitor->HasHashCode()) { in Deflate()
1018 LockWord new_lw = LockWord::FromHashCode(monitor->GetHashCode(), lw.GCState()); in Deflate()
1021 VLOG(monitor) << "Deflated " << obj << " to hash monitor " << monitor->GetHashCode(); in Deflate()
1027 VLOG(monitor) << "Deflated" << obj << " to empty lock word"; in Deflate()
1029 monitor->monitor_lock_.ExclusiveUnlock(self); in Deflate()
1030 DCHECK(!(monitor->monitor_lock_.IsExclusiveHeld(self))); in Deflate()
1031 // The monitor is deflated, mark the object as null so that we know to delete it during the in Deflate()
1033 monitor->obj_ = GcRoot<mirror::Object>(nullptr); in Deflate()
1038 void Monitor::Inflate(Thread* self, Thread* owner, ObjPtr<mirror::Object> obj, int32_t hash_code) { in Inflate()
1041 // Allocate and acquire a new monitor. in Inflate()
1042 Monitor* m = MonitorPool::CreateMonitor(self, owner, obj, hash_code); in Inflate()
1046 VLOG(monitor) << "monitor: thread" << owner->GetThreadId() in Inflate()
1047 << " created monitor " << m << " for object " << obj; in Inflate()
1049 VLOG(monitor) << "monitor: Inflate with hashcode " << hash_code in Inflate()
1050 << " created monitor " << m << " for object " << obj; in Inflate()
1059 void Monitor::InflateThinLocked(Thread* self, in InflateThinLocked()
1067 // We own the monitor, we can easily inflate it. in InflateThinLocked()
1106 ObjPtr<mirror::Object> Monitor::MonitorEnter(Thread* self, in MonitorEnter()
1162 // We'd overflow the recursion count, so inflate the monitor. in MonitorEnter()
1191 // visibility of the monitor data structure. Use an explicit fence instead. in MonitorEnter()
1193 Monitor* mon = lock_word.FatLockMonitor(); in MonitorEnter()
1209 LOG(FATAL) << "Invalid monitor state " << lock_word.GetState(); in MonitorEnter()
1216 bool Monitor::MonitorExit(Thread* self, ObjPtr<mirror::Object> obj) { in MonitorExit()
1267 Monitor* mon = lock_word.FatLockMonitor(); in MonitorExit()
1271 LOG(FATAL) << "Invalid monitor state " << lock_word.GetState(); in MonitorExit()
1278 void Monitor::Wait(Thread* self, in Wait()
1310 // We own the lock, inflate to enqueue ourself on the Monitor. May fail spuriously so in Wait()
1319 LOG(FATAL) << "Invalid monitor state " << lock_word.GetState(); in Wait()
1324 Monitor* mon = lock_word.FatLockMonitor(); in Wait()
1328 void Monitor::DoNotify(Thread* self, ObjPtr<mirror::Object> obj, bool notify_all) { in DoNotify()
1345 // We own the lock but there's no Monitor and therefore no waiters. in DoNotify()
1350 Monitor* mon = lock_word.FatLockMonitor(); in DoNotify()
1359 LOG(FATAL) << "Invalid monitor state " << lock_word.GetState(); in DoNotify()
1365 uint32_t Monitor::GetLockOwnerThreadId(ObjPtr<mirror::Object> obj) { in GetLockOwnerThreadId()
1377 Monitor* mon = lock_word.FatLockMonitor(); in GetLockOwnerThreadId()
1389 ThreadState Monitor::FetchState(const Thread* thread, in FetchState()
1407 Monitor* monitor = thread->GetWaitMonitor(); in FetchState() local
1408 if (monitor != nullptr) { in FetchState()
1409 *monitor_object = monitor->GetObject(); in FetchState()
1439 ObjPtr<mirror::Object> Monitor::GetContendedMonitor(Thread* thread) { in GetContendedMonitor()
1441 // definition of contended that includes a monitor a thread is trying to enter... in GetContendedMonitor()
1444 // ...but also a monitor that the thread is waiting on. in GetContendedMonitor()
1446 Monitor* monitor = thread->GetWaitMonitor(); in GetContendedMonitor() local
1447 if (monitor != nullptr) { in GetContendedMonitor()
1448 result = monitor->GetObject(); in GetContendedMonitor()
1454 void Monitor::VisitLocks(StackVisitor* stack_visitor, in VisitLocks()
1506 // Ask the verifier for the dex pcs of all the monitor-enter instructions corresponding to in VisitLocks()
1514 // As a debug check, check that dex PC corresponds to a monitor-enter. in VisitLocks()
1518 << "expected monitor-enter @" << dex_lock_info.dex_pc << "; was " in VisitLocks()
1528 // For optimized code we expect the DexRegisterMap to be present - monitor information in VisitLocks()
1546 LOG(ERROR) << "Failed to find/read reference for monitor-enter at dex pc " in VisitLocks()
1553 LOG(ERROR) << "Held monitor information in stack trace will be incomplete!"; in VisitLocks()
1559 bool Monitor::IsValidLockWord(LockWord lock_word) { in IsValidLockWord()
1568 // Check the monitor appears in the monitor list. in IsValidLockWord()
1569 Monitor* mon = lock_word.FatLockMonitor(); in IsValidLockWord()
1572 for (Monitor* list_mon : list->list_) { in IsValidLockWord()
1574 return true; // Found our monitor. in IsValidLockWord()
1577 return false; // Fail - unowned monitor in an object. in IsValidLockWord()
1587 bool Monitor::IsLocked() REQUIRES_SHARED(Locks::mutator_lock_) { in IsLocked()
1591 void Monitor::TranslateLocation(ArtMethod* method, in TranslateLocation()
1608 uint32_t Monitor::GetOwnerThreadId() { in GetOwnerThreadId()
1653 void MonitorList::Add(Monitor* m) { in Add()
1672 Monitor* m = *it; in SweepMonitorList()
1675 // The object of a monitor can be null if we have deflated it. in SweepMonitorList()
1678 VLOG(monitor) << "freeing monitor " << m << " belonging to unmarked object " in SweepMonitorList()
1700 if (Monitor::Deflate(self_, object)) { in IsMarked()
1703 // If we deflated, return null so that the monitor gets removed from the array. in IsMarked()
1706 return object; // Monitor was not deflated. in IsMarked()
1737 Monitor* mon = lock_word.FatLockMonitor(); in MonitorInfo()
1747 DCHECK_EQ(mon->lock_count_, 0u) << "Monitor is fat-locked without any owner!"; in MonitorInfo()
1757 void Monitor::MaybeEnableTimeout() { in MaybeEnableTimeout()
1759 bool enabled_for_app = android::base::GetBoolProperty("debug.art.monitor.app", false); in MaybeEnableTimeout()