summaryrefslogtreecommitdiffstats
path: root/runtime/gc
diff options
context:
space:
mode:
authorMathieu Chartier <mathieuc@google.com>2015-05-12 10:47:11 -0700
committerMathieu Chartier <mathieuc@google.com>2015-05-12 13:41:43 -0700
commita395c0a492079d86b312c9edc796d63001576954 (patch)
tree5172c3a64e30577561db38ff3de883a4e639dfbb /runtime/gc
parent3d8ac11e412aeb186e2e14270d09585bc34e229e (diff)
downloadart-a395c0a492079d86b312c9edc796d63001576954.zip
art-a395c0a492079d86b312c9edc796d63001576954.tar.gz
art-a395c0a492079d86b312c9edc796d63001576954.tar.bz2
Hold heap bitmap lock in Heap::GetObjectsAllocated
Fixes a race condition where add and remove space could cause a crash when we iterated over the spaces. TODO: Add a spaces lock or something to guard against this. Bug: 21031927 Change-Id: I7f0d558316f8e9d9f22ffd182e8666355bf50d47
Diffstat (limited to 'runtime/gc')
-rw-r--r--runtime/gc/heap.cc13
1 files changed, 11 insertions, 2 deletions
diff --git a/runtime/gc/heap.cc b/runtime/gc/heap.cc
index 4129d75..11a0e3c 100644
--- a/runtime/gc/heap.cc
+++ b/runtime/gc/heap.cc
@@ -1612,10 +1612,19 @@ void Heap::SetTargetHeapUtilization(float target) {
}
size_t Heap::GetObjectsAllocated() const {
+ Thread* self = Thread::Current();
+ ScopedThreadStateChange tsc(self, kWaitingForGetObjectsAllocated);
+ auto* tl = Runtime::Current()->GetThreadList();
+ // Need SuspendAll here to prevent lock violation if RosAlloc does it during InspectAll.
+ tl->SuspendAll(__FUNCTION__);
size_t total = 0;
- for (space::AllocSpace* space : alloc_spaces_) {
- total += space->GetObjectsAllocated();
+ {
+ ReaderMutexLock mu(self, *Locks::heap_bitmap_lock_);
+ for (space::AllocSpace* space : alloc_spaces_) {
+ total += space->GetObjectsAllocated();
+ }
}
+ tl->ResumeAll();
return total;
}