Skip to content

Commit 3b4ca91

Browse files
tunztunamagur0
authored andcommitted
deps: V8: cherry-pick c172ffc5bf54
Original commit message: Compact retained maps array more often When we add maps to the retained maps array, we compacted the array if it's full. But, since we are now adding maps in a batch, it's unlikely to meet the condition. Thus, update the condition to check whether new size exceeds the capacity. Bug: 398528460 Change-Id: I89caa47b69532c6397596edfe5caf7c7d24768cc Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/6330019 Reviewed-by: Michael Lippautz <[email protected]> Commit-Queue: Choongwoo Han <[email protected]> Cr-Commit-Position: refs/heads/main@{#99163} Refs: v8/v8@c172ffc PR-URL: nodejs#57437 Fixes: nodejs#57412 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Richard Lau <[email protected]> Co-Authored-By: tunamagur0 <[email protected]>
1 parent bd55b2d commit 3b4ca91

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

common.gypi

Lines changed: 1 addition & 1 deletion
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.13',
41+
'v8_embedder_string': '-node.14',
4242

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

deps/v8/src/heap/heap.cc

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6270,12 +6270,13 @@ void Heap::AddRetainedMaps(DirectHandle<NativeContext> context,
62706270
GlobalHandleVector<Map> maps) {
62716271
Handle<WeakArrayList> array(Cast<WeakArrayList>(context->retained_maps()),
62726272
isolate());
6273-
if (array->IsFull()) {
6273+
int new_maps_size = static_cast<int>(maps.size()) * kRetainMapEntrySize;
6274+
if (array->length() + new_maps_size > array->capacity()) {
62746275
CompactRetainedMaps(*array);
62756276
}
62766277
int cur_length = array->length();
6277-
array = WeakArrayList::EnsureSpace(
6278-
isolate(), array, cur_length + static_cast<int>(maps.size()) * 2);
6278+
array =
6279+
WeakArrayList::EnsureSpace(isolate(), array, cur_length + new_maps_size);
62796280
if (*array != context->retained_maps()) {
62806281
context->set_retained_maps(*array);
62816282
}
@@ -6293,7 +6294,7 @@ void Heap::AddRetainedMaps(DirectHandle<NativeContext> context,
62936294
raw_array->Set(cur_length, MakeWeak(*map));
62946295
raw_array->Set(cur_length + 1,
62956296
Smi::FromInt(v8_flags.retain_maps_for_n_gc));
6296-
cur_length += 2;
6297+
cur_length += kRetainMapEntrySize;
62976298
raw_array->set_length(cur_length);
62986299

62996300
map->set_is_in_retained_map_list(true);
@@ -6305,7 +6306,7 @@ void Heap::CompactRetainedMaps(Tagged<WeakArrayList> retained_maps) {
63056306
int length = retained_maps->length();
63066307
int new_length = 0;
63076308
// This loop compacts the array by removing cleared weak cells.
6308-
for (int i = 0; i < length; i += 2) {
6309+
for (int i = 0; i < length; i += kRetainMapEntrySize) {
63096310
Tagged<MaybeObject> maybe_object = retained_maps->Get(i);
63106311
if (maybe_object.IsCleared()) {
63116312
continue;
@@ -6319,7 +6320,7 @@ void Heap::CompactRetainedMaps(Tagged<WeakArrayList> retained_maps) {
63196320
retained_maps->Set(new_length, maybe_object);
63206321
retained_maps->Set(new_length + 1, age);
63216322
}
6322-
new_length += 2;
6323+
new_length += kRetainMapEntrySize;
63236324
}
63246325
Tagged<HeapObject> undefined = ReadOnlyRoots(this).undefined_value();
63256326
for (int i = new_length; i < length; i++) {

deps/v8/src/heap/heap.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1802,6 +1802,8 @@ class Heap final {
18021802
void AddToRingBuffer(const char* string);
18031803
void GetFromRingBuffer(char* buffer);
18041804

1805+
static constexpr int kRetainMapEntrySize = 2;
1806+
18051807
void CompactRetainedMaps(Tagged<WeakArrayList> retained_maps);
18061808

18071809
void CollectGarbageOnMemoryPressure();

0 commit comments

Comments
 (0)