Skip to content

Commit 2d07fd7

Browse files
ofrobotsMylesBorins
authored andcommitted
deps: backport e093a04, 09db540 from upstream V8
Original commit messages: v8/v8@e093a04 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 [email protected] LOG=n Review URL: https://codereview.chromium.org/1877233005 Cr-Commit-Position: refs/heads/master@{#35514} v8/v8@09db540 Reland of Rehash and clear deleted entries in weak collections during GC BUG=v8:4909 [email protected],[email protected] LOG=n Review URL: https://codereview.chromium.org/1890123002 Cr-Commit-Position: refs/heads/master@{#35538} Ref: https://crbug.com/v8/4909 Ref: #7883 Fixes: #6180 PR-URL: #7689 Reviewed-By: Matt Loring <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]>
1 parent 52bb377 commit 2d07fd7

File tree

6 files changed

+42
-4
lines changed

6 files changed

+42
-4
lines changed

deps/v8/include/v8-version.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#define V8_MAJOR_VERSION 4
1212
#define V8_MINOR_VERSION 5
1313
#define V8_BUILD_NUMBER 103
14-
#define V8_PATCH_LEVEL 38
14+
#define V8_PATCH_LEVEL 39
1515

1616
// Use 1 for candidates and 0 otherwise.
1717
// (Boolean macro values are not supported by all preprocessors.)

deps/v8/src/heap/mark-compact.cc

+7
Original file line numberDiff line numberDiff line change
@@ -2614,6 +2614,13 @@ void MarkCompactCollector::ClearWeakCollections() {
26142614
table->RemoveEntry(i);
26152615
}
26162616
}
2617+
// Rehash if more than 25% of the entries are deleted entries.
2618+
// TODO(jochen): Consider to shrink the fixed array in place.
2619+
if ((table->NumberOfDeletedElements() << kJSWeakCollectionLoadFactorExp) >
2620+
table->NumberOfElements()) {
2621+
HandleScope scope(heap()->isolate());
2622+
table->Rehash(heap()->isolate()->factory()->undefined_value());
2623+
}
26172624
}
26182625
weak_collection_obj = weak_collection->next();
26192626
weak_collection->set_next(heap()->undefined_value());

deps/v8/src/heap/mark-compact.h

+4
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,10 @@ class MarkCompactCollector {
612612
static const uint32_t kSingleFreeEncoding = 0;
613613
static const uint32_t kMultiFreeEncoding = 1;
614614

615+
// If the number of deleted slots in a JSWeakCollection exceeds the number
616+
// of entries / 2^(factor), we rehash the table.
617+
static const int kJSWeakCollectionLoadFactorExp = 1;
618+
615619
static inline bool IsMarked(Object* obj);
616620
static bool IsUnmarkedHeapObjectWithHeap(Heap* heap, Object** p);
617621

deps/v8/src/objects.cc

+27
Original file line numberDiff line numberDiff line change
@@ -13744,6 +13744,16 @@ void HashTable<Derived, Shape, Key>::Rehash(Key key) {
1374413744
}
1374513745
}
1374613746
}
13747+
// Wipe deleted entries.
13748+
Heap* heap = GetHeap();
13749+
Object* the_hole = heap->the_hole_value();
13750+
Object* undefined = heap->undefined_value();
13751+
for (uint32_t current = 0; current < capacity; current++) {
13752+
if (get(EntryToIndex(current)) == the_hole) {
13753+
set(EntryToIndex(current), undefined);
13754+
}
13755+
}
13756+
SetNumberOfDeletedElements(0);
1374713757
}
1374813758

1374913759

@@ -14656,6 +14666,7 @@ Handle<CompilationCacheTable> CompilationCacheTable::PutRegExp(
1465614666
void CompilationCacheTable::Age() {
1465714667
DisallowHeapAllocation no_allocation;
1465814668
Object* the_hole_value = GetHeap()->the_hole_value();
14669+
uint32_t capacity = Capacity();
1465914670
for (int entry = 0, size = Capacity(); entry < size; entry++) {
1466014671
int entry_index = EntryToIndex(entry);
1466114672
int value_index = entry_index + 1;
@@ -14679,6 +14690,16 @@ void CompilationCacheTable::Age() {
1467914690
}
1468014691
}
1468114692
}
14693+
// Wipe deleted entries.
14694+
Heap* heap = GetHeap();
14695+
Object* the_hole = heap->the_hole_value();
14696+
Object* undefined = heap->undefined_value();
14697+
for (uint32_t current = 0; current < capacity; current++) {
14698+
if (get(EntryToIndex(current)) == the_hole) {
14699+
set(EntryToIndex(current), undefined);
14700+
}
14701+
}
14702+
SetNumberOfDeletedElements(0);
1468214703
}
1468314704

1468414705

@@ -15187,6 +15208,12 @@ Handle<ObjectHashTable> ObjectHashTable::Put(Handle<ObjectHashTable> table,
1518715208
return table;
1518815209
}
1518915210

15211+
// Rehash if more than 25% of the entries are deleted entries.
15212+
// TODO(jochen): Consider to shrink the fixed array in place.
15213+
if ((table->NumberOfDeletedElements() << 1) > table->NumberOfElements()) {
15214+
table->Rehash(isolate->factory()->undefined_value());
15215+
}
15216+
1519015217
// Check whether the hash table should be extended.
1519115218
table = EnsureCapacity(table, 1, key);
1519215219
table->AddEntry(table->FindInsertionEntry(hash), *key, *value);

deps/v8/test/cctest/test-weakmaps.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ TEST(Weakness) {
123123
heap->CollectAllGarbage(false);
124124
CHECK_EQ(1, NumberOfWeakCalls);
125125
CHECK_EQ(0, ObjectHashTable::cast(weakmap->table())->NumberOfElements());
126-
CHECK_EQ(2,
126+
CHECK_EQ(0,
127127
ObjectHashTable::cast(weakmap->table())->NumberOfDeletedElements());
128128
}
129129

deps/v8/test/cctest/test-weaksets.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ TEST(WeakSet_Weakness) {
122122
heap->CollectAllGarbage(false);
123123
CHECK_EQ(1, NumberOfWeakCalls);
124124
CHECK_EQ(0, ObjectHashTable::cast(weakset->table())->NumberOfElements());
125-
CHECK_EQ(
126-
1, ObjectHashTable::cast(weakset->table())->NumberOfDeletedElements());
125+
CHECK_EQ(0,
126+
ObjectHashTable::cast(weakset->table())->NumberOfDeletedElements());
127127
}
128128

129129

0 commit comments

Comments
 (0)