| 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 #include "src/heap/store-buffer.h" | |
| 11 | 10 |
| 12 namespace v8 { | 11 namespace v8 { |
| 13 namespace internal { | 12 namespace internal { |
| 14 | 13 |
| 15 // Callback function, returns whether an object is alive. The heap size | 14 // Callback function, returns whether an object is alive. The heap size |
| 16 // of the object is returned in size. It optionally updates the offset | 15 // of the object is returned in size. It optionally updates the offset |
| 17 // to the first live object in the page (only used for old and map objects). | 16 // to the first live object in the page (only used for old and map objects). |
| 18 typedef bool (*IsAliveFunction)(HeapObject* obj, int* size, int* offset); | 17 typedef bool (*IsAliveFunction)(HeapObject* obj, int* size, int* offset); |
| 19 | 18 |
| 20 // Callback function to mark an object in a given heap. | 19 // Callback function to mark an object in a given heap. |
| (...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 void RecordCodeTargetPatch(Address pc, Code* target); | 399 void RecordCodeTargetPatch(Address pc, Code* target); |
| 401 INLINE(void RecordSlot(HeapObject* object, Object** slot, Object* target)); | 400 INLINE(void RecordSlot(HeapObject* object, Object** slot, Object* target)); |
| 402 INLINE(void ForceRecordSlot(HeapObject* object, Object** slot, | 401 INLINE(void ForceRecordSlot(HeapObject* object, Object** slot, |
| 403 Object* target)); | 402 Object* target)); |
| 404 | 403 |
| 405 void UpdateSlots(SlotsBuffer* buffer); | 404 void UpdateSlots(SlotsBuffer* buffer); |
| 406 void UpdateSlotsRecordedIn(SlotsBuffer* buffer); | 405 void UpdateSlotsRecordedIn(SlotsBuffer* buffer); |
| 407 | 406 |
| 408 void MigrateObject(HeapObject* dst, HeapObject* src, int size, | 407 void MigrateObject(HeapObject* dst, HeapObject* src, int size, |
| 409 AllocationSpace to_old_space, | 408 AllocationSpace to_old_space, |
| 410 SlotsBuffer** evacuation_slots_buffer, | 409 SlotsBuffer** evacuation_slots_buffer); |
| 411 LocalStoreBuffer* local_store_buffer); | |
| 412 | 410 |
| 413 void InvalidateCode(Code* code); | 411 void InvalidateCode(Code* code); |
| 414 | 412 |
| 415 void ClearMarkbits(); | 413 void ClearMarkbits(); |
| 416 | 414 |
| 417 bool is_compacting() const { return compacting_; } | 415 bool is_compacting() const { return compacting_; } |
| 418 | 416 |
| 419 MarkingParity marking_parity() { return marking_parity_; } | 417 MarkingParity marking_parity() { return marking_parity_; } |
| 420 | 418 |
| 421 // Concurrent and parallel sweeping support. If required_freed_bytes was set | 419 // Concurrent and parallel sweeping support. If required_freed_bytes was set |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 504 } | 502 } |
| 505 base::SmartPointer<FreeList>& free_list_map_space() { | 503 base::SmartPointer<FreeList>& free_list_map_space() { |
| 506 return free_list_map_space_; | 504 return free_list_map_space_; |
| 507 } | 505 } |
| 508 | 506 |
| 509 private: | 507 private: |
| 510 class CompactionTask; | 508 class CompactionTask; |
| 511 class EvacuateNewSpaceVisitor; | 509 class EvacuateNewSpaceVisitor; |
| 512 class EvacuateOldSpaceVisitor; | 510 class EvacuateOldSpaceVisitor; |
| 513 class EvacuateVisitorBase; | 511 class EvacuateVisitorBase; |
| 514 class Evacuator; | |
| 515 class HeapObjectVisitor; | 512 class HeapObjectVisitor; |
| 516 class SweeperTask; | 513 class SweeperTask; |
| 517 | 514 |
| 518 typedef std::vector<Page*> SweepingList; | 515 typedef std::vector<Page*> SweepingList; |
| 519 | 516 |
| 517 static const int kInitialLocalPretenuringFeedbackCapacity = 256; |
| 518 |
| 520 explicit MarkCompactCollector(Heap* heap); | 519 explicit MarkCompactCollector(Heap* heap); |
| 521 | 520 |
| 522 bool WillBeDeoptimized(Code* code); | 521 bool WillBeDeoptimized(Code* code); |
| 523 void EvictPopularEvacuationCandidate(Page* page); | 522 void EvictPopularEvacuationCandidate(Page* page); |
| 524 void ClearInvalidStoreAndSlotsBufferEntries(); | 523 void ClearInvalidStoreAndSlotsBufferEntries(); |
| 525 | 524 |
| 526 void StartSweeperThreads(); | 525 void StartSweeperThreads(); |
| 527 | 526 |
| 528 void ComputeEvacuationHeuristics(int area_size, | 527 void ComputeEvacuationHeuristics(int area_size, |
| 529 int* target_fragmentation_percent, | 528 int* target_fragmentation_percent, |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 698 // | 697 // |
| 699 | 698 |
| 700 inline SweepingList& sweeping_list(Space* space); | 699 inline SweepingList& sweeping_list(Space* space); |
| 701 | 700 |
| 702 // If we are not compacting the heap, we simply sweep the spaces except | 701 // If we are not compacting the heap, we simply sweep the spaces except |
| 703 // for the large object space, clearing mark bits and adding unmarked | 702 // for the large object space, clearing mark bits and adding unmarked |
| 704 // regions to each space's free list. | 703 // regions to each space's free list. |
| 705 void SweepSpaces(); | 704 void SweepSpaces(); |
| 706 | 705 |
| 707 void EvacuateNewSpacePrologue(); | 706 void EvacuateNewSpacePrologue(); |
| 708 void EvacuateNewSpaceEpilogue(); | 707 |
| 708 // Returns local pretenuring feedback. |
| 709 HashMap* EvacuateNewSpaceInParallel(); |
| 709 | 710 |
| 710 void AddEvacuationSlotsBufferSynchronized( | 711 void AddEvacuationSlotsBufferSynchronized( |
| 711 SlotsBuffer* evacuation_slots_buffer); | 712 SlotsBuffer* evacuation_slots_buffer); |
| 712 | 713 |
| 714 void EvacuatePages(CompactionSpaceCollection* compaction_spaces, |
| 715 SlotsBuffer** evacuation_slots_buffer); |
| 716 |
| 713 void EvacuatePagesInParallel(); | 717 void EvacuatePagesInParallel(); |
| 714 | 718 |
| 715 // The number of parallel compaction tasks, including the main thread. | 719 // The number of parallel compaction tasks, including the main thread. |
| 716 int NumberOfParallelCompactionTasks(int pages, intptr_t live_bytes); | 720 int NumberOfParallelCompactionTasks(); |
| 717 | 721 |
| 718 void StartParallelCompaction(Evacuator** evacuators, int len); | 722 |
| 719 void WaitUntilCompactionCompleted(Evacuator** evacuators, int len); | 723 void StartParallelCompaction(CompactionSpaceCollection** compaction_spaces, |
| 724 uint32_t* task_ids, int len); |
| 725 void WaitUntilCompactionCompleted(uint32_t* task_ids, int len); |
| 720 | 726 |
| 721 void EvacuateNewSpaceAndCandidates(); | 727 void EvacuateNewSpaceAndCandidates(); |
| 722 | 728 |
| 723 void UpdatePointersAfterEvacuation(); | 729 void UpdatePointersAfterEvacuation(); |
| 724 | 730 |
| 725 // Iterates through all live objects on a page using marking information. | 731 // Iterates through all live objects on a page using marking information. |
| 726 // Returns whether all objects have successfully been visited. | 732 // Returns whether all objects have successfully been visited. |
| 727 bool VisitLiveObjects(MemoryChunk* page, HeapObjectVisitor* visitor, | 733 bool VisitLiveObjects(MemoryChunk* page, HeapObjectVisitor* visitor, |
| 728 IterationMode mode); | 734 IterationMode mode); |
| 729 | 735 |
| 730 void VisitLiveObjectsBody(Page* page, ObjectVisitor* visitor); | 736 void VisitLiveObjectsBody(Page* page, ObjectVisitor* visitor); |
| 731 | 737 |
| 732 void RecomputeLiveBytes(MemoryChunk* page); | 738 void RecomputeLiveBytes(MemoryChunk* page); |
| 733 | 739 |
| 734 void SweepAbortedPages(); | 740 void SweepAbortedPages(); |
| 735 | 741 |
| 736 void ReleaseEvacuationCandidates(); | 742 void ReleaseEvacuationCandidates(); |
| 737 | 743 |
| 738 // Starts sweeping of a space by contributing on the main thread and setting | 744 // Starts sweeping of a space by contributing on the main thread and setting |
| 739 // up other pages for sweeping. | 745 // up other pages for sweeping. |
| 740 void StartSweepSpace(PagedSpace* space); | 746 void StartSweepSpace(PagedSpace* space); |
| 741 | 747 |
| 742 // Finalizes the parallel sweeping phase. Marks all the pages that were | 748 // Finalizes the parallel sweeping phase. Marks all the pages that were |
| 743 // swept in parallel. | 749 // swept in parallel. |
| 744 void ParallelSweepSpacesComplete(); | 750 void ParallelSweepSpacesComplete(); |
| 745 | 751 |
| 746 // Updates store buffer and slot buffer for a pointer in a migrating object. | 752 // Updates store buffer and slot buffer for a pointer in a migrating object. |
| 747 void RecordMigratedSlot(Object* value, Address slot, | 753 void RecordMigratedSlot(Object* value, Address slot, |
| 748 SlotsBuffer** evacuation_slots_buffer, | 754 SlotsBuffer** evacuation_slots_buffer); |
| 749 LocalStoreBuffer* local_store_buffer); | |
| 750 | 755 |
| 751 // Adds the code entry slot to the slots buffer. | 756 // Adds the code entry slot to the slots buffer. |
| 752 void RecordMigratedCodeEntrySlot(Address code_entry, Address code_entry_slot, | 757 void RecordMigratedCodeEntrySlot(Address code_entry, Address code_entry_slot, |
| 753 SlotsBuffer** evacuation_slots_buffer); | 758 SlotsBuffer** evacuation_slots_buffer); |
| 754 | 759 |
| 755 // Adds the slot of a moved code object. | 760 // Adds the slot of a moved code object. |
| 756 void RecordMigratedCodeObjectSlot(Address code_object, | 761 void RecordMigratedCodeObjectSlot(Address code_object, |
| 757 SlotsBuffer** evacuation_slots_buffer); | 762 SlotsBuffer** evacuation_slots_buffer); |
| 758 | 763 |
| 759 #ifdef DEBUG | 764 #ifdef DEBUG |
| 760 friend class MarkObjectVisitor; | 765 friend class MarkObjectVisitor; |
| 761 static void VisitObject(HeapObject* obj); | 766 static void VisitObject(HeapObject* obj); |
| 762 | 767 |
| 763 friend class UnmarkObjectVisitor; | 768 friend class UnmarkObjectVisitor; |
| 764 static void UnmarkObject(HeapObject* obj); | 769 static void UnmarkObject(HeapObject* obj); |
| 765 #endif | 770 #endif |
| 766 | 771 |
| 767 Heap* heap_; | 772 Heap* heap_; |
| 768 base::VirtualMemory* marking_deque_memory_; | 773 base::VirtualMemory* marking_deque_memory_; |
| 769 size_t marking_deque_memory_committed_; | 774 size_t marking_deque_memory_committed_; |
| 770 MarkingDeque marking_deque_; | 775 MarkingDeque marking_deque_; |
| 771 CodeFlusher* code_flusher_; | 776 CodeFlusher* code_flusher_; |
| 772 bool have_code_to_deoptimize_; | 777 bool have_code_to_deoptimize_; |
| 773 | 778 |
| 774 List<Page*> evacuation_candidates_; | 779 List<Page*> evacuation_candidates_; |
| 775 List<NewSpacePage*> newspace_evacuation_candidates_; | 780 |
| 781 List<MemoryChunk*> newspace_evacuation_candidates_; |
| 776 | 782 |
| 777 // The evacuation_slots_buffers_ are used by the compaction threads. | 783 // The evacuation_slots_buffers_ are used by the compaction threads. |
| 778 // When a compaction task finishes, it uses | 784 // When a compaction task finishes, it uses |
| 779 // AddEvacuationSlotsbufferSynchronized to adds its slots buffer to the | 785 // AddEvacuationSlotsbufferSynchronized to adds its slots buffer to the |
| 780 // evacuation_slots_buffers_ list using the evacuation_slots_buffers_mutex_ | 786 // evacuation_slots_buffers_ list using the evacuation_slots_buffers_mutex_ |
| 781 // lock. | 787 // lock. |
| 782 base::Mutex evacuation_slots_buffers_mutex_; | 788 base::Mutex evacuation_slots_buffers_mutex_; |
| 783 List<SlotsBuffer*> evacuation_slots_buffers_; | 789 List<SlotsBuffer*> evacuation_slots_buffers_; |
| 784 | 790 |
| 785 base::SmartPointer<FreeList> free_list_old_space_; | 791 base::SmartPointer<FreeList> free_list_old_space_; |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 892 private: | 898 private: |
| 893 MarkCompactCollector* collector_; | 899 MarkCompactCollector* collector_; |
| 894 }; | 900 }; |
| 895 | 901 |
| 896 | 902 |
| 897 const char* AllocationSpaceName(AllocationSpace space); | 903 const char* AllocationSpaceName(AllocationSpace space); |
| 898 } // namespace internal | 904 } // namespace internal |
| 899 } // namespace v8 | 905 } // namespace v8 |
| 900 | 906 |
| 901 #endif // V8_HEAP_MARK_COMPACT_H_ | 907 #endif // V8_HEAP_MARK_COMPACT_H_ |
| OLD | NEW |