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 5748 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5759 class HeapObjectsFilter { | 5759 class HeapObjectsFilter { |
5760 public: | 5760 public: |
5761 virtual ~HeapObjectsFilter() {} | 5761 virtual ~HeapObjectsFilter() {} |
5762 virtual bool SkipObject(HeapObject* object) = 0; | 5762 virtual bool SkipObject(HeapObject* object) = 0; |
5763 }; | 5763 }; |
5764 | 5764 |
5765 | 5765 |
5766 class UnreachableObjectsFilter : public HeapObjectsFilter { | 5766 class UnreachableObjectsFilter : public HeapObjectsFilter { |
5767 public: | 5767 public: |
5768 UnreachableObjectsFilter() { | 5768 UnreachableObjectsFilter() { |
5769 MarkUnreachableObjects(); | 5769 MarkReachableObjects(); |
| 5770 } |
| 5771 |
| 5772 ~UnreachableObjectsFilter() { |
| 5773 Isolate::Current()->heap()->mark_compact_collector()->ClearMarkbits(); |
5770 } | 5774 } |
5771 | 5775 |
5772 bool SkipObject(HeapObject* object) { | 5776 bool SkipObject(HeapObject* object) { |
5773 if (IntrusiveMarking::IsMarked(object)) { | 5777 MarkBit mark_bit = Marking::MarkBitFrom(object); |
5774 IntrusiveMarking::ClearMark(object); | 5778 return !mark_bit.Get(); |
5775 return true; | |
5776 } else { | |
5777 return false; | |
5778 } | |
5779 } | 5779 } |
5780 | 5780 |
5781 private: | 5781 private: |
5782 class UnmarkingVisitor : public ObjectVisitor { | 5782 class MarkingVisitor : public ObjectVisitor { |
5783 public: | 5783 public: |
5784 UnmarkingVisitor() : list_(10) {} | 5784 MarkingVisitor() : marking_stack_(10) {} |
5785 | 5785 |
5786 void VisitPointers(Object** start, Object** end) { | 5786 void VisitPointers(Object** start, Object** end) { |
5787 for (Object** p = start; p < end; p++) { | 5787 for (Object** p = start; p < end; p++) { |
5788 if (!(*p)->IsHeapObject()) continue; | 5788 if (!(*p)->IsHeapObject()) continue; |
5789 HeapObject* obj = HeapObject::cast(*p); | 5789 HeapObject* obj = HeapObject::cast(*p); |
5790 if (IntrusiveMarking::IsMarked(obj)) { | 5790 MarkBit mark_bit = Marking::MarkBitFrom(obj); |
5791 IntrusiveMarking::ClearMark(obj); | 5791 if (!mark_bit.Get()) { |
5792 list_.Add(obj); | 5792 mark_bit.Set(); |
| 5793 marking_stack_.Add(obj); |
5793 } | 5794 } |
5794 } | 5795 } |
5795 } | 5796 } |
5796 | 5797 |
5797 bool can_process() { return !list_.is_empty(); } | 5798 void TransitiveClosure() { |
5798 | 5799 while (!marking_stack_.is_empty()) { |
5799 void ProcessNext() { | 5800 HeapObject* obj = marking_stack_.RemoveLast(); |
5800 HeapObject* obj = list_.RemoveLast(); | 5801 obj->Iterate(this); |
5801 obj->Iterate(this); | 5802 } |
5802 } | 5803 } |
5803 | 5804 |
5804 private: | 5805 private: |
5805 List<HeapObject*> list_; | 5806 List<HeapObject*> marking_stack_; |
5806 }; | 5807 }; |
5807 | 5808 |
5808 void MarkUnreachableObjects() { | 5809 void MarkReachableObjects() { |
5809 HeapIterator iterator; | 5810 Heap* heap = Isolate::Current()->heap(); |
5810 for (HeapObject* obj = iterator.next(); | 5811 MarkingVisitor visitor; |
5811 obj != NULL; | 5812 heap->IterateRoots(&visitor, VISIT_ALL); |
5812 obj = iterator.next()) { | 5813 visitor.TransitiveClosure(); |
5813 IntrusiveMarking::SetMark(obj); | |
5814 } | |
5815 UnmarkingVisitor visitor; | |
5816 HEAP->IterateRoots(&visitor, VISIT_ALL); | |
5817 while (visitor.can_process()) | |
5818 visitor.ProcessNext(); | |
5819 } | 5814 } |
5820 | 5815 |
5821 AssertNoAllocation no_alloc; | 5816 AssertNoAllocation no_alloc; |
5822 }; | 5817 }; |
5823 | 5818 |
5824 | 5819 |
5825 HeapIterator::HeapIterator() | 5820 HeapIterator::HeapIterator() |
5826 : filtering_(HeapIterator::kNoFiltering), | 5821 : filtering_(HeapIterator::kNoFiltering), |
5827 filter_(NULL) { | 5822 filter_(NULL) { |
5828 Init(); | 5823 Init(); |
5829 } | 5824 } |
5830 | 5825 |
5831 | 5826 |
5832 HeapIterator::HeapIterator(HeapIterator::HeapObjectsFiltering filtering) | 5827 HeapIterator::HeapIterator(HeapIterator::HeapObjectsFiltering filtering) |
5833 : filtering_(filtering), | 5828 : filtering_(filtering), |
5834 filter_(NULL) { | 5829 filter_(NULL) { |
5835 Init(); | 5830 Init(); |
5836 } | 5831 } |
5837 | 5832 |
5838 | 5833 |
5839 HeapIterator::~HeapIterator() { | 5834 HeapIterator::~HeapIterator() { |
5840 Shutdown(); | 5835 Shutdown(); |
5841 } | 5836 } |
5842 | 5837 |
5843 | 5838 |
5844 void HeapIterator::Init() { | 5839 void HeapIterator::Init() { |
5845 // Start the iteration. | 5840 // Start the iteration. |
5846 space_iterator_ = filtering_ == kNoFiltering ? new SpaceIterator : | 5841 space_iterator_ = new SpaceIterator; |
5847 new SpaceIterator(Isolate::Current()->heap()-> | |
5848 GcSafeSizeOfOldObjectFunction()); | |
5849 switch (filtering_) { | 5842 switch (filtering_) { |
5850 case kFilterFreeListNodes: | |
5851 // TODO(gc): Not handled. | |
5852 break; | |
5853 case kFilterUnreachable: | 5843 case kFilterUnreachable: |
5854 filter_ = new UnreachableObjectsFilter; | 5844 filter_ = new UnreachableObjectsFilter; |
5855 break; | 5845 break; |
5856 default: | 5846 default: |
5857 break; | 5847 break; |
5858 } | 5848 } |
5859 object_iterator_ = space_iterator_->next(); | 5849 object_iterator_ = space_iterator_->next(); |
5860 } | 5850 } |
5861 | 5851 |
5862 | 5852 |
(...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6406 isolate_->heap()->store_buffer()->Compact(); | 6396 isolate_->heap()->store_buffer()->Compact(); |
6407 isolate_->heap()->store_buffer()->Filter(MemoryChunk::ABOUT_TO_BE_FREED); | 6397 isolate_->heap()->store_buffer()->Filter(MemoryChunk::ABOUT_TO_BE_FREED); |
6408 for (chunk = chunks_queued_for_free_; chunk != NULL; chunk = next) { | 6398 for (chunk = chunks_queued_for_free_; chunk != NULL; chunk = next) { |
6409 next = chunk->next_chunk(); | 6399 next = chunk->next_chunk(); |
6410 isolate_->memory_allocator()->Free(chunk); | 6400 isolate_->memory_allocator()->Free(chunk); |
6411 } | 6401 } |
6412 chunks_queued_for_free_ = NULL; | 6402 chunks_queued_for_free_ = NULL; |
6413 } | 6403 } |
6414 | 6404 |
6415 } } // namespace v8::internal | 6405 } } // namespace v8::internal |
OLD | NEW |