| 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 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 // for visited objects are cleared for each successfully visited object. | 270 // for visited objects are cleared for each successfully visited object. |
| 271 template <class Visitor> | 271 template <class Visitor> |
| 272 bool VisitBlackObjects(MemoryChunk* chunk, const MarkingState& state, | 272 bool VisitBlackObjects(MemoryChunk* chunk, const MarkingState& state, |
| 273 Visitor* visitor, IterationMode iteration_mode); | 273 Visitor* visitor, IterationMode iteration_mode); |
| 274 | 274 |
| 275 private: | 275 private: |
| 276 void RecomputeLiveBytes(MemoryChunk* chunk, const MarkingState& state); | 276 void RecomputeLiveBytes(MemoryChunk* chunk, const MarkingState& state); |
| 277 }; | 277 }; |
| 278 | 278 |
| 279 enum PageEvacuationMode { NEW_TO_NEW, NEW_TO_OLD }; | 279 enum PageEvacuationMode { NEW_TO_NEW, NEW_TO_OLD }; |
| 280 enum FreeSpaceTreatmentMode { IGNORE_FREE_SPACE, ZAP_FREE_SPACE }; |
| 281 enum MarkingTreatmentMode { KEEP, CLEAR }; |
| 280 | 282 |
| 281 // Base class for minor and full MC collectors. | 283 // Base class for minor and full MC collectors. |
| 282 class MarkCompactCollectorBase { | 284 class MarkCompactCollectorBase { |
| 283 public: | 285 public: |
| 284 virtual ~MarkCompactCollectorBase() {} | 286 virtual ~MarkCompactCollectorBase() {} |
| 285 | 287 |
| 286 // Note: Make sure to refer to the instances by their concrete collector | 288 // Note: Make sure to refer to the instances by their concrete collector |
| 287 // type to avoid vtable lookups marking state methods when used in hot paths. | 289 // type to avoid vtable lookups marking state methods when used in hot paths. |
| 288 virtual MarkingState marking_state(HeapObject* object) const = 0; | 290 virtual MarkingState marking_state(HeapObject* object) const = 0; |
| 289 virtual MarkingState marking_state(MemoryChunk* chunk) const = 0; | 291 virtual MarkingState marking_state(MemoryChunk* chunk) const = 0; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 315 // The number of parallel compaction tasks, including the main thread. | 317 // The number of parallel compaction tasks, including the main thread. |
| 316 int NumberOfParallelCompactionTasks(int pages, intptr_t live_bytes); | 318 int NumberOfParallelCompactionTasks(int pages, intptr_t live_bytes); |
| 317 | 319 |
| 318 template <class Evacuator, class Collector> | 320 template <class Evacuator, class Collector> |
| 319 void CreateAndExecuteEvacuationTasks( | 321 void CreateAndExecuteEvacuationTasks( |
| 320 Collector* collector, PageParallelJob<EvacuationJobTraits>* job, | 322 Collector* collector, PageParallelJob<EvacuationJobTraits>* job, |
| 321 RecordMigratedSlotVisitor* record_visitor, | 323 RecordMigratedSlotVisitor* record_visitor, |
| 322 MigrationObserver* migration_observer, const intptr_t live_bytes, | 324 MigrationObserver* migration_observer, const intptr_t live_bytes, |
| 323 const int& abandoned_pages); | 325 const int& abandoned_pages); |
| 324 | 326 |
| 327 // Returns whether this page should be moved according to heuristics. |
| 328 bool ShouldMovePage(Page* p, intptr_t live_bytes); |
| 329 |
| 325 Heap* heap_; | 330 Heap* heap_; |
| 326 }; | 331 }; |
| 327 | 332 |
| 328 // Collector for young-generation only. | 333 // Collector for young-generation only. |
| 329 class MinorMarkCompactCollector final : public MarkCompactCollectorBase { | 334 class MinorMarkCompactCollector final : public MarkCompactCollectorBase { |
| 330 public: | 335 public: |
| 331 explicit MinorMarkCompactCollector(Heap* heap) | 336 explicit MinorMarkCompactCollector(Heap* heap) |
| 332 : MarkCompactCollectorBase(heap), | 337 : MarkCompactCollectorBase(heap), |
| 333 marking_deque_(heap), | 338 marking_deque_(heap), |
| 334 page_parallel_job_semaphore_(0) {} | 339 page_parallel_job_semaphore_(0) {} |
| 335 | 340 |
| 336 MarkingState marking_state(HeapObject* object) const override { | 341 MarkingState marking_state(HeapObject* object) const override { |
| 337 return MarkingState::External(object); | 342 return MarkingState::External(object); |
| 338 } | 343 } |
| 339 | 344 |
| 340 MarkingState marking_state(MemoryChunk* chunk) const override { | 345 MarkingState marking_state(MemoryChunk* chunk) const override { |
| 341 return MarkingState::External(chunk); | 346 return MarkingState::External(chunk); |
| 342 } | 347 } |
| 343 | 348 |
| 344 void SetUp() override; | 349 void SetUp() override; |
| 345 void TearDown() override; | 350 void TearDown() override; |
| 346 void CollectGarbage() override; | 351 void CollectGarbage() override; |
| 347 | 352 |
| 353 void MakeIterable(Page* page, MarkingTreatmentMode marking_mode, |
| 354 FreeSpaceTreatmentMode free_space_mode); |
| 355 void CleanupSweepToIteratePages(); |
| 356 |
| 348 private: | 357 private: |
| 349 class RootMarkingVisitor; | 358 class RootMarkingVisitor; |
| 350 | 359 |
| 351 inline MarkingDeque* marking_deque() { return &marking_deque_; } | 360 inline MarkingDeque* marking_deque() { return &marking_deque_; } |
| 352 | 361 |
| 353 V8_INLINE void MarkObject(HeapObject* obj); | 362 V8_INLINE void MarkObject(HeapObject* obj); |
| 354 V8_INLINE void PushBlack(HeapObject* obj); | 363 V8_INLINE void PushBlack(HeapObject* obj); |
| 355 | 364 |
| 356 SlotCallbackResult CheckAndMarkObject(Heap* heap, Address slot_address); | 365 SlotCallbackResult CheckAndMarkObject(Heap* heap, Address slot_address); |
| 357 void MarkLiveObjects() override; | 366 void MarkLiveObjects() override; |
| 358 void ProcessMarkingDeque() override; | 367 void ProcessMarkingDeque() override; |
| 359 void EmptyMarkingDeque() override; | 368 void EmptyMarkingDeque() override; |
| 360 void ClearNonLiveReferences() override; | 369 void ClearNonLiveReferences() override; |
| 361 | 370 |
| 362 void EvacuatePrologue() override; | 371 void EvacuatePrologue() override; |
| 363 void EvacuateEpilogue() override; | 372 void EvacuateEpilogue() override; |
| 364 void Evacuate() override; | 373 void Evacuate() override; |
| 365 void EvacuatePagesInParallel() override; | 374 void EvacuatePagesInParallel() override; |
| 366 void UpdatePointersAfterEvacuation() override; | 375 void UpdatePointersAfterEvacuation() override; |
| 367 | 376 |
| 368 MarkingDeque marking_deque_; | 377 MarkingDeque marking_deque_; |
| 369 base::Semaphore page_parallel_job_semaphore_; | 378 base::Semaphore page_parallel_job_semaphore_; |
| 370 List<Page*> new_space_evacuation_pages_; | 379 List<Page*> new_space_evacuation_pages_; |
| 380 std::vector<Page*> sweep_to_iterate_pages_; |
| 371 | 381 |
| 372 friend class StaticYoungGenerationMarkingVisitor; | 382 friend class StaticYoungGenerationMarkingVisitor; |
| 373 }; | 383 }; |
| 374 | 384 |
| 375 // Collector for young and old generation. | 385 // Collector for young and old generation. |
| 376 class MarkCompactCollector final : public MarkCompactCollectorBase { | 386 class MarkCompactCollector final : public MarkCompactCollectorBase { |
| 377 public: | 387 public: |
| 378 class RootMarkingVisitor; | 388 class RootMarkingVisitor; |
| 379 | 389 |
| 380 class Sweeper { | 390 class Sweeper { |
| 381 public: | 391 public: |
| 382 class SweeperTask; | 392 class SweeperTask; |
| 383 | 393 |
| 384 enum FreeListRebuildingMode { REBUILD_FREE_LIST, IGNORE_FREE_LIST }; | 394 enum FreeListRebuildingMode { REBUILD_FREE_LIST, IGNORE_FREE_LIST }; |
| 385 enum FreeSpaceTreatmentMode { IGNORE_FREE_SPACE, ZAP_FREE_SPACE }; | |
| 386 enum ClearOldToNewSlotsMode { | 395 enum ClearOldToNewSlotsMode { |
| 387 DO_NOT_CLEAR, | 396 DO_NOT_CLEAR, |
| 388 CLEAR_REGULAR_SLOTS, | 397 CLEAR_REGULAR_SLOTS, |
| 389 CLEAR_TYPED_SLOTS | 398 CLEAR_TYPED_SLOTS |
| 390 }; | 399 }; |
| 391 | 400 |
| 392 typedef std::deque<Page*> SweepingList; | 401 typedef std::deque<Page*> SweepingList; |
| 393 typedef List<Page*> SweptList; | 402 typedef List<Page*> SweptList; |
| 394 | 403 |
| 395 static int RawSweep(Page* p, FreeListRebuildingMode free_list_mode, | 404 static int RawSweep(Page* p, FreeListRebuildingMode free_list_mode, |
| (...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 745 ~EvacuationScope() { collector_->set_evacuation(false); } | 754 ~EvacuationScope() { collector_->set_evacuation(false); } |
| 746 | 755 |
| 747 private: | 756 private: |
| 748 MarkCompactCollector* collector_; | 757 MarkCompactCollector* collector_; |
| 749 }; | 758 }; |
| 750 | 759 |
| 751 } // namespace internal | 760 } // namespace internal |
| 752 } // namespace v8 | 761 } // namespace v8 |
| 753 | 762 |
| 754 #endif // V8_HEAP_MARK_COMPACT_H_ | 763 #endif // V8_HEAP_MARK_COMPACT_H_ |
| OLD | NEW |