| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 Object** end_slot = reinterpret_cast<Object**>(object->address() + | 214 Object** end_slot = reinterpret_cast<Object**>(object->address() + |
| 215 end_offset); | 215 end_offset); |
| 216 StaticVisitor::VisitPointers(heap, start_slot, end_slot); | 216 StaticVisitor::VisitPointers(heap, start_slot, end_slot); |
| 217 } | 217 } |
| 218 }; | 218 }; |
| 219 | 219 |
| 220 | 220 |
| 221 template<typename StaticVisitor, typename BodyDescriptor, typename ReturnType> | 221 template<typename StaticVisitor, typename BodyDescriptor, typename ReturnType> |
| 222 class FlexibleBodyVisitor : public BodyVisitorBase<StaticVisitor> { | 222 class FlexibleBodyVisitor : public BodyVisitorBase<StaticVisitor> { |
| 223 public: | 223 public: |
| 224 static inline ReturnType Visit(Map* map, HeapObject* object) { | 224 INLINE(static ReturnType Visit(Map* map, HeapObject* object)) { |
| 225 int object_size = BodyDescriptor::SizeOf(map, object); | 225 int object_size = BodyDescriptor::SizeOf(map, object); |
| 226 BodyVisitorBase<StaticVisitor>::IteratePointers( | 226 BodyVisitorBase<StaticVisitor>::IteratePointers( |
| 227 map->GetHeap(), | 227 map->GetHeap(), |
| 228 object, | 228 object, |
| 229 BodyDescriptor::kStartOffset, | 229 BodyDescriptor::kStartOffset, |
| 230 object_size); | 230 object_size); |
| 231 return static_cast<ReturnType>(object_size); | 231 return static_cast<ReturnType>(object_size); |
| 232 } | 232 } |
| 233 | 233 |
| 234 template<int object_size> | 234 template<int object_size> |
| 235 static inline ReturnType VisitSpecialized(Map* map, HeapObject* object) { | 235 static inline ReturnType VisitSpecialized(Map* map, HeapObject* object) { |
| 236 ASSERT(BodyDescriptor::SizeOf(map, object) == object_size); | 236 ASSERT(BodyDescriptor::SizeOf(map, object) == object_size); |
| 237 BodyVisitorBase<StaticVisitor>::IteratePointers( | 237 BodyVisitorBase<StaticVisitor>::IteratePointers( |
| 238 map->GetHeap(), | 238 map->GetHeap(), |
| 239 object, | 239 object, |
| 240 BodyDescriptor::kStartOffset, | 240 BodyDescriptor::kStartOffset, |
| 241 object_size); | 241 object_size); |
| 242 return static_cast<ReturnType>(object_size); | 242 return static_cast<ReturnType>(object_size); |
| 243 } | 243 } |
| 244 }; | 244 }; |
| 245 | 245 |
| 246 | 246 |
| 247 template<typename StaticVisitor, typename BodyDescriptor, typename ReturnType> | 247 template<typename StaticVisitor, typename BodyDescriptor, typename ReturnType> |
| 248 class FixedBodyVisitor : public BodyVisitorBase<StaticVisitor> { | 248 class FixedBodyVisitor : public BodyVisitorBase<StaticVisitor> { |
| 249 public: | 249 public: |
| 250 static inline ReturnType Visit(Map* map, HeapObject* object) { | 250 INLINE(static ReturnType Visit(Map* map, HeapObject* object)) { |
| 251 BodyVisitorBase<StaticVisitor>::IteratePointers( | 251 BodyVisitorBase<StaticVisitor>::IteratePointers( |
| 252 map->GetHeap(), | 252 map->GetHeap(), |
| 253 object, | 253 object, |
| 254 BodyDescriptor::kStartOffset, | 254 BodyDescriptor::kStartOffset, |
| 255 BodyDescriptor::kEndOffset); | 255 BodyDescriptor::kEndOffset); |
| 256 return static_cast<ReturnType>(BodyDescriptor::kSize); | 256 return static_cast<ReturnType>(BodyDescriptor::kSize); |
| 257 } | 257 } |
| 258 }; | 258 }; |
| 259 | 259 |
| 260 | 260 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 272 // | 272 // |
| 273 // This is an example of Curiously recurring template pattern | 273 // This is an example of Curiously recurring template pattern |
| 274 // (see http://en.wikipedia.org/wiki/Curiously_recurring_template_pattern). | 274 // (see http://en.wikipedia.org/wiki/Curiously_recurring_template_pattern). |
| 275 // We use CRTP to guarantee aggressive compile time optimizations (i.e. | 275 // We use CRTP to guarantee aggressive compile time optimizations (i.e. |
| 276 // inlining and specialization of StaticVisitor::VisitPointers methods). | 276 // inlining and specialization of StaticVisitor::VisitPointers methods). |
| 277 template<typename StaticVisitor> | 277 template<typename StaticVisitor> |
| 278 class StaticNewSpaceVisitor : public StaticVisitorBase { | 278 class StaticNewSpaceVisitor : public StaticVisitorBase { |
| 279 public: | 279 public: |
| 280 static void Initialize(); | 280 static void Initialize(); |
| 281 | 281 |
| 282 static inline int IterateBody(Map* map, HeapObject* obj) { | 282 INLINE(static int IterateBody(Map* map, HeapObject* obj)) { |
| 283 return table_.GetVisitor(map)(map, obj); | 283 return table_.GetVisitor(map)(map, obj); |
| 284 } | 284 } |
| 285 | 285 |
| 286 static inline void VisitPointers(Heap* heap, Object** start, Object** end) { | 286 INLINE(static void VisitPointers(Heap* heap, Object** start, Object** end)) { |
| 287 for (Object** p = start; p < end; p++) StaticVisitor::VisitPointer(heap, p); | 287 for (Object** p = start; p < end; p++) StaticVisitor::VisitPointer(heap, p); |
| 288 } | 288 } |
| 289 | 289 |
| 290 private: | 290 private: |
| 291 static inline int VisitJSFunction(Map* map, HeapObject* object) { | 291 INLINE(static int VisitJSFunction(Map* map, HeapObject* object)) { |
| 292 Heap* heap = map->GetHeap(); | 292 Heap* heap = map->GetHeap(); |
| 293 VisitPointers(heap, | 293 VisitPointers(heap, |
| 294 HeapObject::RawField(object, JSFunction::kPropertiesOffset), | 294 HeapObject::RawField(object, JSFunction::kPropertiesOffset), |
| 295 HeapObject::RawField(object, JSFunction::kCodeEntryOffset)); | 295 HeapObject::RawField(object, JSFunction::kCodeEntryOffset)); |
| 296 | 296 |
| 297 // Don't visit code entry. We are using this visitor only during scavenges. | 297 // Don't visit code entry. We are using this visitor only during scavenges. |
| 298 | 298 |
| 299 VisitPointers( | 299 VisitPointers( |
| 300 heap, | 300 heap, |
| 301 HeapObject::RawField(object, | 301 HeapObject::RawField(object, |
| 302 JSFunction::kCodeEntryOffset + kPointerSize), | 302 JSFunction::kCodeEntryOffset + kPointerSize), |
| 303 HeapObject::RawField(object, | 303 HeapObject::RawField(object, |
| 304 JSFunction::kNonWeakFieldsEndOffset)); | 304 JSFunction::kNonWeakFieldsEndOffset)); |
| 305 return JSFunction::kSize; | 305 return JSFunction::kSize; |
| 306 } | 306 } |
| 307 | 307 |
| 308 static inline int VisitByteArray(Map* map, HeapObject* object) { | 308 INLINE(static int VisitByteArray(Map* map, HeapObject* object)) { |
| 309 return reinterpret_cast<ByteArray*>(object)->ByteArraySize(); | 309 return reinterpret_cast<ByteArray*>(object)->ByteArraySize(); |
| 310 } | 310 } |
| 311 | 311 |
| 312 static inline int VisitFixedDoubleArray(Map* map, HeapObject* object) { | 312 INLINE(static int VisitFixedDoubleArray(Map* map, HeapObject* object)) { |
| 313 int length = reinterpret_cast<FixedDoubleArray*>(object)->length(); | 313 int length = reinterpret_cast<FixedDoubleArray*>(object)->length(); |
| 314 return FixedDoubleArray::SizeFor(length); | 314 return FixedDoubleArray::SizeFor(length); |
| 315 } | 315 } |
| 316 | 316 |
| 317 static inline int VisitJSObject(Map* map, HeapObject* object) { | 317 INLINE(static int VisitJSObject(Map* map, HeapObject* object)) { |
| 318 return JSObjectVisitor::Visit(map, object); | 318 return JSObjectVisitor::Visit(map, object); |
| 319 } | 319 } |
| 320 | 320 |
| 321 static inline int VisitSeqOneByteString(Map* map, HeapObject* object) { | 321 INLINE(static int VisitSeqOneByteString(Map* map, HeapObject* object)) { |
| 322 return SeqOneByteString::cast(object)-> | 322 return SeqOneByteString::cast(object)-> |
| 323 SeqOneByteStringSize(map->instance_type()); | 323 SeqOneByteStringSize(map->instance_type()); |
| 324 } | 324 } |
| 325 | 325 |
| 326 static inline int VisitSeqTwoByteString(Map* map, HeapObject* object) { | 326 INLINE(static int VisitSeqTwoByteString(Map* map, HeapObject* object)) { |
| 327 return SeqTwoByteString::cast(object)-> | 327 return SeqTwoByteString::cast(object)-> |
| 328 SeqTwoByteStringSize(map->instance_type()); | 328 SeqTwoByteStringSize(map->instance_type()); |
| 329 } | 329 } |
| 330 | 330 |
| 331 static inline int VisitFreeSpace(Map* map, HeapObject* object) { | 331 INLINE(static int VisitFreeSpace(Map* map, HeapObject* object)) { |
| 332 return FreeSpace::cast(object)->Size(); | 332 return FreeSpace::cast(object)->Size(); |
| 333 } | 333 } |
| 334 | 334 |
| 335 class DataObjectVisitor { | 335 class DataObjectVisitor { |
| 336 public: | 336 public: |
| 337 template<int object_size> | 337 template<int object_size> |
| 338 static inline int VisitSpecialized(Map* map, HeapObject* object) { | 338 static inline int VisitSpecialized(Map* map, HeapObject* object) { |
| 339 return object_size; | 339 return object_size; |
| 340 } | 340 } |
| 341 | 341 |
| 342 static inline int Visit(Map* map, HeapObject* object) { | 342 INLINE(static int Visit(Map* map, HeapObject* object)) { |
| 343 return map->instance_size(); | 343 return map->instance_size(); |
| 344 } | 344 } |
| 345 }; | 345 }; |
| 346 | 346 |
| 347 typedef FlexibleBodyVisitor<StaticVisitor, | 347 typedef FlexibleBodyVisitor<StaticVisitor, |
| 348 StructBodyDescriptor, | 348 StructBodyDescriptor, |
| 349 int> StructVisitor; | 349 int> StructVisitor; |
| 350 | 350 |
| 351 typedef FlexibleBodyVisitor<StaticVisitor, | 351 typedef FlexibleBodyVisitor<StaticVisitor, |
| 352 JSObject::BodyDescriptor, | 352 JSObject::BodyDescriptor, |
| (...skipping 22 matching lines...) Expand all Loading... |
| 375 // class SomeVisitor : public StaticMarkingVisitor<SomeVisitor> { | 375 // class SomeVisitor : public StaticMarkingVisitor<SomeVisitor> { |
| 376 // ... | 376 // ... |
| 377 // } | 377 // } |
| 378 // | 378 // |
| 379 // This is an example of Curiously recurring template pattern. | 379 // This is an example of Curiously recurring template pattern. |
| 380 template<typename StaticVisitor> | 380 template<typename StaticVisitor> |
| 381 class StaticMarkingVisitor : public StaticVisitorBase { | 381 class StaticMarkingVisitor : public StaticVisitorBase { |
| 382 public: | 382 public: |
| 383 static void Initialize(); | 383 static void Initialize(); |
| 384 | 384 |
| 385 static inline void IterateBody(Map* map, HeapObject* obj) { | 385 INLINE(static void IterateBody(Map* map, HeapObject* obj)) { |
| 386 table_.GetVisitor(map)(map, obj); | 386 table_.GetVisitor(map)(map, obj); |
| 387 } | 387 } |
| 388 | 388 |
| 389 static inline void VisitCodeEntry(Heap* heap, Address entry_address); | 389 INLINE(static void VisitCodeEntry(Heap* heap, Address entry_address)); |
| 390 static inline void VisitEmbeddedPointer(Heap* heap, RelocInfo* rinfo); | 390 INLINE(static void VisitEmbeddedPointer(Heap* heap, RelocInfo* rinfo)); |
| 391 static inline void VisitGlobalPropertyCell(Heap* heap, RelocInfo* rinfo); | 391 INLINE(static void VisitGlobalPropertyCell(Heap* heap, RelocInfo* rinfo)); |
| 392 static inline void VisitDebugTarget(Heap* heap, RelocInfo* rinfo); | 392 INLINE(static void VisitDebugTarget(Heap* heap, RelocInfo* rinfo)); |
| 393 static inline void VisitCodeTarget(Heap* heap, RelocInfo* rinfo); | 393 INLINE(static void VisitCodeTarget(Heap* heap, RelocInfo* rinfo)); |
| 394 static inline void VisitCodeAgeSequence(Heap* heap, RelocInfo* rinfo); | 394 INLINE(static void VisitCodeAgeSequence(Heap* heap, RelocInfo* rinfo)); |
| 395 static inline void VisitExternalReference(RelocInfo* rinfo) { } | 395 INLINE(static void VisitExternalReference(RelocInfo* rinfo)) { } |
| 396 static inline void VisitRuntimeEntry(RelocInfo* rinfo) { } | 396 INLINE(static void VisitRuntimeEntry(RelocInfo* rinfo)) { } |
| 397 | 397 |
| 398 // TODO(mstarzinger): This should be made protected once refactoring is done. | 398 // TODO(mstarzinger): This should be made protected once refactoring is done. |
| 399 // Mark non-optimize code for functions inlined into the given optimized | 399 // Mark non-optimize code for functions inlined into the given optimized |
| 400 // code. This will prevent it from being flushed. | 400 // code. This will prevent it from being flushed. |
| 401 static void MarkInlinedFunctionsCode(Heap* heap, Code* code); | 401 static void MarkInlinedFunctionsCode(Heap* heap, Code* code); |
| 402 | 402 |
| 403 protected: | 403 protected: |
| 404 static inline void VisitMap(Map* map, HeapObject* object); | 404 INLINE(static void VisitMap(Map* map, HeapObject* object)); |
| 405 static inline void VisitCode(Map* map, HeapObject* object); | 405 INLINE(static void VisitCode(Map* map, HeapObject* object)); |
| 406 static inline void VisitSharedFunctionInfo(Map* map, HeapObject* object); | 406 INLINE(static void VisitSharedFunctionInfo(Map* map, HeapObject* object)); |
| 407 static inline void VisitJSFunction(Map* map, HeapObject* object); | 407 INLINE(static void VisitJSFunction(Map* map, HeapObject* object)); |
| 408 static inline void VisitJSRegExp(Map* map, HeapObject* object); | 408 INLINE(static void VisitJSRegExp(Map* map, HeapObject* object)); |
| 409 static inline void VisitNativeContext(Map* map, HeapObject* object); | 409 INLINE(static void VisitNativeContext(Map* map, HeapObject* object)); |
| 410 | 410 |
| 411 // Mark pointers in a Map and its TransitionArray together, possibly | 411 // Mark pointers in a Map and its TransitionArray together, possibly |
| 412 // treating transitions or back pointers weak. | 412 // treating transitions or back pointers weak. |
| 413 static void MarkMapContents(Heap* heap, Map* map); | 413 static void MarkMapContents(Heap* heap, Map* map); |
| 414 static void MarkTransitionArray(Heap* heap, TransitionArray* transitions); | 414 static void MarkTransitionArray(Heap* heap, TransitionArray* transitions); |
| 415 | 415 |
| 416 // Code flushing support. | 416 // Code flushing support. |
| 417 static inline bool IsFlushable(Heap* heap, JSFunction* function); | 417 INLINE(static bool IsFlushable(Heap* heap, JSFunction* function)); |
| 418 static inline bool IsFlushable(Heap* heap, SharedFunctionInfo* shared_info); | 418 INLINE(static bool IsFlushable(Heap* heap, SharedFunctionInfo* shared_info)); |
| 419 | 419 |
| 420 // Helpers used by code flushing support that visit pointer fields and treat | 420 // Helpers used by code flushing support that visit pointer fields and treat |
| 421 // references to code objects either strongly or weakly. | 421 // references to code objects either strongly or weakly. |
| 422 static void VisitSharedFunctionInfoStrongCode(Heap* heap, HeapObject* object); | 422 static void VisitSharedFunctionInfoStrongCode(Heap* heap, HeapObject* object); |
| 423 static void VisitSharedFunctionInfoWeakCode(Heap* heap, HeapObject* object); | 423 static void VisitSharedFunctionInfoWeakCode(Heap* heap, HeapObject* object); |
| 424 static void VisitJSFunctionStrongCode(Heap* heap, HeapObject* object); | 424 static void VisitJSFunctionStrongCode(Heap* heap, HeapObject* object); |
| 425 static void VisitJSFunctionWeakCode(Heap* heap, HeapObject* object); | 425 static void VisitJSFunctionWeakCode(Heap* heap, HeapObject* object); |
| 426 | 426 |
| 427 class DataObjectVisitor { | 427 class DataObjectVisitor { |
| 428 public: | 428 public: |
| 429 template<int size> | 429 template<int size> |
| 430 static inline void VisitSpecialized(Map* map, HeapObject* object) { | 430 static inline void VisitSpecialized(Map* map, HeapObject* object) { |
| 431 } | 431 } |
| 432 | 432 |
| 433 static inline void Visit(Map* map, HeapObject* object) { | 433 INLINE(static void Visit(Map* map, HeapObject* object)) { |
| 434 } | 434 } |
| 435 }; | 435 }; |
| 436 | 436 |
| 437 typedef FlexibleBodyVisitor<StaticVisitor, | 437 typedef FlexibleBodyVisitor<StaticVisitor, |
| 438 FixedArray::BodyDescriptor, | 438 FixedArray::BodyDescriptor, |
| 439 void> FixedArrayVisitor; | 439 void> FixedArrayVisitor; |
| 440 | 440 |
| 441 typedef FlexibleBodyVisitor<StaticVisitor, | 441 typedef FlexibleBodyVisitor<StaticVisitor, |
| 442 JSObject::BodyDescriptor, | 442 JSObject::BodyDescriptor, |
| 443 void> JSObjectVisitor; | 443 void> JSObjectVisitor; |
| 444 | 444 |
| 445 typedef FlexibleBodyVisitor<StaticVisitor, | 445 typedef FlexibleBodyVisitor<StaticVisitor, |
| 446 StructBodyDescriptor, | 446 StructBodyDescriptor, |
| 447 void> StructObjectVisitor; | 447 void> StructObjectVisitor; |
| 448 | 448 |
| 449 typedef void (*Callback)(Map* map, HeapObject* object); | 449 typedef void (*Callback)(Map* map, HeapObject* object); |
| 450 | 450 |
| 451 static VisitorDispatchTable<Callback> table_; | 451 static VisitorDispatchTable<Callback> table_; |
| 452 }; | 452 }; |
| 453 | 453 |
| 454 | 454 |
| 455 template<typename StaticVisitor> | 455 template<typename StaticVisitor> |
| 456 VisitorDispatchTable<typename StaticMarkingVisitor<StaticVisitor>::Callback> | 456 VisitorDispatchTable<typename StaticMarkingVisitor<StaticVisitor>::Callback> |
| 457 StaticMarkingVisitor<StaticVisitor>::table_; | 457 StaticMarkingVisitor<StaticVisitor>::table_; |
| 458 | 458 |
| 459 | 459 |
| 460 } } // namespace v8::internal | 460 } } // namespace v8::internal |
| 461 | 461 |
| 462 #endif // V8_OBJECTS_VISITING_H_ | 462 #endif // V8_OBJECTS_VISITING_H_ |
| OLD | NEW |