Commit e093a047 authored by jochen's avatar jochen Committed by Commit bot

Rehash and clear deleted entries in weak collections during GC

Otherwise, they'll just keep growing until we run out of memory or hit the FixedArray's maximum capacity.

BUG=v8:4909
R=hpayer@chromium.org
LOG=n

Review URL: https://codereview.chromium.org/1877233005

Cr-Commit-Position: refs/heads/master@{#35514}
parent 71453f1c
......@@ -2572,6 +2572,13 @@ void MarkCompactCollector::ClearWeakCollections() {
table->RemoveEntry(i);
}
}
// Rehash if more than 25% of the entries are deleted entries.
// TODO(jochen): Consider to shrink the fixed array in place.
if ((table->NumberOfDeletedElements() << kJSWeakCollectionLoadFactorExp) >
table->NumberOfElements()) {
HandleScope scope(heap()->isolate());
table->Rehash(heap()->isolate()->factory()->undefined_value());
}
}
weak_collection_obj = weak_collection->next();
weak_collection->set_next(heap()->undefined_value());
......
......@@ -512,6 +512,10 @@ class MarkCompactCollector {
static const uint32_t kSingleFreeEncoding = 0;
static const uint32_t kMultiFreeEncoding = 1;
// If the number of deleted slots in a JSWeakCollection exceeds the number
// of entries / 2^(factor), we rehash the table.
static const int kJSWeakCollectionLoadFactorExp = 1;
static inline bool IsMarked(Object* obj);
static bool IsUnmarkedHeapObjectWithHeap(Heap* heap, Object** p);
......
......@@ -16860,6 +16860,16 @@ void HashTable<Derived, Shape, Key>::Rehash(Key key) {
}
}
}
// Wipe deleted entries.
Heap* heap = GetHeap();
Object* the_hole = heap->the_hole_value();
Object* undefined = heap->undefined_value();
for (uint32_t current = 0; current < capacity; current++) {
if (get(EntryToIndex(current)) == the_hole) {
set(EntryToIndex(current), undefined);
}
}
SetNumberOfDeletedElements(0);
}
......
......@@ -124,7 +124,7 @@ TEST(Weakness) {
heap->CollectAllGarbage(false);
CHECK_EQ(1, NumberOfWeakCalls);
CHECK_EQ(0, ObjectHashTable::cast(weakmap->table())->NumberOfElements());
CHECK_EQ(2,
CHECK_EQ(0,
ObjectHashTable::cast(weakmap->table())->NumberOfDeletedElements());
}
......
......@@ -123,8 +123,8 @@ TEST(WeakSet_Weakness) {
heap->CollectAllGarbage(false);
CHECK_EQ(1, NumberOfWeakCalls);
CHECK_EQ(0, ObjectHashTable::cast(weakset->table())->NumberOfElements());
CHECK_EQ(
1, ObjectHashTable::cast(weakset->table())->NumberOfDeletedElements());
CHECK_EQ(0,
ObjectHashTable::cast(weakset->table())->NumberOfDeletedElements());
}
......
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