From 07cbc5ba4f117ea74faecffe14ffc0ce8aa7ee0e Mon Sep 17 00:00:00 2001 From: Hans Boehm Date: Wed, 26 Jan 2022 02:43:33 +0000 Subject: Revert "Reduce pauses for weak reference access" This reverts commit 0ab5b6d2afbdd71a18f8fb9b1fcf39e54cfd55a5. Reason for revert: Breaks CMS builds Change-Id: Ib3dfcc90ac5b7259c7f718a0373b48acc2ba10b2 --- runtime/gc/reference_queue.cc | 49 +++++++++++++------------------------------ 1 file changed, 14 insertions(+), 35 deletions(-) (limited to 'runtime/gc/reference_queue.cc') diff --git a/runtime/gc/reference_queue.cc b/runtime/gc/reference_queue.cc index 6bdacaf18c..568ca04c1d 100644 --- a/runtime/gc/reference_queue.cc +++ b/runtime/gc/reference_queue.cc @@ -131,8 +131,7 @@ size_t ReferenceQueue::GetLength() const { } void ReferenceQueue::ClearWhiteReferences(ReferenceQueue* cleared_references, - collector::GarbageCollector* collector, - bool report_cleared) { + collector::GarbageCollector* collector) { while (!IsEmpty()) { ObjPtr ref = DequeuePendingReference(); mirror::HeapReference* referent_addr = ref->GetReferentReferenceAddr(); @@ -146,15 +145,6 @@ void ReferenceQueue::ClearWhiteReferences(ReferenceQueue* cleared_references, ref->ClearReferent(); } cleared_references->EnqueueReference(ref); - if (report_cleared) { - static bool already_reported = false; - if (!already_reported) { - // TODO: Maybe do this only if the queue is non-null? - LOG(WARNING) - << "Cleared Reference was only reachable from finalizer (only reported once)"; - already_reported = true; - } - } } // Delay disabling the read barrier until here so that the ClearReferent call above in // transaction mode will trigger the read barrier. @@ -192,33 +182,22 @@ FinalizerStats ReferenceQueue::EnqueueFinalizerReferences(ReferenceQueue* cleare } uint32_t ReferenceQueue::ForwardSoftReferences(MarkObjectVisitor* visitor) { + if (UNLIKELY(IsEmpty())) { + return 0; + } uint32_t num_refs(0); - Thread* self = Thread::Current(); - static constexpr int SR_BUF_SIZE = 32; - ObjPtr buf[SR_BUF_SIZE]; - int n_entries; - bool empty; + const ObjPtr head = list_; + ObjPtr ref = head; do { - { - // Acquire lock only a few times and hold it as briefly as possible. - MutexLock mu(self, *lock_); - empty = IsEmpty(); - for (n_entries = 0; n_entries < SR_BUF_SIZE && !empty; ++n_entries) { - // Dequeuing the Reference here means it could possibly be enqueued again during this GC. - // That's unlikely and benign. - buf[n_entries] = DequeuePendingReference(); - empty = IsEmpty(); - } - } - for (int i = 0; i < n_entries; ++i) { - mirror::HeapReference* referent_addr = buf[i]->GetReferentReferenceAddr(); - if (referent_addr->AsMirrorPtr() != nullptr) { - visitor->MarkHeapReference(referent_addr, /*do_atomic_update=*/ true); - ++num_refs; - } - DisableReadBarrierForReference(buf[i]->AsReference()); + mirror::HeapReference* referent_addr = ref->GetReferentReferenceAddr(); + if (referent_addr->AsMirrorPtr() != nullptr) { + // do_atomic_update is false because mutators can't access the referent due to the weak ref + // access blocking. + visitor->MarkHeapReference(referent_addr, /*do_atomic_update=*/ false); + ++num_refs; } - } while (!empty); + ref = ref->GetPendingNext(); + } while (LIKELY(ref != head)); return num_refs; } -- cgit v1.2.3-59-g8ed1b