Commit a26f9f54 authored by Omer Katz's avatar Omer Katz Committed by V8 LUCI CQ

[heap] Introduce NewSpace::EvacuatePrologue

Calls to Flip and ResetLinearAllocationArea of SemiSpaceNewSpace are
(almost) always called together, and always at the start of evacuation.
Introducing NewSpace::EvacuatePrologue, allows removing these methods
from SemiSpaceNewSpace public interface and reduces future branches
between the semi space and paged new space cases.

Bug: v8:12612
Change-Id: Ic589a48c1e7751631603da757f4f5f7edb69e571
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3650599Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Commit-Queue: Omer Katz <omerkatz@chromium.org>
Cr-Commit-Position: refs/heads/main@{#80561}
parent 6e887c93
......@@ -65,6 +65,7 @@
#include "src/heap/memory-chunk-layout.h"
#include "src/heap/memory-measurement.h"
#include "src/heap/memory-reducer.h"
#include "src/heap/new-spaces.h"
#include "src/heap/object-stats.h"
#include "src/heap/objects-visiting-inl.h"
#include "src/heap/objects-visiting.h"
......@@ -2740,14 +2741,7 @@ void Heap::Scavenge() {
SetGCState(SCAVENGE);
// Flip the semispaces. After flipping, to space is empty, from space has
// live objects.
{
SemiSpaceNewSpace* semi_space_new_space =
SemiSpaceNewSpace::From(new_space());
semi_space_new_space->Flip();
semi_space_new_space->ResetLinearAllocationArea();
}
SemiSpaceNewSpace::From(new_space())->EvacuatePrologue();
// We also flip the young generation large object space. All large objects
// will be in the from space.
......
......@@ -3591,8 +3591,7 @@ void MarkCompactCollector::EvacuatePrologue() {
PageRange(new_space->first_allocatable_address(), new_space->top())) {
new_space_evacuation_pages_.push_back(p);
}
SemiSpaceNewSpace::From(new_space)->Flip();
new_space->ResetLinearAllocationArea();
new_space->EvacuatePrologue();
DCHECK_EQ(new_space->Size(), 0);
}
......@@ -5683,8 +5682,7 @@ void MinorMarkCompactCollector::EvacuatePrologue() {
new_space_evacuation_pages_.push_back(p);
}
SemiSpaceNewSpace::From(new_space)->Flip();
new_space->ResetLinearAllocationArea();
new_space->EvacuatePrologue();
heap()->new_lo_space()->Flip();
heap()->new_lo_space()->ResetPendingObject();
......
......@@ -601,8 +601,6 @@ SemiSpaceNewSpace::~SemiSpaceNewSpace() {
from_space_.TearDown();
}
void SemiSpaceNewSpace::Flip() { SemiSpace::Swap(&from_space_, &to_space_); }
void SemiSpaceNewSpace::Grow() {
heap()->safepoint()->AssertActive();
// Double the semispace size but only up to maximum capacity.
......@@ -820,5 +818,12 @@ size_t SemiSpaceNewSpace::AllocatedSinceLastGC() const {
return allocated;
}
void SemiSpaceNewSpace::EvacuatePrologue() {
// Flip the semispaces. After flipping, to space is empty, from space has
// live objects.
SemiSpace::Swap(&from_space_, &to_space_);
ResetLinearAllocationArea();
}
} // namespace internal
} // namespace v8
......@@ -306,10 +306,10 @@ class NewSpace : NON_EXPORTED_BASE(public SpaceWithLinearArea) {
virtual Address first_allocatable_address() const = 0;
virtual void ResetLinearAllocationArea() = 0;
virtual bool AddFreshPage() = 0;
virtual void EvacuatePrologue() = 0;
protected:
static const int kAllocationBufferParkingThreshold = 4 * KB;
......@@ -343,9 +343,6 @@ class V8_EXPORT_PRIVATE SemiSpaceNewSpace final : public NewSpace {
bool ContainsSlow(Address a) const final;
// Flip the pair of spaces.
void Flip();
// Grow the capacity of the semispaces. Assumes that they are not at
// their maximum capacity.
void Grow() final;
......@@ -441,9 +438,6 @@ class V8_EXPORT_PRIVATE SemiSpaceNewSpace final : public NewSpace {
// Set the age mark in the active semispace.
void set_age_mark(Address mark) { to_space_.set_age_mark(mark); }
// Reset the allocation pointer to the beginning of the active semispace.
void ResetLinearAllocationArea() final;
// When inline allocation stepping is active, either because of incremental
// marking, idle scavenge, or allocation statistics gathering, we 'interrupt'
// inline allocation every once in a while. This is done by setting
......@@ -509,7 +503,12 @@ class V8_EXPORT_PRIVATE SemiSpaceNewSpace final : public NewSpace {
bool ShouldBePromoted(Address address) const final;
void EvacuatePrologue() final;
private:
// Reset the allocation pointer to the beginning of the active semispace.
void ResetLinearAllocationArea();
// Update linear allocation area to match the current to-space page.
void UpdateLinearAllocationArea(Address known_top = 0);
......
......@@ -47,10 +47,10 @@ void PromoteYoungGenerationGC::EvacuateYoungGeneration() {
}
// Reset new space.
semi_space_new_space->EvacuatePrologue();
if (!semi_space_new_space->Rebalance()) {
V8::FatalProcessOutOfMemory(heap_->isolate(), "NewSpace::Rebalance", true);
}
semi_space_new_space->ResetLinearAllocationArea();
semi_space_new_space->set_age_mark(semi_space_new_space->top());
for (auto it = heap_->new_lo_space()->begin();
......
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