Skip to content

Commit e972ff7

Browse files
legendecasrichardlau
authored andcommitted
deps: V8: backport bbd800c6e359
Original commit message: [heap] Fix incorrect from space committed size NewSpace page operations like RemovePage, PrependPage, and EnsureCurrentCapacity should account for committed page size. This may happen when a page was promoted from the new space to old space on mark-compact. Also, add DCHECKs on Commit and Uncommit to ensure the final committed page size is the same as the current state. Bug: v8:12657 Change-Id: I7aebc1fd3f51f177ae2ef6420f757f0c573e126b Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3504766 Reviewed-by: Dominik Inführ <[email protected]> Commit-Queue: Chengzhong Wu <[email protected]> Cr-Commit-Position: refs/heads/main@{#79426} Refs: v8/v8@bbd800c PR-URL: #44947 Refs: v8/v8@b953542 Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Jiawen Geng <[email protected]> Reviewed-By: Richard Lau <[email protected]>
1 parent af9d821 commit e972ff7

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

common.gypi

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

3838
# Reset this number to 0 on major V8 upgrades.
3939
# Increment by one for each non-official patch applied to deps/v8.
40-
'v8_embedder_string': '-node.23',
40+
'v8_embedder_string': '-node.24',
4141

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

deps/v8/src/heap/new-spaces.cc

+16-1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ bool SemiSpace::EnsureCurrentCapacity() {
5454
// Free all overallocated pages which are behind current_page.
5555
while (current_page) {
5656
MemoryChunk* next_current = current_page->list_node().next();
57+
AccountUncommitted(Page::kPageSize);
5758
memory_chunk_list_.Remove(current_page);
5859
// Clear new space flags to avoid this page being treated as a new
5960
// space page that is potentially being swept.
@@ -74,6 +75,7 @@ bool SemiSpace::EnsureCurrentCapacity() {
7475
NOT_EXECUTABLE);
7576
if (current_page == nullptr) return false;
7677
DCHECK_NOT_NULL(current_page);
78+
AccountCommitted(Page::kPageSize);
7779
memory_chunk_list_.PushBack(current_page);
7880
marking_state->ClearLiveness(current_page);
7981
current_page->SetFlags(first_page()->GetFlags(),
@@ -106,6 +108,7 @@ void SemiSpace::TearDown() {
106108

107109
bool SemiSpace::Commit() {
108110
DCHECK(!IsCommitted());
111+
DCHECK_EQ(CommittedMemory(), size_t(0));
109112
const int num_pages = static_cast<int>(target_capacity_ / Page::kPageSize);
110113
DCHECK(num_pages);
111114
for (int pages_added = 0; pages_added < num_pages; pages_added++) {
@@ -134,14 +137,19 @@ bool SemiSpace::Commit() {
134137

135138
bool SemiSpace::Uncommit() {
136139
DCHECK(IsCommitted());
140+
int actual_pages = 0;
137141
while (!memory_chunk_list_.Empty()) {
142+
actual_pages++;
138143
MemoryChunk* chunk = memory_chunk_list_.front();
139144
memory_chunk_list_.Remove(chunk);
140145
heap()->memory_allocator()->Free<MemoryAllocator::kPooledAndQueue>(chunk);
141146
}
142147
current_page_ = nullptr;
143148
current_capacity_ = 0;
144-
AccountUncommitted(target_capacity_);
149+
size_t removed_page_size =
150+
static_cast<size_t>(actual_pages * Page::kPageSize);
151+
DCHECK_EQ(CommittedMemory(), removed_page_size);
152+
AccountUncommitted(removed_page_size);
145153
heap()->memory_allocator()->unmapper()->FreeQueuedChunks();
146154
DCHECK(!IsCommitted());
147155
return true;
@@ -246,6 +254,7 @@ void SemiSpace::RemovePage(Page* page) {
246254
}
247255
}
248256
memory_chunk_list_.Remove(page);
257+
AccountUncommitted(Page::kPageSize);
249258
for (size_t i = 0; i < ExternalBackingStoreType::kNumTypes; i++) {
250259
ExternalBackingStoreType t = static_cast<ExternalBackingStoreType>(i);
251260
DecrementExternalBackingStoreBytes(t, page->ExternalBackingStoreBytes(t));
@@ -258,6 +267,7 @@ void SemiSpace::PrependPage(Page* page) {
258267
page->set_owner(this);
259268
memory_chunk_list_.PushFront(page);
260269
current_capacity_ += Page::kPageSize;
270+
AccountCommitted(Page::kPageSize);
261271
for (size_t i = 0; i < ExternalBackingStoreType::kNumTypes; i++) {
262272
ExternalBackingStoreType t = static_cast<ExternalBackingStoreType>(i);
263273
IncrementExternalBackingStoreBytes(t, page->ExternalBackingStoreBytes(t));
@@ -319,6 +329,7 @@ void SemiSpace::Verify() {
319329
external_backing_store_bytes[static_cast<ExternalBackingStoreType>(i)] = 0;
320330
}
321331

332+
int actual_pages = 0;
322333
for (Page* page : *this) {
323334
CHECK_EQ(page->owner(), this);
324335
CHECK(page->InNewSpace());
@@ -344,7 +355,11 @@ void SemiSpace::Verify() {
344355

345356
CHECK_IMPLIES(page->list_node().prev(),
346357
page->list_node().prev()->list_node().next() == page);
358+
359+
actual_pages++;
347360
}
361+
CHECK_EQ(actual_pages * size_t(Page::kPageSize), CommittedMemory());
362+
348363
for (int i = 0; i < kNumTypes; i++) {
349364
ExternalBackingStoreType t = static_cast<ExternalBackingStoreType>(i);
350365
CHECK_EQ(external_backing_store_bytes[t], ExternalBackingStoreBytes(t));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright 2022 the V8 project authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
// Flags: --gc-global --expose-statistics --max-semi-space-size=1
6+
7+
const a = new Array();
8+
for (var i = 0; i < 50000; i++) {
9+
a[i] = new Object();
10+
}
11+
assertTrue(getV8Statistics().new_space_commited_bytes <= 2 * 1024 * 1024);

0 commit comments

Comments
 (0)