cppgc: Mark allocated pages as young when switching to generational GC

When generational GC is enabled, some objects may already be allocated.
However, the age table entries corresponding to them would not be
marked, which would break marking verifier. The CL fixes it by
explicitly marking all entries as young.

Bug: v8:13475
Change-Id: I5b4206c0c978f0486e85c6c02a6c76b59152d7bf
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4061731
Commit-Queue: Anton Bikineev <bikineev@chromium.org>
Reviewed-by: Michael Lippautz <mlippautz@chromium.org>
Cr-Commit-Position: refs/heads/main@{#84554}
This commit is contained in:
Anton Bikineev 2022-11-29 14:12:50 +01:00 committed by V8 LUCI CQ
parent 86e1bdc92c
commit a2bfd1c6b8
3 changed files with 23 additions and 0 deletions

View File

@ -217,6 +217,8 @@ void HeapBase::EnableGenerationalGC() {
YoungGenerationEnabler::Enable();
// Enable young generation for the current heap.
HeapHandle::is_young_generation_enabled_ = true;
// Assume everything that has so far been allocated is young.
object_allocator_.MarkAllPagesAsYoung();
}
void HeapBase::ResetRememberedSet() {

View File

@ -283,6 +283,26 @@ void ObjectAllocator::ResetLinearAllocationBuffers() {
visitor.Traverse(raw_heap_);
}
void ObjectAllocator::MarkAllPagesAsYoung() {
class YoungMarker : public HeapVisitor<YoungMarker> {
public:
bool VisitNormalPage(NormalPage& page) {
MarkRangeAsYoung(page, page.PayloadStart(), page.PayloadEnd());
return true;
}
bool VisitLargePage(LargePage& page) {
MarkRangeAsYoung(page, page.PayloadStart(), page.PayloadEnd());
return true;
}
} visitor;
USE(visitor);
#if defined(CPPGC_YOUNG_GENERATION)
visitor.Traverse(raw_heap_);
#endif // defined(CPPGC_YOUNG_GENERATION)
}
bool ObjectAllocator::in_disallow_gc_scope() const {
return raw_heap_.heap()->in_disallow_gc_scope();
}

View File

@ -52,6 +52,7 @@ class V8_EXPORT_PRIVATE ObjectAllocator final : public cppgc::AllocationHandle {
GCInfoIndex gcinfo, CustomSpaceIndex space_index);
void ResetLinearAllocationBuffers();
void MarkAllPagesAsYoung();
private:
bool in_disallow_gc_scope() const;