@@ -6376,12 +6376,13 @@ void Heap::AddRetainedMaps(DirectHandle<NativeContext> context, |
6376 | 6376 | GlobalHandleVector<Map> maps) { |
6377 | 6377 | Handle<WeakArrayList> array(Cast<WeakArrayList>(context->retained_maps()), |
6378 | 6378 | 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()) { |
6380 | 6381 | CompactRetainedMaps(*array); |
6381 | 6382 | } |
6382 | 6383 | 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); |
6385 | 6386 | if (*array != context->retained_maps()) { |
6386 | 6387 | context->set_retained_maps(*array); |
6387 | 6388 | } |
@@ -6399,7 +6400,7 @@ void Heap::AddRetainedMaps(DirectHandle<NativeContext> context, |
6399 | 6400 | raw_array->Set(cur_length, MakeWeak(*map)); |
6400 | 6401 | raw_array->Set(cur_length + 1, |
6401 | 6402 | Smi::FromInt(v8_flags.retain_maps_for_n_gc)); |
6402 | | - cur_length += 2; |
| 6403 | + cur_length += kRetainMapEntrySize; |
6403 | 6404 | raw_array->set_length(cur_length); |
6404 | 6405 |
|
6405 | 6406 | map->set_is_in_retained_map_list(true); |
@@ -6411,7 +6412,7 @@ void Heap::CompactRetainedMaps(Tagged<WeakArrayList> retained_maps) { |
6411 | 6412 | int length = retained_maps->length(); |
6412 | 6413 | int new_length = 0; |
6413 | 6414 | // 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) { |
6415 | 6416 | Tagged<MaybeObject> maybe_object = retained_maps->Get(i); |
6416 | 6417 | if (maybe_object.IsCleared()) { |
6417 | 6418 | continue; |
@@ -6425,7 +6426,7 @@ void Heap::CompactRetainedMaps(Tagged<WeakArrayList> retained_maps) { |
6425 | 6426 | retained_maps->Set(new_length, maybe_object); |
6426 | 6427 | retained_maps->Set(new_length + 1, age); |
6427 | 6428 | } |
6428 | | - new_length += 2; |
| 6429 | + new_length += kRetainMapEntrySize; |
6429 | 6430 | } |
6430 | 6431 | Tagged<HeapObject> undefined = ReadOnlyRoots(this).undefined_value(); |
6431 | 6432 | for (int i = new_length; i < length; i++) { |
|