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 3406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3417 // - a hard limit | 3417 // - a hard limit |
3418 const int kPagesPerCompactionTask = 4; | 3418 const int kPagesPerCompactionTask = 4; |
3419 const int kMaxCompactionTasks = 8; | 3419 const int kMaxCompactionTasks = 8; |
3420 return Min(kMaxCompactionTasks, | 3420 return Min(kMaxCompactionTasks, |
3421 Min(1 + evacuation_candidates_.length() / kPagesPerCompactionTask, | 3421 Min(1 + evacuation_candidates_.length() / kPagesPerCompactionTask, |
3422 Max(1, base::SysInfo::NumberOfProcessors() - 1))); | 3422 Max(1, base::SysInfo::NumberOfProcessors() - 1))); |
3423 } | 3423 } |
3424 | 3424 |
3425 | 3425 |
3426 void MarkCompactCollector::EvacuatePagesInParallel() { | 3426 void MarkCompactCollector::EvacuatePagesInParallel() { |
3427 if (evacuation_candidates_.length() == 0) return; | 3427 const int num_pages = evacuation_candidates_.length(); |
| 3428 if (num_pages == 0) return; |
3428 | 3429 |
3429 const int num_tasks = NumberOfParallelCompactionTasks(); | 3430 const int num_tasks = NumberOfParallelCompactionTasks(); |
3430 | 3431 |
3431 // Set up compaction spaces. | 3432 // Set up compaction spaces. |
3432 CompactionSpaceCollection** compaction_spaces_for_tasks = | 3433 CompactionSpaceCollection** compaction_spaces_for_tasks = |
3433 new CompactionSpaceCollection*[num_tasks]; | 3434 new CompactionSpaceCollection*[num_tasks]; |
3434 for (int i = 0; i < num_tasks; i++) { | 3435 for (int i = 0; i < num_tasks; i++) { |
3435 compaction_spaces_for_tasks[i] = new CompactionSpaceCollection(heap()); | 3436 compaction_spaces_for_tasks[i] = new CompactionSpaceCollection(heap()); |
3436 } | 3437 } |
3437 | 3438 |
(...skipping 23 matching lines...) Expand all Loading... |
3461 for (int i = 0; i < num_tasks; i++) { | 3462 for (int i = 0; i < num_tasks; i++) { |
3462 heap()->old_space()->MergeCompactionSpace( | 3463 heap()->old_space()->MergeCompactionSpace( |
3463 compaction_spaces_for_tasks[i]->Get(OLD_SPACE)); | 3464 compaction_spaces_for_tasks[i]->Get(OLD_SPACE)); |
3464 heap()->code_space()->MergeCompactionSpace( | 3465 heap()->code_space()->MergeCompactionSpace( |
3465 compaction_spaces_for_tasks[i]->Get(CODE_SPACE)); | 3466 compaction_spaces_for_tasks[i]->Get(CODE_SPACE)); |
3466 delete compaction_spaces_for_tasks[i]; | 3467 delete compaction_spaces_for_tasks[i]; |
3467 } | 3468 } |
3468 delete[] compaction_spaces_for_tasks; | 3469 delete[] compaction_spaces_for_tasks; |
3469 | 3470 |
3470 // Finalize sequentially. | 3471 // Finalize sequentially. |
3471 const int num_pages = evacuation_candidates_.length(); | |
3472 int abandoned_pages = 0; | 3472 int abandoned_pages = 0; |
3473 for (int i = 0; i < num_pages; i++) { | 3473 for (int i = 0; i < num_pages; i++) { |
3474 Page* p = evacuation_candidates_[i]; | 3474 Page* p = evacuation_candidates_[i]; |
3475 switch (p->parallel_compaction_state().Value()) { | 3475 switch (p->parallel_compaction_state().Value()) { |
3476 case MemoryChunk::ParallelCompactingState::kCompactingAborted: | 3476 case MemoryChunk::ParallelCompactingState::kCompactingAborted: |
3477 // We have partially compacted the page, i.e., some objects may have | 3477 // We have partially compacted the page, i.e., some objects may have |
3478 // moved, others are still in place. | 3478 // moved, others are still in place. |
3479 // We need to: | 3479 // We need to: |
3480 // - Leave the evacuation candidate flag for later processing of | 3480 // - Leave the evacuation candidate flag for later processing of |
3481 // slots buffer entries. | 3481 // slots buffer entries. |
(...skipping 15 matching lines...) Expand all Loading... |
3497 case MemoryChunk::kCompactingDone: | 3497 case MemoryChunk::kCompactingDone: |
3498 DCHECK(p->IsFlagSet(Page::POPULAR_PAGE)); | 3498 DCHECK(p->IsFlagSet(Page::POPULAR_PAGE)); |
3499 DCHECK(p->IsFlagSet(Page::RESCAN_ON_EVACUATION)); | 3499 DCHECK(p->IsFlagSet(Page::RESCAN_ON_EVACUATION)); |
3500 break; | 3500 break; |
3501 default: | 3501 default: |
3502 // We should not observe kCompactingInProgress, or kCompactingDone. | 3502 // We should not observe kCompactingInProgress, or kCompactingDone. |
3503 UNREACHABLE(); | 3503 UNREACHABLE(); |
3504 } | 3504 } |
3505 p->parallel_compaction_state().SetValue(MemoryChunk::kCompactingDone); | 3505 p->parallel_compaction_state().SetValue(MemoryChunk::kCompactingDone); |
3506 } | 3506 } |
3507 if (num_pages > 0) { | 3507 if (FLAG_trace_fragmentation) { |
3508 if (FLAG_trace_fragmentation) { | 3508 PrintIsolate(isolate(), |
3509 if (abandoned_pages != 0) { | 3509 "%8.0f ms: compaction: parallel=%d pages=%d aborted=%d " |
3510 PrintF( | 3510 "tasks=%d cores=%d\n", |
3511 " Abandoned (at least partially) %d out of %d page compactions due" | 3511 isolate()->time_millis_since_init(), FLAG_parallel_compaction, |
3512 " to lack of memory\n", | 3512 num_pages, abandoned_pages, num_tasks, |
3513 abandoned_pages, num_pages); | 3513 base::SysInfo::NumberOfProcessors()); |
3514 } else { | |
3515 PrintF(" Compacted %d pages\n", num_pages); | |
3516 } | |
3517 } | |
3518 } | 3514 } |
3519 } | 3515 } |
3520 | 3516 |
3521 | 3517 |
3522 void MarkCompactCollector::WaitUntilCompactionCompleted() { | 3518 void MarkCompactCollector::WaitUntilCompactionCompleted() { |
3523 while (concurrent_compaction_tasks_active_ > 0) { | 3519 while (concurrent_compaction_tasks_active_ > 0) { |
3524 pending_compaction_tasks_semaphore_.Wait(); | 3520 pending_compaction_tasks_semaphore_.Wait(); |
3525 concurrent_compaction_tasks_active_--; | 3521 concurrent_compaction_tasks_active_--; |
3526 } | 3522 } |
3527 compaction_in_progress_ = false; | 3523 compaction_in_progress_ = false; |
(...skipping 1111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4639 MarkBit mark_bit = Marking::MarkBitFrom(host); | 4635 MarkBit mark_bit = Marking::MarkBitFrom(host); |
4640 if (Marking::IsBlack(mark_bit)) { | 4636 if (Marking::IsBlack(mark_bit)) { |
4641 RelocInfo rinfo(pc, RelocInfo::CODE_TARGET, 0, host); | 4637 RelocInfo rinfo(pc, RelocInfo::CODE_TARGET, 0, host); |
4642 RecordRelocSlot(&rinfo, target); | 4638 RecordRelocSlot(&rinfo, target); |
4643 } | 4639 } |
4644 } | 4640 } |
4645 } | 4641 } |
4646 | 4642 |
4647 } // namespace internal | 4643 } // namespace internal |
4648 } // namespace v8 | 4644 } // namespace v8 |
OLD | NEW |