Skip to content

Commit ccf1178

Browse files
committed
deps: V8: cherry-pick d3a1a5b6c491
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 <[email protected]> Reviewed-by: Igor Sheludko <[email protected]> Commit-Queue: Dominik Inführ <[email protected]> Cr-Commit-Position: refs/heads/master@{#65456} Refs: v8/v8@d3a1a5b Fixes: #30753 PR-URL: #31005 Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Gus Caplan <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Rich Trott <[email protected]>
1 parent 9d2e8c5 commit ccf1178

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

common.gypi

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939
# Reset this number to 0 on major V8 upgrades.
4040
# Increment by one for each non-official patch applied to deps/v8.
41-
'v8_embedder_string': '-node.24',
41+
'v8_embedder_string': '-node.25',
4242

4343
##### V8 defaults for Node.js #####
4444

deps/v8/src/objects/objects.cc

+16
Original file line numberDiff line numberDiff line change
@@ -4025,6 +4025,13 @@ Handle<WeakArrayList> PrototypeUsers::Add(Isolate* isolate,
40254025

40264026
// If there are empty slots, use one of them.
40274027
int empty_slot = Smi::ToInt(empty_slot_index(*array));
4028+
4029+
if (empty_slot == kNoEmptySlotsMarker) {
4030+
// GCs might have cleared some references, rescan the array for empty slots.
4031+
PrototypeUsers::ScanForEmptySlots(*array);
4032+
empty_slot = Smi::ToInt(empty_slot_index(*array));
4033+
}
4034+
40284035
if (empty_slot != kNoEmptySlotsMarker) {
40294036
DCHECK_GE(empty_slot, kFirstIndex);
40304037
CHECK_LT(empty_slot, array->length());
@@ -4047,6 +4054,15 @@ Handle<WeakArrayList> PrototypeUsers::Add(Isolate* isolate,
40474054
return array;
40484055
}
40494056

4057+
// static
4058+
void PrototypeUsers::ScanForEmptySlots(WeakArrayList array) {
4059+
for (int i = kFirstIndex; i < array.length(); i++) {
4060+
if (array.Get(i)->IsCleared()) {
4061+
PrototypeUsers::MarkSlotEmpty(array, i);
4062+
}
4063+
}
4064+
}
4065+
40504066
WeakArrayList PrototypeUsers::Compact(Handle<WeakArrayList> array, Heap* heap,
40514067
CompactionCallback callback,
40524068
AllocationType allocation) {

deps/v8/src/objects/prototype-info.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class V8_EXPORT_PRIVATE PrototypeUsers : public WeakArrayList {
9999
static inline Smi empty_slot_index(WeakArrayList array);
100100
static inline void set_empty_slot_index(WeakArrayList array, int index);
101101

102-
static void IsSlotEmpty(WeakArrayList array, int index);
102+
static void ScanForEmptySlots(WeakArrayList array);
103103

104104
DISALLOW_IMPLICIT_CONSTRUCTORS(PrototypeUsers);
105105
};

0 commit comments

Comments
 (0)