Commit ece19e99 authored by Michael Lippautz's avatar Michael Lippautz Committed by Commit Bot

[heap] MinorMC: Use HeapVisitor instead of StaticNewSpacevisitor

Bug: chromium:651354
Change-Id: I797a0eee698c9c5a6bf191fb041111c9ff5440cf
Reviewed-on: https://chromium-review.googlesource.com/503227Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Reviewed-by: 's avatarHannes Payer <hpayer@chromium.org>
Commit-Queue: Michael Lippautz <mlippautz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#45258}
parent 84f244dd
......@@ -21,15 +21,6 @@ void MarkCompactCollector::PushBlack(HeapObject* obj) {
}
}
void MinorMarkCompactCollector::PushBlack(HeapObject* obj) {
DCHECK((ObjectMarking::IsBlack<MarkBit::NON_ATOMIC>(
obj, MarkingState::External(obj))));
if (!marking_deque()->Push(obj)) {
ObjectMarking::BlackToGrey<MarkBit::NON_ATOMIC>(
obj, MarkingState::External(obj));
}
}
void MarkCompactCollector::UnshiftBlack(HeapObject* obj) {
DCHECK(ObjectMarking::IsBlack(obj, MarkingState::Internal(obj)));
if (!marking_deque()->Unshift(obj)) {
......@@ -44,13 +35,6 @@ void MarkCompactCollector::MarkObject(HeapObject* obj) {
}
}
void MinorMarkCompactCollector::MarkObject(HeapObject* obj) {
if (ObjectMarking::WhiteToBlack<MarkBit::NON_ATOMIC>(
obj, MarkingState::External(obj))) {
PushBlack(obj);
}
}
void MarkCompactCollector::RecordSlot(HeapObject* object, Object** slot,
Object* target) {
Page* target_page = Page::FromAddress(reinterpret_cast<Address>(target));
......
......@@ -1164,36 +1164,6 @@ void CodeFlusher::EvictCandidate(JSFunction* function) {
}
}
class StaticYoungGenerationMarkingVisitor
: public StaticNewSpaceVisitor<StaticYoungGenerationMarkingVisitor> {
public:
static void Initialize(Heap* heap) {
StaticNewSpaceVisitor<StaticYoungGenerationMarkingVisitor>::Initialize();
}
inline static void VisitPointer(Heap* heap, HeapObject* object, Object** p) {
Object* target = *p;
if (heap->InNewSpace(target)) {
HeapObject* target_object = HeapObject::cast(target);
if (MarkRecursively(heap, target_object)) return;
heap->minor_mark_compact_collector()->MarkObject(target_object);
}
}
protected:
inline static bool MarkRecursively(Heap* heap, HeapObject* object) {
StackLimitCheck check(heap->isolate());
if (check.HasOverflowed()) return false;
if (ObjectMarking::WhiteToBlack<MarkBit::NON_ATOMIC>(
object, MarkingState::External(object))) {
IterateBody(object->map(), object);
}
return true;
}
};
class MarkCompactMarkingVisitor
: public StaticMarkingVisitor<MarkCompactMarkingVisitor> {
public:
......@@ -1454,38 +1424,6 @@ void MinorMarkCompactCollector::CleanupSweepToIteratePages() {
sweep_to_iterate_pages_.clear();
}
class MinorMarkCompactCollector::RootMarkingVisitor : public RootVisitor {
public:
explicit RootMarkingVisitor(MinorMarkCompactCollector* collector)
: collector_(collector) {}
void VisitRootPointer(Root root, Object** p) override {
MarkObjectByPointer(p);
}
void VisitRootPointers(Root root, Object** start, Object** end) override {
for (Object** p = start; p < end; p++) MarkObjectByPointer(p);
}
private:
void MarkObjectByPointer(Object** p) {
if (!(*p)->IsHeapObject()) return;
HeapObject* object = HeapObject::cast(*p);
if (!collector_->heap()->InNewSpace(object)) return;
if (ObjectMarking::WhiteToBlack<MarkBit::NON_ATOMIC>(
object, MarkingState::External(object))) {
Map* map = object->map();
StaticYoungGenerationMarkingVisitor::IterateBody(map, object);
collector_->EmptyMarkingDeque();
}
}
MinorMarkCompactCollector* collector_;
};
// Visitor class for marking heap roots.
// TODO(ulan): Remove ObjectVisitor base class after fixing marking of
// the string table and the top optimized code.
......@@ -2473,6 +2411,141 @@ void MarkCompactCollector::RecordObjectStats() {
}
}
class YoungGenerationMarkingVisitor final
: public HeapVisitor<void, YoungGenerationMarkingVisitor> {
public:
using BaseClass = HeapVisitor<int, YoungGenerationMarkingVisitor>;
YoungGenerationMarkingVisitor(Heap* heap, MarkingDeque* marking_deque)
: heap_(heap), marking_deque_(marking_deque) {}
void VisitPointers(HeapObject* host, Object** start, Object** end) final {
for (Object** p = start; p < end; p++) {
VisitPointer(host, p);
}
}
void VisitPointer(HeapObject* host, Object** slot) final {
Object* target = *slot;
if (heap_->InNewSpace(target)) {
HeapObject* target_object = HeapObject::cast(target);
if (MarkRecursively(target_object)) return;
MarkObjectViaMarkingDeque(target_object);
}
}
// Special cases for young generation. Also see StaticNewSpaceVisitor.
void VisitJSFunction(Map* map, JSFunction* object) final {
if (!ShouldVisit(object)) return;
int size = JSFunction::BodyDescriptorWeakCode::SizeOf(map, object);
VisitMapPointer(object, object->map_slot());
JSFunction::BodyDescriptorWeakCode::IterateBody(object, size, this);
return;
}
void VisitNativeContext(Map* map, Context* object) final {
if (!ShouldVisit(object)) return;
int size = Context::ScavengeBodyDescriptor::SizeOf(map, object);
VisitMapPointer(object, object->map_slot());
Context::ScavengeBodyDescriptor::IterateBody(object, size, this);
return;
}
void VisitJSApiObject(Map* map, JSObject* object) final {
return VisitJSObject(map, object);
}
void VisitBytecodeArray(Map* map, BytecodeArray* object) final {
UNREACHABLE();
return;
}
void VisitSharedFunctionInfo(Map* map, SharedFunctionInfo* object) final {
UNREACHABLE();
return;
}
private:
inline MarkingState marking_state(HeapObject* object) {
SLOW_DCHECK(
MarkingState::External(object).bitmap() ==
heap_->minor_mark_compact_collector()->marking_state(object).bitmap());
return MarkingState::External(object);
}
inline void MarkObjectViaMarkingDeque(HeapObject* object) {
if (ObjectMarking::WhiteToBlack<MarkBit::NON_ATOMIC>(
object, marking_state(object))) {
// Marking deque overflow is unsupported for the young generation.
CHECK(marking_deque_->Push(object));
}
}
inline bool MarkRecursively(HeapObject* object) {
StackLimitCheck check(heap_->isolate());
if (check.HasOverflowed()) return false;
if (ObjectMarking::WhiteToBlack<MarkBit::NON_ATOMIC>(
object, marking_state(object))) {
Visit(object);
}
return true;
}
Heap* heap_;
MarkingDeque* marking_deque_;
};
class MinorMarkCompactCollector::RootMarkingVisitor : public RootVisitor {
public:
explicit RootMarkingVisitor(MinorMarkCompactCollector* collector)
: collector_(collector) {}
void VisitRootPointer(Root root, Object** p) override {
MarkObjectByPointer(p);
}
void VisitRootPointers(Root root, Object** start, Object** end) override {
for (Object** p = start; p < end; p++) MarkObjectByPointer(p);
}
private:
inline MarkingState marking_state(HeapObject* object) {
SLOW_DCHECK(MarkingState::External(object).bitmap() ==
collector_->marking_state(object).bitmap());
return MarkingState::External(object);
}
void MarkObjectByPointer(Object** p) {
if (!(*p)->IsHeapObject()) return;
HeapObject* object = HeapObject::cast(*p);
if (!collector_->heap()->InNewSpace(object)) return;
if (ObjectMarking::WhiteToBlack<MarkBit::NON_ATOMIC>(
object, marking_state(object))) {
collector_->marking_visitor_->Visit(object);
collector_->EmptyMarkingDeque();
}
}
MinorMarkCompactCollector* collector_;
};
MinorMarkCompactCollector::MinorMarkCompactCollector(Heap* heap)
: MarkCompactCollectorBase(heap),
marking_deque_(heap),
marking_visitor_(
new YoungGenerationMarkingVisitor(heap, &marking_deque_)),
page_parallel_job_semaphore_(0) {}
MinorMarkCompactCollector::~MinorMarkCompactCollector() {
DCHECK_NOT_NULL(marking_visitor_);
delete marking_visitor_;
}
SlotCallbackResult MinorMarkCompactCollector::CheckAndMarkObject(
Heap* heap, Address slot_address) {
Object* object = *reinterpret_cast<Object**>(slot_address);
......@@ -2482,12 +2555,10 @@ SlotCallbackResult MinorMarkCompactCollector::CheckAndMarkObject(
DCHECK(heap->InToSpace(object));
HeapObject* heap_object = reinterpret_cast<HeapObject*>(object);
const MarkingState state = MarkingState::External(heap_object);
if (ObjectMarking::IsBlackOrGrey<MarkBit::NON_ATOMIC>(heap_object, state)) {
return KEEP_SLOT;
if (ObjectMarking::WhiteToBlack<MarkBit::NON_ATOMIC>(heap_object, state)) {
heap->minor_mark_compact_collector()->marking_visitor_->Visit(
heap_object);
}
ObjectMarking::WhiteToBlack<MarkBit::NON_ATOMIC>(heap_object, state);
StaticYoungGenerationMarkingVisitor::IterateBody(heap_object->map(),
heap_object);
return KEEP_SLOT;
}
return REMOVE_SLOT;
......@@ -2505,7 +2576,6 @@ void MinorMarkCompactCollector::MarkLiveObjects() {
PostponeInterruptsScope postpone(isolate());
StaticYoungGenerationMarkingVisitor::Initialize(heap());
RootMarkingVisitor root_visitor(this);
marking_deque()->StartUsing();
......@@ -2572,12 +2642,11 @@ void MinorMarkCompactCollector::EmptyMarkingDeque() {
DCHECK(heap()->Contains(object));
DCHECK(!(ObjectMarking::IsWhite<MarkBit::NON_ATOMIC>(
object, MarkingState::External(object))));
object, marking_state(object))));
Map* map = object->map();
DCHECK((ObjectMarking::IsBlack<MarkBit::NON_ATOMIC>(
object, MarkingState::External(object))));
StaticYoungGenerationMarkingVisitor::IterateBody(map, object);
object, marking_state(object))));
marking_visitor_->Visit(object);
}
}
......
......@@ -31,6 +31,7 @@ template <typename JobTraits>
class PageParallelJob;
class RecordMigratedSlotVisitor;
class ThreadLocalTop;
class YoungGenerationMarkingVisitor;
#if V8_CONCURRENT_MARKING
using MarkingDeque = ConcurrentMarkingDeque;
......@@ -340,10 +341,8 @@ class MarkCompactCollectorBase {
// Collector for young-generation only.
class MinorMarkCompactCollector final : public MarkCompactCollectorBase {
public:
explicit MinorMarkCompactCollector(Heap* heap)
: MarkCompactCollectorBase(heap),
marking_deque_(heap),
page_parallel_job_semaphore_(0) {}
explicit MinorMarkCompactCollector(Heap* heap);
~MinorMarkCompactCollector();
MarkingState marking_state(HeapObject* object) const override {
return MarkingState::External(object);
......@@ -366,9 +365,6 @@ class MinorMarkCompactCollector final : public MarkCompactCollectorBase {
inline MarkingDeque* marking_deque() { return &marking_deque_; }
V8_INLINE void MarkObject(HeapObject* obj);
V8_INLINE void PushBlack(HeapObject* obj);
SlotCallbackResult CheckAndMarkObject(Heap* heap, Address slot_address);
void MarkLiveObjects() override;
void ProcessMarkingDeque() override;
......@@ -382,11 +378,12 @@ class MinorMarkCompactCollector final : public MarkCompactCollectorBase {
void UpdatePointersAfterEvacuation() override;
MarkingDeque marking_deque_;
YoungGenerationMarkingVisitor* marking_visitor_;
base::Semaphore page_parallel_job_semaphore_;
List<Page*> new_space_evacuation_pages_;
std::vector<Page*> sweep_to_iterate_pages_;
friend class StaticYoungGenerationMarkingVisitor;
friend class YoungGenerationMarkingVisitor;
};
// Collector for young and old generation.
......@@ -747,7 +744,6 @@ class MarkCompactCollector final : public MarkCompactCollectorBase {
friend class MarkingVisitor;
friend class RecordMigratedSlotVisitor;
friend class SharedFunctionInfoMarkingVisitor;
friend class StaticYoungGenerationMarkingVisitor;
friend class StoreBuffer;
};
......
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