Skip to content

Commit 2cb1d07

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: #57437 Fixes: #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 ee0a006 commit 2cb1d07

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
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.11',
41+
'v8_embedder_string': '-node.12',
4242

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

deps/v8/src/heap/heap.cc

+7-6
Original file line numberDiff line numberDiff line change
@@ -6356,12 +6356,13 @@ void Heap::AddRetainedMaps(DirectHandle<NativeContext> context,
63566356
GlobalHandleVector<Map> maps) {
63576357
Handle<WeakArrayList> array(Cast<WeakArrayList>(context->retained_maps()),
63586358
isolate());
6359-
if (array->IsFull()) {
6359+
int new_maps_size = static_cast<int>(maps.size()) * kRetainMapEntrySize;
6360+
if (array->length() + new_maps_size > array->capacity()) {
63606361
CompactRetainedMaps(*array);
63616362
}
63626363
int cur_length = array->length();
6363-
array = WeakArrayList::EnsureSpace(
6364-
isolate(), array, cur_length + static_cast<int>(maps.size()) * 2);
6364+
array =
6365+
WeakArrayList::EnsureSpace(isolate(), array, cur_length + new_maps_size);
63656366
if (*array != context->retained_maps()) {
63666367
context->set_retained_maps(*array);
63676368
}
@@ -6379,7 +6380,7 @@ void Heap::AddRetainedMaps(DirectHandle<NativeContext> context,
63796380
raw_array->Set(cur_length, MakeWeak(*map));
63806381
raw_array->Set(cur_length + 1,
63816382
Smi::FromInt(v8_flags.retain_maps_for_n_gc));
6382-
cur_length += 2;
6383+
cur_length += kRetainMapEntrySize;
63836384
raw_array->set_length(cur_length);
63846385

63856386
map->set_is_in_retained_map_list(true);
@@ -6391,7 +6392,7 @@ void Heap::CompactRetainedMaps(Tagged<WeakArrayList> retained_maps) {
63916392
int length = retained_maps->length();
63926393
int new_length = 0;
63936394
// This loop compacts the array by removing cleared weak cells.
6394-
for (int i = 0; i < length; i += 2) {
6395+
for (int i = 0; i < length; i += kRetainMapEntrySize) {
63956396
Tagged<MaybeObject> maybe_object = retained_maps->Get(i);
63966397
if (maybe_object.IsCleared()) {
63976398
continue;
@@ -6405,7 +6406,7 @@ void Heap::CompactRetainedMaps(Tagged<WeakArrayList> retained_maps) {
64056406
retained_maps->Set(new_length, maybe_object);
64066407
retained_maps->Set(new_length + 1, age);
64076408
}
6408-
new_length += 2;
6409+
new_length += kRetainMapEntrySize;
64096410
}
64106411
Tagged<HeapObject> undefined = ReadOnlyRoots(this).undefined_value();
64116412
for (int i = new_length; i < length; i++) {

deps/v8/src/heap/heap.h

+2
Original file line numberDiff line numberDiff line change
@@ -1812,6 +1812,8 @@ class Heap final {
18121812
void AddToRingBuffer(const char* string);
18131813
void GetFromRingBuffer(char* buffer);
18141814

1815+
static constexpr int kRetainMapEntrySize = 2;
1816+
18151817
void CompactRetainedMaps(Tagged<WeakArrayList> retained_maps);
18161818

18171819
void CollectGarbageOnMemoryPressure();

0 commit comments

Comments
 (0)