Skip to content

Commit

Permalink
deps: backport e093a04, 09db540 from upstream V8
Browse files Browse the repository at this point in the history
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@{nodejs#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@{nodejs#35538}

V8-Bug: https://crbug.com/v8/4909
Fixes: nodejs#6180
  • Loading branch information
ofrobots committed Apr 15, 2016
1 parent 61167c3 commit 244cc9e
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 3 deletions.
7 changes: 7 additions & 0 deletions deps/v8/src/heap/mark-compact.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2587,6 +2587,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());
Expand Down
4 changes: 4 additions & 0 deletions deps/v8/src/heap/mark-compact.h
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,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);

Expand Down
26 changes: 26 additions & 0 deletions deps/v8/src/objects.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13483,6 +13483,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);
}


Expand Down Expand Up @@ -14292,6 +14302,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 @@ -14779,6 +14799,12 @@ Handle<ObjectHashTable> ObjectHashTable::Put(Handle<ObjectHashTable> table,
return 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 244cc9e

Please sign in to comment.