Commit 05eb0e41 authored by Sigurd Schneider's avatar Sigurd Schneider Committed by Commit Bot

[heap-profiler] Improve reporting for WeakMap entries

This CL improves reporting for WeakMap entries: If a retaining chain
goes through a WeakMap entry (i.e. key and weak map are alive, and keep
value alive) then both the key and the value are reported. Additionally
the phrasing is clarified, such that entries in retaining paths are
easier to understand.

Bug: chromium:1020096
Change-Id: Ib05cd6f7939c6de41b554c682ad1fbf685b87608
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1893335Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Commit-Queue: Sigurd Schneider <sigurds@chromium.org>
Cr-Commit-Position: refs/heads/master@{#64721}
parent c0d21ab1
...@@ -942,11 +942,16 @@ void V8HeapExplorer::ExtractEphemeronHashTableReferences( ...@@ -942,11 +942,16 @@ void V8HeapExplorer::ExtractEphemeronHashTableReferences(
table.OffsetOfElementAt(value_index)); table.OffsetOfElementAt(value_index));
HeapEntry* key_entry = GetEntry(key); HeapEntry* key_entry = GetEntry(key);
HeapEntry* value_entry = GetEntry(value); HeapEntry* value_entry = GetEntry(value);
if (key_entry && value_entry) { HeapEntry* table_entry = GetEntry(table);
const char* edge_name = if (key_entry && value_entry && !key.IsUndefined()) {
names_->GetFormatted("key %s in WeakMap", key_entry->name()); const char* edge_name = names_->GetFormatted(
"part of key (%s @%u) -> value (%s @%u) pair in WeakMap (table @%u)",
key_entry->name(), key_entry->id(), value_entry->name(),
value_entry->id(), table_entry->id());
key_entry->SetNamedAutoIndexReference(HeapGraphEdge::kInternal, edge_name, key_entry->SetNamedAutoIndexReference(HeapGraphEdge::kInternal, edge_name,
value_entry, names_); value_entry, names_);
table_entry->SetNamedAutoIndexReference(HeapGraphEdge::kInternal,
edge_name, value_entry, names_);
} }
} }
} }
......
...@@ -839,13 +839,24 @@ TEST(HeapSnapshotEphemeron) { ...@@ -839,13 +839,24 @@ TEST(HeapSnapshotEphemeron) {
const v8::HeapGraphNode* key = GetProperty( const v8::HeapGraphNode* key = GetProperty(
env->GetIsolate(), global, v8::HeapGraphEdge::kProperty, "key"); env->GetIsolate(), global, v8::HeapGraphEdge::kProperty, "key");
CHECK(key); CHECK(key);
const v8::HeapGraphNode* weakmap = GetProperty(
env->GetIsolate(), global, v8::HeapGraphEdge::kProperty, "wm");
CHECK(weakmap);
const v8::HeapGraphNode* weakmap_table = GetProperty(
env->GetIsolate(), weakmap, v8::HeapGraphEdge::kInternal, "table");
CHECK(weakmap_table);
bool success = false; bool success = false;
for (int i = 0, count = key->GetChildrenCount(); i < count; ++i) { for (int i = 0, count = key->GetChildrenCount(); i < count; ++i) {
const v8::HeapGraphEdge* edge = key->GetChild(i); const v8::HeapGraphEdge* edge = key->GetChild(i);
const v8::HeapGraphNode* child = edge->GetToNode(); const v8::HeapGraphNode* child = edge->GetToNode();
if (!strcmp("ValueClass", GetName(child))) { if (!strcmp("ValueClass", GetName(child))) {
v8::String::Utf8Value edge_name(CcTest::isolate(), edge->GetName()); v8::String::Utf8Value edge_name(CcTest::isolate(), edge->GetName());
CHECK(EndsWith(*edge_name, " / key KeyClass in WeakMap")); std::stringstream end_of_label;
end_of_label << "/ part of key (KeyClass @" << key->GetId()
<< ") -> value (ValueClass @" << child->GetId()
<< ") pair in WeakMap (table @" << weakmap_table->GetId()
<< ")";
CHECK(EndsWith(*edge_name, end_of_label.str().c_str()));
success = true; success = true;
break; break;
} }
......
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