OSDN Git Service

Expect null referent in DequeuePendingReference().
authorHiroshi Yamauchi <yamauchi@google.com>
Mon, 14 Sep 2015 22:10:50 +0000 (15:10 -0700)
committerHiroshi Yamauchi <yamauchi@google.com>
Tue, 15 Sep 2015 17:33:03 +0000 (10:33 -0700)
Following up on CL 170735.

It's possible that the referent may potentially be cleared which would
cause a check failure. Avoid that.

Bug: 12687968
Bug: 23896462
Change-Id: I8ccc5936b61ceacf250624681e65307f23ce0405

runtime/gc/reference_queue.cc

index 0c0ab6d..56957ba 100644 (file)
@@ -115,10 +115,12 @@ mirror::Reference* ReferenceQueue::DequeuePendingReference() {
             << "ref=" << ref << " rb_ptr=" << ref->GetReadBarrierPointer();
       }
       mirror::Object* referent = ref->GetReferent<kWithoutReadBarrier>();
-      CHECK(referent != nullptr) << "Reference should not have been enqueued if referent is null";
-      CHECK(concurrent_copying->IsInToSpace(referent))
-          << "ref=" << ref << " rb_ptr=" << ref->GetReadBarrierPointer()
-          << " referent=" << referent;
+      // The referent could be null if it's cleared by a mutator (Reference.clear()).
+      if (referent != nullptr) {
+        CHECK(concurrent_copying->IsInToSpace(referent))
+            << "ref=" << ref << " rb_ptr=" << ref->GetReadBarrierPointer()
+            << " referent=" << referent;
+      }
     }
   }
   return ref;