Commit d82727d8 authored by Hannes Payer's avatar Hannes Payer Committed by Commit Bot

[heap] Simplify SemiSpace shrinking logic.

Bug: chromium:1054771
Change-Id: I5120ce65f6a83728048398db0bf4705ae67b826f
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2565124Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Commit-Queue: Hannes Payer <hpayer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#71485}
parent f35243bb
......@@ -198,7 +198,7 @@ void SemiSpace::RewindPages(int num_pages) {
}
}
bool SemiSpace::ShrinkTo(size_t new_capacity) {
void SemiSpace::ShrinkTo(size_t new_capacity) {
DCHECK_EQ(new_capacity & kPageAlignmentMask, 0u);
DCHECK_GE(new_capacity, minimum_capacity_);
DCHECK_LT(new_capacity, target_capacity_);
......@@ -211,7 +211,6 @@ bool SemiSpace::ShrinkTo(size_t new_capacity) {
heap()->memory_allocator()->unmapper()->FreeQueuedChunks();
}
target_capacity_ = new_capacity;
return true;
}
void SemiSpace::FixPagesFlags(intptr_t flags, intptr_t mask) {
......@@ -441,11 +440,7 @@ void NewSpace::Grow() {
if (!from_space_.GrowTo(new_capacity)) {
// If we managed to grow to-space but couldn't grow from-space,
// attempt to shrink to-space.
if (!to_space_.ShrinkTo(from_space_.target_capacity())) {
// We are in an inconsistent state because we could not
// commit/uncommit memory from new space.
FATAL("inconsistent state");
}
to_space_.ShrinkTo(from_space_.target_capacity());
}
}
DCHECK_SEMISPACE_ALLOCATION_INFO(allocation_info_, to_space_);
......@@ -454,19 +449,11 @@ void NewSpace::Grow() {
void NewSpace::Shrink() {
size_t new_capacity = std::max(InitialTotalCapacity(), 2 * Size());
size_t rounded_new_capacity = ::RoundUp(new_capacity, Page::kPageSize);
if (rounded_new_capacity < TotalCapacity() &&
to_space_.ShrinkTo(rounded_new_capacity)) {
if (rounded_new_capacity < TotalCapacity()) {
to_space_.ShrinkTo(rounded_new_capacity);
// Only shrink from-space if we managed to shrink to-space.
if (from_space_.IsCommitted()) from_space_.Reset();
if (!from_space_.ShrinkTo(rounded_new_capacity)) {
// If we managed to shrink to-space but couldn't shrink from
// space, attempt to grow to-space again.
if (!to_space_.GrowTo(from_space_.target_capacity())) {
// We are in an inconsistent state because we could not
// commit/uncommit memory from new space.
FATAL("inconsistent state");
}
}
from_space_.ShrinkTo(rounded_new_capacity);
}
DCHECK_SEMISPACE_ALLOCATION_INFO(allocation_info_, to_space_);
}
......
......@@ -69,7 +69,7 @@ class SemiSpace : public Space {
// Shrinks the semispace to the new capacity. The new capacity requested
// must be more than the amount of used memory in the semispace and less
// than the current capacity.
bool ShrinkTo(size_t new_capacity);
void ShrinkTo(size_t new_capacity);
bool EnsureCurrentCapacity();
......
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