Commit c52236ab authored by Seth Brenith's avatar Seth Brenith Committed by V8 LUCI CQ

Avoid incorrect retaining paths through Code objects in heap snapshots

The heap snapshot view in the dev tools reports some incorrect retaining
paths involving weak references from relocation data in Code objects.
This change updates IndexedReferencesExtractor::VisitEmbeddedPointer to
better match the behavior in MarkingVisitorBase.

Drive-by cleanup: ObjectVisitor::VisitRelocInfo needn't be virtual
because there's only one implementation.

Bug: v8:12126
Change-Id: I669a7408e7a46e797b8c2b372235b4ea42ee22e1
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3107214Reviewed-by: 's avatarYang Guo <yangguo@chromium.org>
Commit-Queue: Seth Brenith <seth.brenith@microsoft.com>
Cr-Commit-Position: refs/heads/main@{#76406}
parent 6a76a3a1
......@@ -168,7 +168,7 @@ class ObjectVisitor {
virtual void VisitOffHeapTarget(Code host, RelocInfo* rinfo) {}
// Visits the relocation info using the given iterator.
virtual void VisitRelocInfo(RelocIterator* it);
void VisitRelocInfo(RelocIterator* it);
// Visits the object's map pointer, decoding as necessary
virtual void VisitMapPointer(HeapObject host) { UNREACHABLE(); }
......
......@@ -763,7 +763,12 @@ class IndexedReferencesExtractor : public ObjectVisitor {
}
void VisitEmbeddedPointer(Code host, RelocInfo* rinfo) override {
VisitHeapObjectImpl(rinfo->target_object(), -1);
HeapObject object = rinfo->target_object();
if (host.IsWeakObject(object)) {
generator_->SetWeakReference(parent_, next_index_++, object, {});
} else {
VisitHeapObjectImpl(rinfo->target_object(), -1);
}
}
private:
......@@ -778,9 +783,7 @@ class IndexedReferencesExtractor : public ObjectVisitor {
if (loaded_value.GetHeapObjectIfStrong(&heap_object)) {
VisitHeapObjectImpl(heap_object, field_index);
} else if (loaded_value.GetHeapObjectIfWeak(&heap_object)) {
generator_->SetWeakReference(parent_, next_index_++, heap_object,
field_index * kTaggedSize);
generator_->visited_fields_[field_index] = false;
generator_->SetWeakReference(parent_, next_index_++, heap_object, {});
}
}
}
......@@ -1786,7 +1789,8 @@ void V8HeapExplorer::SetWeakReference(HeapEntry* parent_entry,
}
void V8HeapExplorer::SetWeakReference(HeapEntry* parent_entry, int index,
Object child_obj, int field_offset) {
Object child_obj,
base::Optional<int> field_offset) {
if (!IsEssentialObject(child_obj)) {
return;
}
......@@ -1794,7 +1798,9 @@ void V8HeapExplorer::SetWeakReference(HeapEntry* parent_entry, int index,
DCHECK_NOT_NULL(child_entry);
parent_entry->SetNamedReference(
HeapGraphEdge::kWeak, names_->GetFormatted("%d", index), child_entry);
MarkVisitedField(field_offset);
if (field_offset.has_value()) {
MarkVisitedField(*field_offset);
}
}
void V8HeapExplorer::SetDataOrAccessorPropertyReference(
......
......@@ -436,7 +436,7 @@ class V8_EXPORT_PRIVATE V8HeapExplorer : public HeapEntriesAllocator {
void SetWeakReference(HeapEntry* parent_entry, const char* reference_name,
Object child_obj, int field_offset);
void SetWeakReference(HeapEntry* parent_entry, int index, Object child_obj,
int field_offset);
base::Optional<int> field_offset);
void SetPropertyReference(HeapEntry* parent_entry, Name reference_name,
Object child,
const char* name_format_string = nullptr,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment