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

[heap] Remove references to semi spaces from heap.cc

This includes:
1) Inline UncommintFromSpace into Shrink (always called together)
2) Replace ZapFromSpace with virtual ZapUnusedMemory
3) Replace EnsureFromSpaceIsCommited with virtual Prologue

Bug: v8:12612
Change-Id: I934479761c877e10734f54e6d5896a4741b92ef7
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3650738Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Commit-Queue: Omer Katz <omerkatz@chromium.org>
Cr-Commit-Position: refs/heads/main@{#80563}
parent b514973d
...@@ -1028,11 +1028,6 @@ void Heap::IncrementDeferredCount(v8::Isolate::UseCounterFeature feature) { ...@@ -1028,11 +1028,6 @@ void Heap::IncrementDeferredCount(v8::Isolate::UseCounterFeature feature) {
deferred_counters_[feature]++; deferred_counters_[feature]++;
} }
void Heap::UncommitFromSpace() {
DCHECK_NOT_NULL(new_space_);
SemiSpaceNewSpace::From(new_space_)->UncommitFromSpace();
}
void Heap::GarbageCollectionPrologue( void Heap::GarbageCollectionPrologue(
GarbageCollectionReason gc_reason, GarbageCollectionReason gc_reason,
const v8::GCCallbackFlags gc_callback_flags) { const v8::GCCallbackFlags gc_callback_flags) {
...@@ -1454,11 +1449,10 @@ void Heap::GarbageCollectionEpilogueInSafepoint(GarbageCollector collector) { ...@@ -1454,11 +1449,10 @@ void Heap::GarbageCollectionEpilogueInSafepoint(GarbageCollector collector) {
if (FLAG_check_handle_count) CheckHandleCount(); if (FLAG_check_handle_count) CheckHandleCount();
#endif #endif
if (Heap::ShouldZapGarbage() || FLAG_clear_free_memory) {
ZapFromSpace();
}
if (new_space()) { if (new_space()) {
if (Heap::ShouldZapGarbage() || FLAG_clear_free_memory) {
new_space()->ZapUnusedMemory();
}
TRACE_GC(tracer(), GCTracer::Scope::HEAP_EPILOGUE_REDUCE_NEW_SPACE); TRACE_GC(tracer(), GCTracer::Scope::HEAP_EPILOGUE_REDUCE_NEW_SPACE);
ReduceNewSpaceSize(); ReduceNewSpaceSize();
} }
...@@ -2173,11 +2167,6 @@ void Heap::CopyRange(HeapObject dst_object, const TSlot dst_slot, ...@@ -2173,11 +2167,6 @@ void Heap::CopyRange(HeapObject dst_object, const TSlot dst_slot,
WriteBarrierForRange(dst_object, dst_slot, dst_end); WriteBarrierForRange(dst_object, dst_slot, dst_end);
} }
void Heap::EnsureFromSpaceIsCommitted() {
if (!new_space_) return;
SemiSpaceNewSpace::From(new_space_)->CommitFromSpaceIfNeeded();
}
bool Heap::CollectionRequested() { bool Heap::CollectionRequested() {
return collection_barrier_->WasGCRequested(); return collection_barrier_->WasGCRequested();
} }
...@@ -2305,7 +2294,7 @@ size_t Heap::PerformGarbageCollection( ...@@ -2305,7 +2294,7 @@ size_t Heap::PerformGarbageCollection(
GarbageCollectionPrologueInSafepoint(); GarbageCollectionPrologueInSafepoint();
EnsureFromSpaceIsCommitted(); if (new_space()) new_space()->Prologue();
size_t start_young_generation_size = size_t start_young_generation_size =
NewSpaceSize() + (new_lo_space() ? new_lo_space()->SizeOfObjects() : 0); NewSpaceSize() + (new_lo_space() ? new_lo_space()->SizeOfObjects() : 0);
...@@ -3821,7 +3810,6 @@ void Heap::ReduceNewSpaceSize() { ...@@ -3821,7 +3810,6 @@ void Heap::ReduceNewSpaceSize() {
(allocation_throughput < kLowAllocationThroughput))) { (allocation_throughput < kLowAllocationThroughput))) {
new_space_->Shrink(); new_space_->Shrink();
new_lo_space_->SetCapacity(new_space_->Capacity()); new_lo_space_->SetCapacity(new_space_->Capacity());
UncommitFromSpace();
} }
} }
...@@ -4856,18 +4844,6 @@ void Heap::VerifyCommittedPhysicalMemory() { ...@@ -4856,18 +4844,6 @@ void Heap::VerifyCommittedPhysicalMemory() {
} }
#endif // DEBUG #endif // DEBUG
void Heap::ZapFromSpace() {
if (!new_space_) return;
SemiSpaceNewSpace* semi_space_new_space = SemiSpaceNewSpace::From(new_space_);
if (!semi_space_new_space->IsFromSpaceCommitted()) return;
for (Page* page :
PageRange(semi_space_new_space->from_space().first_page(), nullptr)) {
memory_allocator()->ZapBlock(page->area_start(),
page->HighWaterMark() - page->area_start(),
ZapValue());
}
}
void Heap::ZapCodeObject(Address start_address, int size_in_bytes) { void Heap::ZapCodeObject(Address start_address, int size_in_bytes) {
#ifdef DEBUG #ifdef DEBUG
DCHECK(IsAligned(start_address, kIntSize)); DCHECK(IsAligned(start_address, kIntSize));
......
...@@ -1819,15 +1819,6 @@ class Heap { ...@@ -1819,15 +1819,6 @@ class Heap {
void CreateInternalAccessorInfoObjects(); void CreateInternalAccessorInfoObjects();
void CreateInitialObjects(); void CreateInitialObjects();
// Commits from space if it is uncommitted.
void EnsureFromSpaceIsCommitted();
// Uncommit unused semi space.
V8_EXPORT_PRIVATE void UncommitFromSpace();
// Fill in bogus values in from space
void ZapFromSpace();
// Zaps the memory of a code object. // Zaps the memory of a code object.
V8_EXPORT_PRIVATE void ZapCodeObject(Address start_address, V8_EXPORT_PRIVATE void ZapCodeObject(Address start_address,
int size_in_bytes); int size_in_bytes);
......
...@@ -629,6 +629,8 @@ void SemiSpaceNewSpace::Shrink() { ...@@ -629,6 +629,8 @@ void SemiSpaceNewSpace::Shrink() {
from_space_.ShrinkTo(rounded_new_capacity); from_space_.ShrinkTo(rounded_new_capacity);
} }
DCHECK_SEMISPACE_ALLOCATION_INFO(allocation_info_, to_space_); DCHECK_SEMISPACE_ALLOCATION_INFO(allocation_info_, to_space_);
if (!from_space_.IsCommitted()) return;
from_space_.Uncommit();
} }
size_t SemiSpaceNewSpace::CommittedPhysicalMemory() const { size_t SemiSpaceNewSpace::CommittedPhysicalMemory() const {
...@@ -818,6 +820,14 @@ size_t SemiSpaceNewSpace::AllocatedSinceLastGC() const { ...@@ -818,6 +820,14 @@ size_t SemiSpaceNewSpace::AllocatedSinceLastGC() const {
return allocated; return allocated;
} }
void SemiSpaceNewSpace::Prologue() {
if (from_space_.IsCommitted() || from_space_.Commit()) return;
// Committing memory to from space failed.
// Memory is exhausted and we will die.
heap_->FatalProcessOutOfMemory("Committing semi space failed.");
}
void SemiSpaceNewSpace::EvacuatePrologue() { void SemiSpaceNewSpace::EvacuatePrologue() {
// Flip the semispaces. After flipping, to space is empty, from space has // Flip the semispaces. After flipping, to space is empty, from space has
// live objects. // live objects.
...@@ -825,5 +835,14 @@ void SemiSpaceNewSpace::EvacuatePrologue() { ...@@ -825,5 +835,14 @@ void SemiSpaceNewSpace::EvacuatePrologue() {
ResetLinearAllocationArea(); ResetLinearAllocationArea();
} }
void SemiSpaceNewSpace::ZapUnusedMemory() {
if (!IsFromSpaceCommitted()) return;
for (Page* page : PageRange(from_space().first_page(), nullptr)) {
heap_->memory_allocator()->ZapBlock(
page->area_start(), page->HighWaterMark() - page->area_start(),
heap_->ZapValue());
}
}
} // namespace internal } // namespace internal
} // namespace v8 } // namespace v8
...@@ -308,8 +308,12 @@ class NewSpace : NON_EXPORTED_BASE(public SpaceWithLinearArea) { ...@@ -308,8 +308,12 @@ class NewSpace : NON_EXPORTED_BASE(public SpaceWithLinearArea) {
virtual bool AddFreshPage() = 0; virtual bool AddFreshPage() = 0;
virtual void Prologue() {}
virtual void EvacuatePrologue() = 0; virtual void EvacuatePrologue() = 0;
virtual void ZapUnusedMemory() {}
protected: protected:
static const int kAllocationBufferParkingThreshold = 4 * KB; static const int kAllocationBufferParkingThreshold = 4 * KB;
...@@ -464,20 +468,6 @@ class V8_EXPORT_PRIVATE SemiSpaceNewSpace final : public NewSpace { ...@@ -464,20 +468,6 @@ class V8_EXPORT_PRIVATE SemiSpaceNewSpace final : public NewSpace {
void Print() override { to_space_.Print(); } void Print() override { to_space_.Print(); }
#endif #endif
// Return whether the operation succeeded.
bool CommitFromSpaceIfNeeded() {
if (from_space_.IsCommitted() || from_space_.Commit()) return true;
// Committing memory to from space failed.
// Memory is exhausted and we will die.
heap_->FatalProcessOutOfMemory("Committing semi space failed.");
}
void UncommitFromSpace() {
if (!from_space_.IsCommitted()) return;
from_space_.Uncommit();
}
bool IsFromSpaceCommitted() const { return from_space_.IsCommitted(); } bool IsFromSpaceCommitted() const { return from_space_.IsCommitted(); }
SemiSpace* active_space() { return &to_space_; } SemiSpace* active_space() { return &to_space_; }
...@@ -503,8 +493,12 @@ class V8_EXPORT_PRIVATE SemiSpaceNewSpace final : public NewSpace { ...@@ -503,8 +493,12 @@ class V8_EXPORT_PRIVATE SemiSpaceNewSpace final : public NewSpace {
bool ShouldBePromoted(Address address) const final; bool ShouldBePromoted(Address address) const final;
void Prologue() final;
void EvacuatePrologue() final; void EvacuatePrologue() final;
void ZapUnusedMemory() final;
private: private:
// Reset the allocation pointer to the beginning of the active semispace. // Reset the allocation pointer to the beginning of the active semispace.
void ResetLinearAllocationArea(); void ResetLinearAllocationArea();
......
...@@ -116,7 +116,7 @@ class HeapTester { ...@@ -116,7 +116,7 @@ class HeapTester {
static AllocationResult AllocateFixedArrayForTest(Heap* heap, int length, static AllocationResult AllocateFixedArrayForTest(Heap* heap, int length,
AllocationType allocation); AllocationType allocation);
static void UncommitFromSpace(Heap* heap); static void UncommitUnusedMemory(Heap* heap);
}; };
} // namespace heap } // namespace heap
......
...@@ -7114,8 +7114,8 @@ UNINITIALIZED_TEST(RestoreHeapLimit) { ...@@ -7114,8 +7114,8 @@ UNINITIALIZED_TEST(RestoreHeapLimit) {
reinterpret_cast<v8::Isolate*>(isolate)->Dispose(); reinterpret_cast<v8::Isolate*>(isolate)->Dispose();
} }
void HeapTester::UncommitFromSpace(Heap* heap) { void HeapTester::UncommitUnusedMemory(Heap* heap) {
heap->UncommitFromSpace(); heap->new_space()->Shrink();
heap->memory_allocator()->unmapper()->EnsureUnmappingCompleted(); heap->memory_allocator()->unmapper()->EnsureUnmappingCompleted();
} }
......
...@@ -622,7 +622,7 @@ TEST(Regress7768) { ...@@ -622,7 +622,7 @@ TEST(Regress7768) {
// Make sure the memory where it's stored is invalidated, so that we'll crash // Make sure the memory where it's stored is invalidated, so that we'll crash
// if we try to access it. // if we try to access it.
HeapTester::UncommitFromSpace(heap); HeapTester::UncommitUnusedMemory(heap);
// This used to crash when processing the dead weak reference. // This used to crash when processing the dead weak reference.
CcTest::CollectAllGarbage(); CcTest::CollectAllGarbage();
......
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