Commit 9ed0ec65 authored by Dominik Inführ's avatar Dominik Inführ Committed by V8 LUCI CQ

[heap] Improve --track-retaining-path for incremental marking

This CL improves --track-retaining-path with incremental marking:

* Retainers need to be cleared *after* the GC and for full GCs only.
  Otherwise a scavenger that runs during incremental marking would
  clear all retainers.
* Register marked root objects in IncrementalMarking::MarkRoots with
  retaining_root_.

Change-Id: I18ab9da48fb7ac45f9ec0826334fd338dc202edc
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3297893Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Commit-Queue: Dominik Inführ <dinfuehr@chromium.org>
Cr-Commit-Position: refs/heads/main@{#78056}
parent 27925000
......@@ -936,11 +936,6 @@ void Heap::GarbageCollectionPrologue() {
} else {
maximum_size_scavenges_ = 0;
}
if (FLAG_track_retaining_path) {
retainer_.clear();
ephemeron_retainer_.clear();
retaining_root_.clear();
}
memory_allocator()->unmapper()->PrepareForGC();
}
......@@ -1335,12 +1330,19 @@ void Heap::GarbageCollectionEpilogueInSafepoint(GarbageCollector collector) {
collection_barrier_->ResumeThreadsAwaitingCollection();
}
void Heap::GarbageCollectionEpilogue() {
void Heap::GarbageCollectionEpilogue(GarbageCollector collector) {
TRACE_GC(tracer(), GCTracer::Scope::HEAP_EPILOGUE);
AllowGarbageCollection for_the_rest_of_the_epilogue;
UpdateMaximumCommitted();
if (FLAG_track_retaining_path &&
collector == GarbageCollector::MARK_COMPACTOR) {
retainer_.clear();
ephemeron_retainer_.clear();
retaining_root_.clear();
}
isolate_->counters()->alive_after_last_gc()->Set(
static_cast<int>(SizeOfObjects()));
......@@ -1821,7 +1823,7 @@ bool Heap::CollectGarbage(AllocationSpace space,
}
}
GarbageCollectionEpilogue();
GarbageCollectionEpilogue(collector);
if (collector == GarbageCollector::MARK_COMPACTOR &&
FLAG_track_detached_contexts) {
isolate()->CheckDetachedContextsAfterGC();
......
......@@ -1934,7 +1934,7 @@ class Heap {
// reporting/verification activities when compiled with DEBUG set.
void GarbageCollectionPrologue();
void GarbageCollectionPrologueInSafepoint();
void GarbageCollectionEpilogue();
void GarbageCollectionEpilogue(GarbageCollector collector);
void GarbageCollectionEpilogueInSafepoint(GarbageCollector collector);
// Performs a major collection in the whole heap.
......
......@@ -41,6 +41,14 @@ bool IncrementalMarking::WhiteToGreyAndPush(HeapObject obj) {
return false;
}
void IncrementalMarking::MarkRootObject(Root root, HeapObject obj) {
if (heap_->incremental_marking()->WhiteToGreyAndPush(obj)) {
if (V8_UNLIKELY(FLAG_track_retaining_path)) {
heap_->AddRetainingRoot(root, obj);
}
}
}
void IncrementalMarking::RestartIfNotMarking() {
if (state_ == COMPLETE) {
state_ = MARKING;
......
......@@ -109,19 +109,19 @@ class IncrementalMarkingRootMarkingVisitor : public RootVisitor {
void VisitRootPointer(Root root, const char* description,
FullObjectSlot p) override {
DCHECK(!MapWord::IsPacked((*p).ptr()));
MarkObjectByPointer(p);
MarkObjectByPointer(root, p);
}
void VisitRootPointers(Root root, const char* description,
FullObjectSlot start, FullObjectSlot end) override {
for (FullObjectSlot p = start; p < end; ++p) {
DCHECK(!MapWord::IsPacked((*p).ptr()));
MarkObjectByPointer(p);
MarkObjectByPointer(root, p);
}
}
private:
void MarkObjectByPointer(FullObjectSlot p) {
void MarkObjectByPointer(Root root, FullObjectSlot p) {
Object object = *p;
if (!object.IsHeapObject()) return;
DCHECK(!MapWord::IsPacked(object.ptr()));
......@@ -129,7 +129,7 @@ class IncrementalMarkingRootMarkingVisitor : public RootVisitor {
BasicMemoryChunk* target_page =
BasicMemoryChunk::FromHeapObject(heap_object);
if (target_page->InSharedHeap()) return;
heap_->incremental_marking()->WhiteToGreyAndPush(heap_object);
heap_->incremental_marking()->MarkRootObject(root, heap_object);
}
Heap* heap_;
......
......@@ -182,6 +182,9 @@ class V8_EXPORT_PRIVATE IncrementalMarking final {
// from white to grey.
V8_INLINE bool WhiteToGreyAndPush(HeapObject obj);
// Marks object referenced from roots.
V8_INLINE void MarkRootObject(Root root, HeapObject obj);
// This function is used to color the object black before it undergoes an
// unsafe layout change. This is a part of synchronization protocol with
// the concurrent marker.
......
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