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