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 #include "src/heap/mark-compact.h" | 5 #include "src/heap/mark-compact.h" |
6 | 6 |
7 #include "src/base/atomicops.h" | 7 #include "src/base/atomicops.h" |
8 #include "src/base/bits.h" | 8 #include "src/base/bits.h" |
9 #include "src/code-stubs.h" | 9 #include "src/code-stubs.h" |
10 #include "src/compilation-cache.h" | 10 #include "src/compilation-cache.h" |
(...skipping 30 matching lines...) Expand all Loading... |
41 MarkCompactCollector::MarkCompactCollector(Heap* heap) | 41 MarkCompactCollector::MarkCompactCollector(Heap* heap) |
42 : // NOLINT | 42 : // NOLINT |
43 #ifdef DEBUG | 43 #ifdef DEBUG |
44 state_(IDLE), | 44 state_(IDLE), |
45 #endif | 45 #endif |
46 marking_parity_(ODD_MARKING_PARITY), | 46 marking_parity_(ODD_MARKING_PARITY), |
47 compacting_(false), | 47 compacting_(false), |
48 was_marked_incrementally_(false), | 48 was_marked_incrementally_(false), |
49 sweeping_in_progress_(false), | 49 sweeping_in_progress_(false), |
50 pending_sweeper_jobs_semaphore_(0), | 50 pending_sweeper_jobs_semaphore_(0), |
| 51 pending_compaction_jobs_semaphore_(0), |
51 evacuation_(false), | 52 evacuation_(false), |
52 migration_slots_buffer_(NULL), | 53 migration_slots_buffer_(NULL), |
53 heap_(heap), | 54 heap_(heap), |
54 marking_deque_memory_(NULL), | 55 marking_deque_memory_(NULL), |
55 marking_deque_memory_committed_(0), | 56 marking_deque_memory_committed_(0), |
56 code_flusher_(NULL), | 57 code_flusher_(NULL), |
57 have_code_to_deoptimize_(false) { | 58 have_code_to_deoptimize_(false) { |
58 } | 59 } |
59 | 60 |
60 #ifdef VERIFY_HEAP | 61 #ifdef VERIFY_HEAP |
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
452 | 453 |
453 LargeObjectIterator it(heap_->lo_space()); | 454 LargeObjectIterator it(heap_->lo_space()); |
454 for (HeapObject* obj = it.Next(); obj != NULL; obj = it.Next()) { | 455 for (HeapObject* obj = it.Next(); obj != NULL; obj = it.Next()) { |
455 Marking::MarkWhite(Marking::MarkBitFrom(obj)); | 456 Marking::MarkWhite(Marking::MarkBitFrom(obj)); |
456 Page::FromAddress(obj->address())->ResetProgressBar(); | 457 Page::FromAddress(obj->address())->ResetProgressBar(); |
457 Page::FromAddress(obj->address())->ResetLiveBytes(); | 458 Page::FromAddress(obj->address())->ResetLiveBytes(); |
458 } | 459 } |
459 } | 460 } |
460 | 461 |
461 | 462 |
| 463 class MarkCompactCollector::CompactionTask : public v8::Task { |
| 464 public: |
| 465 explicit CompactionTask(Heap* heap) : heap_(heap) {} |
| 466 |
| 467 virtual ~CompactionTask() {} |
| 468 |
| 469 private: |
| 470 // v8::Task overrides. |
| 471 void Run() override { |
| 472 // TODO(mlippautz, hpayer): EvacuatePages is not thread-safe and can just be |
| 473 // called by one thread concurrently. |
| 474 heap_->mark_compact_collector()->EvacuatePages(); |
| 475 heap_->mark_compact_collector() |
| 476 ->pending_compaction_jobs_semaphore_.Signal(); |
| 477 } |
| 478 |
| 479 Heap* heap_; |
| 480 |
| 481 DISALLOW_COPY_AND_ASSIGN(CompactionTask); |
| 482 }; |
| 483 |
| 484 |
462 class MarkCompactCollector::SweeperTask : public v8::Task { | 485 class MarkCompactCollector::SweeperTask : public v8::Task { |
463 public: | 486 public: |
464 SweeperTask(Heap* heap, PagedSpace* space) : heap_(heap), space_(space) {} | 487 SweeperTask(Heap* heap, PagedSpace* space) : heap_(heap), space_(space) {} |
465 | 488 |
466 virtual ~SweeperTask() {} | 489 virtual ~SweeperTask() {} |
467 | 490 |
468 private: | 491 private: |
469 // v8::Task overrides. | 492 // v8::Task overrides. |
470 void Run() override { | 493 void Run() override { |
471 heap_->mark_compact_collector()->SweepInParallel(space_, 0); | 494 heap_->mark_compact_collector()->SweepInParallel(space_, 0); |
(...skipping 2810 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3282 DCHECK(object->map_word().IsForwardingAddress()); | 3305 DCHECK(object->map_word().IsForwardingAddress()); |
3283 } | 3306 } |
3284 | 3307 |
3285 // Clear marking bits for current cell. | 3308 // Clear marking bits for current cell. |
3286 *cell = 0; | 3309 *cell = 0; |
3287 } | 3310 } |
3288 p->ResetLiveBytes(); | 3311 p->ResetLiveBytes(); |
3289 } | 3312 } |
3290 | 3313 |
3291 | 3314 |
| 3315 void MarkCompactCollector::EvacuatePagesInParallel() { |
| 3316 V8::GetCurrentPlatform()->CallOnBackgroundThread( |
| 3317 new CompactionTask(heap()), v8::Platform::kShortRunningTask); |
| 3318 } |
| 3319 |
| 3320 |
3292 void MarkCompactCollector::EvacuatePages() { | 3321 void MarkCompactCollector::EvacuatePages() { |
3293 int npages = evacuation_candidates_.length(); | 3322 int npages = evacuation_candidates_.length(); |
3294 int abandoned_pages = 0; | 3323 int abandoned_pages = 0; |
3295 for (int i = 0; i < npages; i++) { | 3324 for (int i = 0; i < npages; i++) { |
3296 Page* p = evacuation_candidates_[i]; | 3325 Page* p = evacuation_candidates_[i]; |
3297 DCHECK(p->IsEvacuationCandidate() || | 3326 DCHECK(p->IsEvacuationCandidate() || |
3298 p->IsFlagSet(Page::RESCAN_ON_EVACUATION)); | 3327 p->IsFlagSet(Page::RESCAN_ON_EVACUATION)); |
3299 DCHECK(static_cast<int>(p->parallel_sweeping()) == | 3328 DCHECK(static_cast<int>(p->parallel_sweeping()) == |
3300 MemoryChunk::SWEEPING_DONE); | 3329 MemoryChunk::SWEEPING_DONE); |
3301 PagedSpace* space = static_cast<PagedSpace*>(p->owner()); | 3330 PagedSpace* space = static_cast<PagedSpace*>(p->owner()); |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3588 GCTracer::Scope gc_scope(heap()->tracer(), | 3617 GCTracer::Scope gc_scope(heap()->tracer(), |
3589 GCTracer::Scope::MC_SWEEP_NEWSPACE); | 3618 GCTracer::Scope::MC_SWEEP_NEWSPACE); |
3590 EvacuationScope evacuation_scope(this); | 3619 EvacuationScope evacuation_scope(this); |
3591 EvacuateNewSpace(); | 3620 EvacuateNewSpace(); |
3592 } | 3621 } |
3593 | 3622 |
3594 { | 3623 { |
3595 GCTracer::Scope gc_scope(heap()->tracer(), | 3624 GCTracer::Scope gc_scope(heap()->tracer(), |
3596 GCTracer::Scope::MC_EVACUATE_PAGES); | 3625 GCTracer::Scope::MC_EVACUATE_PAGES); |
3597 EvacuationScope evacuation_scope(this); | 3626 EvacuationScope evacuation_scope(this); |
3598 EvacuatePages(); | 3627 if (FLAG_parallel_compaction) { |
| 3628 EvacuatePagesInParallel(); |
| 3629 pending_compaction_jobs_semaphore_.Wait(); |
| 3630 } else { |
| 3631 EvacuatePages(); |
| 3632 } |
3599 } | 3633 } |
3600 | 3634 |
3601 // Second pass: find pointers to new space and update them. | 3635 // Second pass: find pointers to new space and update them. |
3602 PointersUpdatingVisitor updating_visitor(heap()); | 3636 PointersUpdatingVisitor updating_visitor(heap()); |
3603 | 3637 |
3604 { | 3638 { |
3605 GCTracer::Scope gc_scope(heap()->tracer(), | 3639 GCTracer::Scope gc_scope(heap()->tracer(), |
3606 GCTracer::Scope::MC_UPDATE_NEW_TO_NEW_POINTERS); | 3640 GCTracer::Scope::MC_UPDATE_NEW_TO_NEW_POINTERS); |
3607 // Update pointers in to space. | 3641 // Update pointers in to space. |
3608 SemiSpaceIterator to_it(heap()->new_space()); | 3642 SemiSpaceIterator to_it(heap()->new_space()); |
(...skipping 1087 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4696 SlotsBuffer* buffer = *buffer_address; | 4730 SlotsBuffer* buffer = *buffer_address; |
4697 while (buffer != NULL) { | 4731 while (buffer != NULL) { |
4698 SlotsBuffer* next_buffer = buffer->next(); | 4732 SlotsBuffer* next_buffer = buffer->next(); |
4699 DeallocateBuffer(buffer); | 4733 DeallocateBuffer(buffer); |
4700 buffer = next_buffer; | 4734 buffer = next_buffer; |
4701 } | 4735 } |
4702 *buffer_address = NULL; | 4736 *buffer_address = NULL; |
4703 } | 4737 } |
4704 } // namespace internal | 4738 } // namespace internal |
4705 } // namespace v8 | 4739 } // namespace v8 |
OLD | NEW |