OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_OBJECTS_VISITING_H_ | 5 #ifndef V8_OBJECTS_VISITING_H_ |
6 #define V8_OBJECTS_VISITING_H_ | 6 #define V8_OBJECTS_VISITING_H_ |
7 | 7 |
8 #include "src/allocation.h" | 8 #include "src/allocation.h" |
9 | 9 |
10 // This file provides base classes and auxiliary methods for defining | 10 // This file provides base classes and auxiliary methods for defining |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 | 108 |
109 static VisitorId GetVisitorId(Map* map) { | 109 static VisitorId GetVisitorId(Map* map) { |
110 return GetVisitorId(map->instance_type(), map->instance_size()); | 110 return GetVisitorId(map->instance_type(), map->instance_size()); |
111 } | 111 } |
112 | 112 |
113 // For visitors that allow specialization by size calculate VisitorId based | 113 // For visitors that allow specialization by size calculate VisitorId based |
114 // on size, base visitor id and generic visitor id. | 114 // on size, base visitor id and generic visitor id. |
115 static VisitorId GetVisitorIdForSize(VisitorId base, | 115 static VisitorId GetVisitorIdForSize(VisitorId base, |
116 VisitorId generic, | 116 VisitorId generic, |
117 int object_size) { | 117 int object_size) { |
118 ASSERT((base == kVisitDataObject) || | 118 DCHECK((base == kVisitDataObject) || |
119 (base == kVisitStruct) || | 119 (base == kVisitStruct) || |
120 (base == kVisitJSObject)); | 120 (base == kVisitJSObject)); |
121 ASSERT(IsAligned(object_size, kPointerSize)); | 121 DCHECK(IsAligned(object_size, kPointerSize)); |
122 ASSERT(kMinObjectSizeInWords * kPointerSize <= object_size); | 122 DCHECK(kMinObjectSizeInWords * kPointerSize <= object_size); |
123 ASSERT(object_size <= Page::kMaxRegularHeapObjectSize); | 123 DCHECK(object_size <= Page::kMaxRegularHeapObjectSize); |
124 | 124 |
125 const VisitorId specialization = static_cast<VisitorId>( | 125 const VisitorId specialization = static_cast<VisitorId>( |
126 base + (object_size >> kPointerSizeLog2) - kMinObjectSizeInWords); | 126 base + (object_size >> kPointerSizeLog2) - kMinObjectSizeInWords); |
127 | 127 |
128 return Min(specialization, generic); | 128 return Min(specialization, generic); |
129 } | 129 } |
130 }; | 130 }; |
131 | 131 |
132 | 132 |
133 template<typename Callback> | 133 template<typename Callback> |
(...skipping 10 matching lines...) Expand all Loading... |
144 | 144 |
145 inline Callback GetVisitorById(StaticVisitorBase::VisitorId id) { | 145 inline Callback GetVisitorById(StaticVisitorBase::VisitorId id) { |
146 return reinterpret_cast<Callback>(callbacks_[id]); | 146 return reinterpret_cast<Callback>(callbacks_[id]); |
147 } | 147 } |
148 | 148 |
149 inline Callback GetVisitor(Map* map) { | 149 inline Callback GetVisitor(Map* map) { |
150 return reinterpret_cast<Callback>(callbacks_[map->visitor_id()]); | 150 return reinterpret_cast<Callback>(callbacks_[map->visitor_id()]); |
151 } | 151 } |
152 | 152 |
153 void Register(StaticVisitorBase::VisitorId id, Callback callback) { | 153 void Register(StaticVisitorBase::VisitorId id, Callback callback) { |
154 ASSERT(id < StaticVisitorBase::kVisitorIdCount); // id is unsigned. | 154 DCHECK(id < StaticVisitorBase::kVisitorIdCount); // id is unsigned. |
155 callbacks_[id] = reinterpret_cast<base::AtomicWord>(callback); | 155 callbacks_[id] = reinterpret_cast<base::AtomicWord>(callback); |
156 } | 156 } |
157 | 157 |
158 template<typename Visitor, | 158 template<typename Visitor, |
159 StaticVisitorBase::VisitorId base, | 159 StaticVisitorBase::VisitorId base, |
160 StaticVisitorBase::VisitorId generic, | 160 StaticVisitorBase::VisitorId generic, |
161 int object_size_in_words> | 161 int object_size_in_words> |
162 void RegisterSpecialization() { | 162 void RegisterSpecialization() { |
163 static const int size = object_size_in_words * kPointerSize; | 163 static const int size = object_size_in_words * kPointerSize; |
164 Register(StaticVisitorBase::GetVisitorIdForSize(base, generic, size), | 164 Register(StaticVisitorBase::GetVisitorIdForSize(base, generic, size), |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 BodyVisitorBase<StaticVisitor>::IteratePointers( | 212 BodyVisitorBase<StaticVisitor>::IteratePointers( |
213 map->GetHeap(), | 213 map->GetHeap(), |
214 object, | 214 object, |
215 BodyDescriptor::kStartOffset, | 215 BodyDescriptor::kStartOffset, |
216 object_size); | 216 object_size); |
217 return static_cast<ReturnType>(object_size); | 217 return static_cast<ReturnType>(object_size); |
218 } | 218 } |
219 | 219 |
220 template<int object_size> | 220 template<int object_size> |
221 static inline ReturnType VisitSpecialized(Map* map, HeapObject* object) { | 221 static inline ReturnType VisitSpecialized(Map* map, HeapObject* object) { |
222 ASSERT(BodyDescriptor::SizeOf(map, object) == object_size); | 222 DCHECK(BodyDescriptor::SizeOf(map, object) == object_size); |
223 BodyVisitorBase<StaticVisitor>::IteratePointers( | 223 BodyVisitorBase<StaticVisitor>::IteratePointers( |
224 map->GetHeap(), | 224 map->GetHeap(), |
225 object, | 225 object, |
226 BodyDescriptor::kStartOffset, | 226 BodyDescriptor::kStartOffset, |
227 object_size); | 227 object_size); |
228 return static_cast<ReturnType>(object_size); | 228 return static_cast<ReturnType>(object_size); |
229 } | 229 } |
230 }; | 230 }; |
231 | 231 |
232 | 232 |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
467 // the next element. Given the head of the list, this function removes dead | 467 // the next element. Given the head of the list, this function removes dead |
468 // elements from the list and if requested records slots for next-element | 468 // elements from the list and if requested records slots for next-element |
469 // pointers. The template parameter T is a WeakListVisitor that defines how to | 469 // pointers. The template parameter T is a WeakListVisitor that defines how to |
470 // access the next-element pointers. | 470 // access the next-element pointers. |
471 template <class T> | 471 template <class T> |
472 Object* VisitWeakList(Heap* heap, Object* list, WeakObjectRetainer* retainer); | 472 Object* VisitWeakList(Heap* heap, Object* list, WeakObjectRetainer* retainer); |
473 | 473 |
474 } } // namespace v8::internal | 474 } } // namespace v8::internal |
475 | 475 |
476 #endif // V8_OBJECTS_VISITING_H_ | 476 #endif // V8_OBJECTS_VISITING_H_ |
OLD | NEW |