Add more weak reference information to traces
Separate the marking piece of EnqueueFinalizerReferences.
Report the number of finalizable objects.
Similarly report the number of SoftReferences we encounter
and the amount of time we spend marking as a result.
Add trace information and possibly log entry when we block
dereferencing a WeakReference or the like.
Do the same for JNI WeakGlobals, with some code restructuring
to enable that.
Delete one of the two nested and almost entirely redundant
ProcessReferences ATrace tags, thus reducing the space needed
to display HeapTaskDaemon back to what it was.
Bug: 189738006
Test: Boot sc-dev and look at trace
Change-Id: I198db632d957bcb9353ab945cedc92aa733963f0
diff --git a/runtime/gc/reference_queue.cc b/runtime/gc/reference_queue.cc
index 1c751e1..1e3cf93 100644
--- a/runtime/gc/reference_queue.cc
+++ b/runtime/gc/reference_queue.cc
@@ -152,10 +152,12 @@
}
}
-void ReferenceQueue::EnqueueFinalizerReferences(ReferenceQueue* cleared_references,
+FinalizerStats ReferenceQueue::EnqueueFinalizerReferences(ReferenceQueue* cleared_references,
collector::GarbageCollector* collector) {
+ uint32_t num_refs(0), num_enqueued(0);
while (!IsEmpty()) {
ObjPtr<mirror::FinalizerReference> ref = DequeuePendingReference()->AsFinalizerReference();
+ ++num_refs;
mirror::HeapReference<mirror::Object>* referent_addr = ref->GetReferentReferenceAddr();
// do_atomic_update is false because this happens during the reference processing phase where
// Reference.clear() would block.
@@ -170,17 +172,20 @@
ref->ClearReferent<false>();
}
cleared_references->EnqueueReference(ref);
+ ++num_enqueued;
}
// Delay disabling the read barrier until here so that the ClearReferent call above in
// transaction mode will trigger the read barrier.
DisableReadBarrierForReference(ref->AsReference());
}
+ return FinalizerStats(num_refs, num_enqueued);
}
-void ReferenceQueue::ForwardSoftReferences(MarkObjectVisitor* visitor) {
+uint32_t ReferenceQueue::ForwardSoftReferences(MarkObjectVisitor* visitor) {
if (UNLIKELY(IsEmpty())) {
- return;
+ return 0;
}
+ uint32_t num_refs(0);
const ObjPtr<mirror::Reference> head = list_;
ObjPtr<mirror::Reference> ref = head;
do {
@@ -189,9 +194,11 @@
// 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;
}
ref = ref->GetPendingNext();
} while (LIKELY(ref != head));
+ return num_refs;
}
void ReferenceQueue::UpdateRoots(IsMarkedVisitor* visitor) {