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 590 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
601 // Any PagedSpace might invoke RefillFreeLists, so we need to make sure | 601 // Any PagedSpace might invoke RefillFreeLists, so we need to make sure |
602 // to only refill them for the old space. | 602 // to only refill them for the old space. |
603 return; | 603 return; |
604 } | 604 } |
605 | 605 |
606 intptr_t added = space->free_list()->Concatenate(free_list); | 606 intptr_t added = space->free_list()->Concatenate(free_list); |
607 space->accounting_stats_.IncreaseCapacity(added); | 607 space->accounting_stats_.IncreaseCapacity(added); |
608 } | 608 } |
609 | 609 |
610 | 610 |
| 611 void MarkCompactCollector::RefillFreeList(CompactionSpace* space) { |
| 612 FreeList* free_list = nullptr; |
| 613 if (space->identity() == OLD_SPACE) { |
| 614 free_list = free_list_old_space_.get(); |
| 615 } else if (space->identity() == CODE_SPACE) { |
| 616 free_list = free_list_code_space_.get(); |
| 617 } else { |
| 618 UNREACHABLE(); |
| 619 } |
| 620 |
| 621 intptr_t refilled = 0; |
| 622 while (refilled < kCompactionSpaceMemoryWanted) { |
| 623 FreeSpace* node = |
| 624 free_list->TryRemoveMemory(kCompactionSpaceMemoryWanted - refilled); |
| 625 if (node == nullptr) return; |
| 626 refilled += node->size(); |
| 627 space->AddMemory(node->address(), node->size()); |
| 628 } |
| 629 } |
| 630 |
| 631 |
611 void Marking::TransferMark(Heap* heap, Address old_start, Address new_start) { | 632 void Marking::TransferMark(Heap* heap, Address old_start, Address new_start) { |
612 // This is only used when resizing an object. | 633 // This is only used when resizing an object. |
613 DCHECK(MemoryChunk::FromAddress(old_start) == | 634 DCHECK(MemoryChunk::FromAddress(old_start) == |
614 MemoryChunk::FromAddress(new_start)); | 635 MemoryChunk::FromAddress(new_start)); |
615 | 636 |
616 if (!heap->incremental_marking()->IsMarking()) return; | 637 if (!heap->incremental_marking()->IsMarking()) return; |
617 | 638 |
618 // If the mark doesn't move, we don't check the color of the object. | 639 // If the mark doesn't move, we don't check the color of the object. |
619 // It doesn't matter whether the object is black, since it hasn't changed | 640 // It doesn't matter whether the object is black, since it hasn't changed |
620 // size, so the adjustment to the live data count will be zero anyway. | 641 // size, so the adjustment to the live data count will be zero anyway. |
(...skipping 2769 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3390 | 3411 |
3391 const int num_tasks = NumberOfParallelCompactionTasks(); | 3412 const int num_tasks = NumberOfParallelCompactionTasks(); |
3392 | 3413 |
3393 // Set up compaction spaces. | 3414 // Set up compaction spaces. |
3394 CompactionSpaceCollection** compaction_spaces_for_tasks = | 3415 CompactionSpaceCollection** compaction_spaces_for_tasks = |
3395 new CompactionSpaceCollection*[num_tasks]; | 3416 new CompactionSpaceCollection*[num_tasks]; |
3396 for (int i = 0; i < num_tasks; i++) { | 3417 for (int i = 0; i < num_tasks; i++) { |
3397 compaction_spaces_for_tasks[i] = new CompactionSpaceCollection(heap()); | 3418 compaction_spaces_for_tasks[i] = new CompactionSpaceCollection(heap()); |
3398 } | 3419 } |
3399 | 3420 |
3400 compaction_spaces_for_tasks[0]->Get(OLD_SPACE)->MoveOverFreeMemory( | 3421 heap()->old_space()->DivideUponCompactionSpaces( |
3401 heap()->old_space()); | 3422 compaction_spaces_for_tasks, num_tasks, kCompactionSpaceMemoryWanted); |
3402 compaction_spaces_for_tasks[0] | 3423 heap()->code_space()->DivideUponCompactionSpaces( |
3403 ->Get(CODE_SPACE) | 3424 compaction_spaces_for_tasks, num_tasks, kCompactionSpaceMemoryWanted); |
3404 ->MoveOverFreeMemory(heap()->code_space()); | |
3405 | 3425 |
3406 compaction_in_progress_ = true; | 3426 compaction_in_progress_ = true; |
3407 // Kick off parallel tasks. | 3427 // Kick off parallel tasks. |
3408 for (int i = 1; i < num_tasks; i++) { | 3428 for (int i = 1; i < num_tasks; i++) { |
3409 concurrent_compaction_tasks_active_++; | 3429 concurrent_compaction_tasks_active_++; |
3410 V8::GetCurrentPlatform()->CallOnBackgroundThread( | 3430 V8::GetCurrentPlatform()->CallOnBackgroundThread( |
3411 new CompactionTask(heap(), compaction_spaces_for_tasks[i]), | 3431 new CompactionTask(heap(), compaction_spaces_for_tasks[i]), |
3412 v8::Platform::kShortRunningTask); | 3432 v8::Platform::kShortRunningTask); |
3413 } | 3433 } |
3414 | 3434 |
3415 // Contribute in main thread. Counter and signal are in principal not needed. | 3435 // Contribute in main thread. Counter and signal are in principal not needed. |
3416 concurrent_compaction_tasks_active_++; | |
3417 EvacuatePages(compaction_spaces_for_tasks[0], &migration_slots_buffer_); | 3436 EvacuatePages(compaction_spaces_for_tasks[0], &migration_slots_buffer_); |
3418 pending_compaction_tasks_semaphore_.Signal(); | |
3419 | 3437 |
3420 WaitUntilCompactionCompleted(); | 3438 WaitUntilCompactionCompleted(); |
3421 | 3439 |
3422 // Merge back memory (compacted and unused) from compaction spaces. | 3440 // Merge back memory (compacted and unused) from compaction spaces. |
3423 for (int i = 0; i < num_tasks; i++) { | 3441 for (int i = 0; i < num_tasks; i++) { |
3424 heap()->old_space()->MergeCompactionSpace( | 3442 heap()->old_space()->MergeCompactionSpace( |
3425 compaction_spaces_for_tasks[i]->Get(OLD_SPACE)); | 3443 compaction_spaces_for_tasks[i]->Get(OLD_SPACE)); |
3426 heap()->code_space()->MergeCompactionSpace( | 3444 heap()->code_space()->MergeCompactionSpace( |
3427 compaction_spaces_for_tasks[i]->Get(CODE_SPACE)); | 3445 compaction_spaces_for_tasks[i]->Get(CODE_SPACE)); |
3428 delete compaction_spaces_for_tasks[i]; | 3446 delete compaction_spaces_for_tasks[i]; |
(...skipping 1172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4601 MarkBit mark_bit = Marking::MarkBitFrom(host); | 4619 MarkBit mark_bit = Marking::MarkBitFrom(host); |
4602 if (Marking::IsBlack(mark_bit)) { | 4620 if (Marking::IsBlack(mark_bit)) { |
4603 RelocInfo rinfo(pc, RelocInfo::CODE_TARGET, 0, host); | 4621 RelocInfo rinfo(pc, RelocInfo::CODE_TARGET, 0, host); |
4604 RecordRelocSlot(&rinfo, target); | 4622 RecordRelocSlot(&rinfo, target); |
4605 } | 4623 } |
4606 } | 4624 } |
4607 } | 4625 } |
4608 | 4626 |
4609 } // namespace internal | 4627 } // namespace internal |
4610 } // namespace v8 | 4628 } // namespace v8 |
OLD | NEW |