| 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 |
| 11 namespace v8 { | 11 namespace v8 { |
| 12 namespace internal { | 12 namespace internal { |
| 13 | 13 |
| 14 // Callback function, returns whether an object is alive. The heap size | 14 // Callback function, returns whether an object is alive. The heap size |
| 15 // of the object is returned in size. It optionally updates the offset | 15 // of the object is returned in size. It optionally updates the offset |
| 16 // to the first live object in the page (only used for old and map objects). | 16 // to the first live object in the page (only used for old and map objects). |
| 17 typedef bool (*IsAliveFunction)(HeapObject* obj, int* size, int* offset); | 17 typedef bool (*IsAliveFunction)(HeapObject* obj, int* size, int* offset); |
| 18 | 18 |
| 19 // Callback function to mark an object in a given heap. | 19 // Callback function to mark an object in a given heap. |
| 20 typedef void (*MarkObjectFunction)(Heap* heap, HeapObject* object); | 20 typedef void (*MarkObjectFunction)(Heap* heap, HeapObject* object); |
| 21 | 21 |
| 22 // Forward declarations. | 22 // Forward declarations. |
| 23 class CodeFlusher; | 23 class CodeFlusher; |
| 24 class MarkCompactCollector; | 24 class MarkCompactCollector; |
| 25 class MarkingVisitor; | 25 class MarkingVisitor; |
| 26 class RootMarkingVisitor; | 26 class RootMarkingVisitor; |
| 27 | 27 |
| 28 | 28 |
| 29 class Marking { | 29 class Marking : public AllStatic { |
| 30 public: | 30 public: |
| 31 explicit Marking(Heap* heap) : heap_(heap) {} | |
| 32 | |
| 33 INLINE(static MarkBit MarkBitFrom(Address addr)); | 31 INLINE(static MarkBit MarkBitFrom(Address addr)); |
| 34 | 32 |
| 35 INLINE(static MarkBit MarkBitFrom(HeapObject* obj)) { | 33 INLINE(static MarkBit MarkBitFrom(HeapObject* obj)) { |
| 36 return MarkBitFrom(reinterpret_cast<Address>(obj)); | 34 return MarkBitFrom(reinterpret_cast<Address>(obj)); |
| 37 } | 35 } |
| 38 | 36 |
| 39 // Impossible markbits: 01 | 37 // Impossible markbits: 01 |
| 40 static const char* kImpossibleBitPattern; | 38 static const char* kImpossibleBitPattern; |
| 41 INLINE(static bool IsImpossible(MarkBit mark_bit)) { | 39 INLINE(static bool IsImpossible(MarkBit mark_bit)) { |
| 42 return !mark_bit.Get() && mark_bit.Next().Get(); | 40 return !mark_bit.Get() && mark_bit.Next().Get(); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 | 111 |
| 114 INLINE(static void AnyToGrey(MarkBit markbit)) { | 112 INLINE(static void AnyToGrey(MarkBit markbit)) { |
| 115 markbit.Set(); | 113 markbit.Set(); |
| 116 markbit.Next().Set(); | 114 markbit.Next().Set(); |
| 117 } | 115 } |
| 118 | 116 |
| 119 static void SetAllMarkBitsInRange(MarkBit start, MarkBit end); | 117 static void SetAllMarkBitsInRange(MarkBit start, MarkBit end); |
| 120 static void ClearAllMarkBitsOfCellsContainedInRange(MarkBit start, | 118 static void ClearAllMarkBitsOfCellsContainedInRange(MarkBit start, |
| 121 MarkBit end); | 119 MarkBit end); |
| 122 | 120 |
| 123 void TransferMark(Address old_start, Address new_start); | 121 static void TransferMark(Heap* heap, Address old_start, Address new_start); |
| 124 | 122 |
| 125 #ifdef DEBUG | 123 #ifdef DEBUG |
| 126 enum ObjectColor { | 124 enum ObjectColor { |
| 127 BLACK_OBJECT, | 125 BLACK_OBJECT, |
| 128 WHITE_OBJECT, | 126 WHITE_OBJECT, |
| 129 GREY_OBJECT, | 127 GREY_OBJECT, |
| 130 IMPOSSIBLE_COLOR | 128 IMPOSSIBLE_COLOR |
| 131 }; | 129 }; |
| 132 | 130 |
| 133 static const char* ColorName(ObjectColor color) { | 131 static const char* ColorName(ObjectColor color) { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 is_black = true; // Looks black so far. | 165 is_black = true; // Looks black so far. |
| 168 } | 166 } |
| 169 if (from_mark_bit.Next().Get()) { | 167 if (from_mark_bit.Next().Get()) { |
| 170 to_mark_bit.Next().Set(); | 168 to_mark_bit.Next().Set(); |
| 171 is_black = false; // Was actually gray. | 169 is_black = false; // Was actually gray. |
| 172 } | 170 } |
| 173 return is_black; | 171 return is_black; |
| 174 } | 172 } |
| 175 | 173 |
| 176 private: | 174 private: |
| 177 Heap* heap_; | 175 DISALLOW_IMPLICIT_CONSTRUCTORS(Marking); |
| 178 }; | 176 }; |
| 179 | 177 |
| 180 // ---------------------------------------------------------------------------- | 178 // ---------------------------------------------------------------------------- |
| 181 // Marking deque for tracing live objects. | 179 // Marking deque for tracing live objects. |
| 182 class MarkingDeque { | 180 class MarkingDeque { |
| 183 public: | 181 public: |
| 184 MarkingDeque() | 182 MarkingDeque() |
| 185 : array_(NULL), | 183 : array_(NULL), |
| 186 top_(0), | 184 top_(0), |
| 187 bottom_(0), | 185 bottom_(0), |
| (...skipping 848 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1036 private: | 1034 private: |
| 1037 MarkCompactCollector* collector_; | 1035 MarkCompactCollector* collector_; |
| 1038 }; | 1036 }; |
| 1039 | 1037 |
| 1040 | 1038 |
| 1041 const char* AllocationSpaceName(AllocationSpace space); | 1039 const char* AllocationSpaceName(AllocationSpace space); |
| 1042 } | 1040 } |
| 1043 } // namespace v8::internal | 1041 } // namespace v8::internal |
| 1044 | 1042 |
| 1045 #endif // V8_HEAP_MARK_COMPACT_H_ | 1043 #endif // V8_HEAP_MARK_COMPACT_H_ |
| OLD | NEW |