Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 257 // marking phase of the mark-sweep garbage collector. | 257 // marking phase of the mark-sweep garbage collector. |
| 258 // | 258 // |
| 259 // Pointers are marked and pushed on the marking stack by calling the | 259 // Pointers are marked and pushed on the marking stack by calling the |
| 260 // |mark| method with the pointer as an argument. | 260 // |mark| method with the pointer as an argument. |
| 261 // | 261 // |
| 262 // Pointers within objects are traced by calling the |trace| methods | 262 // Pointers within objects are traced by calling the |trace| methods |
| 263 // with the object as an argument. Tracing objects will mark all of the | 263 // with the object as an argument. Tracing objects will mark all of the |
| 264 // contained pointers and push them on the marking stack. | 264 // contained pointers and push them on the marking stack. |
| 265 class PLATFORM_EXPORT Visitor { | 265 class PLATFORM_EXPORT Visitor { |
| 266 public: | 266 public: |
| 267 enum VisitorType { | |
| 268 GlobalMarkingVisitorType, | |
| 269 GenericVisitorType, | |
| 270 }; | |
| 271 | |
| 267 virtual ~Visitor() { } | 272 virtual ~Visitor() { } |
| 268 | 273 |
| 269 // One-argument templated mark method. This uses the static type of | 274 // One-argument templated mark method. This uses the static type of |
| 270 // the argument to get the TraceTrait. By default, the mark method | 275 // the argument to get the TraceTrait. By default, the mark method |
| 271 // of the TraceTrait just calls the virtual two-argument mark method on this | 276 // of the TraceTrait just calls the virtual two-argument mark method on this |
| 272 // visitor, where the second argument is the static trace method of the trai t. | 277 // visitor, where the second argument is the static trace method of the trai t. |
| 273 template<typename T> | 278 template<typename T> |
| 274 void mark(T* t) | 279 void mark(T* t) |
| 275 { | 280 { |
| 276 if (!t) | 281 if (!t) |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 524 { | 529 { |
| 525 m_hostObject = object; | 530 m_hostObject = object; |
| 526 m_hostName = name; | 531 m_hostName = name; |
| 527 } | 532 } |
| 528 #endif | 533 #endif |
| 529 | 534 |
| 530 inline bool canTraceEagerly() const { return m_traceDepth < kMaxEagerTraceDe pth; } | 535 inline bool canTraceEagerly() const { return m_traceDepth < kMaxEagerTraceDe pth; } |
| 531 inline void incrementTraceDepth() { m_traceDepth++; } | 536 inline void incrementTraceDepth() { m_traceDepth++; } |
| 532 inline void decrementTraceDepth() { ASSERT(m_traceDepth > 0); m_traceDepth-- ; } | 537 inline void decrementTraceDepth() { ASSERT(m_traceDepth > 0); m_traceDepth-- ; } |
| 533 | 538 |
| 539 inline bool isGlobalMarkingVisitor() const { return m_isGlobalMarkingVisitor ; } | |
| 540 | |
| 534 protected: | 541 protected: |
| 535 Visitor() | 542 Visitor(VisitorType type) |
|
haraken
2014/12/16 06:53:30
Add explicit
kouhei (in TOK)
2014/12/16 06:58:27
Done.
| |
| 536 : m_traceDepth(0) | 543 : m_traceDepth(0) |
| 544 , m_isGlobalMarkingVisitor(type == GlobalMarkingVisitorType) | |
| 537 { | 545 { |
| 538 } | 546 } |
| 539 | 547 |
| 540 virtual void registerWeakCell(void**, WeakPointerCallback) = 0; | 548 virtual void registerWeakCell(void**, WeakPointerCallback) = 0; |
| 541 #if ENABLE(GC_PROFILE_MARKING) | 549 #if ENABLE(GC_PROFILE_MARKING) |
| 542 void* m_hostObject; | 550 void* m_hostObject; |
| 543 String m_hostName; | 551 String m_hostName; |
| 544 #endif | 552 #endif |
| 545 | 553 |
| 546 private: | 554 private: |
| 547 template<typename T> | 555 template<typename T> |
| 548 static void handleWeakCell(Visitor* self, void* obj) | 556 static void handleWeakCell(Visitor* self, void* obj) |
| 549 { | 557 { |
| 550 T** cell = reinterpret_cast<T**>(obj); | 558 T** cell = reinterpret_cast<T**>(obj); |
| 551 if (*cell && !self->isAlive(*cell)) | 559 if (*cell && !self->isAlive(*cell)) |
| 552 *cell = 0; | 560 *cell = 0; |
| 553 } | 561 } |
| 554 | 562 |
| 555 // The maximum depth of eager, unrolled trace() calls that is | 563 // The maximum depth of eager, unrolled trace() calls that is |
| 556 // considered safe and allowed. | 564 // considered safe and allowed. |
| 557 const int kMaxEagerTraceDepth = 100; | 565 const int kMaxEagerTraceDepth = 100; |
| 558 | 566 |
| 559 int m_traceDepth; | 567 int m_traceDepth; |
| 568 bool m_isGlobalMarkingVisitor; | |
|
haraken
2014/12/16 06:53:29
Can we store m_visitorType, instead of m_isGlobalM
kouhei (in TOK)
2014/12/16 06:58:27
"type == GlobalMarkingVisitorType" is slower than
| |
| 560 }; | 569 }; |
| 561 | 570 |
| 562 // We trace vectors by using the trace trait on each element, which means you | 571 // We trace vectors by using the trace trait on each element, which means you |
| 563 // can have vectors of general objects (not just pointers to objects) that can | 572 // can have vectors of general objects (not just pointers to objects) that can |
| 564 // be traced. | 573 // be traced. |
| 565 template<typename T, size_t N> | 574 template<typename T, size_t N> |
| 566 struct OffHeapCollectionTraceTrait<WTF::Vector<T, N, WTF::DefaultAllocator> > { | 575 struct OffHeapCollectionTraceTrait<WTF::Vector<T, N, WTF::DefaultAllocator> > { |
| 567 typedef WTF::Vector<T, N, WTF::DefaultAllocator> Vector; | 576 typedef WTF::Vector<T, N, WTF::DefaultAllocator> Vector; |
| 568 | 577 |
| 569 static void trace(Visitor* visitor, const Vector& vector) | 578 static void trace(Visitor* visitor, const Vector& vector) |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 783 struct GCInfoTrait { | 792 struct GCInfoTrait { |
| 784 static const GCInfo* get() | 793 static const GCInfo* get() |
| 785 { | 794 { |
| 786 return GCInfoAtBase<typename GetGarbageCollectedBase<T>::type>::get(); | 795 return GCInfoAtBase<typename GetGarbageCollectedBase<T>::type>::get(); |
| 787 } | 796 } |
| 788 }; | 797 }; |
| 789 | 798 |
| 790 } | 799 } |
| 791 | 800 |
| 792 #endif | 801 #endif |
| OLD | NEW |