From c004cf51c6c096d3cf485ab978d1dcfebfaba451 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Zasso?= Date: Tue, 17 Dec 2019 17:44:07 +0100 Subject: [PATCH] deps: V8: cherry-pick d3a1a5b6c491 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Original commit message: [objects] Fix memory leak in PrototypeUsers::Add PrototypeUsers::Add now iterates the WeakArrayList to find empty slots before growing the array. Not reusing empty slots caused a memory leak. It might also be desirable to shrink the WeakArrayList in the future. Right now it is only compacted when invoking CreateBlob. Also removed unused PrototypeUsers::IsEmptySlot declaration. Bug: v8:10031 Change-Id: I570ec78fca37e8f0c794f1f40846a4daab47c225 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1967317 Reviewed-by: Ulan Degenbaev Reviewed-by: Igor Sheludko Commit-Queue: Dominik Inführ Cr-Commit-Position: refs/heads/master@{#65456} Refs: https://github.com/v8/v8/commit/d3a1a5b6c4916f22e076e3349ed3619bfb014f29 Fixes: https://github.com/nodejs/node/issues/30753 PR-URL: https://github.com/nodejs/node/pull/31005 Reviewed-By: Richard Lau Reviewed-By: Colin Ihrig Reviewed-By: Gus Caplan Reviewed-By: Ben Noordhuis Reviewed-By: Rich Trott --- common.gypi | 2 +- deps/v8/src/objects/objects.cc | 16 ++++++++++++++++ deps/v8/src/objects/prototype-info.h | 2 +- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/common.gypi b/common.gypi index bdb1f7b32bf08b..7f7f4cc3fb3926 100644 --- a/common.gypi +++ b/common.gypi @@ -38,7 +38,7 @@ # Reset this number to 0 on major V8 upgrades. # Increment by one for each non-official patch applied to deps/v8. - 'v8_embedder_string': '-node.24', + 'v8_embedder_string': '-node.25', ##### V8 defaults for Node.js ##### diff --git a/deps/v8/src/objects/objects.cc b/deps/v8/src/objects/objects.cc index 134cb3998a5585..58cf79b84feb11 100644 --- a/deps/v8/src/objects/objects.cc +++ b/deps/v8/src/objects/objects.cc @@ -4025,6 +4025,13 @@ Handle PrototypeUsers::Add(Isolate* isolate, // If there are empty slots, use one of them. int empty_slot = Smi::ToInt(empty_slot_index(*array)); + + if (empty_slot == kNoEmptySlotsMarker) { + // GCs might have cleared some references, rescan the array for empty slots. + PrototypeUsers::ScanForEmptySlots(*array); + empty_slot = Smi::ToInt(empty_slot_index(*array)); + } + if (empty_slot != kNoEmptySlotsMarker) { DCHECK_GE(empty_slot, kFirstIndex); CHECK_LT(empty_slot, array->length()); @@ -4047,6 +4054,15 @@ Handle PrototypeUsers::Add(Isolate* isolate, return array; } +// static +void PrototypeUsers::ScanForEmptySlots(WeakArrayList array) { + for (int i = kFirstIndex; i < array.length(); i++) { + if (array.Get(i)->IsCleared()) { + PrototypeUsers::MarkSlotEmpty(array, i); + } + } +} + WeakArrayList PrototypeUsers::Compact(Handle array, Heap* heap, CompactionCallback callback, AllocationType allocation) { diff --git a/deps/v8/src/objects/prototype-info.h b/deps/v8/src/objects/prototype-info.h index 94d86d2e1931c3..6f777eda8936c8 100644 --- a/deps/v8/src/objects/prototype-info.h +++ b/deps/v8/src/objects/prototype-info.h @@ -99,7 +99,7 @@ class V8_EXPORT_PRIVATE PrototypeUsers : public WeakArrayList { static inline Smi empty_slot_index(WeakArrayList array); static inline void set_empty_slot_index(WeakArrayList array, int index); - static void IsSlotEmpty(WeakArrayList array, int index); + static void ScanForEmptySlots(WeakArrayList array); DISALLOW_IMPLICIT_CONSTRUCTORS(PrototypeUsers); };