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

[heap] Further devirtualizing for instance-based visitor

Forward the concrete class used in CRTP to avoid having virtual class to
the outmost declaration.

Bug: chromium:736641
Change-Id: I8ab693b8f75507318a892c1994d9c899ba5a41d1
Reviewed-on: https://chromium-review.googlesource.com/549303
Commit-Queue: Michael Lippautz <mlippautz@chromium.org>
Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#46253}
parent 7a6d35e6
......@@ -2203,19 +2203,21 @@ void MarkCompactCollector::RecordObjectStats() {
}
}
class YoungGenerationMarkingVisitor final : public NewSpaceVisitor {
class YoungGenerationMarkingVisitor final
: public NewSpaceVisitor<YoungGenerationMarkingVisitor> {
public:
YoungGenerationMarkingVisitor(Heap* heap, Worklist* global_worklist,
int task_id)
: heap_(heap), worklist_(global_worklist, task_id) {}
void VisitPointers(HeapObject* host, Object** start, Object** end) final {
V8_INLINE 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 {
V8_INLINE void VisitPointer(HeapObject* host, Object** slot) final {
Object* target = *slot;
if (heap_->InNewSpace(target)) {
HeapObject* target_object = HeapObject::cast(target);
......
......@@ -667,8 +667,7 @@ ResultType HeapVisitor<ResultType, ConcreteVisitor>::VisitShortcutCandidate(
int size = ConsString::BodyDescriptor::SizeOf(map, object);
if (visitor->ShouldVisitMapPointer())
visitor->VisitMapPointer(object, object->map_slot());
ConsString::BodyDescriptor::IterateBody(object, size,
static_cast<ConcreteVisitor*>(this));
ConsString::BodyDescriptor::IterateBody(object, size, visitor);
return static_cast<ResultType>(size);
}
......@@ -680,8 +679,7 @@ ResultType HeapVisitor<ResultType, ConcreteVisitor>::VisitNativeContext(
int size = Context::BodyDescriptor::SizeOf(map, object);
if (visitor->ShouldVisitMapPointer())
visitor->VisitMapPointer(object, object->map_slot());
Context::BodyDescriptor::IterateBody(object, size,
static_cast<ConcreteVisitor*>(this));
Context::BodyDescriptor::IterateBody(object, size, visitor);
return static_cast<ResultType>(size);
}
......@@ -704,8 +702,7 @@ ResultType HeapVisitor<ResultType, ConcreteVisitor>::VisitJSObjectFast(
int size = JSObject::FastBodyDescriptor::SizeOf(map, object);
if (visitor->ShouldVisitMapPointer())
visitor->VisitMapPointer(object, object->map_slot());
JSObject::FastBodyDescriptor::IterateBody(
object, size, static_cast<ConcreteVisitor*>(this));
JSObject::FastBodyDescriptor::IterateBody(object, size, visitor);
return static_cast<ResultType>(size);
}
......@@ -717,8 +714,7 @@ ResultType HeapVisitor<ResultType, ConcreteVisitor>::VisitJSApiObject(
int size = JSObject::BodyDescriptor::SizeOf(map, object);
if (visitor->ShouldVisitMapPointer())
visitor->VisitMapPointer(object, object->map_slot());
JSObject::BodyDescriptor::IterateBody(object, size,
static_cast<ConcreteVisitor*>(this));
JSObject::BodyDescriptor::IterateBody(object, size, visitor);
return static_cast<ResultType>(size);
}
......@@ -730,8 +726,7 @@ ResultType HeapVisitor<ResultType, ConcreteVisitor>::VisitStruct(
int size = map->instance_size();
if (visitor->ShouldVisitMapPointer())
visitor->VisitMapPointer(object, object->map_slot());
StructBodyDescriptor::IterateBody(object, size,
static_cast<ConcreteVisitor*>(this));
StructBodyDescriptor::IterateBody(object, size, visitor);
return static_cast<ResultType>(size);
}
......@@ -745,20 +740,29 @@ ResultType HeapVisitor<ResultType, ConcreteVisitor>::VisitFreeSpace(
return static_cast<ResultType>(FreeSpace::cast(object)->size());
}
int NewSpaceVisitor::VisitJSFunction(Map* map, JSFunction* object) {
template <typename ConcreteVisitor>
int NewSpaceVisitor<ConcreteVisitor>::VisitJSFunction(Map* map,
JSFunction* object) {
ConcreteVisitor* visitor = static_cast<ConcreteVisitor*>(this);
int size = JSFunction::BodyDescriptorWeak::SizeOf(map, object);
JSFunction::BodyDescriptorWeak::IterateBody(object, size, this);
JSFunction::BodyDescriptorWeak::IterateBody(object, size, visitor);
return size;
}
int NewSpaceVisitor::VisitNativeContext(Map* map, Context* object) {
template <typename ConcreteVisitor>
int NewSpaceVisitor<ConcreteVisitor>::VisitNativeContext(Map* map,
Context* object) {
ConcreteVisitor* visitor = static_cast<ConcreteVisitor*>(this);
int size = Context::BodyDescriptor::SizeOf(map, object);
Context::BodyDescriptor::IterateBody(object, size, this);
Context::BodyDescriptor::IterateBody(object, size, visitor);
return size;
}
int NewSpaceVisitor::VisitJSApiObject(Map* map, JSObject* object) {
return VisitJSObject(map, object);
template <typename ConcreteVisitor>
int NewSpaceVisitor<ConcreteVisitor>::VisitJSApiObject(Map* map,
JSObject* object) {
ConcreteVisitor* visitor = static_cast<ConcreteVisitor*>(this);
return visitor->VisitJSObject(map, object);
}
} // namespace internal
......
......@@ -284,8 +284,8 @@ VisitorDispatchTable<typename StaticMarkingVisitor<StaticVisitor>::Callback>
template <typename ResultType, typename ConcreteVisitor>
class HeapVisitor : public ObjectVisitor {
public:
ResultType Visit(HeapObject* object);
ResultType Visit(Map* map, HeapObject* object);
V8_INLINE ResultType Visit(HeapObject* object);
V8_INLINE ResultType Visit(Map* map, HeapObject* object);
protected:
// A guard predicate for visiting the object.
......@@ -309,7 +309,8 @@ class HeapVisitor : public ObjectVisitor {
V8_INLINE ResultType VisitFreeSpace(Map* map, FreeSpace* object);
};
class NewSpaceVisitor : public HeapVisitor<int, NewSpaceVisitor> {
template <typename ConcreteVisitor>
class NewSpaceVisitor : public HeapVisitor<int, ConcreteVisitor> {
public:
V8_INLINE bool ShouldVisitMapPointer() { return false; }
......
......@@ -59,11 +59,11 @@ class RootScavengeVisitor : public RootVisitor {
Heap* heap_;
};
class ScavengeVisitor final : public NewSpaceVisitor {
class ScavengeVisitor final : public NewSpaceVisitor<ScavengeVisitor> {
public:
explicit ScavengeVisitor(Heap* heap) : heap_(heap) {}
inline void VisitPointers(HeapObject* host, Object** start,
Object** end) final;
V8_INLINE void VisitPointers(HeapObject* host, Object** start,
Object** end) final;
private:
Heap* heap_;
......
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