Skip to content

Commit d3a1a5b

Browse files
Dominik InführCommit Bot
authored andcommitted
[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 <ulan@chromium.org> Reviewed-by: Igor Sheludko <ishell@chromium.org> Commit-Queue: Dominik Inführ <dinfuehr@chromium.org> Cr-Commit-Position: refs/heads/master@{#65456}
1 parent bf8d8f1 commit d3a1a5b

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

src/objects/objects.cc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4044,6 +4044,13 @@ Handle<WeakArrayList> PrototypeUsers::Add(Isolate* isolate,
40444044

40454045
// If there are empty slots, use one of them.
40464046
int empty_slot = Smi::ToInt(empty_slot_index(*array));
4047+
4048+
if (empty_slot == kNoEmptySlotsMarker) {
4049+
// GCs might have cleared some references, rescan the array for empty slots.
4050+
PrototypeUsers::ScanForEmptySlots(*array);
4051+
empty_slot = Smi::ToInt(empty_slot_index(*array));
4052+
}
4053+
40474054
if (empty_slot != kNoEmptySlotsMarker) {
40484055
DCHECK_GE(empty_slot, kFirstIndex);
40494056
CHECK_LT(empty_slot, array->length());
@@ -4066,6 +4073,15 @@ Handle<WeakArrayList> PrototypeUsers::Add(Isolate* isolate,
40664073
return array;
40674074
}
40684075

4076+
// static
4077+
void PrototypeUsers::ScanForEmptySlots(WeakArrayList array) {
4078+
for (int i = kFirstIndex; i < array.length(); i++) {
4079+
if (array.Get(i)->IsCleared()) {
4080+
PrototypeUsers::MarkSlotEmpty(array, i);
4081+
}
4082+
}
4083+
}
4084+
40694085
WeakArrayList PrototypeUsers::Compact(Handle<WeakArrayList> array, Heap* heap,
40704086
CompactionCallback callback,
40714087
AllocationType allocation) {

src/objects/prototype-info.h

Lines changed: 1 addition & 1 deletion
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)