Lines Matching defs:thread
40 #include "thread.h"
74 * Only one thread can own the monitor at any time. There may be several threads waiting on it
92 Monitor::Monitor(Thread* self, Thread* owner, ObjPtr<mirror::Object> obj, int32_t hash_code)
115 Monitor::Monitor(Thread* self,
116 Thread* owner,
153 bool Monitor::Install(Thread* self) {
169 // The owner_ is suspended but another thread beat us to install a monitor.
193 explicit NextMethodVisitor(Thread* thread) REQUIRES_SHARED(Locks::mutator_lock_)
194 : StackVisitor(thread,
233 void Monitor::AppendToWaitSet(Thread* thread) {
234 // Not checking that the owner is equal to this thread, since we've released
236 DCHECK(thread != nullptr);
237 DCHECK(thread->GetWaitNext() == nullptr) << thread->GetWaitNext();
239 wait_set_ = thread;
244 Thread* t = wait_set_;
248 t->SetWaitNext(thread);
251 void Monitor::RemoveFromWaitSet(Thread *thread) {
252 DCHECK(owner_ == Thread::Current());
253 DCHECK(thread != nullptr);
254 auto remove = [&](Thread*& set){
256 if (set == thread) {
257 set = thread->GetWaitNext();
258 thread->SetWaitNext(nullptr);
261 Thread* t = set;
263 if (t->GetWaitNext() == thread) {
264 t->SetWaitNext(thread->GetWaitNext());
265 thread->SetWaitNext(nullptr);
285 void Monitor::AtraceMonitorLock(Thread* self, ObjPtr<mirror::Object> obj, bool is_wait) {
291 void Monitor::AtraceMonitorLockImpl(Thread* self, ObjPtr<mirror::Object> obj, bool is_wait) {
302 // Note: Adapted from CurrentMethodVisitor in thread.cc. We must not resolve here.
358 Locks::mutator_lock_->AssertSharedHeld(Thread::Current());
374 bool Monitor::TryLockLocked(Thread* self) {
394 bool Monitor::TryLock(Thread* self) {
402 ScopedAssertNotHeld(Thread* self, Mutex& mu) : self_(self), mu_(mu) {
411 Thread* const self_;
417 void Monitor::Lock(Thread* self) {
447 // Add info for contending thread.
502 // Acquire thread-list lock to find thread and keep it from dying until we've got all
505 Locks::thread_list_lock_->ExclusiveLock(Thread::Current());
507 // Re-find the owner in case the thread got killed.
508 Thread* original_owner = Runtime::Current()->GetThreadList()->FindThreadByThreadId(
519 void Run(art::Thread* thread) override
521 thread->DumpJavaStack(oss);
532 Locks::thread_list_lock_->ExclusiveUnlock(Thread::Current());
535 Locks::thread_list_lock_->ExclusiveUnlock(Thread::Current());
537 // This is all the data we need. Now drop the thread-list lock, it's OK for the
545 // This must be here (and not above) because we cannot hold the thread-list lock
566 // TODO: We should maybe check that original_owner is still a live thread.
602 template void Monitor::Lock<LockReason::kForLock>(Thread* self);
603 template void Monitor::Lock<LockReason::kForWait>(Thread* self);
612 Thread* self = Thread::Current();
623 static std::string ThreadToString(Thread* thread) {
624 if (thread == nullptr) {
628 // TODO: alternatively, we could just return the thread's name.
629 oss << *thread;
637 // Acquire thread list lock so threads won't disappear from under us.
643 MutexLock mu(Thread::Current(), *Locks::thread_list_lock_);
645 Thread* expected_owner = thread_list->FindThreadByThreadId(expected_owner_thread_id);
646 Thread* found_owner = thread_list->FindThreadByThreadId(found_owner_thread_id);
649 Thread* current_owner = (monitor != nullptr) ? monitor->GetOwner() : nullptr;
662 " on thread '%s'",
668 " (where now the monitor appears unowned) on thread '%s'",
677 " (originally believed to be unowned) on thread '%s'",
685 " owned by '%s') on object of type '%s' on thread '%s'",
692 " on thread '%s",
701 bool Monitor::Unlock(Thread* self) {
706 Thread* owner = owner_;
732 void Monitor::SignalContendersAndReleaseMonitorLock(Thread* self) {
733 // We want to signal one thread to wake up, to acquire the monitor that
734 // we are releasing. This could either be a Thread waiting on its own
735 // ConditionVariable, or a thread waiting on monitor_contenders_.
738 // return, notify can't move the current thread from wait_set_ to wake_set_ until this
740 Thread* thread = wake_set_;
741 wake_set_ = thread->GetWaitNext();
742 thread->SetWaitNext(nullptr);
744 // Check to see if the thread is still waiting.
746 // In the case of wait(), we'll be acquiring another thread's GetWaitMutex with
748 // for threads in the wake_set_. A thread can only enter wake_set_ from Notify or NotifyAll,
751 // after we've chosen our thread to wake, so there is no risk of the following lock ordering
753 // Thread 1 waits
754 // Thread 2 waits
755 // Thread 3 moves threads 1 and 2 from wait_set_ to wake_set_
756 // Thread 1 enters this block, and attempts to acquire Thread 2's GetWaitMutex to wake it
757 // Thread 2 enters this block, and attempts to acquire Thread 1's GetWaitMutex to wake it
759 // Since monitor_lock_ is not released until the thread-to-be-woken-up's GetWaitMutex is
762 MutexLock wait_mu(self, *thread->GetWaitMutex());
763 if (thread->GetWaitMonitor() != nullptr) {
764 // Release the lock, so that a potentially awakened thread will not
766 // monitor_lock_, self->GetWaitMutex, thread->GetWaitMutex
768 thread->GetWaitConditionVariable()->Signal(self);
779 void Monitor::Wait(Thread* self, int64_t ms, int32_t ns,
789 ThrowIllegalMonitorStateExceptionF("object not locked by thread before wait()");
827 // Update thread state. If the GC wakes up, it'll ignore us, knowing
847 // non-null a notifying or interrupting thread must signal the thread's wait_cond_ to wake it
855 // Handle the case where the thread was interrupted before we called wait().
871 // We reset the thread's wait_monitor_ field after transitioning back to runnable so
872 // that a thread in a waiting/sleeping state has a non-null wait_monitor_ for debugging
886 * un-interruptible thread earlier and we're bailing out immediately.
888 * The doc sayeth: "The interrupted status of the current thread is
906 * We remove our thread from wait set after restoring the count
908 * thread owns the monitor. Aside from that, the order of member
921 void Monitor::Notify(Thread* self) {
926 ThrowIllegalMonitorStateExceptionF("object not locked by thread before notify()");
929 // Move one thread from waiters to wake set
930 Thread* to_move = wait_set_;
938 void Monitor::NotifyAll(Thread* self) {
943 ThrowIllegalMonitorStateExceptionF("object not locked by thread before notifyAll()");
948 Thread* to_move = wait_set_;
951 Thread* move_to = wake_set_;
963 bool Monitor::Deflate(Thread* self, ObjPtr<mirror::Object> obj) {
976 Thread* owner = monitor->owner_;
1013 void Monitor::Inflate(Thread* self, Thread* owner, ObjPtr<mirror::Object> obj, int32_t hash_code) {
1021 VLOG(monitor) << "monitor: thread" << owner->GetThreadId()
1034 void Monitor::InflateThinLocked(Thread* self, Handle<mirror::Object> obj, LockWord lock_word,
1046 Thread* owner;
1054 // We succeeded in suspending the thread, check the lock's status didn't change.
1080 ObjPtr<mirror::Object> Monitor::MonitorEnter(Thread* self,
1116 // Only this thread pays attention to the count. Thus there is no need for stronger
1145 // TODO: Consider switching the thread state to kWaitingForLockInflation when we are
1147 // than the parameter you pass in. This can cause thread suspension to take excessively
1188 bool Monitor::MonitorExit(Thread* self, ObjPtr<mirror::Object> obj) {
1250 void Monitor::Wait(Thread* self,
1273 ThrowIllegalMonitorStateExceptionF("object not locked by thread before wait()");
1279 ThrowIllegalMonitorStateExceptionF("object not locked by thread before wait()");
1300 void Monitor::DoNotify(Thread* self, ObjPtr<mirror::Object> obj, bool notify_all) {
1308 ThrowIllegalMonitorStateExceptionF("object not locked by thread before notify()");
1314 ThrowIllegalMonitorStateExceptionF("object not locked by thread before notify()");
1358 ThreadState Monitor::FetchState(const Thread* thread,
1367 ThreadState state = thread->GetState();
1374 Thread* self = Thread::Current();
1375 MutexLock mu(self, *thread->GetWaitMutex());
1376 Monitor* monitor = thread->GetWaitMonitor();
1386 ObjPtr<mirror::Object> lock_object = thread->GetMonitorEnterObject();
1388 if (kUseReadBarrier && Thread::Current()->GetIsGcMarking()) {
1389 // We may call Thread::Dump() in the middle of the CC thread flip and this thread's stack
1408 ObjPtr<mirror::Object> Monitor::GetContendedMonitor(Thread* thread) {
1410 // definition of contended that includes a monitor a thread is trying to enter...
1411 ObjPtr<mirror::Object> result = thread->GetMonitorEnterObject();
1413 // ...but also a monitor that the thread is waiting on.
1414 MutexLock mu(Thread::Current(), *thread->GetWaitMutex());
1415 Monitor* monitor = thread->GetWaitMonitor();
1514 MutexLock mu(Thread::Current(), list->monitor_list_lock_);
1531 MutexLock mu(Thread::Current(), monitor_lock_);
1553 MutexLock mu(Thread::Current(), monitor_lock_);
1554 Thread* owner = owner_;
1568 Thread* self = Thread::Current();
1578 MutexLock mu(Thread::Current(), monitor_list_lock_);
1584 Thread* self = Thread::Current();
1591 Thread* self = Thread::Current();
1597 Thread* self = Thread::Current();
1612 Thread* self = Thread::Current();
1633 Thread* self = Thread::Current();
1640 MonitorDeflateVisitor() : self_(Thread::Current()), deflate_count_(0) {}
1653 Thread* const self_;
1691 for (Thread* waiter = mon->wait_set_; waiter != nullptr; waiter = waiter->GetWaitNext()) {