monitor.cc revision b363f666883860d40823d5528df3c98c897f74f4
1/* 2 * Copyright (C) 2008 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17#include "monitor.h" 18 19#include <vector> 20 21#include "base/mutex.h" 22#include "base/stl_util.h" 23#include "class_linker.h" 24#include "dex_file-inl.h" 25#include "dex_instruction.h" 26#include "lock_word-inl.h" 27#include "mirror/art_method-inl.h" 28#include "mirror/class-inl.h" 29#include "mirror/object-inl.h" 30#include "mirror/object_array-inl.h" 31#include "scoped_thread_state_change.h" 32#include "thread.h" 33#include "thread_list.h" 34#include "verifier/method_verifier.h" 35#include "well_known_classes.h" 36 37namespace art { 38 39/* 40 * Every Object has a monitor associated with it, but not every Object is actually locked. Even 41 * the ones that are locked do not need a full-fledged monitor until a) there is actual contention 42 * or b) wait() is called on the Object. 43 * 44 * For Android, we have implemented a scheme similar to the one described in Bacon et al.'s 45 * "Thin locks: featherweight synchronization for Java" (ACM 1998). Things are even easier for us, 46 * though, because we have a full 32 bits to work with. 47 * 48 * The two states of an Object's lock are referred to as "thin" and "fat". A lock may transition 49 * from the "thin" state to the "fat" state and this transition is referred to as inflation. Once 50 * a lock has been inflated it remains in the "fat" state indefinitely. 51 * 52 * The lock value itself is stored in mirror::Object::monitor_ and the representation is described 53 * in the LockWord value type. 54 * 55 * Monitors provide: 56 * - mutually exclusive access to resources 57 * - a way for multiple threads to wait for notification 58 * 59 * In effect, they fill the role of both mutexes and condition variables. 60 * 61 * Only one thread can own the monitor at any time. There may be several threads waiting on it 62 * (the wait call unlocks it). One or more waiting threads may be getting interrupted or notified 63 * at any given time. 64 */ 65 66bool (*Monitor::is_sensitive_thread_hook_)() = NULL; 67uint32_t Monitor::lock_profiling_threshold_ = 0; 68 69bool Monitor::IsSensitiveThread() { 70 if (is_sensitive_thread_hook_ != NULL) { 71 return (*is_sensitive_thread_hook_)(); 72 } 73 return false; 74} 75 76void Monitor::Init(uint32_t lock_profiling_threshold, bool (*is_sensitive_thread_hook)()) { 77 lock_profiling_threshold_ = lock_profiling_threshold; 78 is_sensitive_thread_hook_ = is_sensitive_thread_hook; 79} 80 81Monitor::Monitor(Thread* self, Thread* owner, mirror::Object* obj, int32_t hash_code) 82 : monitor_lock_("a monitor lock", kMonitorLock), 83 monitor_contenders_("monitor contenders", monitor_lock_), 84 num_waiters_(0), 85 owner_(owner), 86 lock_count_(0), 87 obj_(obj), 88 wait_set_(NULL), 89 hash_code_(hash_code), 90 locking_method_(NULL), 91 locking_dex_pc_(0), 92 monitor_id_(MonitorPool::ComputeMonitorId(this, self)) { 93#ifdef __LP64__ 94 DCHECK(false) << "Should not be reached in 64b"; 95 next_free_ = nullptr; 96#endif 97 // We should only inflate a lock if the owner is ourselves or suspended. This avoids a race 98 // with the owner unlocking the thin-lock. 99 CHECK(owner == nullptr || owner == self || owner->IsSuspended()); 100 // The identity hash code is set for the life time of the monitor. 101} 102 103Monitor::Monitor(Thread* self, Thread* owner, mirror::Object* obj, int32_t hash_code, 104 MonitorId id) 105 : monitor_lock_("a monitor lock", kMonitorLock), 106 monitor_contenders_("monitor contenders", monitor_lock_), 107 num_waiters_(0), 108 owner_(owner), 109 lock_count_(0), 110 obj_(obj), 111 wait_set_(NULL), 112 hash_code_(hash_code), 113 locking_method_(NULL), 114 locking_dex_pc_(0), 115 monitor_id_(id) { 116#ifdef __LP64__ 117 next_free_ = nullptr; 118#endif 119 // We should only inflate a lock if the owner is ourselves or suspended. This avoids a race 120 // with the owner unlocking the thin-lock. 121 CHECK(owner == nullptr || owner == self || owner->IsSuspended()); 122 // The identity hash code is set for the life time of the monitor. 123} 124 125int32_t Monitor::GetHashCode() { 126 while (!HasHashCode()) { 127 if (hash_code_.CompareExchangeWeakRelaxed(0, mirror::Object::GenerateIdentityHashCode())) { 128 break; 129 } 130 } 131 DCHECK(HasHashCode()); 132 return hash_code_.LoadRelaxed(); 133} 134 135bool Monitor::Install(Thread* self) { 136 MutexLock mu(self, monitor_lock_); // Uncontended mutex acquisition as monitor isn't yet public. 137 CHECK(owner_ == nullptr || owner_ == self || owner_->IsSuspended()); 138 // Propagate the lock state. 139 LockWord lw(GetObject()->GetLockWord(false)); 140 switch (lw.GetState()) { 141 case LockWord::kThinLocked: { 142 CHECK_EQ(owner_->GetThreadId(), lw.ThinLockOwner()); 143 lock_count_ = lw.ThinLockCount(); 144 break; 145 } 146 case LockWord::kHashCode: { 147 CHECK_EQ(hash_code_.LoadRelaxed(), static_cast<int32_t>(lw.GetHashCode())); 148 break; 149 } 150 case LockWord::kFatLocked: { 151 // The owner_ is suspended but another thread beat us to install a monitor. 152 return false; 153 } 154 case LockWord::kUnlocked: { 155 LOG(FATAL) << "Inflating unlocked lock word"; 156 break; 157 } 158 default: { 159 LOG(FATAL) << "Invalid monitor state " << lw.GetState(); 160 return false; 161 } 162 } 163 LockWord fat(this); 164 // Publish the updated lock word, which may race with other threads. 165 bool success = GetObject()->CasLockWordWeakSequentiallyConsistent(lw, fat); 166 // Lock profiling. 167 if (success && owner_ != nullptr && lock_profiling_threshold_ != 0) { 168 locking_method_ = owner_->GetCurrentMethod(&locking_dex_pc_); 169 } 170 return success; 171} 172 173Monitor::~Monitor() { 174 // Deflated monitors have a null object. 175} 176 177/* 178 * Links a thread into a monitor's wait set. The monitor lock must be 179 * held by the caller of this routine. 180 */ 181void Monitor::AppendToWaitSet(Thread* thread) { 182 DCHECK(owner_ == Thread::Current()); 183 DCHECK(thread != NULL); 184 DCHECK(thread->GetWaitNext() == nullptr) << thread->GetWaitNext(); 185 if (wait_set_ == NULL) { 186 wait_set_ = thread; 187 return; 188 } 189 190 // push_back. 191 Thread* t = wait_set_; 192 while (t->GetWaitNext() != nullptr) { 193 t = t->GetWaitNext(); 194 } 195 t->SetWaitNext(thread); 196} 197 198/* 199 * Unlinks a thread from a monitor's wait set. The monitor lock must 200 * be held by the caller of this routine. 201 */ 202void Monitor::RemoveFromWaitSet(Thread *thread) { 203 DCHECK(owner_ == Thread::Current()); 204 DCHECK(thread != NULL); 205 if (wait_set_ == NULL) { 206 return; 207 } 208 if (wait_set_ == thread) { 209 wait_set_ = thread->GetWaitNext(); 210 thread->SetWaitNext(nullptr); 211 return; 212 } 213 214 Thread* t = wait_set_; 215 while (t->GetWaitNext() != NULL) { 216 if (t->GetWaitNext() == thread) { 217 t->SetWaitNext(thread->GetWaitNext()); 218 thread->SetWaitNext(nullptr); 219 return; 220 } 221 t = t->GetWaitNext(); 222 } 223} 224 225void Monitor::SetObject(mirror::Object* object) { 226 obj_ = object; 227} 228 229void Monitor::Lock(Thread* self) { 230 MutexLock mu(self, monitor_lock_); 231 while (true) { 232 if (owner_ == nullptr) { // Unowned. 233 owner_ = self; 234 CHECK_EQ(lock_count_, 0); 235 // When debugging, save the current monitor holder for future 236 // acquisition failures to use in sampled logging. 237 if (lock_profiling_threshold_ != 0) { 238 locking_method_ = self->GetCurrentMethod(&locking_dex_pc_); 239 } 240 return; 241 } else if (owner_ == self) { // Recursive. 242 lock_count_++; 243 return; 244 } 245 // Contended. 246 const bool log_contention = (lock_profiling_threshold_ != 0); 247 uint64_t wait_start_ms = log_contention ? 0 : MilliTime(); 248 mirror::ArtMethod* owners_method = locking_method_; 249 uint32_t owners_dex_pc = locking_dex_pc_; 250 // Do this before releasing the lock so that we don't get deflated. 251 ++num_waiters_; 252 monitor_lock_.Unlock(self); // Let go of locks in order. 253 self->SetMonitorEnterObject(GetObject()); 254 { 255 ScopedThreadStateChange tsc(self, kBlocked); // Change to blocked and give up mutator_lock_. 256 MutexLock mu2(self, monitor_lock_); // Reacquire monitor_lock_ without mutator_lock_ for Wait. 257 if (owner_ != NULL) { // Did the owner_ give the lock up? 258 monitor_contenders_.Wait(self); // Still contended so wait. 259 // Woken from contention. 260 if (log_contention) { 261 uint64_t wait_ms = MilliTime() - wait_start_ms; 262 uint32_t sample_percent; 263 if (wait_ms >= lock_profiling_threshold_) { 264 sample_percent = 100; 265 } else { 266 sample_percent = 100 * wait_ms / lock_profiling_threshold_; 267 } 268 if (sample_percent != 0 && (static_cast<uint32_t>(rand() % 100) < sample_percent)) { 269 const char* owners_filename; 270 uint32_t owners_line_number; 271 TranslateLocation(owners_method, owners_dex_pc, &owners_filename, &owners_line_number); 272 LogContentionEvent(self, wait_ms, sample_percent, owners_filename, owners_line_number); 273 } 274 } 275 } 276 } 277 self->SetMonitorEnterObject(nullptr); 278 monitor_lock_.Lock(self); // Reacquire locks in order. 279 --num_waiters_; 280 } 281} 282 283static void ThrowIllegalMonitorStateExceptionF(const char* fmt, ...) 284 __attribute__((format(printf, 1, 2))); 285 286static void ThrowIllegalMonitorStateExceptionF(const char* fmt, ...) 287 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { 288 va_list args; 289 va_start(args, fmt); 290 Thread* self = Thread::Current(); 291 ThrowLocation throw_location = self->GetCurrentLocationForThrow(); 292 self->ThrowNewExceptionV(throw_location, "Ljava/lang/IllegalMonitorStateException;", fmt, args); 293 if (!Runtime::Current()->IsStarted() || VLOG_IS_ON(monitor)) { 294 std::ostringstream ss; 295 self->Dump(ss); 296 LOG(Runtime::Current()->IsStarted() ? INFO : ERROR) 297 << self->GetException(NULL)->Dump() << "\n" << ss.str(); 298 } 299 va_end(args); 300} 301 302static std::string ThreadToString(Thread* thread) { 303 if (thread == NULL) { 304 return "NULL"; 305 } 306 std::ostringstream oss; 307 // TODO: alternatively, we could just return the thread's name. 308 oss << *thread; 309 return oss.str(); 310} 311 312void Monitor::FailedUnlock(mirror::Object* o, Thread* expected_owner, Thread* found_owner, 313 Monitor* monitor) { 314 Thread* current_owner = NULL; 315 std::string current_owner_string; 316 std::string expected_owner_string; 317 std::string found_owner_string; 318 { 319 // TODO: isn't this too late to prevent threads from disappearing? 320 // Acquire thread list lock so threads won't disappear from under us. 321 MutexLock mu(Thread::Current(), *Locks::thread_list_lock_); 322 // Re-read owner now that we hold lock. 323 current_owner = (monitor != NULL) ? monitor->GetOwner() : NULL; 324 // Get short descriptions of the threads involved. 325 current_owner_string = ThreadToString(current_owner); 326 expected_owner_string = ThreadToString(expected_owner); 327 found_owner_string = ThreadToString(found_owner); 328 } 329 if (current_owner == NULL) { 330 if (found_owner == NULL) { 331 ThrowIllegalMonitorStateExceptionF("unlock of unowned monitor on object of type '%s'" 332 " on thread '%s'", 333 PrettyTypeOf(o).c_str(), 334 expected_owner_string.c_str()); 335 } else { 336 // Race: the original read found an owner but now there is none 337 ThrowIllegalMonitorStateExceptionF("unlock of monitor owned by '%s' on object of type '%s'" 338 " (where now the monitor appears unowned) on thread '%s'", 339 found_owner_string.c_str(), 340 PrettyTypeOf(o).c_str(), 341 expected_owner_string.c_str()); 342 } 343 } else { 344 if (found_owner == NULL) { 345 // Race: originally there was no owner, there is now 346 ThrowIllegalMonitorStateExceptionF("unlock of monitor owned by '%s' on object of type '%s'" 347 " (originally believed to be unowned) on thread '%s'", 348 current_owner_string.c_str(), 349 PrettyTypeOf(o).c_str(), 350 expected_owner_string.c_str()); 351 } else { 352 if (found_owner != current_owner) { 353 // Race: originally found and current owner have changed 354 ThrowIllegalMonitorStateExceptionF("unlock of monitor originally owned by '%s' (now" 355 " owned by '%s') on object of type '%s' on thread '%s'", 356 found_owner_string.c_str(), 357 current_owner_string.c_str(), 358 PrettyTypeOf(o).c_str(), 359 expected_owner_string.c_str()); 360 } else { 361 ThrowIllegalMonitorStateExceptionF("unlock of monitor owned by '%s' on object of type '%s'" 362 " on thread '%s", 363 current_owner_string.c_str(), 364 PrettyTypeOf(o).c_str(), 365 expected_owner_string.c_str()); 366 } 367 } 368 } 369} 370 371bool Monitor::Unlock(Thread* self) { 372 DCHECK(self != NULL); 373 MutexLock mu(self, monitor_lock_); 374 Thread* owner = owner_; 375 if (owner == self) { 376 // We own the monitor, so nobody else can be in here. 377 if (lock_count_ == 0) { 378 owner_ = NULL; 379 locking_method_ = NULL; 380 locking_dex_pc_ = 0; 381 // Wake a contender. 382 monitor_contenders_.Signal(self); 383 } else { 384 --lock_count_; 385 } 386 } else { 387 // We don't own this, so we're not allowed to unlock it. 388 // The JNI spec says that we should throw IllegalMonitorStateException 389 // in this case. 390 FailedUnlock(GetObject(), self, owner, this); 391 return false; 392 } 393 return true; 394} 395 396/* 397 * Wait on a monitor until timeout, interrupt, or notification. Used for 398 * Object.wait() and (somewhat indirectly) Thread.sleep() and Thread.join(). 399 * 400 * If another thread calls Thread.interrupt(), we throw InterruptedException 401 * and return immediately if one of the following are true: 402 * - blocked in wait(), wait(long), or wait(long, int) methods of Object 403 * - blocked in join(), join(long), or join(long, int) methods of Thread 404 * - blocked in sleep(long), or sleep(long, int) methods of Thread 405 * Otherwise, we set the "interrupted" flag. 406 * 407 * Checks to make sure that "ns" is in the range 0-999999 408 * (i.e. fractions of a millisecond) and throws the appropriate 409 * exception if it isn't. 410 * 411 * The spec allows "spurious wakeups", and recommends that all code using 412 * Object.wait() do so in a loop. This appears to derive from concerns 413 * about pthread_cond_wait() on multiprocessor systems. Some commentary 414 * on the web casts doubt on whether these can/should occur. 415 * 416 * Since we're allowed to wake up "early", we clamp extremely long durations 417 * to return at the end of the 32-bit time epoch. 418 */ 419void Monitor::Wait(Thread* self, int64_t ms, int32_t ns, 420 bool interruptShouldThrow, ThreadState why) { 421 DCHECK(self != NULL); 422 DCHECK(why == kTimedWaiting || why == kWaiting || why == kSleeping); 423 424 monitor_lock_.Lock(self); 425 426 // Make sure that we hold the lock. 427 if (owner_ != self) { 428 monitor_lock_.Unlock(self); 429 ThrowIllegalMonitorStateExceptionF("object not locked by thread before wait()"); 430 return; 431 } 432 433 // We need to turn a zero-length timed wait into a regular wait because 434 // Object.wait(0, 0) is defined as Object.wait(0), which is defined as Object.wait(). 435 if (why == kTimedWaiting && (ms == 0 && ns == 0)) { 436 why = kWaiting; 437 } 438 439 // Enforce the timeout range. 440 if (ms < 0 || ns < 0 || ns > 999999) { 441 monitor_lock_.Unlock(self); 442 ThrowLocation throw_location = self->GetCurrentLocationForThrow(); 443 self->ThrowNewExceptionF(throw_location, "Ljava/lang/IllegalArgumentException;", 444 "timeout arguments out of range: ms=%" PRId64 " ns=%d", ms, ns); 445 return; 446 } 447 448 /* 449 * Add ourselves to the set of threads waiting on this monitor, and 450 * release our hold. We need to let it go even if we're a few levels 451 * deep in a recursive lock, and we need to restore that later. 452 * 453 * We append to the wait set ahead of clearing the count and owner 454 * fields so the subroutine can check that the calling thread owns 455 * the monitor. Aside from that, the order of member updates is 456 * not order sensitive as we hold the pthread mutex. 457 */ 458 AppendToWaitSet(self); 459 ++num_waiters_; 460 int prev_lock_count = lock_count_; 461 lock_count_ = 0; 462 owner_ = NULL; 463 mirror::ArtMethod* saved_method = locking_method_; 464 locking_method_ = NULL; 465 uintptr_t saved_dex_pc = locking_dex_pc_; 466 locking_dex_pc_ = 0; 467 468 /* 469 * Update thread state. If the GC wakes up, it'll ignore us, knowing 470 * that we won't touch any references in this state, and we'll check 471 * our suspend mode before we transition out. 472 */ 473 self->TransitionFromRunnableToSuspended(why); 474 475 bool was_interrupted = false; 476 { 477 // Pseudo-atomically wait on self's wait_cond_ and release the monitor lock. 478 MutexLock mu(self, *self->GetWaitMutex()); 479 480 // Set wait_monitor_ to the monitor object we will be waiting on. When wait_monitor_ is 481 // non-NULL a notifying or interrupting thread must signal the thread's wait_cond_ to wake it 482 // up. 483 DCHECK(self->GetWaitMonitor() == nullptr); 484 self->SetWaitMonitor(this); 485 486 // Release the monitor lock. 487 monitor_contenders_.Signal(self); 488 monitor_lock_.Unlock(self); 489 490 // Handle the case where the thread was interrupted before we called wait(). 491 if (self->IsInterruptedLocked()) { 492 was_interrupted = true; 493 } else { 494 // Wait for a notification or a timeout to occur. 495 if (why == kWaiting) { 496 self->GetWaitConditionVariable()->Wait(self); 497 } else { 498 DCHECK(why == kTimedWaiting || why == kSleeping) << why; 499 self->GetWaitConditionVariable()->TimedWait(self, ms, ns); 500 } 501 if (self->IsInterruptedLocked()) { 502 was_interrupted = true; 503 } 504 self->SetInterruptedLocked(false); 505 } 506 } 507 508 // Set self->status back to kRunnable, and self-suspend if needed. 509 self->TransitionFromSuspendedToRunnable(); 510 511 { 512 // We reset the thread's wait_monitor_ field after transitioning back to runnable so 513 // that a thread in a waiting/sleeping state has a non-null wait_monitor_ for debugging 514 // and diagnostic purposes. (If you reset this earlier, stack dumps will claim that threads 515 // are waiting on "null".) 516 MutexLock mu(self, *self->GetWaitMutex()); 517 DCHECK(self->GetWaitMonitor() != nullptr); 518 self->SetWaitMonitor(nullptr); 519 } 520 521 // Re-acquire the monitor and lock. 522 Lock(self); 523 monitor_lock_.Lock(self); 524 self->GetWaitMutex()->AssertNotHeld(self); 525 526 /* 527 * We remove our thread from wait set after restoring the count 528 * and owner fields so the subroutine can check that the calling 529 * thread owns the monitor. Aside from that, the order of member 530 * updates is not order sensitive as we hold the pthread mutex. 531 */ 532 owner_ = self; 533 lock_count_ = prev_lock_count; 534 locking_method_ = saved_method; 535 locking_dex_pc_ = saved_dex_pc; 536 --num_waiters_; 537 RemoveFromWaitSet(self); 538 539 monitor_lock_.Unlock(self); 540 541 if (was_interrupted) { 542 /* 543 * We were interrupted while waiting, or somebody interrupted an 544 * un-interruptible thread earlier and we're bailing out immediately. 545 * 546 * The doc sayeth: "The interrupted status of the current thread is 547 * cleared when this exception is thrown." 548 */ 549 { 550 MutexLock mu(self, *self->GetWaitMutex()); 551 self->SetInterruptedLocked(false); 552 } 553 if (interruptShouldThrow) { 554 ThrowLocation throw_location = self->GetCurrentLocationForThrow(); 555 self->ThrowNewException(throw_location, "Ljava/lang/InterruptedException;", NULL); 556 } 557 } 558} 559 560void Monitor::Notify(Thread* self) { 561 DCHECK(self != NULL); 562 MutexLock mu(self, monitor_lock_); 563 // Make sure that we hold the lock. 564 if (owner_ != self) { 565 ThrowIllegalMonitorStateExceptionF("object not locked by thread before notify()"); 566 return; 567 } 568 // Signal the first waiting thread in the wait set. 569 while (wait_set_ != NULL) { 570 Thread* thread = wait_set_; 571 wait_set_ = thread->GetWaitNext(); 572 thread->SetWaitNext(nullptr); 573 574 // Check to see if the thread is still waiting. 575 MutexLock mu(self, *thread->GetWaitMutex()); 576 if (thread->GetWaitMonitor() != nullptr) { 577 thread->GetWaitConditionVariable()->Signal(self); 578 return; 579 } 580 } 581} 582 583void Monitor::NotifyAll(Thread* self) { 584 DCHECK(self != NULL); 585 MutexLock mu(self, monitor_lock_); 586 // Make sure that we hold the lock. 587 if (owner_ != self) { 588 ThrowIllegalMonitorStateExceptionF("object not locked by thread before notifyAll()"); 589 return; 590 } 591 // Signal all threads in the wait set. 592 while (wait_set_ != NULL) { 593 Thread* thread = wait_set_; 594 wait_set_ = thread->GetWaitNext(); 595 thread->SetWaitNext(nullptr); 596 thread->Notify(); 597 } 598} 599 600bool Monitor::Deflate(Thread* self, mirror::Object* obj) { 601 DCHECK(obj != nullptr); 602 // Don't need volatile since we only deflate with mutators suspended. 603 LockWord lw(obj->GetLockWord(false)); 604 // If the lock isn't an inflated monitor, then we don't need to deflate anything. 605 if (lw.GetState() == LockWord::kFatLocked) { 606 Monitor* monitor = lw.FatLockMonitor(); 607 DCHECK(monitor != nullptr); 608 MutexLock mu(self, monitor->monitor_lock_); 609 // Can't deflate if we have anybody waiting on the CV. 610 if (monitor->num_waiters_ > 0) { 611 return false; 612 } 613 Thread* owner = monitor->owner_; 614 if (owner != nullptr) { 615 // Can't deflate if we are locked and have a hash code. 616 if (monitor->HasHashCode()) { 617 return false; 618 } 619 // Can't deflate if our lock count is too high. 620 if (monitor->lock_count_ > LockWord::kThinLockMaxCount) { 621 return false; 622 } 623 // Deflate to a thin lock. 624 obj->SetLockWord(LockWord::FromThinLockId(owner->GetThreadId(), monitor->lock_count_), false); 625 VLOG(monitor) << "Deflated " << obj << " to thin lock " << owner->GetTid() << " / " 626 << monitor->lock_count_; 627 } else if (monitor->HasHashCode()) { 628 obj->SetLockWord(LockWord::FromHashCode(monitor->GetHashCode()), false); 629 VLOG(monitor) << "Deflated " << obj << " to hash monitor " << monitor->GetHashCode(); 630 } else { 631 // No lock and no hash, just put an empty lock word inside the object. 632 obj->SetLockWord(LockWord(), false); 633 VLOG(monitor) << "Deflated" << obj << " to empty lock word"; 634 } 635 // The monitor is deflated, mark the object as nullptr so that we know to delete it during the 636 // next GC. 637 monitor->obj_ = nullptr; 638 } 639 return true; 640} 641 642/* 643 * Changes the shape of a monitor from thin to fat, preserving the internal lock state. The calling 644 * thread must own the lock or the owner must be suspended. There's a race with other threads 645 * inflating the lock and so the caller should read the monitor following the call. 646 */ 647void Monitor::Inflate(Thread* self, Thread* owner, mirror::Object* obj, int32_t hash_code) { 648 DCHECK(self != nullptr); 649 DCHECK(obj != nullptr); 650 // Allocate and acquire a new monitor. 651 Monitor* m = MonitorPool::CreateMonitor(self, owner, obj, hash_code); 652 DCHECK(m != nullptr); 653 if (m->Install(self)) { 654 if (owner != nullptr) { 655 VLOG(monitor) << "monitor: thread" << owner->GetThreadId() 656 << " created monitor " << m << " for object " << obj; 657 } else { 658 VLOG(monitor) << "monitor: Inflate with hashcode " << hash_code 659 << " created monitor " << m << " for object " << obj; 660 } 661 Runtime::Current()->GetMonitorList()->Add(m); 662 CHECK_EQ(obj->GetLockWord(true).GetState(), LockWord::kFatLocked); 663 } else { 664 MonitorPool::ReleaseMonitor(self, m); 665 } 666} 667 668void Monitor::InflateThinLocked(Thread* self, Handle<mirror::Object> obj, LockWord lock_word, 669 uint32_t hash_code) { 670 DCHECK_EQ(lock_word.GetState(), LockWord::kThinLocked); 671 uint32_t owner_thread_id = lock_word.ThinLockOwner(); 672 if (owner_thread_id == self->GetThreadId()) { 673 // We own the monitor, we can easily inflate it. 674 Inflate(self, self, obj.Get(), hash_code); 675 } else { 676 ThreadList* thread_list = Runtime::Current()->GetThreadList(); 677 // Suspend the owner, inflate. First change to blocked and give up mutator_lock_. 678 self->SetMonitorEnterObject(obj.Get()); 679 bool timed_out; 680 Thread* owner; 681 { 682 ScopedThreadStateChange tsc(self, kBlocked); 683 // Take suspend thread lock to avoid races with threads trying to suspend this one. 684 MutexLock mu(self, *Locks::thread_list_suspend_thread_lock_); 685 owner = thread_list->SuspendThreadByThreadId(owner_thread_id, false, &timed_out); 686 } 687 if (owner != nullptr) { 688 // We succeeded in suspending the thread, check the lock's status didn't change. 689 lock_word = obj->GetLockWord(true); 690 if (lock_word.GetState() == LockWord::kThinLocked && 691 lock_word.ThinLockOwner() == owner_thread_id) { 692 // Go ahead and inflate the lock. 693 Inflate(self, owner, obj.Get(), hash_code); 694 } 695 thread_list->Resume(owner, false); 696 } 697 self->SetMonitorEnterObject(nullptr); 698 } 699} 700 701// Fool annotalysis into thinking that the lock on obj is acquired. 702static mirror::Object* FakeLock(mirror::Object* obj) 703 EXCLUSIVE_LOCK_FUNCTION(obj) NO_THREAD_SAFETY_ANALYSIS { 704 return obj; 705} 706 707// Fool annotalysis into thinking that the lock on obj is release. 708static mirror::Object* FakeUnlock(mirror::Object* obj) 709 UNLOCK_FUNCTION(obj) NO_THREAD_SAFETY_ANALYSIS { 710 return obj; 711} 712 713mirror::Object* Monitor::MonitorEnter(Thread* self, mirror::Object* obj) { 714 DCHECK(self != NULL); 715 DCHECK(obj != NULL); 716 obj = FakeLock(obj); 717 uint32_t thread_id = self->GetThreadId(); 718 size_t contention_count = 0; 719 StackHandleScope<1> hs(self); 720 Handle<mirror::Object> h_obj(hs.NewHandle(obj)); 721 while (true) { 722 LockWord lock_word = h_obj->GetLockWord(true); 723 switch (lock_word.GetState()) { 724 case LockWord::kUnlocked: { 725 LockWord thin_locked(LockWord::FromThinLockId(thread_id, 0)); 726 if (h_obj->CasLockWordWeakSequentiallyConsistent(lock_word, thin_locked)) { 727 // CasLockWord enforces more than the acquire ordering we need here. 728 return h_obj.Get(); // Success! 729 } 730 continue; // Go again. 731 } 732 case LockWord::kThinLocked: { 733 uint32_t owner_thread_id = lock_word.ThinLockOwner(); 734 if (owner_thread_id == thread_id) { 735 // We own the lock, increase the recursion count. 736 uint32_t new_count = lock_word.ThinLockCount() + 1; 737 if (LIKELY(new_count <= LockWord::kThinLockMaxCount)) { 738 LockWord thin_locked(LockWord::FromThinLockId(thread_id, new_count)); 739 h_obj->SetLockWord(thin_locked, true); 740 return h_obj.Get(); // Success! 741 } else { 742 // We'd overflow the recursion count, so inflate the monitor. 743 InflateThinLocked(self, h_obj, lock_word, 0); 744 } 745 } else { 746 // Contention. 747 contention_count++; 748 Runtime* runtime = Runtime::Current(); 749 if (contention_count <= runtime->GetMaxSpinsBeforeThinkLockInflation()) { 750 // TODO: Consider switching the thread state to kBlocked when we are yielding. 751 // Use sched_yield instead of NanoSleep since NanoSleep can wait much longer than the 752 // parameter you pass in. This can cause thread suspension to take excessively long 753 // and make long pauses. See b/16307460. 754 sched_yield(); 755 } else { 756 contention_count = 0; 757 InflateThinLocked(self, h_obj, lock_word, 0); 758 } 759 } 760 continue; // Start from the beginning. 761 } 762 case LockWord::kFatLocked: { 763 Monitor* mon = lock_word.FatLockMonitor(); 764 mon->Lock(self); 765 return h_obj.Get(); // Success! 766 } 767 case LockWord::kHashCode: 768 // Inflate with the existing hashcode. 769 Inflate(self, nullptr, h_obj.Get(), lock_word.GetHashCode()); 770 continue; // Start from the beginning. 771 default: { 772 LOG(FATAL) << "Invalid monitor state " << lock_word.GetState(); 773 return h_obj.Get(); 774 } 775 } 776 } 777} 778 779bool Monitor::MonitorExit(Thread* self, mirror::Object* obj) { 780 DCHECK(self != NULL); 781 DCHECK(obj != NULL); 782 obj = FakeUnlock(obj); 783 LockWord lock_word = obj->GetLockWord(true); 784 StackHandleScope<1> hs(self); 785 Handle<mirror::Object> h_obj(hs.NewHandle(obj)); 786 switch (lock_word.GetState()) { 787 case LockWord::kHashCode: 788 // Fall-through. 789 case LockWord::kUnlocked: 790 FailedUnlock(h_obj.Get(), self, nullptr, nullptr); 791 return false; // Failure. 792 case LockWord::kThinLocked: { 793 uint32_t thread_id = self->GetThreadId(); 794 uint32_t owner_thread_id = lock_word.ThinLockOwner(); 795 if (owner_thread_id != thread_id) { 796 // TODO: there's a race here with the owner dying while we unlock. 797 Thread* owner = 798 Runtime::Current()->GetThreadList()->FindThreadByThreadId(lock_word.ThinLockOwner()); 799 FailedUnlock(h_obj.Get(), self, owner, nullptr); 800 return false; // Failure. 801 } else { 802 // We own the lock, decrease the recursion count. 803 if (lock_word.ThinLockCount() != 0) { 804 uint32_t new_count = lock_word.ThinLockCount() - 1; 805 LockWord thin_locked(LockWord::FromThinLockId(thread_id, new_count)); 806 h_obj->SetLockWord(thin_locked, true); 807 } else { 808 h_obj->SetLockWord(LockWord(), true); 809 } 810 return true; // Success! 811 } 812 } 813 case LockWord::kFatLocked: { 814 Monitor* mon = lock_word.FatLockMonitor(); 815 return mon->Unlock(self); 816 } 817 default: { 818 LOG(FATAL) << "Invalid monitor state " << lock_word.GetState(); 819 return false; 820 } 821 } 822} 823 824/* 825 * Object.wait(). Also called for class init. 826 */ 827void Monitor::Wait(Thread* self, mirror::Object *obj, int64_t ms, int32_t ns, 828 bool interruptShouldThrow, ThreadState why) { 829 DCHECK(self != nullptr); 830 DCHECK(obj != nullptr); 831 LockWord lock_word = obj->GetLockWord(true); 832 switch (lock_word.GetState()) { 833 case LockWord::kHashCode: 834 // Fall-through. 835 case LockWord::kUnlocked: 836 ThrowIllegalMonitorStateExceptionF("object not locked by thread before wait()"); 837 return; // Failure. 838 case LockWord::kThinLocked: { 839 uint32_t thread_id = self->GetThreadId(); 840 uint32_t owner_thread_id = lock_word.ThinLockOwner(); 841 if (owner_thread_id != thread_id) { 842 ThrowIllegalMonitorStateExceptionF("object not locked by thread before wait()"); 843 return; // Failure. 844 } else { 845 // We own the lock, inflate to enqueue ourself on the Monitor. 846 Inflate(self, self, obj, 0); 847 lock_word = obj->GetLockWord(true); 848 } 849 break; 850 } 851 case LockWord::kFatLocked: 852 break; // Already set for a wait. 853 default: { 854 LOG(FATAL) << "Invalid monitor state " << lock_word.GetState(); 855 return; 856 } 857 } 858 Monitor* mon = lock_word.FatLockMonitor(); 859 mon->Wait(self, ms, ns, interruptShouldThrow, why); 860} 861 862void Monitor::DoNotify(Thread* self, mirror::Object* obj, bool notify_all) { 863 DCHECK(self != nullptr); 864 DCHECK(obj != nullptr); 865 LockWord lock_word = obj->GetLockWord(true); 866 switch (lock_word.GetState()) { 867 case LockWord::kHashCode: 868 // Fall-through. 869 case LockWord::kUnlocked: 870 ThrowIllegalMonitorStateExceptionF("object not locked by thread before notify()"); 871 return; // Failure. 872 case LockWord::kThinLocked: { 873 uint32_t thread_id = self->GetThreadId(); 874 uint32_t owner_thread_id = lock_word.ThinLockOwner(); 875 if (owner_thread_id != thread_id) { 876 ThrowIllegalMonitorStateExceptionF("object not locked by thread before notify()"); 877 return; // Failure. 878 } else { 879 // We own the lock but there's no Monitor and therefore no waiters. 880 return; // Success. 881 } 882 } 883 case LockWord::kFatLocked: { 884 Monitor* mon = lock_word.FatLockMonitor(); 885 if (notify_all) { 886 mon->NotifyAll(self); 887 } else { 888 mon->Notify(self); 889 } 890 return; // Success. 891 } 892 default: { 893 LOG(FATAL) << "Invalid monitor state " << lock_word.GetState(); 894 return; 895 } 896 } 897} 898 899uint32_t Monitor::GetLockOwnerThreadId(mirror::Object* obj) { 900 DCHECK(obj != nullptr); 901 LockWord lock_word = obj->GetLockWord(true); 902 switch (lock_word.GetState()) { 903 case LockWord::kHashCode: 904 // Fall-through. 905 case LockWord::kUnlocked: 906 return ThreadList::kInvalidThreadId; 907 case LockWord::kThinLocked: 908 return lock_word.ThinLockOwner(); 909 case LockWord::kFatLocked: { 910 Monitor* mon = lock_word.FatLockMonitor(); 911 return mon->GetOwnerThreadId(); 912 } 913 default: { 914 LOG(FATAL) << "Unreachable"; 915 return ThreadList::kInvalidThreadId; 916 } 917 } 918} 919 920void Monitor::DescribeWait(std::ostream& os, const Thread* thread) { 921 // Determine the wait message and object we're waiting or blocked upon. 922 mirror::Object* pretty_object = nullptr; 923 const char* wait_message = nullptr; 924 uint32_t lock_owner = ThreadList::kInvalidThreadId; 925 ThreadState state = thread->GetState(); 926 if (state == kWaiting || state == kTimedWaiting || state == kSleeping) { 927 wait_message = (state == kSleeping) ? " - sleeping on " : " - waiting on "; 928 Thread* self = Thread::Current(); 929 MutexLock mu(self, *thread->GetWaitMutex()); 930 Monitor* monitor = thread->GetWaitMonitor(); 931 if (monitor != nullptr) { 932 pretty_object = monitor->GetObject(); 933 } 934 } else if (state == kBlocked) { 935 wait_message = " - waiting to lock "; 936 pretty_object = thread->GetMonitorEnterObject(); 937 if (pretty_object != nullptr) { 938 lock_owner = pretty_object->GetLockOwnerThreadId(); 939 } 940 } 941 942 if (wait_message != nullptr) { 943 if (pretty_object == nullptr) { 944 os << wait_message << "an unknown object"; 945 } else { 946 if ((pretty_object->GetLockWord(true).GetState() == LockWord::kThinLocked) && 947 Locks::mutator_lock_->IsExclusiveHeld(Thread::Current())) { 948 // Getting the identity hashcode here would result in lock inflation and suspension of the 949 // current thread, which isn't safe if this is the only runnable thread. 950 os << wait_message << StringPrintf("<@addr=0x%" PRIxPTR "> (a %s)", 951 reinterpret_cast<intptr_t>(pretty_object), 952 PrettyTypeOf(pretty_object).c_str()); 953 } else { 954 // - waiting on <0x6008c468> (a java.lang.Class<java.lang.ref.ReferenceQueue>) 955 os << wait_message << StringPrintf("<0x%08x> (a %s)", pretty_object->IdentityHashCode(), 956 PrettyTypeOf(pretty_object).c_str()); 957 } 958 } 959 // - waiting to lock <0x613f83d8> (a java.lang.Object) held by thread 5 960 if (lock_owner != ThreadList::kInvalidThreadId) { 961 os << " held by thread " << lock_owner; 962 } 963 os << "\n"; 964 } 965} 966 967mirror::Object* Monitor::GetContendedMonitor(Thread* thread) { 968 // This is used to implement JDWP's ThreadReference.CurrentContendedMonitor, and has a bizarre 969 // definition of contended that includes a monitor a thread is trying to enter... 970 mirror::Object* result = thread->GetMonitorEnterObject(); 971 if (result == NULL) { 972 // ...but also a monitor that the thread is waiting on. 973 MutexLock mu(Thread::Current(), *thread->GetWaitMutex()); 974 Monitor* monitor = thread->GetWaitMonitor(); 975 if (monitor != NULL) { 976 result = monitor->GetObject(); 977 } 978 } 979 return result; 980} 981 982void Monitor::VisitLocks(StackVisitor* stack_visitor, void (*callback)(mirror::Object*, void*), 983 void* callback_context) { 984 mirror::ArtMethod* m = stack_visitor->GetMethod(); 985 CHECK(m != NULL); 986 987 // Native methods are an easy special case. 988 // TODO: use the JNI implementation's table of explicit MonitorEnter calls and dump those too. 989 if (m->IsNative()) { 990 if (m->IsSynchronized()) { 991 mirror::Object* jni_this = stack_visitor->GetCurrentHandleScope()->GetReference(0); 992 callback(jni_this, callback_context); 993 } 994 return; 995 } 996 997 // Proxy methods should not be synchronized. 998 if (m->IsProxyMethod()) { 999 CHECK(!m->IsSynchronized()); 1000 return; 1001 } 1002 1003 // <clinit> is another special case. The runtime holds the class lock while calling <clinit>. 1004 if (m->IsClassInitializer()) { 1005 callback(m->GetDeclaringClass(), callback_context); 1006 // Fall through because there might be synchronization in the user code too. 1007 } 1008 1009 // Is there any reason to believe there's any synchronization in this method? 1010 const DexFile::CodeItem* code_item = m->GetCodeItem(); 1011 CHECK(code_item != NULL) << PrettyMethod(m); 1012 if (code_item->tries_size_ == 0) { 1013 return; // No "tries" implies no synchronization, so no held locks to report. 1014 } 1015 1016 // Ask the verifier for the dex pcs of all the monitor-enter instructions corresponding to 1017 // the locks held in this stack frame. 1018 std::vector<uint32_t> monitor_enter_dex_pcs; 1019 verifier::MethodVerifier::FindLocksAtDexPc(m, stack_visitor->GetDexPc(), &monitor_enter_dex_pcs); 1020 if (monitor_enter_dex_pcs.empty()) { 1021 return; 1022 } 1023 1024 for (size_t i = 0; i < monitor_enter_dex_pcs.size(); ++i) { 1025 // The verifier works in terms of the dex pcs of the monitor-enter instructions. 1026 // We want the registers used by those instructions (so we can read the values out of them). 1027 uint32_t dex_pc = monitor_enter_dex_pcs[i]; 1028 uint16_t monitor_enter_instruction = code_item->insns_[dex_pc]; 1029 1030 // Quick sanity check. 1031 if ((monitor_enter_instruction & 0xff) != Instruction::MONITOR_ENTER) { 1032 LOG(FATAL) << "expected monitor-enter @" << dex_pc << "; was " 1033 << reinterpret_cast<void*>(monitor_enter_instruction); 1034 } 1035 1036 uint16_t monitor_register = ((monitor_enter_instruction >> 8) & 0xff); 1037 mirror::Object* o = reinterpret_cast<mirror::Object*>(stack_visitor->GetVReg(m, monitor_register, 1038 kReferenceVReg)); 1039 callback(o, callback_context); 1040 } 1041} 1042 1043bool Monitor::IsValidLockWord(LockWord lock_word) { 1044 switch (lock_word.GetState()) { 1045 case LockWord::kUnlocked: 1046 // Nothing to check. 1047 return true; 1048 case LockWord::kThinLocked: 1049 // Basic sanity check of owner. 1050 return lock_word.ThinLockOwner() != ThreadList::kInvalidThreadId; 1051 case LockWord::kFatLocked: { 1052 // Check the monitor appears in the monitor list. 1053 Monitor* mon = lock_word.FatLockMonitor(); 1054 MonitorList* list = Runtime::Current()->GetMonitorList(); 1055 MutexLock mu(Thread::Current(), list->monitor_list_lock_); 1056 for (Monitor* list_mon : list->list_) { 1057 if (mon == list_mon) { 1058 return true; // Found our monitor. 1059 } 1060 } 1061 return false; // Fail - unowned monitor in an object. 1062 } 1063 case LockWord::kHashCode: 1064 return true; 1065 default: 1066 LOG(FATAL) << "Unreachable"; 1067 return false; 1068 } 1069} 1070 1071bool Monitor::IsLocked() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { 1072 MutexLock mu(Thread::Current(), monitor_lock_); 1073 return owner_ != nullptr; 1074} 1075 1076void Monitor::TranslateLocation(mirror::ArtMethod* method, uint32_t dex_pc, 1077 const char** source_file, uint32_t* line_number) const { 1078 // If method is null, location is unknown 1079 if (method == NULL) { 1080 *source_file = ""; 1081 *line_number = 0; 1082 return; 1083 } 1084 *source_file = method->GetDeclaringClassSourceFile(); 1085 if (*source_file == NULL) { 1086 *source_file = ""; 1087 } 1088 *line_number = method->GetLineNumFromDexPC(dex_pc); 1089} 1090 1091uint32_t Monitor::GetOwnerThreadId() { 1092 MutexLock mu(Thread::Current(), monitor_lock_); 1093 Thread* owner = owner_; 1094 if (owner != NULL) { 1095 return owner->GetThreadId(); 1096 } else { 1097 return ThreadList::kInvalidThreadId; 1098 } 1099} 1100 1101MonitorList::MonitorList() 1102 : allow_new_monitors_(true), monitor_list_lock_("MonitorList lock", kMonitorListLock), 1103 monitor_add_condition_("MonitorList disallow condition", monitor_list_lock_) { 1104} 1105 1106MonitorList::~MonitorList() { 1107 Thread* self = Thread::Current(); 1108 MutexLock mu(self, monitor_list_lock_); 1109 // Release all monitors to the pool. 1110 // TODO: Is it an invariant that *all* open monitors are in the list? Then we could 1111 // clear faster in the pool. 1112 MonitorPool::ReleaseMonitors(self, &list_); 1113} 1114 1115void MonitorList::DisallowNewMonitors() { 1116 MutexLock mu(Thread::Current(), monitor_list_lock_); 1117 allow_new_monitors_ = false; 1118} 1119 1120void MonitorList::AllowNewMonitors() { 1121 Thread* self = Thread::Current(); 1122 MutexLock mu(self, monitor_list_lock_); 1123 allow_new_monitors_ = true; 1124 monitor_add_condition_.Broadcast(self); 1125} 1126 1127void MonitorList::Add(Monitor* m) { 1128 Thread* self = Thread::Current(); 1129 MutexLock mu(self, monitor_list_lock_); 1130 while (UNLIKELY(!allow_new_monitors_)) { 1131 monitor_add_condition_.WaitHoldingLocks(self); 1132 } 1133 list_.push_front(m); 1134} 1135 1136void MonitorList::SweepMonitorList(IsMarkedCallback* callback, void* arg) { 1137 Thread* self = Thread::Current(); 1138 MutexLock mu(self, monitor_list_lock_); 1139 for (auto it = list_.begin(); it != list_.end(); ) { 1140 Monitor* m = *it; 1141 // Disable the read barrier in GetObject() as this is called by GC. 1142 mirror::Object* obj = m->GetObject<kWithoutReadBarrier>(); 1143 // The object of a monitor can be null if we have deflated it. 1144 mirror::Object* new_obj = obj != nullptr ? callback(obj, arg) : nullptr; 1145 if (new_obj == nullptr) { 1146 VLOG(monitor) << "freeing monitor " << m << " belonging to unmarked object " 1147 << obj; 1148 MonitorPool::ReleaseMonitor(self, m); 1149 it = list_.erase(it); 1150 } else { 1151 m->SetObject(new_obj); 1152 ++it; 1153 } 1154 } 1155} 1156 1157struct MonitorDeflateArgs { 1158 MonitorDeflateArgs() : self(Thread::Current()), deflate_count(0) {} 1159 Thread* const self; 1160 size_t deflate_count; 1161}; 1162 1163static mirror::Object* MonitorDeflateCallback(mirror::Object* object, void* arg) 1164 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { 1165 MonitorDeflateArgs* args = reinterpret_cast<MonitorDeflateArgs*>(arg); 1166 if (Monitor::Deflate(args->self, object)) { 1167 DCHECK_NE(object->GetLockWord(true).GetState(), LockWord::kFatLocked); 1168 ++args->deflate_count; 1169 // If we deflated, return nullptr so that the monitor gets removed from the array. 1170 return nullptr; 1171 } 1172 return object; // Monitor was not deflated. 1173} 1174 1175size_t MonitorList::DeflateMonitors() { 1176 MonitorDeflateArgs args; 1177 Locks::mutator_lock_->AssertExclusiveHeld(args.self); 1178 SweepMonitorList(MonitorDeflateCallback, &args); 1179 return args.deflate_count; 1180} 1181 1182MonitorInfo::MonitorInfo(mirror::Object* obj) : owner_(NULL), entry_count_(0) { 1183 DCHECK(obj != nullptr); 1184 LockWord lock_word = obj->GetLockWord(true); 1185 switch (lock_word.GetState()) { 1186 case LockWord::kUnlocked: 1187 // Fall-through. 1188 case LockWord::kForwardingAddress: 1189 // Fall-through. 1190 case LockWord::kHashCode: 1191 break; 1192 case LockWord::kThinLocked: 1193 owner_ = Runtime::Current()->GetThreadList()->FindThreadByThreadId(lock_word.ThinLockOwner()); 1194 entry_count_ = 1 + lock_word.ThinLockCount(); 1195 // Thin locks have no waiters. 1196 break; 1197 case LockWord::kFatLocked: { 1198 Monitor* mon = lock_word.FatLockMonitor(); 1199 owner_ = mon->owner_; 1200 entry_count_ = 1 + mon->lock_count_; 1201 for (Thread* waiter = mon->wait_set_; waiter != NULL; waiter = waiter->GetWaitNext()) { 1202 waiters_.push_back(waiter); 1203 } 1204 break; 1205 } 1206 } 1207} 1208 1209} // namespace art 1210