Commit 2a077a1a authored by ulan's avatar ulan Committed by Commit bot

Allocate semaphore of page parallel job on heap.

BUG=

Review URL: https://codereview.chromium.org/1806283002

Cr-Commit-Position: refs/heads/master@{#34924}
parent b954b187
...@@ -3541,16 +3541,14 @@ int NumberOfPointerUpdateTasks(int pages) { ...@@ -3541,16 +3541,14 @@ int NumberOfPointerUpdateTasks(int pages) {
template <PointerDirection direction> template <PointerDirection direction>
void UpdatePointersInParallel(Heap* heap) { void UpdatePointersInParallel(Heap* heap) {
PageParallelJob<PointerUpdateJobTraits<direction> >* job = PageParallelJob<PointerUpdateJobTraits<direction> > job(
new PageParallelJob<PointerUpdateJobTraits<direction> >( heap, heap->isolate()->cancelable_task_manager());
heap, heap->isolate()->cancelable_task_manager());
RememberedSet<direction>::IterateMemoryChunks( RememberedSet<direction>::IterateMemoryChunks(
heap, [job](MemoryChunk* chunk) { job->AddPage(chunk, 0); }); heap, [&job](MemoryChunk* chunk) { job.AddPage(chunk, 0); });
PointersUpdatingVisitor visitor(heap); PointersUpdatingVisitor visitor(heap);
int num_pages = job->NumberOfPages(); int num_pages = job.NumberOfPages();
int num_tasks = NumberOfPointerUpdateTasks(num_pages); int num_tasks = NumberOfPointerUpdateTasks(num_pages);
job->Run(num_tasks, [&visitor](int i) { return &visitor; }); job.Run(num_tasks, [&visitor](int i) { return &visitor; });
delete job;
} }
class ToSpacePointerUpdateJobTraits { class ToSpacePointerUpdateJobTraits {
......
...@@ -38,7 +38,8 @@ class PageParallelJob { ...@@ -38,7 +38,8 @@ class PageParallelJob {
cancelable_task_manager_(cancelable_task_manager), cancelable_task_manager_(cancelable_task_manager),
items_(nullptr), items_(nullptr),
num_items_(0), num_items_(0),
pending_tasks_(0) {} num_tasks_(0),
pending_tasks_(new base::Semaphore(0)) {}
~PageParallelJob() { ~PageParallelJob() {
Item* item = items_; Item* item = items_;
...@@ -47,6 +48,7 @@ class PageParallelJob { ...@@ -47,6 +48,7 @@ class PageParallelJob {
delete item; delete item;
item = next; item = next;
} }
delete pending_tasks_;
} }
void AddPage(MemoryChunk* chunk, typename JobTraits::PerPageData data) { void AddPage(MemoryChunk* chunk, typename JobTraits::PerPageData data) {
...@@ -81,7 +83,7 @@ class PageParallelJob { ...@@ -81,7 +83,7 @@ class PageParallelJob {
start_index -= num_items_; start_index -= num_items_;
} }
Task* task = new Task(heap_, items_, num_items_, start_index, Task* task = new Task(heap_, items_, num_items_, start_index,
&pending_tasks_, per_task_data_callback(i)); pending_tasks_, per_task_data_callback(i));
task_ids[i] = task->id(); task_ids[i] = task->id();
if (i > 0) { if (i > 0) {
V8::GetCurrentPlatform()->CallOnBackgroundThread( V8::GetCurrentPlatform()->CallOnBackgroundThread(
...@@ -96,7 +98,7 @@ class PageParallelJob { ...@@ -96,7 +98,7 @@ class PageParallelJob {
// Wait for background tasks. // Wait for background tasks.
for (int i = 0; i < num_tasks_; i++) { for (int i = 0; i < num_tasks_; i++) {
if (!cancelable_task_manager_->TryAbort(task_ids[i])) { if (!cancelable_task_manager_->TryAbort(task_ids[i])) {
pending_tasks_.Wait(); pending_tasks_->Wait();
} }
} }
if (JobTraits::NeedSequentialFinalization) { if (JobTraits::NeedSequentialFinalization) {
...@@ -176,7 +178,7 @@ class PageParallelJob { ...@@ -176,7 +178,7 @@ class PageParallelJob {
Item* items_; Item* items_;
int num_items_; int num_items_;
int num_tasks_; int num_tasks_;
base::Semaphore pending_tasks_; base::Semaphore* pending_tasks_;
DISALLOW_COPY_AND_ASSIGN(PageParallelJob); DISALLOW_COPY_AND_ASSIGN(PageParallelJob);
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment