OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 class MarkingVisitor; | 46 class MarkingVisitor; |
47 class RootMarkingVisitor; | 47 class RootMarkingVisitor; |
48 | 48 |
49 | 49 |
50 class Marking { | 50 class Marking { |
51 public: | 51 public: |
52 explicit Marking(Heap* heap) | 52 explicit Marking(Heap* heap) |
53 : heap_(heap) { | 53 : heap_(heap) { |
54 } | 54 } |
55 | 55 |
56 static inline MarkBit MarkBitFrom(Address addr); | 56 INLINE(static MarkBit MarkBitFrom(Address addr)); |
57 | 57 |
58 static inline MarkBit MarkBitFrom(HeapObject* obj) { | 58 INLINE(static MarkBit MarkBitFrom(HeapObject* obj)) { |
59 return MarkBitFrom(reinterpret_cast<Address>(obj)); | 59 return MarkBitFrom(reinterpret_cast<Address>(obj)); |
60 } | 60 } |
61 | 61 |
62 // Impossible markbits: 01 | 62 // Impossible markbits: 01 |
63 static const char* kImpossibleBitPattern; | 63 static const char* kImpossibleBitPattern; |
64 static inline bool IsImpossible(MarkBit mark_bit) { | 64 INLINE(static bool IsImpossible(MarkBit mark_bit)) { |
65 return !mark_bit.Get() && mark_bit.Next().Get(); | 65 return !mark_bit.Get() && mark_bit.Next().Get(); |
66 } | 66 } |
67 | 67 |
68 // Black markbits: 10 - this is required by the sweeper. | 68 // Black markbits: 10 - this is required by the sweeper. |
69 static const char* kBlackBitPattern; | 69 static const char* kBlackBitPattern; |
70 static inline bool IsBlack(MarkBit mark_bit) { | 70 INLINE(static bool IsBlack(MarkBit mark_bit)) { |
71 return mark_bit.Get() && !mark_bit.Next().Get(); | 71 return mark_bit.Get() && !mark_bit.Next().Get(); |
72 } | 72 } |
73 | 73 |
74 // White markbits: 00 - this is required by the mark bit clearer. | 74 // White markbits: 00 - this is required by the mark bit clearer. |
75 static const char* kWhiteBitPattern; | 75 static const char* kWhiteBitPattern; |
76 static inline bool IsWhite(MarkBit mark_bit) { | 76 INLINE(static bool IsWhite(MarkBit mark_bit)) { |
77 return !mark_bit.Get(); | 77 return !mark_bit.Get(); |
78 } | 78 } |
79 | 79 |
80 // Grey markbits: 11 | 80 // Grey markbits: 11 |
81 static const char* kGreyBitPattern; | 81 static const char* kGreyBitPattern; |
82 static inline bool IsGrey(MarkBit mark_bit) { | 82 INLINE(static bool IsGrey(MarkBit mark_bit)) { |
83 return mark_bit.Get() && mark_bit.Next().Get(); | 83 return mark_bit.Get() && mark_bit.Next().Get(); |
84 } | 84 } |
85 | 85 |
86 static inline void MarkBlack(MarkBit mark_bit) { | 86 INLINE(static void MarkBlack(MarkBit mark_bit)) { |
87 mark_bit.Set(); | 87 mark_bit.Set(); |
88 mark_bit.Next().Clear(); | 88 mark_bit.Next().Clear(); |
89 } | 89 } |
90 | 90 |
91 static inline void BlackToGrey(MarkBit markbit) { | 91 INLINE(static void BlackToGrey(MarkBit markbit)) { |
92 markbit.Next().Set(); | 92 markbit.Next().Set(); |
93 } | 93 } |
94 | 94 |
95 static inline void WhiteToGrey(MarkBit markbit) { | 95 INLINE(static void WhiteToGrey(MarkBit markbit)) { |
96 markbit.Set(); | 96 markbit.Set(); |
97 markbit.Next().Set(); | 97 markbit.Next().Set(); |
98 } | 98 } |
99 | 99 |
100 static inline void GreyToBlack(MarkBit markbit) { | 100 INLINE(static void GreyToBlack(MarkBit markbit)) { |
101 markbit.Next().Clear(); | 101 markbit.Next().Clear(); |
102 } | 102 } |
103 | 103 |
104 static inline void BlackToGrey(HeapObject* obj) { | 104 INLINE(static void BlackToGrey(HeapObject* obj)) { |
105 BlackToGrey(MarkBitFrom(obj)); | 105 BlackToGrey(MarkBitFrom(obj)); |
106 } | 106 } |
107 | 107 |
108 static inline void AnyToGrey(MarkBit markbit) { | 108 INLINE(static void AnyToGrey(MarkBit markbit)) { |
109 markbit.Set(); | 109 markbit.Set(); |
110 markbit.Next().Set(); | 110 markbit.Next().Set(); |
111 } | 111 } |
112 | 112 |
113 // Returns true if the the object whose mark is transferred is marked black. | 113 // Returns true if the the object whose mark is transferred is marked black. |
114 bool TransferMark(Address old_start, Address new_start); | 114 bool TransferMark(Address old_start, Address new_start); |
115 | 115 |
116 #ifdef DEBUG | 116 #ifdef DEBUG |
117 enum ObjectColor { | 117 enum ObjectColor { |
118 BLACK_OBJECT, | 118 BLACK_OBJECT, |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 | 187 |
188 bool overflowed() const { return overflowed_; } | 188 bool overflowed() const { return overflowed_; } |
189 | 189 |
190 void ClearOverflowed() { overflowed_ = false; } | 190 void ClearOverflowed() { overflowed_ = false; } |
191 | 191 |
192 void SetOverflowed() { overflowed_ = true; } | 192 void SetOverflowed() { overflowed_ = true; } |
193 | 193 |
194 // Push the (marked) object on the marking stack if there is room, | 194 // Push the (marked) object on the marking stack if there is room, |
195 // otherwise mark the object as overflowed and wait for a rescan of the | 195 // otherwise mark the object as overflowed and wait for a rescan of the |
196 // heap. | 196 // heap. |
197 inline void PushBlack(HeapObject* object) { | 197 INLINE(void PushBlack(HeapObject* object)) { |
198 ASSERT(object->IsHeapObject()); | 198 ASSERT(object->IsHeapObject()); |
199 if (IsFull()) { | 199 if (IsFull()) { |
200 Marking::BlackToGrey(object); | 200 Marking::BlackToGrey(object); |
201 MemoryChunk::IncrementLiveBytesFromGC(object->address(), -object->Size()); | 201 MemoryChunk::IncrementLiveBytesFromGC(object->address(), -object->Size()); |
202 SetOverflowed(); | 202 SetOverflowed(); |
203 } else { | 203 } else { |
204 array_[top_] = object; | 204 array_[top_] = object; |
205 top_ = ((top_ + 1) & mask_); | 205 top_ = ((top_ + 1) & mask_); |
206 } | 206 } |
207 } | 207 } |
208 | 208 |
209 inline void PushGrey(HeapObject* object) { | 209 INLINE(void PushGrey(HeapObject* object)) { |
210 ASSERT(object->IsHeapObject()); | 210 ASSERT(object->IsHeapObject()); |
211 if (IsFull()) { | 211 if (IsFull()) { |
212 SetOverflowed(); | 212 SetOverflowed(); |
213 } else { | 213 } else { |
214 array_[top_] = object; | 214 array_[top_] = object; |
215 top_ = ((top_ + 1) & mask_); | 215 top_ = ((top_ + 1) & mask_); |
216 } | 216 } |
217 } | 217 } |
218 | 218 |
219 inline HeapObject* Pop() { | 219 INLINE(HeapObject* Pop()) { |
220 ASSERT(!IsEmpty()); | 220 ASSERT(!IsEmpty()); |
221 top_ = ((top_ - 1) & mask_); | 221 top_ = ((top_ - 1) & mask_); |
222 HeapObject* object = array_[top_]; | 222 HeapObject* object = array_[top_]; |
223 ASSERT(object->IsHeapObject()); | 223 ASSERT(object->IsHeapObject()); |
224 return object; | 224 return object; |
225 } | 225 } |
226 | 226 |
227 inline void UnshiftGrey(HeapObject* object) { | 227 INLINE(void UnshiftGrey(HeapObject* object)) { |
228 ASSERT(object->IsHeapObject()); | 228 ASSERT(object->IsHeapObject()); |
229 if (IsFull()) { | 229 if (IsFull()) { |
230 SetOverflowed(); | 230 SetOverflowed(); |
231 } else { | 231 } else { |
232 bottom_ = ((bottom_ - 1) & mask_); | 232 bottom_ = ((bottom_ - 1) & mask_); |
233 array_[bottom_] = object; | 233 array_[bottom_] = object; |
234 } | 234 } |
235 } | 235 } |
236 | 236 |
237 HeapObject** array() { return array_; } | 237 HeapObject** array() { return array_; } |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 | 359 |
360 enum AdditionMode { | 360 enum AdditionMode { |
361 FAIL_ON_OVERFLOW, | 361 FAIL_ON_OVERFLOW, |
362 IGNORE_OVERFLOW | 362 IGNORE_OVERFLOW |
363 }; | 363 }; |
364 | 364 |
365 static bool ChainLengthThresholdReached(SlotsBuffer* buffer) { | 365 static bool ChainLengthThresholdReached(SlotsBuffer* buffer) { |
366 return buffer != NULL && buffer->chain_length_ >= kChainLengthThreshold; | 366 return buffer != NULL && buffer->chain_length_ >= kChainLengthThreshold; |
367 } | 367 } |
368 | 368 |
369 static bool AddTo(SlotsBufferAllocator* allocator, | 369 INLINE(static bool AddTo(SlotsBufferAllocator* allocator, |
370 SlotsBuffer** buffer_address, | 370 SlotsBuffer** buffer_address, |
371 ObjectSlot slot, | 371 ObjectSlot slot, |
372 AdditionMode mode) { | 372 AdditionMode mode)) { |
373 SlotsBuffer* buffer = *buffer_address; | 373 SlotsBuffer* buffer = *buffer_address; |
374 if (buffer == NULL || buffer->IsFull()) { | 374 if (buffer == NULL || buffer->IsFull()) { |
375 if (mode == FAIL_ON_OVERFLOW && ChainLengthThresholdReached(buffer)) { | 375 if (mode == FAIL_ON_OVERFLOW && ChainLengthThresholdReached(buffer)) { |
376 allocator->DeallocateChain(buffer_address); | 376 allocator->DeallocateChain(buffer_address); |
377 return false; | 377 return false; |
378 } | 378 } |
379 buffer = allocator->AllocateBuffer(buffer); | 379 buffer = allocator->AllocateBuffer(buffer); |
380 *buffer_address = buffer; | 380 *buffer_address = buffer; |
381 } | 381 } |
382 buffer->Add(slot); | 382 buffer->Add(slot); |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
627 INLINE(static bool ShouldSkipEvacuationSlotRecording(Object* host)) { | 627 INLINE(static bool ShouldSkipEvacuationSlotRecording(Object* host)) { |
628 return Page::FromAddress(reinterpret_cast<Address>(host))-> | 628 return Page::FromAddress(reinterpret_cast<Address>(host))-> |
629 ShouldSkipEvacuationSlotRecording(); | 629 ShouldSkipEvacuationSlotRecording(); |
630 } | 630 } |
631 | 631 |
632 INLINE(static bool IsOnEvacuationCandidate(Object* obj)) { | 632 INLINE(static bool IsOnEvacuationCandidate(Object* obj)) { |
633 return Page::FromAddress(reinterpret_cast<Address>(obj))-> | 633 return Page::FromAddress(reinterpret_cast<Address>(obj))-> |
634 IsEvacuationCandidate(); | 634 IsEvacuationCandidate(); |
635 } | 635 } |
636 | 636 |
637 void EvictEvacuationCandidate(Page* page) { | 637 INLINE(void EvictEvacuationCandidate(Page* page)) { |
638 if (FLAG_trace_fragmentation) { | 638 if (FLAG_trace_fragmentation) { |
639 PrintF("Page %p is too popular. Disabling evacuation.\n", | 639 PrintF("Page %p is too popular. Disabling evacuation.\n", |
640 reinterpret_cast<void*>(page)); | 640 reinterpret_cast<void*>(page)); |
641 } | 641 } |
642 | 642 |
643 // TODO(gc) If all evacuation candidates are too popular we | 643 // TODO(gc) If all evacuation candidates are too popular we |
644 // should stop slots recording entirely. | 644 // should stop slots recording entirely. |
645 page->ClearEvacuationCandidate(); | 645 page->ClearEvacuationCandidate(); |
646 | 646 |
647 // We were not collecting slots on this page that point | 647 // We were not collecting slots on this page that point |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
902 | 902 |
903 friend class Heap; | 903 friend class Heap; |
904 }; | 904 }; |
905 | 905 |
906 | 906 |
907 const char* AllocationSpaceName(AllocationSpace space); | 907 const char* AllocationSpaceName(AllocationSpace space); |
908 | 908 |
909 } } // namespace v8::internal | 909 } } // namespace v8::internal |
910 | 910 |
911 #endif // V8_MARK_COMPACT_H_ | 911 #endif // V8_MARK_COMPACT_H_ |
OLD | NEW |