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

[heap] Introduce explicit grey to MinorMC.

Mark objects as grey when pushing to worklist and mark as black when
objects are visited.

Bug: v8:12612
Change-Id: I5ad28c4481052f41588f43dc39dd44f132a27dfb
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3810467
Commit-Queue: Omer Katz <omerkatz@chromium.org>
Reviewed-by: 's avatarDominik Inführ <dinfuehr@chromium.org>
Cr-Commit-Position: refs/heads/main@{#82290}
parent 37869a07
......@@ -325,9 +325,13 @@ class YoungGenerationConcurrentMarkingVisitor final
// HeapVisitor override.
bool ShouldVisit(HeapObject object) { return true; }
bool ShouldVisit(HeapObject object) {
return marking_state_.GreyToBlack(object);
}
bool ShouldVisitUnaccounted(HeapObject object) { return true; }
bool ShouldVisitUnaccounted(HeapObject object) {
return marking_state_.GreyToBlackUnaccounted(object);
}
template <typename TSlot>
void RecordSlot(HeapObject object, TSlot slot, HeapObject target) {}
......
......@@ -42,7 +42,7 @@ void MarkCompactCollector::MarkRootObject(Root root, HeapObject obj) {
void MinorMarkCompactCollector::MarkRootObject(HeapObject obj) {
if (Heap::InYoungGeneration(obj) &&
non_atomic_marking_state_.WhiteToBlack(obj)) {
non_atomic_marking_state_.WhiteToGrey(obj)) {
local_marking_worklists_->Push(obj);
}
}
......
......@@ -5408,6 +5408,9 @@ class YoungGenerationEvacuationVerifier : public EvacuationVerifier {
bool IsUnmarkedObjectForYoungGeneration(Heap* heap, FullObjectSlot p) {
DCHECK_IMPLIES(Heap::InYoungGeneration(*p), Heap::InToPage(*p));
DCHECK(
!heap->minor_mark_compact_collector()->non_atomic_marking_state()->IsGrey(
HeapObject::cast(*p)));
return Heap::InYoungGeneration(*p) && !heap->minor_mark_compact_collector()
->non_atomic_marking_state()
->IsBlack(HeapObject::cast(*p));
......@@ -5415,13 +5418,17 @@ bool IsUnmarkedObjectForYoungGeneration(Heap* heap, FullObjectSlot p) {
} // namespace
YoungGenerationMarkingVisitor::YoungGenerationMarkingVisitor(
YoungGenerationMainMarkingVisitor::YoungGenerationMainMarkingVisitor(
Isolate* isolate, MarkingState* marking_state,
MarkingWorklists::Local* worklists_local)
: YoungGenerationMarkingVisitorBase<YoungGenerationMarkingVisitor,
: YoungGenerationMarkingVisitorBase<YoungGenerationMainMarkingVisitor,
MarkingState>(isolate, worklists_local),
marking_state_(marking_state) {}
bool YoungGenerationMainMarkingVisitor::ShouldVisit(HeapObject object) {
return marking_state_->GreyToBlack(object);
}
MinorMarkCompactCollector::~MinorMarkCompactCollector() = default;
void MinorMarkCompactCollector::SetUp() {}
......@@ -5462,6 +5469,7 @@ void MinorMarkCompactCollector::CleanupPromotedPages() {
}
void MinorMarkCompactCollector::VisitObject(HeapObject obj) {
DCHECK(marking_state_.IsGrey(obj));
main_marking_visitor_->Visit(obj.map(), obj);
}
......@@ -5637,7 +5645,7 @@ void MinorMarkCompactCollector::Prepare() {
void MinorMarkCompactCollector::StartMarking() {
local_marking_worklists_ =
std::make_unique<MarkingWorklists::Local>(&marking_worklists_);
main_marking_visitor_ = std::make_unique<YoungGenerationMarkingVisitor>(
main_marking_visitor_ = std::make_unique<YoungGenerationMainMarkingVisitor>(
heap()->isolate(), marking_state(), local_marking_worklists());
}
......@@ -5875,8 +5883,10 @@ class YoungGenerationMarkingTask {
void MarkObject(Object object) {
if (!Heap::InYoungGeneration(object)) return;
HeapObject heap_object = HeapObject::cast(object);
if (marking_state_->WhiteToBlack(heap_object)) {
if (marking_state_->WhiteToGrey(heap_object)) {
visitor_.Visit(heap_object);
// Objects transition to black when visited.
DCHECK(marking_state_->IsBlack(heap_object));
}
}
......@@ -5895,7 +5905,7 @@ class YoungGenerationMarkingTask {
private:
std::unique_ptr<MarkingWorklists::Local> marking_worklists_local_;
MarkingState* marking_state_;
YoungGenerationMarkingVisitor visitor_;
YoungGenerationMainMarkingVisitor visitor_;
};
class PageMarkingItem : public ParallelWorkItem {
......
......@@ -305,19 +305,23 @@ class MainMarkingVisitor final
MarkingState>;
};
class YoungGenerationMarkingVisitor final
: public YoungGenerationMarkingVisitorBase<YoungGenerationMarkingVisitor,
MarkingState> {
class YoungGenerationMainMarkingVisitor final
: public YoungGenerationMarkingVisitorBase<
YoungGenerationMainMarkingVisitor, MarkingState> {
public:
YoungGenerationMarkingVisitor(Isolate* isolate, MarkingState* marking_state,
MarkingWorklists::Local* worklists_local);
YoungGenerationMainMarkingVisitor(Isolate* isolate,
MarkingState* marking_state,
MarkingWorklists::Local* worklists_local);
// HeapVisitor override.
bool ShouldVisit(HeapObject object);
private:
MarkingState* marking_state() { return marking_state_; }
MarkingState* const marking_state_;
friend class YoungGenerationMarkingVisitorBase<YoungGenerationMarkingVisitor,
MarkingState>;
friend class YoungGenerationMarkingVisitorBase<
YoungGenerationMainMarkingVisitor, MarkingState>;
};
class CollectorBase {
......@@ -842,7 +846,7 @@ class MinorMarkCompactCollector final : public CollectorBase {
void SweepArrayBufferExtensions();
std::unique_ptr<YoungGenerationMarkingVisitor> main_marking_visitor_;
std::unique_ptr<YoungGenerationMainMarkingVisitor> main_marking_visitor_;
base::Semaphore page_parallel_job_semaphore_;
std::vector<Page*> new_space_evacuation_pages_;
......@@ -851,7 +855,7 @@ class MinorMarkCompactCollector final : public CollectorBase {
friend class YoungGenerationMarkingTask;
friend class YoungGenerationMarkingJob;
friend class YoungGenerationMarkingVisitor;
friend class YoungGenerationMainMarkingVisitor;
};
} // namespace internal
......
......@@ -583,6 +583,7 @@ template <typename ConcreteVisitor, typename MarkingState>
int YoungGenerationMarkingVisitorBase<
ConcreteVisitor, MarkingState>::VisitJSArrayBuffer(Map map,
JSArrayBuffer object) {
if (!concrete_visitor()->ShouldVisit(object)) return 0;
object.YoungMarkExtension();
int size = JSArrayBuffer::BodyDescriptor::SizeOf(map, object);
JSArrayBuffer::BodyDescriptor::IterateBody(map, object, size, this);
......@@ -592,7 +593,7 @@ int YoungGenerationMarkingVisitorBase<
template <typename ConcreteVisitor, typename MarkingState>
void YoungGenerationMarkingVisitorBase<ConcreteVisitor, MarkingState>::
MarkObjectViaMarkingWorklist(HeapObject object) {
if (concrete_visitor()->marking_state()->WhiteToBlack(object)) {
if (concrete_visitor()->marking_state()->WhiteToGrey(object)) {
worklists_local_->Push(object);
}
}
......
......@@ -5,6 +5,7 @@
#ifndef V8_HEAP_OBJECTS_VISITING_INL_H_
#define V8_HEAP_OBJECTS_VISITING_INL_H_
#include "src/base/logging.h"
#include "src/heap/embedder-tracing.h"
#include "src/heap/mark-compact.h"
#include "src/heap/objects-visiting.h"
......@@ -207,10 +208,8 @@ NewSpaceVisitor<ConcreteVisitor>::NewSpaceVisitor(Isolate* isolate)
template <typename ConcreteVisitor>
int NewSpaceVisitor<ConcreteVisitor>::VisitNativeContext(Map map,
NativeContext object) {
ConcreteVisitor* visitor = static_cast<ConcreteVisitor*>(this);
int size = NativeContext::BodyDescriptor::SizeOf(map, object);
NativeContext::BodyDescriptor::IterateBody(map, object, size, visitor);
return size;
// There should be no native contexts in new space.
UNREACHABLE();
}
template <typename ConcreteVisitor>
......
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