Add logging to monitor deflation.

Change-Id: I0251ff19e0a3c3b9edc7c7e296f15eb3229f8f7c
diff --git a/runtime/gc/heap.cc b/runtime/gc/heap.cc
index 6c63e5f..296accc 100644
--- a/runtime/gc/heap.cc
+++ b/runtime/gc/heap.cc
@@ -866,7 +866,10 @@
     // about pauses.
     Runtime* runtime = Runtime::Current();
     runtime->GetThreadList()->SuspendAll();
-    runtime->GetMonitorList()->DeflateMonitors();
+    uint64_t start_time = NanoTime();
+    size_t count = runtime->GetMonitorList()->DeflateMonitors();
+    VLOG(heap) << "Deflating " << count << " monitors took "
+        << PrettyDuration(NanoTime() - start_time);
     runtime->GetThreadList()->ResumeAll();
     // Do a heap trim if it is needed.
     Trim();
diff --git a/runtime/monitor.cc b/runtime/monitor.cc
index a19445b..999a9e5 100644
--- a/runtime/monitor.cc
+++ b/runtime/monitor.cc
@@ -1115,20 +1115,29 @@
   }
 }
 
+struct MonitorDeflateArgs {
+  MonitorDeflateArgs() : self(Thread::Current()), deflate_count(0) {}
+  Thread* const self;
+  size_t deflate_count;
+};
+
 static mirror::Object* MonitorDeflateCallback(mirror::Object* object, void* arg)
     SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
-  if (Monitor::Deflate(reinterpret_cast<Thread*>(arg), object)) {
+  MonitorDeflateArgs* args = reinterpret_cast<MonitorDeflateArgs*>(arg);
+  if (Monitor::Deflate(args->self, object)) {
     DCHECK_NE(object->GetLockWord(true).GetState(), LockWord::kFatLocked);
+    ++args->deflate_count;
     // If we deflated, return nullptr so that the monitor gets removed from the array.
     return nullptr;
   }
   return object;  // Monitor was not deflated.
 }
 
-void MonitorList::DeflateMonitors() {
-  Thread* self = Thread::Current();
-  Locks::mutator_lock_->AssertExclusiveHeld(self);
-  SweepMonitorList(MonitorDeflateCallback, reinterpret_cast<Thread*>(self));
+size_t MonitorList::DeflateMonitors() {
+  MonitorDeflateArgs args;
+  Locks::mutator_lock_->AssertExclusiveHeld(args.self);
+  SweepMonitorList(MonitorDeflateCallback, &args);
+  return args.deflate_count;
 }
 
 MonitorInfo::MonitorInfo(mirror::Object* obj) : owner_(NULL), entry_count_(0) {
diff --git a/runtime/monitor.h b/runtime/monitor.h
index a28823d..d7552a3 100644
--- a/runtime/monitor.h
+++ b/runtime/monitor.h
@@ -229,7 +229,8 @@
       LOCKS_EXCLUDED(monitor_list_lock_) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
   void DisallowNewMonitors() LOCKS_EXCLUDED(monitor_list_lock_);
   void AllowNewMonitors() LOCKS_EXCLUDED(monitor_list_lock_);
-  void DeflateMonitors() LOCKS_EXCLUDED(monitor_list_lock_)
+  // Returns how many monitors were deflated.
+  size_t DeflateMonitors() LOCKS_EXCLUDED(monitor_list_lock_)
       EXCLUSIVE_LOCKS_REQUIRED(Locks::mutator_lock_);
 
  private: