Skip to content

Commit 09db540

Browse files
jeisingerCommit bot
authored andcommitted
Reland of Rehash and clear deleted entries in weak collections during GC
BUG=v8:4909 R=hpayer@chromium.org,ulan@chromium.org LOG=n Review URL: https://codereview.chromium.org/1890123002 Cr-Commit-Position: refs/heads/master@{#35538}
1 parent 146400a commit 09db540

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/objects.cc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16867,6 +16867,16 @@ void HashTable<Derived, Shape, Key>::Rehash(Key key) {
1686716867
}
1686816868
}
1686916869
}
16870+
// Wipe deleted entries.
16871+
Heap* heap = GetHeap();
16872+
Object* the_hole = heap->the_hole_value();
16873+
Object* undefined = heap->undefined_value();
16874+
for (uint32_t current = 0; current < capacity; current++) {
16875+
if (get(EntryToIndex(current)) == the_hole) {
16876+
set(EntryToIndex(current), undefined);
16877+
}
16878+
}
16879+
SetNumberOfDeletedElements(0);
1687016880
}
1687116881

1687216882

@@ -18229,6 +18239,12 @@ Handle<ObjectHashTable> ObjectHashTable::Put(Handle<ObjectHashTable> table,
1822918239
return table;
1823018240
}
1823118241

18242+
// Rehash if more than 25% of the entries are deleted entries.
18243+
// TODO(jochen): Consider to shrink the fixed array in place.
18244+
if ((table->NumberOfDeletedElements() << 1) > table->NumberOfElements()) {
18245+
table->Rehash(isolate->factory()->undefined_value());
18246+
}
18247+
1823218248
// Check whether the hash table should be extended.
1823318249
table = EnsureCapacity(table, 1, key);
1823418250
table->AddEntry(table->FindInsertionEntry(hash), *key, *value);

0 commit comments

Comments
 (0)