Skip to content

Commit

Permalink
Re-apply 2d07fd7 more conservatively.
Browse files Browse the repository at this point in the history
I think this matches up more precisely with the original intention, though I
may be completely wrong.  Notably though, this leaves out the rehashing which
uses kJSWeakCollectionLoadFactorExp.
  • Loading branch information
abernix committed Aug 11, 2017
1 parent 49d20c5 commit 7841772
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
17 changes: 17 additions & 0 deletions deps/v8/src/objects.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14667,6 +14667,7 @@ Handle<CompilationCacheTable> CompilationCacheTable::PutRegExp(
void CompilationCacheTable::Age() {
DisallowHeapAllocation no_allocation;
Object* the_hole_value = GetHeap()->the_hole_value();
uint32_t capacity = Capacity();
for (int entry = 0, size = Capacity(); entry < size; entry++) {
int entry_index = EntryToIndex(entry);
int value_index = entry_index + 1;
Expand All @@ -14690,6 +14691,16 @@ void CompilationCacheTable::Age() {
}
}
}
// 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);
}


Expand Down Expand Up @@ -15212,6 +15223,12 @@ Handle<ObjectHashTable> ObjectHashTable::Put(Handle<ObjectHashTable> table,
}
}

// Rehash if more than 25% of the entries are deleted entries.
// TODO(jochen): Consider to shrink the fixed array in place.
if ((table->NumberOfDeletedElements() << 1) > table->NumberOfElements()) {
table->Rehash(isolate->factory()->undefined_value());
}

// Check whether the hash table should be extended.
table = EnsureCapacity(table, 1, key);
table->AddEntry(table->FindInsertionEntry(hash), *key, *value);
Expand Down
2 changes: 1 addition & 1 deletion deps/v8/test/cctest/test-weakmaps.cc
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,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());
}

Expand Down
4 changes: 2 additions & 2 deletions deps/v8/test/cctest/test-weaksets.cc
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,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());
}


Expand Down

0 comments on commit 7841772

Please sign in to comment.