Commit 28f0b62a authored by Hannes Payer's avatar Hannes Payer Committed by Commit Bot

[heap] Committed SemiSpace state depends on pages being present in the memory_chunk_list_.

Bug: chromium:1054771
Change-Id: Idad2d6464ed29c8aa6d7d0665b84525c0f954df8
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2562245Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Commit-Queue: Hannes Payer <hpayer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#71429}
parent 0c7595b9
......@@ -37,7 +37,7 @@ Page* SemiSpace::InitializePage(MemoryChunk* chunk) {
}
bool SemiSpace::EnsureCurrentCapacity() {
if (is_committed()) {
if (IsCommitted()) {
const int expected_pages =
static_cast<int>(target_capacity_ / Page::kPageSize);
MemoryChunk* current_page = first_page();
......@@ -93,19 +93,18 @@ void SemiSpace::SetUp(size_t initial_capacity, size_t maximum_capacity) {
minimum_capacity_ = RoundDown(initial_capacity, Page::kPageSize);
target_capacity_ = minimum_capacity_;
maximum_capacity_ = RoundDown(maximum_capacity, Page::kPageSize);
committed_ = false;
}
void SemiSpace::TearDown() {
// Properly uncommit memory to keep the allocator counters in sync.
if (is_committed()) {
if (IsCommitted()) {
Uncommit();
}
target_capacity_ = maximum_capacity_ = 0;
}
bool SemiSpace::Commit() {
DCHECK(!is_committed());
DCHECK(!IsCommitted());
const int num_pages = static_cast<int>(target_capacity_ / Page::kPageSize);
for (int pages_added = 0; pages_added < num_pages; pages_added++) {
// Pages in the new spaces can be moved to the old space by the full
......@@ -126,12 +125,11 @@ bool SemiSpace::Commit() {
if (age_mark_ == kNullAddress) {
age_mark_ = first_page()->area_start();
}
committed_ = true;
return true;
}
bool SemiSpace::Uncommit() {
DCHECK(is_committed());
DCHECK(IsCommitted());
while (!memory_chunk_list_.Empty()) {
MemoryChunk* chunk = memory_chunk_list_.front();
memory_chunk_list_.Remove(chunk);
......@@ -139,13 +137,12 @@ bool SemiSpace::Uncommit() {
}
current_page_ = nullptr;
AccountUncommitted(target_capacity_);
committed_ = false;
heap()->memory_allocator()->unmapper()->FreeQueuedChunks();
return true;
}
size_t SemiSpace::CommittedPhysicalMemory() {
if (!is_committed()) return 0;
if (!IsCommitted()) return 0;
size_t size = 0;
for (Page* p : *this) {
size += p->CommittedPhysicalMemory();
......@@ -154,7 +151,7 @@ size_t SemiSpace::CommittedPhysicalMemory() {
}
bool SemiSpace::GrowTo(size_t new_capacity) {
if (!is_committed()) {
if (!IsCommitted()) {
if (!Commit()) return false;
}
DCHECK_EQ(new_capacity & kPageAlignmentMask, 0u);
......@@ -200,7 +197,7 @@ bool SemiSpace::ShrinkTo(size_t new_capacity) {
DCHECK_EQ(new_capacity & kPageAlignmentMask, 0u);
DCHECK_GE(new_capacity, minimum_capacity_);
DCHECK_LT(new_capacity, target_capacity_);
if (is_committed()) {
if (IsCommitted()) {
const size_t delta = target_capacity_ - new_capacity;
DCHECK(IsAligned(delta, Page::kPageSize));
int delta_pages = static_cast<int>(delta / Page::kPageSize);
......@@ -281,7 +278,6 @@ void SemiSpace::Swap(SemiSpace* from, SemiSpace* to) {
std::swap(from->maximum_capacity_, to->maximum_capacity_);
std::swap(from->minimum_capacity_, to->minimum_capacity_);
std::swap(from->age_mark_, to->age_mark_);
std::swap(from->committed_, to->committed_);
std::swap(from->memory_chunk_list_, to->memory_chunk_list_);
std::swap(from->current_page_, to->current_page_);
std::swap(from->external_backing_store_bytes_,
......@@ -389,7 +385,7 @@ size_t NewSpace::CommittedPhysicalMemory() {
if (!base::OS::HasLazyCommits()) return CommittedMemory();
BasicMemoryChunk::UpdateHighWaterMark(allocation_info_.top());
size_t size = to_space_.CommittedPhysicalMemory();
if (from_space_.is_committed()) {
if (from_space_.IsCommitted()) {
size += from_space_.CommittedPhysicalMemory();
}
return size;
......@@ -411,7 +407,7 @@ NewSpace::NewSpace(Heap* heap, v8::PageAllocator* page_allocator,
if (!to_space_.Commit()) {
V8::FatalProcessOutOfMemory(heap->isolate(), "New space setup");
}
DCHECK(!from_space_.is_committed()); // No need to use memory yet.
DCHECK(!from_space_.IsCommitted()); // No need to use memory yet.
ResetLinearAllocationArea();
}
......
......@@ -48,7 +48,6 @@ class SemiSpace : public Space {
maximum_capacity_(0),
minimum_capacity_(0),
age_mark_(kNullAddress),
committed_(false),
id_(semispace),
current_page_(nullptr) {}
......@@ -61,7 +60,7 @@ class SemiSpace : public Space {
bool Commit();
bool Uncommit();
bool is_committed() { return committed_; }
bool IsCommitted() { return !memory_chunk_list_.Empty(); }
// Grow the semispace to the new capacity. The new capacity requested must
// be larger than the current capacity and less than the maximum capacity.
......@@ -192,7 +191,6 @@ class SemiSpace : public Space {
// Used to govern object promotion during mark-compact collection.
Address age_mark_;
bool committed_;
SemiSpaceId id_;
Page* current_page_;
......@@ -431,16 +429,16 @@ class V8_EXPORT_PRIVATE NewSpace
// Return whether the operation succeeded.
bool CommitFromSpaceIfNeeded() {
if (from_space_.is_committed()) return true;
if (from_space_.IsCommitted()) return true;
return from_space_.Commit();
}
bool UncommitFromSpace() {
if (!from_space_.is_committed()) return true;
if (!from_space_.IsCommitted()) return true;
return from_space_.Uncommit();
}
bool IsFromSpaceCommitted() { return from_space_.is_committed(); }
bool IsFromSpaceCommitted() { return from_space_.IsCommitted(); }
SemiSpace* active_space() { return &to_space_; }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment