// Copyright 2012 the V8 project authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef V8_HEAP_OBJECTS_VISITING_INL_H_ #define V8_HEAP_OBJECTS_VISITING_INL_H_ #include "src/heap/objects-visiting.h" #include "src/heap/array-buffer-tracker.h" #include "src/heap/embedder-tracing.h" #include "src/heap/mark-compact.h" #include "src/macro-assembler.h" #include "src/objects-body-descriptors-inl.h" #include "src/objects-inl.h" namespace v8 { namespace internal { template template T* HeapVisitor::Cast(HeapObject* object) { return T::cast(object); } template ResultType HeapVisitor::Visit(HeapObject* object) { return Visit(object->map(), object); } template ResultType HeapVisitor::Visit(Map* map, HeapObject* object) { ConcreteVisitor* visitor = static_cast(this); switch (map->visitor_id()) { #define CASE(type) \ case kVisit##type: \ return visitor->Visit##type(map, \ ConcreteVisitor::template Cast(object)); TYPED_VISITOR_ID_LIST(CASE) #undef CASE case kVisitShortcutCandidate: return visitor->VisitShortcutCandidate( map, ConcreteVisitor::template Cast(object)); case kVisitNativeContext: return visitor->VisitNativeContext( map, ConcreteVisitor::template Cast(object)); case kVisitDataObject: return visitor->VisitDataObject(map, object); case kVisitJSObjectFast: return visitor->VisitJSObjectFast( map, ConcreteVisitor::template Cast(object)); case kVisitJSApiObject: return visitor->VisitJSApiObject( map, ConcreteVisitor::template Cast(object)); case kVisitStruct: return visitor->VisitStruct(map, object); case kVisitFreeSpace: return visitor->VisitFreeSpace(map, FreeSpace::cast(object)); case kVisitWeakArray: return visitor->VisitWeakArray(map, object); case kVisitorIdCount: UNREACHABLE(); } UNREACHABLE(); // Make the compiler happy. return ResultType(); } template void HeapVisitor::VisitMapPointer( HeapObject* host, HeapObject** map) { static_cast(this)->VisitPointer( host, reinterpret_cast(map)); } #define VISIT(type) \ template \ ResultType HeapVisitor::Visit##type( \ Map* map, type* object) { \ ConcreteVisitor* visitor = static_cast(this); \ if (!visitor->ShouldVisit(object)) return ResultType(); \ if (!visitor->AllowDefaultJSObjectVisit()) { \ DCHECK_WITH_MSG(!map->IsJSObjectMap(), \ "Implement custom visitor for new JSObject subclass in " \ "concurrent marker"); \ } \ int size = type::BodyDescriptor::SizeOf(map, object); \ if (visitor->ShouldVisitMapPointer()) \ visitor->VisitMapPointer(object, object->map_slot()); \ type::BodyDescriptor::IterateBody(map, object, size, visitor); \ return static_cast(size); \ } TYPED_VISITOR_ID_LIST(VISIT) #undef VISIT template ResultType HeapVisitor::VisitShortcutCandidate( Map* map, ConsString* object) { return static_cast(this)->VisitConsString(map, object); } template ResultType HeapVisitor::VisitNativeContext( Map* map, Context* object) { ConcreteVisitor* visitor = static_cast(this); if (!visitor->ShouldVisit(object)) return ResultType(); int size = Context::BodyDescriptor::SizeOf(map, object); if (visitor->ShouldVisitMapPointer()) visitor->VisitMapPointer(object, object->map_slot()); Context::BodyDescriptor::IterateBody(map, object, size, visitor); return static_cast(size); } template ResultType HeapVisitor::VisitDataObject( Map* map, HeapObject* object) { ConcreteVisitor* visitor = static_cast(this); if (!visitor->ShouldVisit(object)) return ResultType(); int size = map->instance_size(); if (visitor->ShouldVisitMapPointer()) visitor->VisitMapPointer(object, object->map_slot()); return static_cast(size); } template ResultType HeapVisitor::VisitJSObjectFast( Map* map, JSObject* object) { ConcreteVisitor* visitor = static_cast(this); if (!visitor->ShouldVisit(object)) return ResultType(); int size = JSObject::FastBodyDescriptor::SizeOf(map, object); if (visitor->ShouldVisitMapPointer()) visitor->VisitMapPointer(object, object->map_slot()); JSObject::FastBodyDescriptor::IterateBody(map, object, size, visitor); return static_cast(size); } template ResultType HeapVisitor::VisitJSApiObject( Map* map, JSObject* object) { ConcreteVisitor* visitor = static_cast(this); if (!visitor->ShouldVisit(object)) return ResultType(); int size = JSObject::BodyDescriptor::SizeOf(map, object); if (visitor->ShouldVisitMapPointer()) visitor->VisitMapPointer(object, object->map_slot()); JSObject::BodyDescriptor::IterateBody(map, object, size, visitor); return static_cast(size); } template ResultType HeapVisitor::VisitStruct( Map* map, HeapObject* object) { ConcreteVisitor* visitor = static_cast(this); if (!visitor->ShouldVisit(object)) return ResultType(); int size = map->instance_size(); if (visitor->ShouldVisitMapPointer()) visitor->VisitMapPointer(object, object->map_slot()); StructBodyDescriptor::IterateBody(map, object, size, visitor); return static_cast(size); } template ResultType HeapVisitor::VisitFreeSpace( Map* map, FreeSpace* object) { ConcreteVisitor* visitor = static_cast(this); if (!visitor->ShouldVisit(object)) return ResultType(); if (visitor->ShouldVisitMapPointer()) visitor->VisitMapPointer(object, object->map_slot()); return static_cast(FreeSpace::cast(object)->size()); } template int NewSpaceVisitor::VisitJSFunction(Map* map, JSFunction* object) { ConcreteVisitor* visitor = static_cast(this); int size = JSFunction::BodyDescriptorWeak::SizeOf(map, object); JSFunction::BodyDescriptorWeak::IterateBody(map, object, size, visitor); return size; } template int NewSpaceVisitor::VisitNativeContext(Map* map, Context* object) { ConcreteVisitor* visitor = static_cast(this); int size = Context::BodyDescriptor::SizeOf(map, object); Context::BodyDescriptor::IterateBody(map, object, size, visitor); return size; } template int NewSpaceVisitor::VisitJSApiObject(Map* map, JSObject* object) { ConcreteVisitor* visitor = static_cast(this); return visitor->VisitJSObject(map, object); } template ResultType HeapVisitor::VisitWeakArray( Map* map, HeapObject* object) { ConcreteVisitor* visitor = static_cast(this); if (!visitor->ShouldVisit(object)) return ResultType(); int size = WeakArrayBodyDescriptor::SizeOf(map, object); if (visitor->ShouldVisitMapPointer()) visitor->VisitMapPointer(object, object->map_slot()); WeakArrayBodyDescriptor::IterateBody(map, object, size, visitor); return size; } } // namespace internal } // namespace v8 #endif // V8_HEAP_OBJECTS_VISITING_INL_H_