| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 // ... | 263 // ... |
| 264 // } | 264 // } |
| 265 // | 265 // |
| 266 // This is an example of Curiously recurring template pattern | 266 // This is an example of Curiously recurring template pattern |
| 267 // (see http://en.wikipedia.org/wiki/Curiously_recurring_template_pattern). | 267 // (see http://en.wikipedia.org/wiki/Curiously_recurring_template_pattern). |
| 268 // We use CRTP to guarantee aggressive compile time optimizations (i.e. | 268 // We use CRTP to guarantee aggressive compile time optimizations (i.e. |
| 269 // inlining and specialization of StaticVisitor::VisitPointers methods). | 269 // inlining and specialization of StaticVisitor::VisitPointers methods). |
| 270 template<typename StaticVisitor> | 270 template<typename StaticVisitor> |
| 271 class StaticNewSpaceVisitor : public StaticVisitorBase { | 271 class StaticNewSpaceVisitor : public StaticVisitorBase { |
| 272 public: | 272 public: |
| 273 static void Initialize() { | 273 static void Initialize(); |
| 274 table_.Register(kVisitShortcutCandidate, | |
| 275 &FixedBodyVisitor<StaticVisitor, | |
| 276 ConsString::BodyDescriptor, | |
| 277 int>::Visit); | |
| 278 | |
| 279 table_.Register(kVisitConsString, | |
| 280 &FixedBodyVisitor<StaticVisitor, | |
| 281 ConsString::BodyDescriptor, | |
| 282 int>::Visit); | |
| 283 | |
| 284 table_.Register(kVisitFixedArray, | |
| 285 &FlexibleBodyVisitor<StaticVisitor, | |
| 286 FixedArray::BodyDescriptor, | |
| 287 int>::Visit); | |
| 288 | |
| 289 table_.Register(kVisitGlobalContext, | |
| 290 &FixedBodyVisitor<StaticVisitor, | |
| 291 Context::ScavengeBodyDescriptor, | |
| 292 int>::Visit); | |
| 293 | |
| 294 table_.Register(kVisitByteArray, &VisitByteArray); | |
| 295 | |
| 296 table_.Register(kVisitSharedFunctionInfo, | |
| 297 &FixedBodyVisitor<StaticVisitor, | |
| 298 SharedFunctionInfo::BodyDescriptor, | |
| 299 int>::Visit); | |
| 300 | |
| 301 table_.Register(kVisitSeqAsciiString, &VisitSeqAsciiString); | |
| 302 | |
| 303 table_.Register(kVisitSeqTwoByteString, &VisitSeqTwoByteString); | |
| 304 | |
| 305 table_.Register(kVisitJSFunction, | |
| 306 &JSObjectVisitor:: | |
| 307 template VisitSpecialized<JSFunction::kSize>); | |
| 308 | |
| 309 table_.RegisterSpecializations<DataObjectVisitor, | |
| 310 kVisitDataObject, | |
| 311 kVisitDataObjectGeneric>(); | |
| 312 table_.RegisterSpecializations<JSObjectVisitor, | |
| 313 kVisitJSObject, | |
| 314 kVisitJSObjectGeneric>(); | |
| 315 table_.RegisterSpecializations<StructVisitor, | |
| 316 kVisitStruct, | |
| 317 kVisitStructGeneric>(); | |
| 318 } | |
| 319 | 274 |
| 320 static inline int IterateBody(Map* map, HeapObject* obj) { | 275 static inline int IterateBody(Map* map, HeapObject* obj) { |
| 321 return table_.GetVisitor(map)(map, obj); | 276 return table_.GetVisitor(map)(map, obj); |
| 322 } | 277 } |
| 323 | 278 |
| 324 static inline void VisitPointers(Heap* heap, Object** start, Object** end) { | 279 static inline void VisitPointers(Heap* heap, Object** start, Object** end) { |
| 325 for (Object** p = start; p < end; p++) StaticVisitor::VisitPointer(heap, p); | 280 for (Object** p = start; p < end; p++) StaticVisitor::VisitPointer(heap, p); |
| 326 } | 281 } |
| 327 | 282 |
| 328 private: | 283 private: |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 | 319 |
| 365 static VisitorDispatchTable<Callback> table_; | 320 static VisitorDispatchTable<Callback> table_; |
| 366 }; | 321 }; |
| 367 | 322 |
| 368 | 323 |
| 369 template<typename StaticVisitor> | 324 template<typename StaticVisitor> |
| 370 VisitorDispatchTable<typename StaticNewSpaceVisitor<StaticVisitor>::Callback> | 325 VisitorDispatchTable<typename StaticNewSpaceVisitor<StaticVisitor>::Callback> |
| 371 StaticNewSpaceVisitor<StaticVisitor>::table_; | 326 StaticNewSpaceVisitor<StaticVisitor>::table_; |
| 372 | 327 |
| 373 | 328 |
| 374 void Code::CodeIterateBody(ObjectVisitor* v) { | |
| 375 int mode_mask = RelocInfo::kCodeTargetMask | | |
| 376 RelocInfo::ModeMask(RelocInfo::EMBEDDED_OBJECT) | | |
| 377 RelocInfo::ModeMask(RelocInfo::GLOBAL_PROPERTY_CELL) | | |
| 378 RelocInfo::ModeMask(RelocInfo::EXTERNAL_REFERENCE) | | |
| 379 RelocInfo::ModeMask(RelocInfo::JS_RETURN) | | |
| 380 RelocInfo::ModeMask(RelocInfo::DEBUG_BREAK_SLOT) | | |
| 381 RelocInfo::ModeMask(RelocInfo::RUNTIME_ENTRY); | |
| 382 | |
| 383 // Use the relocation info pointer before it is visited by | |
| 384 // the heap compaction in the next statement. | |
| 385 RelocIterator it(this, mode_mask); | |
| 386 | |
| 387 IteratePointer(v, kRelocationInfoOffset); | |
| 388 IteratePointer(v, kDeoptimizationDataOffset); | |
| 389 | |
| 390 for (; !it.done(); it.next()) { | |
| 391 it.rinfo()->Visit(v); | |
| 392 } | |
| 393 } | |
| 394 | |
| 395 | |
| 396 template<typename StaticVisitor> | |
| 397 void Code::CodeIterateBody(Heap* heap) { | |
| 398 int mode_mask = RelocInfo::kCodeTargetMask | | |
| 399 RelocInfo::ModeMask(RelocInfo::EMBEDDED_OBJECT) | | |
| 400 RelocInfo::ModeMask(RelocInfo::GLOBAL_PROPERTY_CELL) | | |
| 401 RelocInfo::ModeMask(RelocInfo::EXTERNAL_REFERENCE) | | |
| 402 RelocInfo::ModeMask(RelocInfo::JS_RETURN) | | |
| 403 RelocInfo::ModeMask(RelocInfo::DEBUG_BREAK_SLOT) | | |
| 404 RelocInfo::ModeMask(RelocInfo::RUNTIME_ENTRY); | |
| 405 | |
| 406 // Use the relocation info pointer before it is visited by | |
| 407 // the heap compaction in the next statement. | |
| 408 RelocIterator it(this, mode_mask); | |
| 409 | |
| 410 StaticVisitor::VisitPointer( | |
| 411 heap, | |
| 412 reinterpret_cast<Object**>(this->address() + kRelocationInfoOffset)); | |
| 413 StaticVisitor::VisitPointer( | |
| 414 heap, | |
| 415 reinterpret_cast<Object**>(this->address() + kDeoptimizationDataOffset)); | |
| 416 | |
| 417 for (; !it.done(); it.next()) { | |
| 418 it.rinfo()->template Visit<StaticVisitor>(heap); | |
| 419 } | |
| 420 } | |
| 421 | |
| 422 | |
| 423 } } // namespace v8::internal | 329 } } // namespace v8::internal |
| 424 | 330 |
| 425 #endif // V8_OBJECTS_VISITING_H_ | 331 #endif // V8_OBJECTS_VISITING_H_ |
| OLD | NEW |