Chromium Code Reviews| 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 <deque> | 8 #include <deque> |
| 9 | 9 |
| 10 #include "src/base/bits.h" | 10 #include "src/base/bits.h" |
| (...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 433 virtual void TearDown() = 0; | 433 virtual void TearDown() = 0; |
| 434 virtual void CollectGarbage() = 0; | 434 virtual void CollectGarbage() = 0; |
| 435 | 435 |
| 436 inline Heap* heap() const { return heap_; } | 436 inline Heap* heap() const { return heap_; } |
| 437 inline Isolate* isolate() { return heap()->isolate(); } | 437 inline Isolate* isolate() { return heap()->isolate(); } |
| 438 | 438 |
| 439 protected: | 439 protected: |
| 440 explicit MarkCompactCollectorBase(Heap* heap) : heap_(heap) {} | 440 explicit MarkCompactCollectorBase(Heap* heap) : heap_(heap) {} |
| 441 | 441 |
| 442 virtual void MarkLiveObjects() = 0; | 442 virtual void MarkLiveObjects() = 0; |
| 443 virtual void ClearNonLiveReferences() = 0; | |
| 444 virtual void EvacuatePrologue() = 0; | |
| 445 virtual void EvacuateEpilogue() = 0; | |
| 446 virtual void UpdatePointersAfterEvacuation() = 0; | |
| 443 | 447 |
| 444 // The number of parallel compaction tasks, including the main thread. | 448 // The number of parallel compaction tasks, including the main thread. |
| 445 int NumberOfParallelCompactionTasks(int pages, intptr_t live_bytes); | 449 int NumberOfParallelCompactionTasks(int pages, intptr_t live_bytes); |
| 446 | 450 |
| 447 template <class Evacuator, class Collector> | 451 template <class Evacuator, class Collector> |
| 448 void CreateAndExecuteEvacuationTasks( | 452 void CreateAndExecuteEvacuationTasks( |
| 449 Collector* collector, PageParallelJob<EvacuationJobTraits>* job, | 453 Collector* collector, PageParallelJob<EvacuationJobTraits>* job, |
| 450 RecordMigratedSlotVisitor* record_visitor, const intptr_t live_bytes, | 454 RecordMigratedSlotVisitor* record_visitor, |
| 455 MigrationObserver* migration_observer, const intptr_t live_bytes, | |
| 451 const int& abandoned_pages); | 456 const int& abandoned_pages); |
| 452 | 457 |
| 453 Heap* heap_; | 458 Heap* heap_; |
| 454 }; | 459 }; |
| 455 | 460 |
| 456 // Collector for young-generation only. | 461 // Collector for young-generation only. |
| 457 class MinorMarkCompactCollector final : public MarkCompactCollectorBase { | 462 class MinorMarkCompactCollector final : public MarkCompactCollectorBase { |
| 458 public: | 463 public: |
| 459 explicit MinorMarkCompactCollector(Heap* heap) | 464 explicit MinorMarkCompactCollector(Heap* heap) |
| 460 : MarkCompactCollectorBase(heap), marking_deque_(heap) {} | 465 : MarkCompactCollectorBase(heap), |
| 466 marking_deque_(heap), | |
| 467 page_parallel_job_semaphore_(0) {} | |
| 461 | 468 |
| 462 MarkingState marking_state(HeapObject* object) const override { | 469 MarkingState marking_state(HeapObject* object) const override { |
| 463 return MarkingState::External(object); | 470 return MarkingState::External(object); |
| 464 } | 471 } |
| 465 | 472 |
| 466 MarkingState marking_state(MemoryChunk* chunk) const override { | 473 MarkingState marking_state(MemoryChunk* chunk) const override { |
| 467 return MarkingState::External(chunk); | 474 return MarkingState::External(chunk); |
| 468 } | 475 } |
| 469 | 476 |
| 470 void SetUp() override; | 477 void SetUp() override; |
| 471 void TearDown() override; | 478 void TearDown() override; |
| 472 void CollectGarbage() override; | 479 void CollectGarbage() override; |
| 473 | 480 |
| 474 private: | 481 private: |
| 475 class RootMarkingVisitor; | 482 class RootMarkingVisitor; |
| 476 | 483 |
| 477 inline MarkingDeque* marking_deque() { return &marking_deque_; } | 484 inline MarkingDeque* marking_deque() { return &marking_deque_; } |
| 478 | 485 |
| 479 V8_INLINE void MarkObject(HeapObject* obj); | 486 V8_INLINE void MarkObject(HeapObject* obj); |
| 480 V8_INLINE void PushBlack(HeapObject* obj); | 487 V8_INLINE void PushBlack(HeapObject* obj); |
| 481 | 488 |
| 482 SlotCallbackResult CheckAndMarkObject(Heap* heap, Address slot_address); | 489 SlotCallbackResult CheckAndMarkObject(Heap* heap, Address slot_address); |
| 483 void MarkLiveObjects() override; | 490 void MarkLiveObjects() override; |
| 484 void ProcessMarkingDeque(); | 491 void ProcessMarkingDeque(); |
|
Hannes Payer (out of office)
2017/05/02 16:17:26
ProcessMarkingDeque and EmtyMarkingDeque could als
Michael Lippautz
2017/05/02 16:56:17
Done.
| |
| 485 void EmptyMarkingDeque(); | 492 void EmptyMarkingDeque(); |
| 493 void ClearNonLiveReferences() override; | |
| 494 | |
| 495 void EvacuatePrologue() override; | |
| 496 void EvacuateEpilogue() override; | |
| 497 void EvacuateNewSpace(std::vector<HeapObject*>* black_allocation_objects); | |
|
Hannes Payer (out of office)
2017/05/02 16:17:26
Evacuate* could be virtual if we do not expose bla
Michael Lippautz
2017/05/02 16:56:17
See above.
| |
| 498 void EvacuatePagesInParallel( | |
| 499 std::vector<HeapObject*>* black_allocation_objects); | |
| 500 void UpdatePointersAfterEvacuation() override; | |
| 486 | 501 |
| 487 MarkingDeque marking_deque_; | 502 MarkingDeque marking_deque_; |
| 503 base::Semaphore page_parallel_job_semaphore_; | |
| 504 List<Page*> new_space_evacuation_pages_; | |
| 488 | 505 |
| 489 friend class StaticYoungGenerationMarkingVisitor; | 506 friend class StaticYoungGenerationMarkingVisitor; |
| 490 }; | 507 }; |
| 491 | 508 |
| 492 // Collector for young and old generation. | 509 // Collector for young and old generation. |
| 493 class MarkCompactCollector final : public MarkCompactCollectorBase { | 510 class MarkCompactCollector final : public MarkCompactCollectorBase { |
| 494 public: | 511 public: |
| 495 class RootMarkingVisitor; | 512 class RootMarkingVisitor; |
| 496 | 513 |
| 497 class Sweeper { | 514 class Sweeper { |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 751 void DiscoverGreyObjectsOnPage(MemoryChunk* p); | 768 void DiscoverGreyObjectsOnPage(MemoryChunk* p); |
| 752 void DiscoverGreyObjectsInSpace(PagedSpace* space); | 769 void DiscoverGreyObjectsInSpace(PagedSpace* space); |
| 753 void DiscoverGreyObjectsInNewSpace(); | 770 void DiscoverGreyObjectsInNewSpace(); |
| 754 | 771 |
| 755 // Callback function for telling whether the object *p is an unmarked | 772 // Callback function for telling whether the object *p is an unmarked |
| 756 // heap object. | 773 // heap object. |
| 757 static bool IsUnmarkedHeapObject(Object** p); | 774 static bool IsUnmarkedHeapObject(Object** p); |
| 758 | 775 |
| 759 // Clear non-live references in weak cells, transition and descriptor arrays, | 776 // Clear non-live references in weak cells, transition and descriptor arrays, |
| 760 // and deoptimize dependent code of non-live maps. | 777 // and deoptimize dependent code of non-live maps. |
| 761 void ClearNonLiveReferences(); | 778 void ClearNonLiveReferences() override; |
| 762 void MarkDependentCodeForDeoptimization(DependentCode* list); | 779 void MarkDependentCodeForDeoptimization(DependentCode* list); |
| 763 // Find non-live targets of simple transitions in the given list. Clear | 780 // Find non-live targets of simple transitions in the given list. Clear |
| 764 // transitions to non-live targets and if needed trim descriptors arrays. | 781 // transitions to non-live targets and if needed trim descriptors arrays. |
| 765 void ClearSimpleMapTransitions(Object* non_live_map_list); | 782 void ClearSimpleMapTransitions(Object* non_live_map_list); |
| 766 void ClearSimpleMapTransition(Map* map, Map* dead_transition); | 783 void ClearSimpleMapTransition(Map* map, Map* dead_transition); |
| 767 // Compact every array in the global list of transition arrays and | 784 // Compact every array in the global list of transition arrays and |
| 768 // trim the corresponding descriptor array if a transition target is non-live. | 785 // trim the corresponding descriptor array if a transition target is non-live. |
| 769 void ClearFullMapTransitions(); | 786 void ClearFullMapTransitions(); |
| 770 bool CompactTransitionArray(Map* map, TransitionArray* transitions, | 787 bool CompactTransitionArray(Map* map, TransitionArray* transitions, |
| 771 DescriptorArray* descriptors); | 788 DescriptorArray* descriptors); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 790 DependentCode** dependent_code_list); | 807 DependentCode** dependent_code_list); |
| 791 void AbortWeakCells(); | 808 void AbortWeakCells(); |
| 792 | 809 |
| 793 void AbortTransitionArrays(); | 810 void AbortTransitionArrays(); |
| 794 | 811 |
| 795 // Starts sweeping of spaces by contributing on the main thread and setting | 812 // Starts sweeping of spaces by contributing on the main thread and setting |
| 796 // up other pages for sweeping. Does not start sweeper tasks. | 813 // up other pages for sweeping. Does not start sweeper tasks. |
| 797 void StartSweepSpaces(); | 814 void StartSweepSpaces(); |
| 798 void StartSweepSpace(PagedSpace* space); | 815 void StartSweepSpace(PagedSpace* space); |
| 799 | 816 |
| 800 void EvacuatePrologue(); | 817 void EvacuatePrologue() override; |
| 801 void EvacuateEpilogue(); | 818 void EvacuateEpilogue() override; |
| 802 void EvacuatePagesInParallel(); | 819 void EvacuatePagesInParallel(); |
| 803 | 820 |
| 804 void EvacuateNewSpaceAndCandidates(); | 821 void EvacuateNewSpaceAndCandidates(); |
| 805 | 822 |
| 806 void UpdatePointersAfterEvacuation(); | 823 void UpdatePointersAfterEvacuation() override; |
| 807 | 824 |
| 808 void ReleaseEvacuationCandidates(); | 825 void ReleaseEvacuationCandidates(); |
| 809 | 826 |
| 810 base::Semaphore page_parallel_job_semaphore_; | 827 base::Semaphore page_parallel_job_semaphore_; |
| 811 | 828 |
| 812 #ifdef DEBUG | 829 #ifdef DEBUG |
| 813 enum CollectorState { | 830 enum CollectorState { |
| 814 IDLE, | 831 IDLE, |
| 815 PREPARE_GC, | 832 PREPARE_GC, |
| 816 MARK_LIVE_OBJECTS, | 833 MARK_LIVE_OBJECTS, |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 869 ~EvacuationScope() { collector_->set_evacuation(false); } | 886 ~EvacuationScope() { collector_->set_evacuation(false); } |
| 870 | 887 |
| 871 private: | 888 private: |
| 872 MarkCompactCollector* collector_; | 889 MarkCompactCollector* collector_; |
| 873 }; | 890 }; |
| 874 | 891 |
| 875 } // namespace internal | 892 } // namespace internal |
| 876 } // namespace v8 | 893 } // namespace v8 |
| 877 | 894 |
| 878 #endif // V8_HEAP_MARK_COMPACT_H_ | 895 #endif // V8_HEAP_MARK_COMPACT_H_ |
| OLD | NEW |