From b98063a4d54c5a741152a1eebc262d8e223b3b25 Mon Sep 17 00:00:00 2001 From: Sebastien Hertz Date: Wed, 26 Mar 2014 10:57:20 +0100 Subject: [PATCH] Fix alloc tracker locking issue Fixes a lock level violation where we attempt to take the thread list lock while already holding the alloc tracker lock. We now avoid holding the alloc tracker lock when updating allocation entrypoints. Bug: 13646642 Change-Id: Iab505dae67d0c754031fe30d50a7cbd5e4ba5785 --- runtime/debugger.cc | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/runtime/debugger.cc b/runtime/debugger.cc index c18d5c6e0..1ff200387 100644 --- a/runtime/debugger.cc +++ b/runtime/debugger.cc @@ -3767,22 +3767,27 @@ static size_t GetAllocTrackerMax() { } void Dbg::SetAllocTrackingEnabled(bool enabled) { - MutexLock mu(Thread::Current(), *alloc_tracker_lock_); if (enabled) { - if (recent_allocation_records_ == NULL) { - alloc_record_max_ = GetAllocTrackerMax(); - LOG(INFO) << "Enabling alloc tracker (" << alloc_record_max_ << " entries of " - << kMaxAllocRecordStackDepth << " frames, taking " - << PrettySize(sizeof(AllocRecord) * alloc_record_max_) << ")"; - alloc_record_head_ = alloc_record_count_ = 0; - recent_allocation_records_ = new AllocRecord[alloc_record_max_]; - CHECK(recent_allocation_records_ != NULL); + { + MutexLock mu(Thread::Current(), *alloc_tracker_lock_); + if (recent_allocation_records_ == NULL) { + alloc_record_max_ = GetAllocTrackerMax(); + LOG(INFO) << "Enabling alloc tracker (" << alloc_record_max_ << " entries of " + << kMaxAllocRecordStackDepth << " frames, taking " + << PrettySize(sizeof(AllocRecord) * alloc_record_max_) << ")"; + alloc_record_head_ = alloc_record_count_ = 0; + recent_allocation_records_ = new AllocRecord[alloc_record_max_]; + CHECK(recent_allocation_records_ != NULL); + } } Runtime::Current()->GetInstrumentation()->InstrumentQuickAllocEntryPoints(); } else { Runtime::Current()->GetInstrumentation()->UninstrumentQuickAllocEntryPoints(); - delete[] recent_allocation_records_; - recent_allocation_records_ = NULL; + { + MutexLock mu(Thread::Current(), *alloc_tracker_lock_); + delete[] recent_allocation_records_; + recent_allocation_records_ = NULL; + } } } -- 2.11.0