Skip to content

Commit 7e13ae7

Browse files
targosBridgeAR
authored andcommittedJan 3, 2020
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 afecc97 commit 7e13ae7

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
@@ -39,7 +39,7 @@
3939

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

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

‎deps/v8/src/objects/objects.cc

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

40394039
// If there are empty slots, use one of them.
40404040
int empty_slot = Smi::ToInt(empty_slot_index(*array));
4041+
4042+
if (empty_slot == kNoEmptySlotsMarker) {
4043+
// GCs might have cleared some references, rescan the array for empty slots.
4044+
PrototypeUsers::ScanForEmptySlots(*array);
4045+
empty_slot = Smi::ToInt(empty_slot_index(*array));
4046+
}
4047+
40414048
if (empty_slot != kNoEmptySlotsMarker) {
40424049
DCHECK_GE(empty_slot, kFirstIndex);
40434050
CHECK_LT(empty_slot, array->length());
@@ -4060,6 +4067,15 @@ Handle<WeakArrayList> PrototypeUsers::Add(Isolate* isolate,
40604067
return array;
40614068
}
40624069

4070+
// static
4071+
void PrototypeUsers::ScanForEmptySlots(WeakArrayList array) {
4072+
for (int i = kFirstIndex; i < array.length(); i++) {
4073+
if (array.Get(i)->IsCleared()) {
4074+
PrototypeUsers::MarkSlotEmpty(array, i);
4075+
}
4076+
}
4077+
}
4078+
40634079
WeakArrayList PrototypeUsers::Compact(Handle<WeakArrayList> array, Heap* heap,
40644080
CompactionCallback callback,
40654081
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)