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 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 inline bool IsEmpty() { return top_ == bottom_; } | 198 inline bool IsEmpty() { return top_ == bottom_; } |
199 | 199 |
200 bool overflowed() const { return overflowed_; } | 200 bool overflowed() const { return overflowed_; } |
201 | 201 |
202 bool in_use() const { return in_use_; } | 202 bool in_use() const { return in_use_; } |
203 | 203 |
204 void ClearOverflowed() { overflowed_ = false; } | 204 void ClearOverflowed() { overflowed_ = false; } |
205 | 205 |
206 void SetOverflowed() { overflowed_ = true; } | 206 void SetOverflowed() { overflowed_ = true; } |
207 | 207 |
208 // Push the (marked) object on the marking stack if there is room, | 208 // Push the (marked) object on the marking stack if there is room, otherwise |
209 // otherwise mark the object as overflowed and wait for a rescan of the | 209 // mark the deque as overflowed and wait for a rescan of the heap. |
210 // heap. | 210 INLINE(bool PushBlack(HeapObject* object)) { |
211 INLINE(void PushBlack(HeapObject* object)) { | |
212 DCHECK(object->IsHeapObject()); | 211 DCHECK(object->IsHeapObject()); |
213 if (IsFull()) { | 212 if (IsFull()) { |
214 Marking::BlackToGrey(object); | |
215 MemoryChunk::IncrementLiveBytesFromGC(object, -object->Size()); | |
216 SetOverflowed(); | 213 SetOverflowed(); |
| 214 return false; |
217 } else { | 215 } else { |
218 array_[top_] = object; | 216 array_[top_] = object; |
219 top_ = ((top_ + 1) & mask_); | 217 top_ = ((top_ + 1) & mask_); |
| 218 return true; |
220 } | 219 } |
221 } | 220 } |
222 | 221 |
223 INLINE(void PushGrey(HeapObject* object)) { | 222 INLINE(void PushGrey(HeapObject* object)) { |
224 DCHECK(object->IsHeapObject()); | 223 DCHECK(object->IsHeapObject()); |
225 if (IsFull()) { | 224 if (IsFull()) { |
226 SetOverflowed(); | 225 SetOverflowed(); |
227 } else { | 226 } else { |
228 array_[top_] = object; | 227 array_[top_] = object; |
229 top_ = ((top_ + 1) & mask_); | 228 top_ = ((top_ + 1) & mask_); |
(...skipping 11 matching lines...) Expand all Loading... |
241 INLINE(void UnshiftGrey(HeapObject* object)) { | 240 INLINE(void UnshiftGrey(HeapObject* object)) { |
242 DCHECK(object->IsHeapObject()); | 241 DCHECK(object->IsHeapObject()); |
243 if (IsFull()) { | 242 if (IsFull()) { |
244 SetOverflowed(); | 243 SetOverflowed(); |
245 } else { | 244 } else { |
246 bottom_ = ((bottom_ - 1) & mask_); | 245 bottom_ = ((bottom_ - 1) & mask_); |
247 array_[bottom_] = object; | 246 array_[bottom_] = object; |
248 } | 247 } |
249 } | 248 } |
250 | 249 |
251 INLINE(void UnshiftBlack(HeapObject* object)) { | 250 INLINE(bool UnshiftBlack(HeapObject* object)) { |
252 DCHECK(object->IsHeapObject()); | 251 DCHECK(object->IsHeapObject()); |
253 DCHECK(Marking::IsBlack(Marking::MarkBitFrom(object))); | 252 DCHECK(Marking::IsBlack(Marking::MarkBitFrom(object))); |
254 if (IsFull()) { | 253 if (IsFull()) { |
255 Marking::BlackToGrey(object); | |
256 MemoryChunk::IncrementLiveBytesFromGC(object, -object->Size()); | |
257 SetOverflowed(); | 254 SetOverflowed(); |
| 255 return false; |
258 } else { | 256 } else { |
259 bottom_ = ((bottom_ - 1) & mask_); | 257 bottom_ = ((bottom_ - 1) & mask_); |
260 array_[bottom_] = object; | 258 array_[bottom_] = object; |
| 259 return true; |
261 } | 260 } |
262 } | 261 } |
263 | 262 |
264 HeapObject** array() { return array_; } | 263 HeapObject** array() { return array_; } |
265 int bottom() { return bottom_; } | 264 int bottom() { return bottom_; } |
266 int top() { return top_; } | 265 int top() { return top_; } |
267 int mask() { return mask_; } | 266 int mask() { return mask_; } |
268 void set_top(int top) { top_ = top; } | 267 void set_top(int top) { top_ = top; } |
269 | 268 |
270 private: | 269 private: |
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
754 | 753 |
755 // ----------------------------------------------------------------------- | 754 // ----------------------------------------------------------------------- |
756 // Phase 1: Marking live objects. | 755 // Phase 1: Marking live objects. |
757 // | 756 // |
758 // Before: The heap has been prepared for garbage collection by | 757 // Before: The heap has been prepared for garbage collection by |
759 // MarkCompactCollector::Prepare() and is otherwise in its | 758 // MarkCompactCollector::Prepare() and is otherwise in its |
760 // normal state. | 759 // normal state. |
761 // | 760 // |
762 // After: Live objects are marked and non-live objects are unmarked. | 761 // After: Live objects are marked and non-live objects are unmarked. |
763 | 762 |
| 763 friend class CodeMarkingVisitor; |
| 764 friend class MarkCompactMarkingVisitor; |
| 765 friend class MarkingVisitor; |
764 friend class RootMarkingVisitor; | 766 friend class RootMarkingVisitor; |
765 friend class MarkingVisitor; | |
766 friend class MarkCompactMarkingVisitor; | |
767 friend class CodeMarkingVisitor; | |
768 friend class SharedFunctionInfoMarkingVisitor; | 767 friend class SharedFunctionInfoMarkingVisitor; |
| 768 friend class IncrementalMarkingMarkingVisitor; |
769 | 769 |
770 // Mark code objects that are active on the stack to prevent them | 770 // Mark code objects that are active on the stack to prevent them |
771 // from being flushed. | 771 // from being flushed. |
772 void PrepareThreadForCodeFlushing(Isolate* isolate, ThreadLocalTop* top); | 772 void PrepareThreadForCodeFlushing(Isolate* isolate, ThreadLocalTop* top); |
773 | 773 |
774 void PrepareForCodeFlushing(); | 774 void PrepareForCodeFlushing(); |
775 | 775 |
776 // Marking operations for objects reachable from roots. | 776 // Marking operations for objects reachable from roots. |
777 void MarkLiveObjects(); | 777 void MarkLiveObjects(); |
778 | 778 |
779 void AfterMarking(); | 779 void AfterMarking(); |
780 | 780 |
| 781 // Pushes a black object onto the marking stack and accounts for live bytes. |
| 782 // Note that this assumes live bytes have not yet been counted. |
| 783 INLINE(void PushBlack(HeapObject* obj)); |
| 784 |
| 785 // Unshifts a black object into the marking stack and accounts for live bytes. |
| 786 // Note that this assumes lives bytes have already been counted. |
| 787 INLINE(void UnshiftBlack(HeapObject* obj)); |
| 788 |
781 // Marks the object black and pushes it on the marking stack. | 789 // Marks the object black and pushes it on the marking stack. |
782 // This is for non-incremental marking only. | 790 // This is for non-incremental marking only. |
783 INLINE(void MarkObject(HeapObject* obj, MarkBit mark_bit)); | 791 INLINE(void MarkObject(HeapObject* obj, MarkBit mark_bit)); |
784 | 792 |
785 // Marks the object black assuming that it is not yet marked. | 793 // Marks the object black assuming that it is not yet marked. |
786 // This is for non-incremental marking only. | 794 // This is for non-incremental marking only. |
787 INLINE(void SetMark(HeapObject* obj, MarkBit mark_bit)); | 795 INLINE(void SetMark(HeapObject* obj, MarkBit mark_bit)); |
788 | 796 |
789 // Mark the heap roots and all objects reachable from them. | 797 // Mark the heap roots and all objects reachable from them. |
790 void MarkRoots(RootMarkingVisitor* visitor); | 798 void MarkRoots(RootMarkingVisitor* visitor); |
(...skipping 28 matching lines...) Expand all Loading... |
819 // stack. This function empties the marking stack, but may leave | 827 // stack. This function empties the marking stack, but may leave |
820 // overflowed objects in the heap, in which case the marking stack's | 828 // overflowed objects in the heap, in which case the marking stack's |
821 // overflow flag will be set. | 829 // overflow flag will be set. |
822 void EmptyMarkingDeque(); | 830 void EmptyMarkingDeque(); |
823 | 831 |
824 // Refill the marking stack with overflowed objects from the heap. This | 832 // Refill the marking stack with overflowed objects from the heap. This |
825 // function either leaves the marking stack full or clears the overflow | 833 // function either leaves the marking stack full or clears the overflow |
826 // flag on the marking stack. | 834 // flag on the marking stack. |
827 void RefillMarkingDeque(); | 835 void RefillMarkingDeque(); |
828 | 836 |
| 837 // Helper methods for refilling the marking stack by discovering grey objects |
| 838 // on various pages of the heap. Used by {RefillMarkingDeque} only. |
| 839 template <class T> |
| 840 void DiscoverGreyObjectsWithIterator(T* it); |
| 841 void DiscoverGreyObjectsOnPage(MemoryChunk* p); |
| 842 void DiscoverGreyObjectsInSpace(PagedSpace* space); |
| 843 void DiscoverGreyObjectsInNewSpace(); |
| 844 |
829 // Callback function for telling whether the object *p is an unmarked | 845 // Callback function for telling whether the object *p is an unmarked |
830 // heap object. | 846 // heap object. |
831 static bool IsUnmarkedHeapObject(Object** p); | 847 static bool IsUnmarkedHeapObject(Object** p); |
832 | 848 |
833 // Map transitions from a live map to a dead map must be killed. | 849 // Map transitions from a live map to a dead map must be killed. |
834 // We replace them with a null descriptor, with the same key. | 850 // We replace them with a null descriptor, with the same key. |
835 void ClearNonLiveReferences(); | 851 void ClearNonLiveReferences(); |
836 void ClearNonLivePrototypeTransitions(Map* map); | 852 void ClearNonLivePrototypeTransitions(Map* map); |
837 void ClearNonLiveMapTransitions(Map* map, MarkBit map_mark); | 853 void ClearNonLiveMapTransitions(Map* map, MarkBit map_mark); |
838 void ClearMapTransitions(Map* map, Map* dead_transition); | 854 void ClearMapTransitions(Map* map, Map* dead_transition); |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
981 private: | 997 private: |
982 MarkCompactCollector* collector_; | 998 MarkCompactCollector* collector_; |
983 }; | 999 }; |
984 | 1000 |
985 | 1001 |
986 const char* AllocationSpaceName(AllocationSpace space); | 1002 const char* AllocationSpaceName(AllocationSpace space); |
987 } | 1003 } |
988 } // namespace v8::internal | 1004 } // namespace v8::internal |
989 | 1005 |
990 #endif // V8_HEAP_MARK_COMPACT_H_ | 1006 #endif // V8_HEAP_MARK_COMPACT_H_ |
OLD | NEW |