Commit 8844d601 authored by Anton Bikineev's avatar Anton Bikineev Committed by V8 LUCI CQ

cppgc: young-gen: Enable generational GC before weak processing

During weak processing we remember weak callbacks for objects in the old
generation. We should check the young-gc flag and enable generational GC
before weak processing, as otherwise we would miss the callbacks and
forget to update the weak refs.

Bug: chromium:1029379
Change-Id: I72c98d4926b57c36af6cc503ce34712f67d50f42
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3616721Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Commit-Queue: Anton Bikineev <bikineev@chromium.org>
Cr-Commit-Position: refs/heads/main@{#80286}
parent 98f6f100
......@@ -637,6 +637,15 @@ bool CppHeap::FinishConcurrentMarkingIfNeeded() {
void CppHeap::TraceEpilogue() {
CHECK(in_atomic_pause_);
CHECK(marking_done_);
#if defined(CPPGC_YOUNG_GENERATION)
// Check if the young generation was enabled via flag. We must enable young
// generation before calling the custom weak callbacks to make sure that the
// callbacks for old objects are registered in the remembered set.
if (FLAG_cppgc_young_generation) {
EnableGenerationalGC();
}
#endif // defined(CPPGC_YOUNG_GENERATION)
{
cppgc::subtle::DisallowGarbageCollectionScope disallow_gc_scope(*this);
marker_->LeaveAtomicPause();
......@@ -662,9 +671,6 @@ void CppHeap::TraceEpilogue() {
USE(bytes_allocated_in_prefinalizers);
#if defined(CPPGC_YOUNG_GENERATION)
// Check if the young generation was enabled via flag.
if (FLAG_cppgc_young_generation) EnableGenerationalGC();
ResetRememberedSet();
#endif // defined(CPPGC_YOUNG_GENERATION)
......
......@@ -170,6 +170,15 @@ void Heap::FinalizeGarbageCollection(Config::StackState stack_state) {
config_.stack_state = stack_state;
SetStackEndOfCurrentGC(v8::base::Stack::GetCurrentStackPosition());
in_atomic_pause_ = true;
#if defined(CPPGC_YOUNG_GENERATION)
// Check if the young generation was enabled. We must enable young generation
// before calling the custom weak callbacks to make sure that the callbacks
// for old objects are registered in the remembered set.
if (generational_gc_enabled_) {
HeapBase::EnableGenerationalGC();
}
#endif // defined(CPPGC_YOUNG_GENERATION)
{
// This guards atomic pause marking, meaning that no internal method or
// external callbacks are allowed to allocate new objects.
......@@ -190,9 +199,6 @@ void Heap::FinalizeGarbageCollection(Config::StackState stack_state) {
USE(bytes_allocated_in_prefinalizers);
#if defined(CPPGC_YOUNG_GENERATION)
if (generational_gc_enabled_) {
HeapBase::EnableGenerationalGC();
}
ResetRememberedSet();
#endif // defined(CPPGC_YOUNG_GENERATION)
......
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