| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 | 54 |
| 55 static inline MarkBit MarkBitFrom(Address addr); | 55 static inline MarkBit MarkBitFrom(Address addr); |
| 56 | 56 |
| 57 static inline MarkBit MarkBitFrom(HeapObject* obj) { | 57 static inline MarkBit MarkBitFrom(HeapObject* obj) { |
| 58 return MarkBitFrom(reinterpret_cast<Address>(obj)); | 58 return MarkBitFrom(reinterpret_cast<Address>(obj)); |
| 59 } | 59 } |
| 60 | 60 |
| 61 // Impossible markbits: 01 | 61 // Impossible markbits: 01 |
| 62 static const char* kImpossibleBitPattern; | 62 static const char* kImpossibleBitPattern; |
| 63 static inline bool IsImpossible(MarkBit mark_bit) { | 63 static inline bool IsImpossible(MarkBit mark_bit) { |
| 64 ASSERT(strcmp(kImpossibleBitPattern, "01") == 0); | |
| 65 return !mark_bit.Get() && mark_bit.Next().Get(); | 64 return !mark_bit.Get() && mark_bit.Next().Get(); |
| 66 } | 65 } |
| 67 | 66 |
| 68 // Black markbits: 10 - this is required by the sweeper. | 67 // Black markbits: 10 - this is required by the sweeper. |
| 69 static const char* kBlackBitPattern; | 68 static const char* kBlackBitPattern; |
| 70 static inline bool IsBlack(MarkBit mark_bit) { | 69 static inline bool IsBlack(MarkBit mark_bit) { |
| 71 ASSERT(strcmp(kBlackBitPattern, "10") == 0); | |
| 72 ASSERT(!IsImpossible(mark_bit)); | |
| 73 return mark_bit.Get() && !mark_bit.Next().Get(); | 70 return mark_bit.Get() && !mark_bit.Next().Get(); |
| 74 } | 71 } |
| 75 | 72 |
| 76 // White markbits: 00 - this is required by the mark bit clearer. | 73 // White markbits: 00 - this is required by the mark bit clearer. |
| 77 static const char* kWhiteBitPattern; | 74 static const char* kWhiteBitPattern; |
| 78 static inline bool IsWhite(MarkBit mark_bit) { | 75 static inline bool IsWhite(MarkBit mark_bit) { |
| 79 ASSERT(strcmp(kWhiteBitPattern, "00") == 0); | |
| 80 ASSERT(!IsImpossible(mark_bit)); | |
| 81 return !mark_bit.Get(); | 76 return !mark_bit.Get(); |
| 82 } | 77 } |
| 83 | 78 |
| 84 // Grey markbits: 11 | 79 // Grey markbits: 11 |
| 85 static const char* kGreyBitPattern; | 80 static const char* kGreyBitPattern; |
| 86 static inline bool IsGrey(MarkBit mark_bit) { | 81 static inline bool IsGrey(MarkBit mark_bit) { |
| 87 ASSERT(strcmp(kGreyBitPattern, "11") == 0); | |
| 88 ASSERT(!IsImpossible(mark_bit)); | |
| 89 return mark_bit.Get() && mark_bit.Next().Get(); | 82 return mark_bit.Get() && mark_bit.Next().Get(); |
| 90 } | 83 } |
| 91 | 84 |
| 92 static inline void MarkBlack(MarkBit mark_bit) { | 85 static inline void MarkBlack(MarkBit mark_bit) { |
| 93 mark_bit.Set(); | 86 mark_bit.Set(); |
| 94 mark_bit.Next().Clear(); | 87 mark_bit.Next().Clear(); |
| 95 ASSERT(Marking::IsBlack(mark_bit)); | |
| 96 } | 88 } |
| 97 | 89 |
| 98 static inline void BlackToGrey(MarkBit markbit) { | 90 static inline void BlackToGrey(MarkBit markbit) { |
| 99 ASSERT(IsBlack(markbit)); | |
| 100 markbit.Next().Set(); | 91 markbit.Next().Set(); |
| 101 ASSERT(IsGrey(markbit)); | |
| 102 } | 92 } |
| 103 | 93 |
| 104 static inline void WhiteToGrey(MarkBit markbit) { | 94 static inline void WhiteToGrey(MarkBit markbit) { |
| 105 ASSERT(IsWhite(markbit)); | |
| 106 markbit.Set(); | 95 markbit.Set(); |
| 107 markbit.Next().Set(); | 96 markbit.Next().Set(); |
| 108 ASSERT(IsGrey(markbit)); | |
| 109 } | 97 } |
| 110 | 98 |
| 111 static inline void GreyToBlack(MarkBit markbit) { | 99 static inline void GreyToBlack(MarkBit markbit) { |
| 112 ASSERT(IsGrey(markbit)); | |
| 113 markbit.Next().Clear(); | 100 markbit.Next().Clear(); |
| 114 ASSERT(IsBlack(markbit)); | |
| 115 } | 101 } |
| 116 | 102 |
| 117 static inline void BlackToGrey(HeapObject* obj) { | 103 static inline void BlackToGrey(HeapObject* obj) { |
| 118 ASSERT(obj->Size() >= 2 * kPointerSize); | |
| 119 BlackToGrey(MarkBitFrom(obj)); | 104 BlackToGrey(MarkBitFrom(obj)); |
| 120 } | 105 } |
| 121 | 106 |
| 122 static inline void AnyToGrey(MarkBit markbit) { | 107 static inline void AnyToGrey(MarkBit markbit) { |
| 123 markbit.Set(); | 108 markbit.Set(); |
| 124 markbit.Next().Set(); | 109 markbit.Next().Set(); |
| 125 ASSERT(IsGrey(markbit)); | |
| 126 } | 110 } |
| 127 | 111 |
| 128 // Returns true if the the object whose mark is transferred is marked black. | 112 // Returns true if the the object whose mark is transferred is marked black. |
| 129 bool TransferMark(Address old_start, Address new_start); | 113 bool TransferMark(Address old_start, Address new_start); |
| 130 | 114 |
| 131 #ifdef DEBUG | 115 #ifdef DEBUG |
| 132 enum ObjectColor { | 116 enum ObjectColor { |
| 133 BLACK_OBJECT, | 117 BLACK_OBJECT, |
| 134 WHITE_OBJECT, | 118 WHITE_OBJECT, |
| 135 GREY_OBJECT, | 119 GREY_OBJECT, |
| (...skipping 30 matching lines...) Expand all Loading... |
| 166 MarkBit to_mark_bit = MarkBitFrom(to); | 150 MarkBit to_mark_bit = MarkBitFrom(to); |
| 167 bool is_black = false; | 151 bool is_black = false; |
| 168 if (from_mark_bit.Get()) { | 152 if (from_mark_bit.Get()) { |
| 169 to_mark_bit.Set(); | 153 to_mark_bit.Set(); |
| 170 is_black = true; // Looks black so far. | 154 is_black = true; // Looks black so far. |
| 171 } | 155 } |
| 172 if (from_mark_bit.Next().Get()) { | 156 if (from_mark_bit.Next().Get()) { |
| 173 to_mark_bit.Next().Set(); | 157 to_mark_bit.Next().Set(); |
| 174 is_black = false; // Was actually gray. | 158 is_black = false; // Was actually gray. |
| 175 } | 159 } |
| 176 ASSERT(Color(from) == Color(to)); | |
| 177 ASSERT(is_black == (Color(to) == BLACK_OBJECT)); | |
| 178 return is_black; | 160 return is_black; |
| 179 } | 161 } |
| 180 | 162 |
| 181 private: | 163 private: |
| 182 Heap* heap_; | 164 Heap* heap_; |
| 183 }; | 165 }; |
| 184 | 166 |
| 185 // ---------------------------------------------------------------------------- | 167 // ---------------------------------------------------------------------------- |
| 186 // Marking deque for tracing live objects. | 168 // Marking deque for tracing live objects. |
| 187 | 169 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 SetOverflowed(); | 202 SetOverflowed(); |
| 221 } else { | 203 } else { |
| 222 array_[top_] = object; | 204 array_[top_] = object; |
| 223 top_ = ((top_ + 1) & mask_); | 205 top_ = ((top_ + 1) & mask_); |
| 224 } | 206 } |
| 225 } | 207 } |
| 226 | 208 |
| 227 inline void PushGrey(HeapObject* object) { | 209 inline void PushGrey(HeapObject* object) { |
| 228 ASSERT(object->IsHeapObject()); | 210 ASSERT(object->IsHeapObject()); |
| 229 if (IsFull()) { | 211 if (IsFull()) { |
| 230 ASSERT(Marking::IsGrey(Marking::MarkBitFrom(object))); | |
| 231 SetOverflowed(); | 212 SetOverflowed(); |
| 232 } else { | 213 } else { |
| 233 array_[top_] = object; | 214 array_[top_] = object; |
| 234 top_ = ((top_ + 1) & mask_); | 215 top_ = ((top_ + 1) & mask_); |
| 235 } | 216 } |
| 236 } | 217 } |
| 237 | 218 |
| 238 inline HeapObject* Pop() { | 219 inline HeapObject* Pop() { |
| 239 ASSERT(!IsEmpty()); | 220 ASSERT(!IsEmpty()); |
| 240 top_ = ((top_ - 1) & mask_); | 221 top_ = ((top_ - 1) & mask_); |
| 241 HeapObject* object = array_[top_]; | 222 HeapObject* object = array_[top_]; |
| 242 ASSERT(object->IsHeapObject()); | 223 ASSERT(object->IsHeapObject()); |
| 243 return object; | 224 return object; |
| 244 } | 225 } |
| 245 | 226 |
| 246 inline void UnshiftGrey(HeapObject* object) { | 227 inline void UnshiftGrey(HeapObject* object) { |
| 247 ASSERT(object->IsHeapObject()); | 228 ASSERT(object->IsHeapObject()); |
| 248 if (IsFull()) { | 229 if (IsFull()) { |
| 249 ASSERT(Marking::IsGrey(Marking::MarkBitFrom(object))); | |
| 250 SetOverflowed(); | 230 SetOverflowed(); |
| 251 } else { | 231 } else { |
| 252 bottom_ = ((bottom_ - 1) & mask_); | 232 bottom_ = ((bottom_ - 1) & mask_); |
| 253 array_[bottom_] = object; | 233 array_[bottom_] = object; |
| 254 } | 234 } |
| 255 } | 235 } |
| 256 | 236 |
| 257 HeapObject** array() { return array_; } | 237 HeapObject** array() { return array_; } |
| 258 int bottom() { return bottom_; } | 238 int bottom() { return bottom_; } |
| 259 int top() { return top_; } | 239 int top() { return top_; } |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 551 | 531 |
| 552 bool TryPromoteObject(HeapObject* object, int object_size); | 532 bool TryPromoteObject(HeapObject* object, int object_size); |
| 553 | 533 |
| 554 inline Object* encountered_weak_maps() { return encountered_weak_maps_; } | 534 inline Object* encountered_weak_maps() { return encountered_weak_maps_; } |
| 555 inline void set_encountered_weak_maps(Object* weak_map) { | 535 inline void set_encountered_weak_maps(Object* weak_map) { |
| 556 encountered_weak_maps_ = weak_map; | 536 encountered_weak_maps_ = weak_map; |
| 557 } | 537 } |
| 558 | 538 |
| 559 void InvalidateCode(Code* code); | 539 void InvalidateCode(Code* code); |
| 560 | 540 |
| 541 void ClearMarkbits(); |
| 542 |
| 561 private: | 543 private: |
| 562 MarkCompactCollector(); | 544 MarkCompactCollector(); |
| 563 ~MarkCompactCollector(); | 545 ~MarkCompactCollector(); |
| 564 | 546 |
| 565 bool MarkInvalidatedCode(); | 547 bool MarkInvalidatedCode(); |
| 566 void RemoveDeadInvalidatedCode(); | 548 void RemoveDeadInvalidatedCode(); |
| 567 void ProcessInvalidatedCode(ObjectVisitor* visitor); | 549 void ProcessInvalidatedCode(ObjectVisitor* visitor); |
| 568 | 550 |
| 569 | 551 |
| 570 #ifdef DEBUG | 552 #ifdef DEBUG |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 680 void RefillMarkingDeque(); | 662 void RefillMarkingDeque(); |
| 681 | 663 |
| 682 // After reachable maps have been marked process per context object | 664 // After reachable maps have been marked process per context object |
| 683 // literal map caches removing unmarked entries. | 665 // literal map caches removing unmarked entries. |
| 684 void ProcessMapCaches(); | 666 void ProcessMapCaches(); |
| 685 | 667 |
| 686 // Callback function for telling whether the object *p is an unmarked | 668 // Callback function for telling whether the object *p is an unmarked |
| 687 // heap object. | 669 // heap object. |
| 688 static bool IsUnmarkedHeapObject(Object** p); | 670 static bool IsUnmarkedHeapObject(Object** p); |
| 689 | 671 |
| 690 #ifdef DEBUG | |
| 691 void UpdateLiveObjectCount(HeapObject* obj); | |
| 692 #endif | |
| 693 | |
| 694 // Map transitions from a live map to a dead map must be killed. | 672 // Map transitions from a live map to a dead map must be killed. |
| 695 // We replace them with a null descriptor, with the same key. | 673 // We replace them with a null descriptor, with the same key. |
| 696 void ClearNonLiveTransitions(); | 674 void ClearNonLiveTransitions(); |
| 697 | 675 |
| 698 // Marking detaches initial maps from SharedFunctionInfo objects | 676 // Marking detaches initial maps from SharedFunctionInfo objects |
| 699 // to make this reference weak. We need to reattach initial maps | 677 // to make this reference weak. We need to reattach initial maps |
| 700 // back after collection. This is either done during | 678 // back after collection. This is either done during |
| 701 // ClearNonLiveTransitions pass or by calling this function. | 679 // ClearNonLiveTransitions pass or by calling this function. |
| 702 void ReattachInitialMaps(); | 680 void ReattachInitialMaps(); |
| 703 | 681 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 730 void EvacuateNewSpace(); | 708 void EvacuateNewSpace(); |
| 731 | 709 |
| 732 void EvacuateLiveObjectsFromPage(Page* p); | 710 void EvacuateLiveObjectsFromPage(Page* p); |
| 733 | 711 |
| 734 void EvacuatePages(); | 712 void EvacuatePages(); |
| 735 | 713 |
| 736 void EvacuateNewSpaceAndCandidates(); | 714 void EvacuateNewSpaceAndCandidates(); |
| 737 | 715 |
| 738 void SweepSpace(PagedSpace* space, SweeperType sweeper); | 716 void SweepSpace(PagedSpace* space, SweeperType sweeper); |
| 739 | 717 |
| 740 | |
| 741 #ifdef DEBUG | 718 #ifdef DEBUG |
| 742 // ----------------------------------------------------------------------- | |
| 743 // Debugging variables, functions and classes | |
| 744 // Counters used for debugging the marking phase of mark-compact or | |
| 745 // mark-sweep collection. | |
| 746 | |
| 747 // Size of live objects in Heap::to_space_. | |
| 748 int live_young_objects_size_; | |
| 749 | |
| 750 // Size of live objects in Heap::old_pointer_space_. | |
| 751 int live_old_pointer_objects_size_; | |
| 752 | |
| 753 // Size of live objects in Heap::old_data_space_. | |
| 754 int live_old_data_objects_size_; | |
| 755 | |
| 756 // Size of live objects in Heap::code_space_. | |
| 757 int live_code_objects_size_; | |
| 758 | |
| 759 // Size of live objects in Heap::map_space_. | |
| 760 int live_map_objects_size_; | |
| 761 | |
| 762 // Size of live objects in Heap::cell_space_. | |
| 763 int live_cell_objects_size_; | |
| 764 | |
| 765 // Size of live objects in Heap::lo_space_. | |
| 766 int live_lo_objects_size_; | |
| 767 | |
| 768 // Number of live bytes in this collection. | |
| 769 int live_bytes_; | |
| 770 | |
| 771 friend class MarkObjectVisitor; | 719 friend class MarkObjectVisitor; |
| 772 static void VisitObject(HeapObject* obj); | 720 static void VisitObject(HeapObject* obj); |
| 773 | 721 |
| 774 friend class UnmarkObjectVisitor; | 722 friend class UnmarkObjectVisitor; |
| 775 static void UnmarkObject(HeapObject* obj); | 723 static void UnmarkObject(HeapObject* obj); |
| 776 #endif | 724 #endif |
| 777 | 725 |
| 778 Heap* heap_; | 726 Heap* heap_; |
| 779 MarkingDeque marking_deque_; | 727 MarkingDeque marking_deque_; |
| 780 CodeFlusher* code_flusher_; | 728 CodeFlusher* code_flusher_; |
| 781 Object* encountered_weak_maps_; | 729 Object* encountered_weak_maps_; |
| 782 | 730 |
| 783 List<Page*> evacuation_candidates_; | 731 List<Page*> evacuation_candidates_; |
| 784 List<Code*> invalidated_code_; | 732 List<Code*> invalidated_code_; |
| 785 | 733 |
| 786 friend class Heap; | 734 friend class Heap; |
| 787 }; | 735 }; |
| 788 | 736 |
| 789 | 737 |
| 790 const char* AllocationSpaceName(AllocationSpace space); | 738 const char* AllocationSpaceName(AllocationSpace space); |
| 791 | 739 |
| 792 } } // namespace v8::internal | 740 } } // namespace v8::internal |
| 793 | 741 |
| 794 #endif // V8_MARK_COMPACT_H_ | 742 #endif // V8_MARK_COMPACT_H_ |
| OLD | NEW |