Skip to content

Commit 43bea6b

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 91a824e commit 43bea6b

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.13',
41+
'v8_embedder_string': '-node.14',
4242

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

deps/v8/src/heap/heap.cc

+7-6
Original file line numberDiff line numberDiff line change
@@ -6376,12 +6376,13 @@ void Heap::AddRetainedMaps(DirectHandle<NativeContext> context,
63766376
GlobalHandleVector<Map> maps) {
63776377
Handle<WeakArrayList> array(Cast<WeakArrayList>(context->retained_maps()),
63786378
isolate());
6379-
if (array->IsFull()) {
6379+
int new_maps_size = static_cast<int>(maps.size()) * kRetainMapEntrySize;
6380+
if (array->length() + new_maps_size > array->capacity()) {
63806381
CompactRetainedMaps(*array);
63816382
}
63826383
int cur_length = array->length();
6383-
array = WeakArrayList::EnsureSpace(
6384-
isolate(), array, cur_length + static_cast<int>(maps.size()) * 2);
6384+
array =
6385+
WeakArrayList::EnsureSpace(isolate(), array, cur_length + new_maps_size);
63856386
if (*array != context->retained_maps()) {
63866387
context->set_retained_maps(*array);
63876388
}
@@ -6399,7 +6400,7 @@ void Heap::AddRetainedMaps(DirectHandle<NativeContext> context,
63996400
raw_array->Set(cur_length, MakeWeak(*map));
64006401
raw_array->Set(cur_length + 1,
64016402
Smi::FromInt(v8_flags.retain_maps_for_n_gc));
6402-
cur_length += 2;
6403+
cur_length += kRetainMapEntrySize;
64036404
raw_array->set_length(cur_length);
64046405

64056406
map->set_is_in_retained_map_list(true);
@@ -6411,7 +6412,7 @@ void Heap::CompactRetainedMaps(Tagged<WeakArrayList> retained_maps) {
64116412
int length = retained_maps->length();
64126413
int new_length = 0;
64136414
// This loop compacts the array by removing cleared weak cells.
6414-
for (int i = 0; i < length; i += 2) {
6415+
for (int i = 0; i < length; i += kRetainMapEntrySize) {
64156416
Tagged<MaybeObject> maybe_object = retained_maps->Get(i);
64166417
if (maybe_object.IsCleared()) {
64176418
continue;
@@ -6425,7 +6426,7 @@ void Heap::CompactRetainedMaps(Tagged<WeakArrayList> retained_maps) {
64256426
retained_maps->Set(new_length, maybe_object);
64266427
retained_maps->Set(new_length + 1, age);
64276428
}
6428-
new_length += 2;
6429+
new_length += kRetainMapEntrySize;
64296430
}
64306431
Tagged<HeapObject> undefined = ReadOnlyRoots(this).undefined_value();
64316432
for (int i = new_length; i < length; i++) {

deps/v8/src/heap/heap.h

+2
Original file line numberDiff line numberDiff line change
@@ -1830,6 +1830,8 @@ class Heap final {
18301830
void AddToRingBuffer(const char* string);
18311831
void GetFromRingBuffer(char* buffer);
18321832

1833+
static constexpr int kRetainMapEntrySize = 2;
1834+
18331835
void CompactRetainedMaps(Tagged<WeakArrayList> retained_maps);
18341836

18351837
void CollectGarbageOnMemoryPressure();

0 commit comments

Comments
 (0)