Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(509)

Side by Side Diff: src/heap/mark-compact.cc

Issue 1354383002: [heap] Add more tasks for parallel compaction (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Addressed comments round 2 Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/heap/mark-compact.h ('k') | src/heap/spaces.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/code-stubs.h" 10 #include "src/code-stubs.h"
10 #include "src/compilation-cache.h" 11 #include "src/compilation-cache.h"
11 #include "src/cpu-profiler.h" 12 #include "src/cpu-profiler.h"
12 #include "src/deoptimizer.h" 13 #include "src/deoptimizer.h"
13 #include "src/execution.h" 14 #include "src/execution.h"
14 #include "src/frames-inl.h" 15 #include "src/frames-inl.h"
15 #include "src/gdb-jit.h" 16 #include "src/gdb-jit.h"
16 #include "src/global-handles.h" 17 #include "src/global-handles.h"
17 #include "src/heap/array-buffer-tracker.h" 18 #include "src/heap/array-buffer-tracker.h"
18 #include "src/heap/gc-tracer.h" 19 #include "src/heap/gc-tracer.h"
(...skipping 3341 matching lines...) Expand 10 before | Expand all | Expand 10 after
3360 } 3361 }
3361 3362
3362 // Clear marking bits for current cell. 3363 // Clear marking bits for current cell.
3363 *cell = 0; 3364 *cell = 0;
3364 } 3365 }
3365 p->ResetLiveBytes(); 3366 p->ResetLiveBytes();
3366 return true; 3367 return true;
3367 } 3368 }
3368 3369
3369 3370
3371 int MarkCompactCollector::NumberOfParallelCompactionTasks() {
3372 if (!FLAG_parallel_compaction) return 1;
3373 // We cap the number of parallel compaction tasks by
3374 // - (#cores - 1)
3375 // - a value depending on the list of evacuation candidates
3376 // - a hard limit
3377 const int kPagesPerCompactionTask = 4;
3378 const int kMaxCompactionTasks = 8;
3379 return Min(kMaxCompactionTasks,
3380 Min(1 + evacuation_candidates_.length() / kPagesPerCompactionTask,
3381 Max(1, base::SysInfo::NumberOfProcessors() - 1)));
3382 }
3383
3384
3370 void MarkCompactCollector::EvacuatePagesInParallel() { 3385 void MarkCompactCollector::EvacuatePagesInParallel() {
3371 if (evacuation_candidates_.length() == 0) return; 3386 if (evacuation_candidates_.length() == 0) return;
3372 3387
3373 int num_tasks = 1; 3388 const int num_tasks = NumberOfParallelCompactionTasks();
3374 if (FLAG_parallel_compaction) {
3375 num_tasks = NumberOfParallelCompactionTasks();
3376 }
3377 3389
3378 // Set up compaction spaces. 3390 // Set up compaction spaces.
3379 CompactionSpaceCollection** compaction_spaces_for_tasks = 3391 CompactionSpaceCollection** compaction_spaces_for_tasks =
3380 new CompactionSpaceCollection*[num_tasks]; 3392 new CompactionSpaceCollection*[num_tasks];
3393 FreeList** free_lists = new FreeList*[2 * num_tasks];
3381 for (int i = 0; i < num_tasks; i++) { 3394 for (int i = 0; i < num_tasks; i++) {
3382 compaction_spaces_for_tasks[i] = new CompactionSpaceCollection(heap()); 3395 compaction_spaces_for_tasks[i] = new CompactionSpaceCollection(heap());
3396 free_lists[i] = compaction_spaces_for_tasks[i]->Get(OLD_SPACE)->free_list();
3397 free_lists[i + num_tasks] =
3398 compaction_spaces_for_tasks[i]->Get(CODE_SPACE)->free_list();
3383 } 3399 }
3384 3400 heap()->old_space()->DivideFreeLists(free_lists, num_tasks, 1 * MB);
3385 compaction_spaces_for_tasks[0]->Get(OLD_SPACE)->MoveOverFreeMemory( 3401 heap()->code_space()->DivideFreeLists(&free_lists[num_tasks], num_tasks,
3386 heap()->old_space()); 3402 1 * MB);
3387 compaction_spaces_for_tasks[0] 3403 delete[] free_lists;
3388 ->Get(CODE_SPACE)
3389 ->MoveOverFreeMemory(heap()->code_space());
3390 3404
3391 compaction_in_progress_ = true; 3405 compaction_in_progress_ = true;
3392 // Kick off parallel tasks. 3406 // Kick off parallel tasks.
3393 for (int i = 1; i < num_tasks; i++) { 3407 for (int i = 1; i < num_tasks; i++) {
3394 concurrent_compaction_tasks_active_++; 3408 concurrent_compaction_tasks_active_++;
3395 V8::GetCurrentPlatform()->CallOnBackgroundThread( 3409 V8::GetCurrentPlatform()->CallOnBackgroundThread(
3396 new CompactionTask(heap(), compaction_spaces_for_tasks[i]), 3410 new CompactionTask(heap(), compaction_spaces_for_tasks[i]),
3397 v8::Platform::kShortRunningTask); 3411 v8::Platform::kShortRunningTask);
3398 } 3412 }
3399 3413
3400 // Contribute in main thread. Counter and signal are in principal not needed. 3414 // Perform compaction on the main thread.
3401 concurrent_compaction_tasks_active_++;
3402 EvacuatePages(compaction_spaces_for_tasks[0], &migration_slots_buffer_); 3415 EvacuatePages(compaction_spaces_for_tasks[0], &migration_slots_buffer_);
3403 pending_compaction_tasks_semaphore_.Signal();
3404 3416
3405 WaitUntilCompactionCompleted(); 3417 WaitUntilCompactionCompleted();
3406 3418
3407 // Merge back memory (compacted and unused) from compaction spaces. 3419 // Merge back memory (compacted and unused) from compaction spaces.
3408 for (int i = 0; i < num_tasks; i++) { 3420 for (int i = 0; i < num_tasks; i++) {
3409 heap()->old_space()->MergeCompactionSpace( 3421 heap()->old_space()->MergeCompactionSpace(
3410 compaction_spaces_for_tasks[i]->Get(OLD_SPACE)); 3422 compaction_spaces_for_tasks[i]->Get(OLD_SPACE));
3411 heap()->code_space()->MergeCompactionSpace( 3423 heap()->code_space()->MergeCompactionSpace(
3412 compaction_spaces_for_tasks[i]->Get(CODE_SPACE)); 3424 compaction_spaces_for_tasks[i]->Get(CODE_SPACE));
3413 delete compaction_spaces_for_tasks[i]; 3425 delete compaction_spaces_for_tasks[i];
(...skipping 1172 matching lines...) Expand 10 before | Expand all | Expand 10 after
4586 MarkBit mark_bit = Marking::MarkBitFrom(host); 4598 MarkBit mark_bit = Marking::MarkBitFrom(host);
4587 if (Marking::IsBlack(mark_bit)) { 4599 if (Marking::IsBlack(mark_bit)) {
4588 RelocInfo rinfo(pc, RelocInfo::CODE_TARGET, 0, host); 4600 RelocInfo rinfo(pc, RelocInfo::CODE_TARGET, 0, host);
4589 RecordRelocSlot(&rinfo, target); 4601 RecordRelocSlot(&rinfo, target);
4590 } 4602 }
4591 } 4603 }
4592 } 4604 }
4593 4605
4594 } // namespace internal 4606 } // namespace internal
4595 } // namespace v8 4607 } // namespace v8
OLDNEW
« no previous file with comments | « src/heap/mark-compact.h ('k') | src/heap/spaces.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698