Index: src/objects.cc |
diff --git a/src/objects.cc b/src/objects.cc |
index 9f7524ccefb7a4dc85ae9ee1677840b14e8d1bad..3d8f3d5c99500ee4dd7034a82052b5f1d9ecec64 100644 |
--- a/src/objects.cc |
+++ b/src/objects.cc |
@@ -17747,6 +17747,19 @@ Handle<ObjectHashTable> ObjectHashTable::Put(Handle<ObjectHashTable> table, |
if ((table->NumberOfDeletedElements() << 1) > table->NumberOfElements()) { |
table->Rehash(isolate->factory()->undefined_value()); |
} |
+ // If we're out of luck, we didn't get a GC recently, and so rehashing |
+ // isn't enough to avoid a crash. |
+ int nof = table->NumberOfElements() + 1; |
+ if (!table->HasSufficientCapacity(nof)) { |
+ int capacity = ObjectHashTable::ComputeCapacity(nof * 2); |
+ if (capacity > ObjectHashTable::kMaxCapacity) { |
+ for (size_t i = 0; i < 2; ++i) { |
+ isolate->heap()->CollectAllGarbage( |
+ Heap::kFinalizeIncrementalMarkingMask, "full object hash table"); |
+ } |
+ table->Rehash(isolate->factory()->undefined_value()); |
+ } |
+ } |
// Check whether the hash table should be extended. |
table = EnsureCapacity(table, 1, key); |