のねのBlog

パソコンの問題や、ソフトウェアの開発で起きた問題など書いていきます。よろしくお願いします^^。

art "Long monitor contention event with owner method="

    --------- beginning of main
04-02 14:25:17.040      673-781/system_process W/art﹕ 
Long monitor contention event with owner method=
   void com.android.server.wm.WindowManagerService.removeWindow
   (com.android.server.wm.Session, android.view.IWindow) 
   from WindowManagerService.java:2557 
   waiters=1 
   for 168.591s
    233 void Monitor::Lock(Thread* self) {
    234   MutexLock mu(self, monitor_lock_);
    235   while (true) {
    236     if (owner_ == nullptr) {  // Unowned.
    237       owner_ = self;
    238       CHECK_EQ(lock_count_, 0);
    239       // When debugging, save the current monitor holder for future
    240       // acquisition failures to use in sampled logging.
    241       if (lock_profiling_threshold_ != 0) {
    242         locking_method_ = self->GetCurrentMethod(&locking_dex_pc_);
    243       }
    244       return;
    245     } else if (owner_ == self) {  // Recursive.
    246       lock_count_++;
    247       return;
    248     }
    249     // Contended.
    250     const bool log_contention = (lock_profiling_threshold_ != 0);
    251     uint64_t wait_start_ms = log_contention ? MilliTime() : 0;
    252     mirror::ArtMethod* owners_method = locking_method_;
    253     uint32_t owners_dex_pc = locking_dex_pc_;
    254     // Do this before releasing the lock so that we don't get deflated.
    255     size_t num_waiters = num_waiters_;
    256     ++num_waiters_;
    257     monitor_lock_.Unlock(self);  // Let go of locks in order.
    258     self->SetMonitorEnterObject(GetObject());
    259     {
    260       ScopedThreadStateChange tsc(self, kBlocked);  // Change to blocked and give up mutator_lock_.
    261       MutexLock mu2(self, monitor_lock_);  // Reacquire monitor_lock_ without mutator_lock_ for Wait.
    262       if (owner_ != NULL) {  // Did the owner_ give the lock up?
    263         monitor_contenders_.Wait(self);  // Still contended so wait.
    264         // Woken from contention.
    265         if (log_contention) {
    266           uint64_t wait_ms = MilliTime() - wait_start_ms;
    267           uint32_t sample_percent;
    268           if (wait_ms >= lock_profiling_threshold_) {
    269             sample_percent = 100;
    270           } else {
    271             sample_percent = 100 * wait_ms / lock_profiling_threshold_;
    272           }
    273           if (sample_percent != 0 && (static_cast<uint32_t>(rand() % 100) < sample_percent)) {
    274             const char* owners_filename;
    275             uint32_t owners_line_number;
    276             TranslateLocation(owners_method, owners_dex_pc, &owners_filename, &owners_line_number);
    277             if (wait_ms > kLongWaitMs && owners_method != nullptr) {

    278               LOG(WARNING) << "Long monitor contention event with owner method="

    279                   << PrettyMethod(owners_method) << " from " << owners_filename << ":"
    280                   << owners_line_number 
                          << " waiters=" << num_waiters 
                          << " for "
    281                   << PrettyDuration(MsToNs(wait_ms));
    282             }
    283             LogContentionEvent(self, wait_ms, sample_percent, owners_filename, owners_line_number);
    284           }
    285         }
    286       }
    287     }
    288     self->SetMonitorEnterObject(nullptr);
    289     monitor_lock_.Lock(self);  // Reacquire locks in order.
    290     --num_waiters_;
    291   }
    292 }