• Home
  • Raw
  • Download

Lines Matching full:monitor

16 #include "runtime/monitor.h"
90 void Monitor::InflateThinLock(MTManagedThread *thread, [[maybe_unused]] const VMHandle<ObjectHeader… in InflateThinLock()
94 // and try inflating light monitor (`Inflate` expects lock to still be acquired by target; in InflateThinLock()
95 // otherwise markword CAS fails). If it fails (i.e. thread got suspended when this monitor is in InflateThinLock()
98 // or inflate monitor once this thread acquires light lock), this policy yields much better in InflateThinLock()
101 // monitor still acquired. in InflateThinLock()
115 // NB! Inflate can do nothing if monitor is already unlocked or acquired by other thread. in InflateThinLock()
121 // to heavy monitor in InflateThinLock()
139 Monitor::State Monitor::MonitorEnter(ObjectHeader *obj, bool trylock) in MonitorEnter()
156 …LOG(DEBUG, RUNTIME) << "Try to enter monitor " << std::hex << obj << " with state " << std::dec <… in MonitorEnter()
160 auto monitor = thread->GetMonitorPool()->LookupMonitor(mark.GetMonitorId()); in MonitorEnter() local
161 if (monitor == nullptr) { in MonitorEnter()
165 ret = monitor->Acquire(thread, obj_handle, trylock); in MonitorEnter()
180 … LOG(DEBUG, RUNTIME) << "The lightweight monitor was successfully recursively acquired"; in MonitorEnter()
254 … LOG(DEBUG, RUNTIME) << "The lightweight monitor was successfully acquired for the first time"; in MonitorEnter()
275 Monitor::State Monitor::MonitorExit(ObjectHeader *obj) in MonitorExit()
284 …LOG(DEBUG, RUNTIME) << "Try to exit monitor " << std::hex << obj << " with state " << std::dec <<… in MonitorExit()
287 auto monitor = thread->GetMonitorPool()->LookupMonitor(mark.GetMonitorId()); in MonitorExit() local
288 ret = monitor->Release(thread); in MonitorExit()
318 LOG(ERROR, RUNTIME) << "Try to perform monitor exit from unlocked state"; in MonitorExit()
332 Monitor::State Monitor::Wait(ObjectHeader *obj, ThreadStatus status, uint64_t timeout, uint64_t nan… in Wait()
353 auto monitor = thread->GetMonitorPool()->LookupMonitor(mark.GetMonitorId()); in Wait() local
355 if (monitor->GetOwner() != thread) { in Wait()
356 // The monitor is acquired by other thread in Wait()
358 … LOG(ERROR, RUNTIME) << "Illegal monitor state: try to wait with monitor acquired by other thread"; in Wait()
370 uint64_t counter = monitor->recursive_counter_; in Wait()
371 // Wait should be called under the monitor. We checked it in the previous if. in Wait()
373 monitor->waiters_.PushFront(*thread); in Wait()
374 thread->SetWaitingMonitor(monitor); in Wait()
377 monitor->recursive_counter_ = 1; in Wait()
378 // Atomic with relaxed order reason: memory access in monitor in Wait()
379 monitor->waiters_counter_.fetch_add(1, std::memory_order_relaxed); in Wait()
380 monitor->Release(thread); in Wait()
394 // As the monitor was already released for external users in Wait()
396 [[maybe_unused]] bool ret = monitor->Acquire(thread, obj_handle, false); in Wait()
398 // Atomic with relaxed order reason: memory access in monitor in Wait()
399 monitor->waiters_counter_.fetch_sub(1, std::memory_order_relaxed); in Wait()
400 monitor->recursive_counter_ = counter; in Wait()
408 bool found = monitor->waiters_.RemoveIf( in Wait()
413 monitor->to_wakeup_.RemoveIf( in Wait()
425 … LOG(FATAL, RUNTIME) << "Illegal monitor state: try to wait with monitor acquired by other thread"; in Wait()
443 Monitor::State Monitor::Notify(ObjectHeader *obj) in Notify()
453 auto monitor = thread->GetMonitorPool()->LookupMonitor(mark.GetMonitorId()); in Notify() local
455 if (monitor->GetOwner() != thread) { in Notify()
456 // The monitor is acquired by other thread in Notify()
458 …LOG(ERROR, RUNTIME) << "Illegal monitor state: try to notify with monitor acquired by other thread… in Notify()
462 // Notify should be called under the monitor. We checked it in the previous if. in Notify()
466 if (!monitor->waiters_.Empty()) { in Notify()
469 auto &waiter = monitor->waiters_.Front(); in Notify()
470 monitor->waiters_.PopFront(); in Notify()
471 monitor->to_wakeup_.PushFront(waiter); in Notify()
477 …LOG(ERROR, RUNTIME) << "Illegal monitor state: try to notify with monitor acquired by other thread… in Notify()
492 Monitor::State Monitor::NotifyAll(ObjectHeader *obj) in NotifyAll()
502 auto monitor = thread->GetMonitorPool()->LookupMonitor(mark.GetMonitorId()); in NotifyAll() local
504 if (monitor->GetOwner() != thread) { in NotifyAll()
505 // The monitor is acquired by other thread in NotifyAll()
507 …LOG(ERROR, RUNTIME) << "Illegal monitor state: try to notify with monitor acquired by other thread… in NotifyAll()
511 // NotifyAll should be called under the monitor. We checked it in the previous if. in NotifyAll()
513 if (monitor->to_wakeup_.Empty()) { in NotifyAll()
514 monitor->to_wakeup_.Swap(monitor->waiters_); in NotifyAll()
519 if (!monitor->waiters_.Empty()) { in NotifyAll()
520 monitor->to_wakeup_.Splice(monitor->waiters_); in NotifyAll()
521 monitor->waiters_.Clear(); in NotifyAll()
527 …LOG(ERROR, RUNTIME) << "Illegal monitor state: try to notify with monitor acquired by other thread… in NotifyAll()
542 bool Monitor::Acquire(MTManagedThread *thread, const VMHandle<ObjectHeader> &obj_handle, bool trylo… in Acquire()
550 LOG(DEBUG, RUNTIME) << "The fat monitor was successfully recursively acquired"; in Acquire()
569 // Atomic with relaxed order reason: memory access in monitor in Acquire()
575 // Save current monitor, on which the given thread is blocked. in Acquire()
581 // Do this inside scope for thread to release this monitor during runtime destroy in Acquire()
583 LOG(FATAL, RUNTIME) << "Set monitor owner failed in Acquire"; in Acquire()
590 // Atomic with relaxed order reason: memory access in monitor in Acquire()
593 // Otherwise we would see that lock was done on one monitor address, in Acquire()
597 LOG(DEBUG, RUNTIME) << "The fat monitor was successfully acquired for the first time"; in Acquire()
605 LOG(FATAL, RUNTIME) << "Set monitor owner failed in Acquire"; in Acquire()
609 LOG(DEBUG, RUNTIME) << "The fat monitor was successfully acquired for the first time"; in Acquire()
614 void Monitor::InitWithOwner(MTManagedThread *thread, ObjectHeader *obj) in Acquire()
628 LOG(FATAL, RUNTIME) << "Set monitor owner failed in InitWithOwner"; in Acquire()
631 LOG(DEBUG, RUNTIME) << "The fat monitor was successfully initialized for the first time"; in Acquire()
635 void Monitor::ReleaseOnFailedInflate(MTManagedThread *thread) in Acquire()
653 LOG(DEBUG, RUNTIME) << "The fat monitor was successfully released after failed inflation"; in Acquire()
656 bool Monitor::Release(MTManagedThread *thread) in Acquire()
666 LOG(FATAL, RUNTIME) << "Set monitor owner failed in Release"; in Acquire()
670 Monitor *waiting_mon = nullptr; in Acquire()
686 LOG(DEBUG, RUNTIME) << "The fat monitor was successfully released"; in Acquire()
691 bool Monitor::Inflate(ObjectHeader *obj, MTManagedThread *thread) in Acquire()
694 Monitor *monitor = nullptr; in Acquire() local
706 // Dont inflate if monitor got unlocked or acquired by other thread. in Acquire()
713 monitor = monitor_pool->CreateMonitor(obj); in Acquire()
714 if (monitor == nullptr) { in Acquire()
715 LOG(FATAL, RUNTIME) << "Couldn't create new monitor. Out of memory?"; in Acquire()
718 monitor->InitWithOwner(thread, obj); in Acquire()
723 monitor->ReleaseOnFailedInflate(thread); in Acquire()
724 monitor_pool->FreeMonitor(monitor->GetId()); in Acquire()
727 monitor->recursive_counter_ = old_mark.GetLockCount(); in Acquire()
730 monitor->SetHashCode(old_mark.GetHash()); in Acquire()
751 new_mark = old_mark.DecodeFromMonitor(monitor->GetId()); in Acquire()
755 monitor->recursive_counter_ = 1; in Acquire()
756 monitor->ReleaseOnFailedInflate(thread); in Acquire()
757 monitor_pool->FreeMonitor(monitor->GetId()); in Acquire()
761 thread->AddMonitor(monitor); in Acquire()
766 bool Monitor::Deflate(ObjectHeader *obj) in Acquire()
768 Monitor *monitor = nullptr; in Acquire() local
779 monitor = monitor_pool->LookupMonitor(old_mark.GetMonitorId()); in Acquire()
780 if (monitor == nullptr) { in Acquire()
781 LOG(DEBUG, RUNTIME) << "Monitor was already destroyed by someone else."; in Acquire()
785 ret = monitor->DeflateInternal(); in Acquire()
787 monitor_pool->FreeMonitor(monitor->GetId()); in Acquire()
792 bool Monitor::DeflateInternal() in Acquire()
795 LOG(DEBUG, RUNTIME) << "Trying to deflate monitor which already has owner"; in Acquire()
798 // Atomic with relaxed order reason: memory access in monitor in Acquire()
800 …LOG(DEBUG, RUNTIME) << "Trying to deflate monitor which is trying to be acquired by other threads"; in Acquire()
804 LOG(DEBUG, RUNTIME) << "Couldn't TryLock monitor for deflation"; in Acquire()
816 LOG(DEBUG, RUNTIME) << "Deflating monitor to hash"; in Acquire()
819 LOG(DEBUG, RUNTIME) << "Deflating monitor to unlocked"; in Acquire()
834 uint8_t Monitor::HoldsLock(ObjectHeader *obj) in Acquire()
842 Monitor *monitor = thread->GetMonitorPool()->LookupMonitor(mark.GetMonitorId()); in Acquire() local
844 return (monitor->GetOwner() == thread) ? 1 : 0; in Acquire()
858 uint32_t Monitor::GetLockOwnerOsThreadID(ObjectHeader *obj) in Acquire()
868Monitor *monitor = MTManagedThread::GetCurrent()->GetMonitorPool()->LookupMonitor(mark.GetMonitorI… in Acquire() local
869 MTManagedThread *owner = monitor->GetOwner(); in Acquire()
888 Monitor *Monitor::GetMonitorFromObject(ObjectHeader *obj) in Acquire()
906 inline void Monitor::TraceMonitorLock(ObjectHeader *obj, bool is_wait) in Acquire()
922 inline void Monitor::TraceMonitorUnLock() in Acquire()
929 uint32_t Monitor::GetHashCode() in Acquire()
939 // Atomic with relaxed order reason: memory access in monitor in Acquire()
943 bool Monitor::HasHashCode() const in Acquire()
945 // Atomic with relaxed order reason: memory access in monitor in Acquire()
949 void Monitor::SetHashCode(uint32_t hash) in Acquire()
953 // Atomic with relaxed order reason: memory access in monitor in Acquire()
956 LOG(FATAL, RUNTIME) << "Attempt to rewrite hash in monitor"; in Acquire()