diff options
author | 2014-02-13 10:23:27 -0800 | |
---|---|---|
committer | 2014-02-13 10:40:24 -0800 | |
commit | ebdf3f320d71563cf0236c31d35d633be9576d8c (patch) | |
tree | d371569a07fd95b2fba833a7f670c72f2e1e2a5c | |
parent | d2be39a0c106728bc9087ff0c0500b796aadea25 (diff) |
Prevent object allocation related races in VisitObjects.
Prevents the following race conditions:
Someone is in the process of pushing a reference in the allocation
stack but hasn't yet written the reference. This caused VisitObjects
to occasionally send null objects to the visitor.
Fixed another race where the object had just been allocated but the
class had not been written. We now skip objects in the allocation
stack which have a null class.
Bug: 13004631
Change-Id: Iad789c5e277a7717ce595c7124f0d65b44392fd8
-rw-r--r-- | runtime/gc/heap.cc | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/runtime/gc/heap.cc b/runtime/gc/heap.cc index a324925094..5c174f8f71 100644 --- a/runtime/gc/heap.cc +++ b/runtime/gc/heap.cc @@ -381,7 +381,11 @@ void Heap::VisitObjects(ObjectCallback callback, void* arg) { for (mirror::Object** it = allocation_stack_->Begin(), **end = allocation_stack_->End(); it < end; ++it) { mirror::Object* obj = *it; - callback(obj, arg); + if (obj != nullptr && obj->GetClass() != nullptr) { + // Avoid the race condition caused by the object not yet being written into the allocation + // stack or the class not yet being written in the object. + callback(obj, arg); + } } GetLiveBitmap()->Walk(callback, arg); self->EndAssertNoThreadSuspension(old_cause); |