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 <mlippautz@chromium.org>
    Commit-Queue: Choongwoo Han <choongwoo.han@microsoft.com>
    Cr-Commit-Position: refs/heads/main@{#99163}

Refs: c172ffc5bf
PR-URL: https://github.com/nodejs/node/pull/57437
Fixes: https://github.com/nodejs/node/issues/57412
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Richard Lau <rlau@redhat.com>
Co-Authored-By: tunamagur0
  <47546832+tunamagur0@users.noreply.github.com>
This commit is contained in:
Choongwoo Han 2025-03-06 07:02:23 -08:00 committed by Antoine du Hamel
parent ee0a006a20
commit 2cb1d07e0f
No known key found for this signature in database
GPG Key ID: 21D900FFDB233756
3 changed files with 10 additions and 7 deletions

View File

@ -38,7 +38,7 @@
# Reset this number to 0 on major V8 upgrades. # Reset this number to 0 on major V8 upgrades.
# Increment by one for each non-official patch applied to deps/v8. # Increment by one for each non-official patch applied to deps/v8.
'v8_embedder_string': '-node.11', 'v8_embedder_string': '-node.12',
##### V8 defaults for Node.js ##### ##### V8 defaults for Node.js #####

View File

@ -6356,12 +6356,13 @@ void Heap::AddRetainedMaps(DirectHandle<NativeContext> context,
GlobalHandleVector<Map> maps) { GlobalHandleVector<Map> maps) {
Handle<WeakArrayList> array(Cast<WeakArrayList>(context->retained_maps()), Handle<WeakArrayList> array(Cast<WeakArrayList>(context->retained_maps()),
isolate()); isolate());
if (array->IsFull()) { int new_maps_size = static_cast<int>(maps.size()) * kRetainMapEntrySize;
if (array->length() + new_maps_size > array->capacity()) {
CompactRetainedMaps(*array); CompactRetainedMaps(*array);
} }
int cur_length = array->length(); int cur_length = array->length();
array = WeakArrayList::EnsureSpace( array =
isolate(), array, cur_length + static_cast<int>(maps.size()) * 2); WeakArrayList::EnsureSpace(isolate(), array, cur_length + new_maps_size);
if (*array != context->retained_maps()) { if (*array != context->retained_maps()) {
context->set_retained_maps(*array); context->set_retained_maps(*array);
} }
@ -6379,7 +6380,7 @@ void Heap::AddRetainedMaps(DirectHandle<NativeContext> context,
raw_array->Set(cur_length, MakeWeak(*map)); raw_array->Set(cur_length, MakeWeak(*map));
raw_array->Set(cur_length + 1, raw_array->Set(cur_length + 1,
Smi::FromInt(v8_flags.retain_maps_for_n_gc)); Smi::FromInt(v8_flags.retain_maps_for_n_gc));
cur_length += 2; cur_length += kRetainMapEntrySize;
raw_array->set_length(cur_length); raw_array->set_length(cur_length);
map->set_is_in_retained_map_list(true); map->set_is_in_retained_map_list(true);
@ -6391,7 +6392,7 @@ void Heap::CompactRetainedMaps(Tagged<WeakArrayList> retained_maps) {
int length = retained_maps->length(); int length = retained_maps->length();
int new_length = 0; int new_length = 0;
// This loop compacts the array by removing cleared weak cells. // This loop compacts the array by removing cleared weak cells.
for (int i = 0; i < length; i += 2) { for (int i = 0; i < length; i += kRetainMapEntrySize) {
Tagged<MaybeObject> maybe_object = retained_maps->Get(i); Tagged<MaybeObject> maybe_object = retained_maps->Get(i);
if (maybe_object.IsCleared()) { if (maybe_object.IsCleared()) {
continue; continue;
@ -6405,7 +6406,7 @@ void Heap::CompactRetainedMaps(Tagged<WeakArrayList> retained_maps) {
retained_maps->Set(new_length, maybe_object); retained_maps->Set(new_length, maybe_object);
retained_maps->Set(new_length + 1, age); retained_maps->Set(new_length + 1, age);
} }
new_length += 2; new_length += kRetainMapEntrySize;
} }
Tagged<HeapObject> undefined = ReadOnlyRoots(this).undefined_value(); Tagged<HeapObject> undefined = ReadOnlyRoots(this).undefined_value();
for (int i = new_length; i < length; i++) { for (int i = new_length; i < length; i++) {

View File

@ -1812,6 +1812,8 @@ class Heap final {
void AddToRingBuffer(const char* string); void AddToRingBuffer(const char* string);
void GetFromRingBuffer(char* buffer); void GetFromRingBuffer(char* buffer);
static constexpr int kRetainMapEntrySize = 2;
void CompactRetainedMaps(Tagged<WeakArrayList> retained_maps); void CompactRetainedMaps(Tagged<WeakArrayList> retained_maps);
void CollectGarbageOnMemoryPressure(); void CollectGarbageOnMemoryPressure();