[heap-profiler] Do not treat WeakMap values as weak.

For the WeakHashTable objects only mark keys as weak while leaving values as strong references.

BUG=chomium:773722

Change-Id: Iabd5ba293d05fe68a2af6503fcdd711ecc182482
Reviewed-on: https://chromium-review.googlesource.com/730771
Commit-Queue: Alexei Filippov <alph@chromium.org>
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#48985}
This commit is contained in:
Alexei Filippov 2017-10-26 12:07:52 -07:00 committed by Commit Bot
parent 9ae967fe12
commit c34042cc64
3 changed files with 18 additions and 11 deletions

View File

@ -597,17 +597,15 @@ class WeakHashTable : public HashTable<WeakHashTable, WeakHashTableShape<2>> {
Handle<HeapObject> key, Handle<HeapObject> key,
Handle<HeapObject> value); Handle<HeapObject> value);
static Handle<FixedArray> GetValues(Handle<WeakHashTable> table); // Returns the index to the value of an entry.
static inline int EntryToValueIndex(int entry) {
return EntryToIndex(entry) + 1;
}
private: private:
friend class MarkCompactCollector; friend class MarkCompactCollector;
void AddEntry(int entry, Handle<WeakCell> key, Handle<HeapObject> value); void AddEntry(int entry, Handle<WeakCell> key, Handle<HeapObject> value);
// Returns the index to the value of an entry.
static inline int EntryToValueIndex(int entry) {
return EntryToIndex(entry) + 1;
}
}; };
// This is similar to the OrderedHashTable, except for the memory // This is similar to the OrderedHashTable, except for the memory

View File

@ -1345,12 +1345,21 @@ void V8HeapExplorer::ExtractFixedArrayReferences(int entry, FixedArray* array) {
return; return;
} }
switch (it->second) { switch (it->second) {
case JS_WEAK_COLLECTION_SUB_TYPE: case JS_WEAK_COLLECTION_SUB_TYPE: {
for (int i = 0, l = array->length(); i < l; ++i) { WeakHashTable* table = WeakHashTable::cast(array);
SetWeakReference(array, entry, i, array->get(i), for (int i = 0, capacity = table->Capacity(); i < capacity; ++i) {
array->OffsetOfElementAt(i)); int key_index =
WeakHashTable::EntryToIndex(i) + WeakHashTable::kEntryKeyIndex;
int value_index = WeakHashTable::EntryToValueIndex(i);
SetWeakReference(table, entry, key_index, table->get(key_index),
table->OffsetOfElementAt(key_index));
SetInternalReference(table, entry, value_index, table->get(value_index),
table->OffsetOfElementAt(value_index));
// TODO(alph): Add a strong link (shortcut?) from key to value per
// WeakMap the key was added to. See crbug.com/778739
} }
break; break;
}
// TODO(alph): Add special processing for other types of FixedArrays. // TODO(alph): Add special processing for other types of FixedArrays.

View File

@ -558,7 +558,7 @@ TEST(HeapSnapshotWeakCollection) {
++weak_entries; ++weak_entries;
} }
} }
CHECK_EQ(2, weak_entries); CHECK_EQ(1, weak_entries); // Key is the only weak.
const v8::HeapGraphNode* wm_s = const v8::HeapGraphNode* wm_s =
GetProperty(env->GetIsolate(), wm, v8::HeapGraphEdge::kProperty, "str"); GetProperty(env->GetIsolate(), wm, v8::HeapGraphEdge::kProperty, "str");
CHECK(wm_s); CHECK(wm_s);