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/base/sys-info.h" | 9 #include "src/base/sys-info.h" |
10 #include "src/code-stubs.h" | 10 #include "src/code-stubs.h" |
(...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
559 } | 559 } |
560 | 560 |
561 if (heap()->concurrent_sweeping_enabled()) { | 561 if (heap()->concurrent_sweeping_enabled()) { |
562 pending_sweeper_tasks_semaphore_.Wait(); | 562 pending_sweeper_tasks_semaphore_.Wait(); |
563 pending_sweeper_tasks_semaphore_.Wait(); | 563 pending_sweeper_tasks_semaphore_.Wait(); |
564 pending_sweeper_tasks_semaphore_.Wait(); | 564 pending_sweeper_tasks_semaphore_.Wait(); |
565 } | 565 } |
566 | 566 |
567 ParallelSweepSpacesComplete(); | 567 ParallelSweepSpacesComplete(); |
568 sweeping_in_progress_ = false; | 568 sweeping_in_progress_ = false; |
569 heap()->old_space()->RefillFreeList(); | 569 RefillFreeList(heap()->paged_space(OLD_SPACE)); |
570 heap()->code_space()->RefillFreeList(); | 570 RefillFreeList(heap()->paged_space(CODE_SPACE)); |
571 heap()->map_space()->RefillFreeList(); | 571 RefillFreeList(heap()->paged_space(MAP_SPACE)); |
572 | 572 |
573 #ifdef VERIFY_HEAP | 573 #ifdef VERIFY_HEAP |
574 if (FLAG_verify_heap && !evacuation()) { | 574 if (FLAG_verify_heap && !evacuation()) { |
575 VerifyEvacuation(heap_); | 575 VerifyEvacuation(heap_); |
576 } | 576 } |
577 #endif | 577 #endif |
578 } | 578 } |
579 | 579 |
580 | 580 |
581 bool MarkCompactCollector::IsSweepingCompleted() { | 581 bool MarkCompactCollector::IsSweepingCompleted() { |
582 if (!pending_sweeper_tasks_semaphore_.WaitFor( | 582 if (!pending_sweeper_tasks_semaphore_.WaitFor( |
583 base::TimeDelta::FromSeconds(0))) { | 583 base::TimeDelta::FromSeconds(0))) { |
584 return false; | 584 return false; |
585 } | 585 } |
586 pending_sweeper_tasks_semaphore_.Signal(); | 586 pending_sweeper_tasks_semaphore_.Signal(); |
587 return true; | 587 return true; |
588 } | 588 } |
589 | 589 |
590 | 590 |
| 591 void MarkCompactCollector::RefillFreeList(PagedSpace* space) { |
| 592 FreeList* free_list; |
| 593 |
| 594 if (space == heap()->old_space()) { |
| 595 free_list = free_list_old_space_.get(); |
| 596 } else if (space == heap()->code_space()) { |
| 597 free_list = free_list_code_space_.get(); |
| 598 } else if (space == heap()->map_space()) { |
| 599 free_list = free_list_map_space_.get(); |
| 600 } else { |
| 601 // Any PagedSpace might invoke RefillFreeLists, so we need to make sure |
| 602 // to only refill them for the old space. |
| 603 return; |
| 604 } |
| 605 |
| 606 intptr_t added = space->free_list()->Concatenate(free_list); |
| 607 space->accounting_stats_.IncreaseCapacity(added); |
| 608 } |
| 609 |
| 610 |
591 void Marking::TransferMark(Heap* heap, Address old_start, Address new_start) { | 611 void Marking::TransferMark(Heap* heap, Address old_start, Address new_start) { |
592 // This is only used when resizing an object. | 612 // This is only used when resizing an object. |
593 DCHECK(MemoryChunk::FromAddress(old_start) == | 613 DCHECK(MemoryChunk::FromAddress(old_start) == |
594 MemoryChunk::FromAddress(new_start)); | 614 MemoryChunk::FromAddress(new_start)); |
595 | 615 |
596 if (!heap->incremental_marking()->IsMarking()) return; | 616 if (!heap->incremental_marking()->IsMarking()) return; |
597 | 617 |
598 // If the mark doesn't move, we don't check the color of the object. | 618 // If the mark doesn't move, we don't check the color of the object. |
599 // It doesn't matter whether the object is black, since it hasn't changed | 619 // It doesn't matter whether the object is black, since it hasn't changed |
600 // size, so the adjustment to the live data count will be zero anyway. | 620 // size, so the adjustment to the live data count will be zero anyway. |
(...skipping 2770 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3371 | 3391 |
3372 const int num_tasks = NumberOfParallelCompactionTasks(); | 3392 const int num_tasks = NumberOfParallelCompactionTasks(); |
3373 | 3393 |
3374 // Set up compaction spaces. | 3394 // Set up compaction spaces. |
3375 CompactionSpaceCollection** compaction_spaces_for_tasks = | 3395 CompactionSpaceCollection** compaction_spaces_for_tasks = |
3376 new CompactionSpaceCollection*[num_tasks]; | 3396 new CompactionSpaceCollection*[num_tasks]; |
3377 for (int i = 0; i < num_tasks; i++) { | 3397 for (int i = 0; i < num_tasks; i++) { |
3378 compaction_spaces_for_tasks[i] = new CompactionSpaceCollection(heap()); | 3398 compaction_spaces_for_tasks[i] = new CompactionSpaceCollection(heap()); |
3379 } | 3399 } |
3380 | 3400 |
3381 heap()->old_space()->DivideUponCompactionSpaces(compaction_spaces_for_tasks, | 3401 compaction_spaces_for_tasks[0]->Get(OLD_SPACE)->MoveOverFreeMemory( |
3382 num_tasks); | 3402 heap()->old_space()); |
3383 heap()->code_space()->DivideUponCompactionSpaces(compaction_spaces_for_tasks, | 3403 compaction_spaces_for_tasks[0] |
3384 num_tasks); | 3404 ->Get(CODE_SPACE) |
| 3405 ->MoveOverFreeMemory(heap()->code_space()); |
3385 | 3406 |
3386 compaction_in_progress_ = true; | 3407 compaction_in_progress_ = true; |
3387 // Kick off parallel tasks. | 3408 // Kick off parallel tasks. |
3388 for (int i = 1; i < num_tasks; i++) { | 3409 for (int i = 1; i < num_tasks; i++) { |
3389 concurrent_compaction_tasks_active_++; | 3410 concurrent_compaction_tasks_active_++; |
3390 V8::GetCurrentPlatform()->CallOnBackgroundThread( | 3411 V8::GetCurrentPlatform()->CallOnBackgroundThread( |
3391 new CompactionTask(heap(), compaction_spaces_for_tasks[i]), | 3412 new CompactionTask(heap(), compaction_spaces_for_tasks[i]), |
3392 v8::Platform::kShortRunningTask); | 3413 v8::Platform::kShortRunningTask); |
3393 } | 3414 } |
3394 | 3415 |
3395 // Contribute in main thread. Counter and signal are in principal not needed. | 3416 // Contribute in main thread. Counter and signal are in principal not needed. |
| 3417 concurrent_compaction_tasks_active_++; |
3396 EvacuatePages(compaction_spaces_for_tasks[0], &migration_slots_buffer_); | 3418 EvacuatePages(compaction_spaces_for_tasks[0], &migration_slots_buffer_); |
| 3419 pending_compaction_tasks_semaphore_.Signal(); |
3397 | 3420 |
3398 WaitUntilCompactionCompleted(); | 3421 WaitUntilCompactionCompleted(); |
3399 | 3422 |
3400 // Merge back memory (compacted and unused) from compaction spaces. | 3423 // Merge back memory (compacted and unused) from compaction spaces. |
3401 for (int i = 0; i < num_tasks; i++) { | 3424 for (int i = 0; i < num_tasks; i++) { |
3402 heap()->old_space()->MergeCompactionSpace( | 3425 heap()->old_space()->MergeCompactionSpace( |
3403 compaction_spaces_for_tasks[i]->Get(OLD_SPACE)); | 3426 compaction_spaces_for_tasks[i]->Get(OLD_SPACE)); |
3404 heap()->code_space()->MergeCompactionSpace( | 3427 heap()->code_space()->MergeCompactionSpace( |
3405 compaction_spaces_for_tasks[i]->Get(CODE_SPACE)); | 3428 compaction_spaces_for_tasks[i]->Get(CODE_SPACE)); |
3406 delete compaction_spaces_for_tasks[i]; | 3429 delete compaction_spaces_for_tasks[i]; |
(...skipping 1172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4579 MarkBit mark_bit = Marking::MarkBitFrom(host); | 4602 MarkBit mark_bit = Marking::MarkBitFrom(host); |
4580 if (Marking::IsBlack(mark_bit)) { | 4603 if (Marking::IsBlack(mark_bit)) { |
4581 RelocInfo rinfo(pc, RelocInfo::CODE_TARGET, 0, host); | 4604 RelocInfo rinfo(pc, RelocInfo::CODE_TARGET, 0, host); |
4582 RecordRelocSlot(&rinfo, target); | 4605 RecordRelocSlot(&rinfo, target); |
4583 } | 4606 } |
4584 } | 4607 } |
4585 } | 4608 } |
4586 | 4609 |
4587 } // namespace internal | 4610 } // namespace internal |
4588 } // namespace v8 | 4611 } // namespace v8 |
OLD | NEW |