| 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 "src/base/bits.h" | 8 #include "src/base/bits.h" |
| 9 #include "src/heap/spaces.h" | 9 #include "src/heap/spaces.h" |
| 10 | 10 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 INLINE(static MarkBit MarkBitFrom(HeapObject* obj)) { | 38 INLINE(static MarkBit MarkBitFrom(HeapObject* obj)) { |
| 39 return MarkBitFrom(reinterpret_cast<Address>(obj)); | 39 return MarkBitFrom(reinterpret_cast<Address>(obj)); |
| 40 } | 40 } |
| 41 | 41 |
| 42 // Impossible markbits: 01 | 42 // Impossible markbits: 01 |
| 43 static const char* kImpossibleBitPattern; | 43 static const char* kImpossibleBitPattern; |
| 44 INLINE(static bool IsImpossible(MarkBit mark_bit)) { | 44 INLINE(static bool IsImpossible(MarkBit mark_bit)) { |
| 45 return !mark_bit.Get() && mark_bit.Next().Get(); | 45 return !mark_bit.Get() && mark_bit.Next().Get(); |
| 46 } | 46 } |
| 47 | 47 |
| 48 // Black markbits: 10 - this is required by the sweeper. | 48 // Black markbits: 11 |
| 49 static const char* kBlackBitPattern; | 49 static const char* kBlackBitPattern; |
| 50 INLINE(static bool IsBlack(MarkBit mark_bit)) { | 50 INLINE(static bool IsBlack(MarkBit mark_bit)) { |
| 51 return mark_bit.Get() && !mark_bit.Next().Get(); | 51 return mark_bit.Get() && mark_bit.Next().Get(); |
| 52 } | 52 } |
| 53 | 53 |
| 54 // White markbits: 00 - this is required by the mark bit clearer. | 54 // White markbits: 00 - this is required by the mark bit clearer. |
| 55 static const char* kWhiteBitPattern; | 55 static const char* kWhiteBitPattern; |
| 56 INLINE(static bool IsWhite(MarkBit mark_bit)) { | 56 INLINE(static bool IsWhite(MarkBit mark_bit)) { |
| 57 DCHECK(!IsImpossible(mark_bit)); | 57 DCHECK(!IsImpossible(mark_bit)); |
| 58 return !mark_bit.Get(); | 58 return !mark_bit.Get(); |
| 59 } | 59 } |
| 60 | 60 |
| 61 // Grey markbits: 11 | 61 // Grey markbits: 10 |
| 62 static const char* kGreyBitPattern; | 62 static const char* kGreyBitPattern; |
| 63 INLINE(static bool IsGrey(MarkBit mark_bit)) { | 63 INLINE(static bool IsGrey(MarkBit mark_bit)) { |
| 64 return mark_bit.Get() && mark_bit.Next().Get(); | 64 return mark_bit.Get() && !mark_bit.Next().Get(); |
| 65 } | 65 } |
| 66 | 66 |
| 67 // IsBlackOrGrey assumes that the first bit is set for black or grey | 67 // IsBlackOrGrey assumes that the first bit is set for black or grey |
| 68 // objects. | 68 // objects. |
| 69 INLINE(static bool IsBlackOrGrey(MarkBit mark_bit)) { return mark_bit.Get(); } | 69 INLINE(static bool IsBlackOrGrey(MarkBit mark_bit)) { return mark_bit.Get(); } |
| 70 | 70 |
| 71 INLINE(static void MarkBlack(MarkBit mark_bit)) { | 71 INLINE(static void MarkBlack(MarkBit mark_bit)) { |
| 72 mark_bit.Set(); | 72 mark_bit.Set(); |
| 73 mark_bit.Next().Clear(); | 73 mark_bit.Next().Set(); |
| 74 } | 74 } |
| 75 | 75 |
| 76 INLINE(static void MarkWhite(MarkBit mark_bit)) { | 76 INLINE(static void MarkWhite(MarkBit mark_bit)) { |
| 77 mark_bit.Clear(); | 77 mark_bit.Clear(); |
| 78 mark_bit.Next().Clear(); | 78 mark_bit.Next().Clear(); |
| 79 } | 79 } |
| 80 | 80 |
| 81 INLINE(static void BlackToWhite(MarkBit markbit)) { | 81 INLINE(static void BlackToWhite(MarkBit markbit)) { |
| 82 DCHECK(IsBlack(markbit)); | 82 DCHECK(IsBlack(markbit)); |
| 83 markbit.Clear(); | 83 markbit.Clear(); |
| 84 markbit.Next().Clear(); |
| 84 } | 85 } |
| 85 | 86 |
| 86 INLINE(static void GreyToWhite(MarkBit markbit)) { | 87 INLINE(static void GreyToWhite(MarkBit markbit)) { |
| 87 DCHECK(IsGrey(markbit)); | 88 DCHECK(IsGrey(markbit)); |
| 88 markbit.Clear(); | 89 markbit.Clear(); |
| 89 markbit.Next().Clear(); | 90 markbit.Next().Clear(); |
| 90 } | 91 } |
| 91 | 92 |
| 92 INLINE(static void BlackToGrey(MarkBit markbit)) { | 93 INLINE(static void BlackToGrey(MarkBit markbit)) { |
| 93 DCHECK(IsBlack(markbit)); | 94 DCHECK(IsBlack(markbit)); |
| 94 markbit.Next().Set(); | 95 markbit.Next().Clear(); |
| 95 } | 96 } |
| 96 | 97 |
| 97 INLINE(static void WhiteToGrey(MarkBit markbit)) { | 98 INLINE(static void WhiteToGrey(MarkBit markbit)) { |
| 98 DCHECK(IsWhite(markbit)); | 99 DCHECK(IsWhite(markbit)); |
| 99 markbit.Set(); | 100 markbit.Set(); |
| 100 markbit.Next().Set(); | |
| 101 } | 101 } |
| 102 | 102 |
| 103 INLINE(static void WhiteToBlack(MarkBit markbit)) { | 103 INLINE(static void WhiteToBlack(MarkBit markbit)) { |
| 104 DCHECK(IsWhite(markbit)); | 104 DCHECK(IsWhite(markbit)); |
| 105 markbit.Set(); | 105 markbit.Set(); |
| 106 markbit.Next().Set(); |
| 106 } | 107 } |
| 107 | 108 |
| 108 INLINE(static void GreyToBlack(MarkBit markbit)) { | 109 INLINE(static void GreyToBlack(MarkBit markbit)) { |
| 109 DCHECK(IsGrey(markbit)); | 110 DCHECK(IsGrey(markbit)); |
| 110 markbit.Next().Clear(); | 111 markbit.Next().Set(); |
| 111 } | 112 } |
| 112 | 113 |
| 113 INLINE(static void BlackToGrey(HeapObject* obj)) { | 114 INLINE(static void BlackToGrey(HeapObject* obj)) { |
| 114 BlackToGrey(MarkBitFrom(obj)); | 115 BlackToGrey(MarkBitFrom(obj)); |
| 115 } | 116 } |
| 116 | 117 |
| 117 INLINE(static void AnyToGrey(MarkBit markbit)) { | 118 INLINE(static void AnyToGrey(MarkBit markbit)) { |
| 118 markbit.Set(); | 119 markbit.Set(); |
| 119 markbit.Next().Set(); | 120 markbit.Next().Clear(); |
| 120 } | 121 } |
| 121 | 122 |
| 122 static void TransferMark(Heap* heap, Address old_start, Address new_start); | 123 static void TransferMark(Heap* heap, Address old_start, Address new_start); |
| 123 | 124 |
| 124 #ifdef DEBUG | 125 #ifdef DEBUG |
| 125 enum ObjectColor { | 126 enum ObjectColor { |
| 126 BLACK_OBJECT, | 127 BLACK_OBJECT, |
| 127 WHITE_OBJECT, | 128 WHITE_OBJECT, |
| 128 GREY_OBJECT, | 129 GREY_OBJECT, |
| 129 IMPOSSIBLE_COLOR | 130 IMPOSSIBLE_COLOR |
| (...skipping 23 matching lines...) Expand all Loading... |
| 153 if (IsGrey(mark_bit)) return GREY_OBJECT; | 154 if (IsGrey(mark_bit)) return GREY_OBJECT; |
| 154 UNREACHABLE(); | 155 UNREACHABLE(); |
| 155 return IMPOSSIBLE_COLOR; | 156 return IMPOSSIBLE_COLOR; |
| 156 } | 157 } |
| 157 #endif | 158 #endif |
| 158 | 159 |
| 159 // Returns true if the transferred color is black. | 160 // Returns true if the transferred color is black. |
| 160 INLINE(static bool TransferColor(HeapObject* from, HeapObject* to)) { | 161 INLINE(static bool TransferColor(HeapObject* from, HeapObject* to)) { |
| 161 MarkBit from_mark_bit = MarkBitFrom(from); | 162 MarkBit from_mark_bit = MarkBitFrom(from); |
| 162 MarkBit to_mark_bit = MarkBitFrom(to); | 163 MarkBit to_mark_bit = MarkBitFrom(to); |
| 163 bool is_black = false; | 164 DCHECK(Marking::IsWhite(to_mark_bit)); |
| 164 if (from_mark_bit.Get()) { | 165 if (from_mark_bit.Get()) { |
| 165 to_mark_bit.Set(); | 166 to_mark_bit.Set(); |
| 166 is_black = true; // Looks black so far. | 167 if (from_mark_bit.Next().Get()) { |
| 168 to_mark_bit.Next().Set(); |
| 169 return true; |
| 170 } |
| 167 } | 171 } |
| 168 if (from_mark_bit.Next().Get()) { | 172 return false; |
| 169 to_mark_bit.Next().Set(); | |
| 170 is_black = false; // Was actually gray. | |
| 171 } | |
| 172 return is_black; | |
| 173 } | 173 } |
| 174 | 174 |
| 175 private: | 175 private: |
| 176 DISALLOW_IMPLICIT_CONSTRUCTORS(Marking); | 176 DISALLOW_IMPLICIT_CONSTRUCTORS(Marking); |
| 177 }; | 177 }; |
| 178 | 178 |
| 179 // ---------------------------------------------------------------------------- | 179 // ---------------------------------------------------------------------------- |
| 180 // Marking deque for tracing live objects. | 180 // Marking deque for tracing live objects. |
| 181 class MarkingDeque { | 181 class MarkingDeque { |
| 182 public: | 182 public: |
| (...skipping 663 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 846 } | 846 } |
| 847 | 847 |
| 848 private: | 848 private: |
| 849 MemoryChunk* chunk_; | 849 MemoryChunk* chunk_; |
| 850 MarkBit::CellType* cells_; | 850 MarkBit::CellType* cells_; |
| 851 unsigned int last_cell_index_; | 851 unsigned int last_cell_index_; |
| 852 unsigned int cell_index_; | 852 unsigned int cell_index_; |
| 853 Address cell_base_; | 853 Address cell_base_; |
| 854 }; | 854 }; |
| 855 | 855 |
| 856 enum LiveObjectIterationMode { kBlackObjects, kGreyObjects, kAllLiveObjects }; |
| 857 |
| 858 template <LiveObjectIterationMode T> |
| 859 class LiveObjectIterator BASE_EMBEDDED { |
| 860 public: |
| 861 explicit LiveObjectIterator(MemoryChunk* chunk) |
| 862 : chunk_(chunk), |
| 863 it_(chunk_), |
| 864 cell_base_(it_.CurrentCellBase()), |
| 865 current_cell_(*it_.CurrentCell()) {} |
| 866 |
| 867 HeapObject* Next(); |
| 868 |
| 869 private: |
| 870 MemoryChunk* chunk_; |
| 871 MarkBitCellIterator it_; |
| 872 Address cell_base_; |
| 873 MarkBit::CellType current_cell_; |
| 874 }; |
| 875 |
| 856 | 876 |
| 857 class EvacuationScope BASE_EMBEDDED { | 877 class EvacuationScope BASE_EMBEDDED { |
| 858 public: | 878 public: |
| 859 explicit EvacuationScope(MarkCompactCollector* collector) | 879 explicit EvacuationScope(MarkCompactCollector* collector) |
| 860 : collector_(collector) { | 880 : collector_(collector) { |
| 861 collector_->set_evacuation(true); | 881 collector_->set_evacuation(true); |
| 862 } | 882 } |
| 863 | 883 |
| 864 ~EvacuationScope() { collector_->set_evacuation(false); } | 884 ~EvacuationScope() { collector_->set_evacuation(false); } |
| 865 | 885 |
| 866 private: | 886 private: |
| 867 MarkCompactCollector* collector_; | 887 MarkCompactCollector* collector_; |
| 868 }; | 888 }; |
| 869 | 889 |
| 870 | 890 |
| 871 const char* AllocationSpaceName(AllocationSpace space); | 891 const char* AllocationSpaceName(AllocationSpace space); |
| 872 } // namespace internal | 892 } // namespace internal |
| 873 } // namespace v8 | 893 } // namespace v8 |
| 874 | 894 |
| 875 #endif // V8_HEAP_MARK_COMPACT_H_ | 895 #endif // V8_HEAP_MARK_COMPACT_H_ |
| OLD | NEW |