diff options
| -rw-r--r-- | runtime/gc/heap.cc | 5 | ||||
| -rw-r--r-- | runtime/monitor.cc | 19 | ||||
| -rw-r--r-- | runtime/monitor.h | 3 |
3 files changed, 20 insertions, 7 deletions
diff --git a/runtime/gc/heap.cc b/runtime/gc/heap.cc index 6c63e5f13e..296acccd55 100644 --- a/runtime/gc/heap.cc +++ b/runtime/gc/heap.cc @@ -866,7 +866,10 @@ void Heap::DoPendingTransitionOrTrim() { // 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 a19445b189..999a9e504b 100644 --- a/runtime/monitor.cc +++ b/runtime/monitor.cc @@ -1115,20 +1115,29 @@ void MonitorList::SweepMonitorList(IsMarkedCallback* callback, void* arg) { } } +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 a28823d184..d7552a3fd5 100644 --- a/runtime/monitor.h +++ b/runtime/monitor.h @@ -229,7 +229,8 @@ class MonitorList { 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: |