| 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_HEAP_MARK_COMPACT_H_ | 5 #ifndef V8_HEAP_MARK_COMPACT_H_ |
| 6 #define V8_HEAP_MARK_COMPACT_H_ | 6 #define V8_HEAP_MARK_COMPACT_H_ |
| 7 | 7 |
| 8 #include <deque> | 8 #include <deque> |
| 9 | 9 |
| 10 #include "src/base/bits.h" | 10 #include "src/base/bits.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 | 46 |
| 47 private: | 47 private: |
| 48 DISALLOW_IMPLICIT_CONSTRUCTORS(ObjectMarking); | 48 DISALLOW_IMPLICIT_CONSTRUCTORS(ObjectMarking); |
| 49 }; | 49 }; |
| 50 | 50 |
| 51 // ---------------------------------------------------------------------------- | 51 // ---------------------------------------------------------------------------- |
| 52 // Marking deque for tracing live objects. | 52 // Marking deque for tracing live objects. |
| 53 class MarkingDeque { | 53 class MarkingDeque { |
| 54 public: | 54 public: |
| 55 MarkingDeque() | 55 MarkingDeque() |
| 56 : array_(NULL), | 56 : backing_store_(nullptr), |
| 57 backing_store_committed_size_(0), |
| 58 array_(nullptr), |
| 57 top_(0), | 59 top_(0), |
| 58 bottom_(0), | 60 bottom_(0), |
| 59 mask_(0), | 61 mask_(0), |
| 60 overflowed_(false), | 62 overflowed_(false), |
| 61 in_use_(false) {} | 63 in_use_(false) {} |
| 62 | 64 |
| 63 void Initialize(Address low, Address high); | 65 void SetUp(); |
| 64 void Uninitialize(bool aborting = false); | 66 void TearDown(); |
| 67 |
| 68 void StartUsing(); |
| 69 void StopUsing(); |
| 70 void Clear(); |
| 65 | 71 |
| 66 inline bool IsFull() { return ((top_ + 1) & mask_) == bottom_; } | 72 inline bool IsFull() { return ((top_ + 1) & mask_) == bottom_; } |
| 67 | 73 |
| 68 inline bool IsEmpty() { return top_ == bottom_; } | 74 inline bool IsEmpty() { return top_ == bottom_; } |
| 69 | 75 |
| 70 bool overflowed() const { return overflowed_; } | 76 bool overflowed() const { return overflowed_; } |
| 71 | 77 |
| 72 bool in_use() const { return in_use_; } | |
| 73 | |
| 74 void ClearOverflowed() { overflowed_ = false; } | 78 void ClearOverflowed() { overflowed_ = false; } |
| 75 | 79 |
| 76 void SetOverflowed() { overflowed_ = true; } | 80 void SetOverflowed() { overflowed_ = true; } |
| 77 | 81 |
| 78 // Push the object on the marking stack if there is room, otherwise mark the | 82 // Push the object on the marking stack if there is room, otherwise mark the |
| 79 // deque as overflowed and wait for a rescan of the heap. | 83 // deque as overflowed and wait for a rescan of the heap. |
| 80 INLINE(bool Push(HeapObject* object)) { | 84 INLINE(bool Push(HeapObject* object)) { |
| 81 DCHECK(object->IsHeapObject()); | 85 DCHECK(object->IsHeapObject()); |
| 82 if (IsFull()) { | 86 if (IsFull()) { |
| 83 SetOverflowed(); | 87 SetOverflowed(); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 111 } | 115 } |
| 112 } | 116 } |
| 113 | 117 |
| 114 HeapObject** array() { return array_; } | 118 HeapObject** array() { return array_; } |
| 115 int bottom() { return bottom_; } | 119 int bottom() { return bottom_; } |
| 116 int top() { return top_; } | 120 int top() { return top_; } |
| 117 int mask() { return mask_; } | 121 int mask() { return mask_; } |
| 118 void set_top(int top) { top_ = top; } | 122 void set_top(int top) { top_ = top; } |
| 119 | 123 |
| 120 private: | 124 private: |
| 125 static const size_t kMaxSize = 4 * MB; |
| 126 static const size_t kMinSize = 256 * KB; |
| 127 |
| 128 void EnsureCommitted(); |
| 129 void Uncommit(); |
| 130 |
| 131 base::VirtualMemory* backing_store_; |
| 132 size_t backing_store_committed_size_; |
| 121 HeapObject** array_; | 133 HeapObject** array_; |
| 122 // array_[(top - 1) & mask_] is the top element in the deque. The Deque is | 134 // array_[(top - 1) & mask_] is the top element in the deque. The Deque is |
| 123 // empty when top_ == bottom_. It is full when top_ + 1 == bottom | 135 // empty when top_ == bottom_. It is full when top_ + 1 == bottom |
| 124 // (mod mask + 1). | 136 // (mod mask + 1). |
| 125 int top_; | 137 int top_; |
| 126 int bottom_; | 138 int bottom_; |
| 127 int mask_; | 139 int mask_; |
| 128 bool overflowed_; | 140 bool overflowed_; |
| 129 bool in_use_; | 141 bool in_use_; |
| 130 | 142 |
| (...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 463 // Special case for processing weak references in a full collection. We need | 475 // Special case for processing weak references in a full collection. We need |
| 464 // to artificially keep AllocationSites alive for a time. | 476 // to artificially keep AllocationSites alive for a time. |
| 465 void MarkAllocationSite(AllocationSite* site); | 477 void MarkAllocationSite(AllocationSite* site); |
| 466 | 478 |
| 467 // Mark objects in implicit references groups if their parent object | 479 // Mark objects in implicit references groups if their parent object |
| 468 // is marked. | 480 // is marked. |
| 469 void MarkImplicitRefGroups(MarkObjectFunction mark_object); | 481 void MarkImplicitRefGroups(MarkObjectFunction mark_object); |
| 470 | 482 |
| 471 MarkingDeque* marking_deque() { return &marking_deque_; } | 483 MarkingDeque* marking_deque() { return &marking_deque_; } |
| 472 | 484 |
| 473 static const size_t kMaxMarkingDequeSize = 4 * MB; | |
| 474 static const size_t kMinMarkingDequeSize = 256 * KB; | |
| 475 | |
| 476 void EnsureMarkingDequeIsCommittedAndInitialize(size_t max_size) { | |
| 477 if (!marking_deque()->in_use()) { | |
| 478 EnsureMarkingDequeIsCommitted(max_size); | |
| 479 InitializeMarkingDeque(); | |
| 480 } | |
| 481 } | |
| 482 | |
| 483 void EnsureMarkingDequeIsCommitted(size_t max_size); | |
| 484 void EnsureMarkingDequeIsReserved(); | |
| 485 | |
| 486 void InitializeMarkingDeque(); | |
| 487 | |
| 488 Sweeper& sweeper() { return sweeper_; } | 485 Sweeper& sweeper() { return sweeper_; } |
| 489 | 486 |
| 490 private: | 487 private: |
| 491 class EvacuateNewSpacePageVisitor; | 488 class EvacuateNewSpacePageVisitor; |
| 492 class EvacuateNewSpaceVisitor; | 489 class EvacuateNewSpaceVisitor; |
| 493 class EvacuateOldSpaceVisitor; | 490 class EvacuateOldSpaceVisitor; |
| 494 class EvacuateRecordOnlyVisitor; | 491 class EvacuateRecordOnlyVisitor; |
| 495 class EvacuateVisitorBase; | 492 class EvacuateVisitorBase; |
| 496 class HeapObjectVisitor; | 493 class HeapObjectVisitor; |
| 497 class ObjectStatsVisitor; | 494 class ObjectStatsVisitor; |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 701 bool evacuation_; | 698 bool evacuation_; |
| 702 | 699 |
| 703 // True if we are collecting slots to perform evacuation from evacuation | 700 // True if we are collecting slots to perform evacuation from evacuation |
| 704 // candidates. | 701 // candidates. |
| 705 bool compacting_; | 702 bool compacting_; |
| 706 | 703 |
| 707 bool black_allocation_; | 704 bool black_allocation_; |
| 708 | 705 |
| 709 bool have_code_to_deoptimize_; | 706 bool have_code_to_deoptimize_; |
| 710 | 707 |
| 711 base::VirtualMemory* marking_deque_memory_; | |
| 712 size_t marking_deque_memory_committed_; | |
| 713 MarkingDeque marking_deque_; | 708 MarkingDeque marking_deque_; |
| 714 | 709 |
| 715 CodeFlusher* code_flusher_; | 710 CodeFlusher* code_flusher_; |
| 716 | 711 |
| 717 List<Page*> evacuation_candidates_; | 712 List<Page*> evacuation_candidates_; |
| 718 List<Page*> newspace_evacuation_candidates_; | 713 List<Page*> newspace_evacuation_candidates_; |
| 719 | 714 |
| 720 Sweeper sweeper_; | 715 Sweeper sweeper_; |
| 721 | 716 |
| 722 friend class Heap; | 717 friend class Heap; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 735 | 730 |
| 736 private: | 731 private: |
| 737 MarkCompactCollector* collector_; | 732 MarkCompactCollector* collector_; |
| 738 }; | 733 }; |
| 739 | 734 |
| 740 V8_EXPORT_PRIVATE const char* AllocationSpaceName(AllocationSpace space); | 735 V8_EXPORT_PRIVATE const char* AllocationSpaceName(AllocationSpace space); |
| 741 } // namespace internal | 736 } // namespace internal |
| 742 } // namespace v8 | 737 } // namespace v8 |
| 743 | 738 |
| 744 #endif // V8_HEAP_MARK_COMPACT_H_ | 739 #endif // V8_HEAP_MARK_COMPACT_H_ |
| OLD | NEW |