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 |
(...skipping 10 matching lines...) Expand all Loading... |
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 void ParallelSweepSpaceComplete(PagedSpace* space); | 746 void ParallelSweepSpaceComplete(PagedSpace* space); |
753 | 747 |
754 // Updates store buffer and slot buffer for a pointer in a migrating object. | 748 // Updates store buffer and slot buffer for a pointer in a migrating object. |
755 void RecordMigratedSlot(Object* value, Address slot, | 749 void RecordMigratedSlot(Object* value, Address slot, |
756 SlotsBuffer** evacuation_slots_buffer); | 750 SlotsBuffer** evacuation_slots_buffer, |
| 751 LocalStoreBuffer* local_store_buffer); |
757 | 752 |
758 // Adds the code entry slot to the slots buffer. | 753 // Adds the code entry slot to the slots buffer. |
759 void RecordMigratedCodeEntrySlot(Address code_entry, Address code_entry_slot, | 754 void RecordMigratedCodeEntrySlot(Address code_entry, Address code_entry_slot, |
760 SlotsBuffer** evacuation_slots_buffer); | 755 SlotsBuffer** evacuation_slots_buffer); |
761 | 756 |
762 // Adds the slot of a moved code object. | 757 // Adds the slot of a moved code object. |
763 void RecordMigratedCodeObjectSlot(Address code_object, | 758 void RecordMigratedCodeObjectSlot(Address code_object, |
764 SlotsBuffer** evacuation_slots_buffer); | 759 SlotsBuffer** evacuation_slots_buffer); |
765 | 760 |
766 #ifdef DEBUG | 761 #ifdef DEBUG |
767 friend class MarkObjectVisitor; | 762 friend class MarkObjectVisitor; |
768 static void VisitObject(HeapObject* obj); | 763 static void VisitObject(HeapObject* obj); |
769 | 764 |
770 friend class UnmarkObjectVisitor; | 765 friend class UnmarkObjectVisitor; |
771 static void UnmarkObject(HeapObject* obj); | 766 static void UnmarkObject(HeapObject* obj); |
772 #endif | 767 #endif |
773 | 768 |
774 Heap* heap_; | 769 Heap* heap_; |
775 base::VirtualMemory* marking_deque_memory_; | 770 base::VirtualMemory* marking_deque_memory_; |
776 size_t marking_deque_memory_committed_; | 771 size_t marking_deque_memory_committed_; |
777 MarkingDeque marking_deque_; | 772 MarkingDeque marking_deque_; |
778 CodeFlusher* code_flusher_; | 773 CodeFlusher* code_flusher_; |
779 bool have_code_to_deoptimize_; | 774 bool have_code_to_deoptimize_; |
780 | 775 |
781 List<Page*> evacuation_candidates_; | 776 List<Page*> evacuation_candidates_; |
782 | 777 List<NewSpacePage*> newspace_evacuation_candidates_; |
783 List<MemoryChunk*> newspace_evacuation_candidates_; | |
784 | 778 |
785 // The evacuation_slots_buffers_ are used by the compaction threads. | 779 // The evacuation_slots_buffers_ are used by the compaction threads. |
786 // When a compaction task finishes, it uses | 780 // When a compaction task finishes, it uses |
787 // AddEvacuationSlotsbufferSynchronized to adds its slots buffer to the | 781 // AddEvacuationSlotsbufferSynchronized to adds its slots buffer to the |
788 // evacuation_slots_buffers_ list using the evacuation_slots_buffers_mutex_ | 782 // evacuation_slots_buffers_ list using the evacuation_slots_buffers_mutex_ |
789 // lock. | 783 // lock. |
790 base::Mutex evacuation_slots_buffers_mutex_; | 784 base::Mutex evacuation_slots_buffers_mutex_; |
791 List<SlotsBuffer*> evacuation_slots_buffers_; | 785 List<SlotsBuffer*> evacuation_slots_buffers_; |
792 | 786 |
793 base::SmartPointer<FreeList> free_list_old_space_; | 787 base::SmartPointer<FreeList> free_list_old_space_; |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
900 private: | 894 private: |
901 MarkCompactCollector* collector_; | 895 MarkCompactCollector* collector_; |
902 }; | 896 }; |
903 | 897 |
904 | 898 |
905 const char* AllocationSpaceName(AllocationSpace space); | 899 const char* AllocationSpaceName(AllocationSpace space); |
906 } // namespace internal | 900 } // namespace internal |
907 } // namespace v8 | 901 } // namespace v8 |
908 | 902 |
909 #endif // V8_HEAP_MARK_COMPACT_H_ | 903 #endif // V8_HEAP_MARK_COMPACT_H_ |
OLD | NEW |