Commit cd3209e8 authored by Ulan Degenbaev's avatar Ulan Degenbaev Committed by Commit Bot

[heap] Make concurrent marking tasks cancelable.

Bug: chromium:694255
Change-Id: I5c0c0b58cdcf3cf745670148724e3c6ecc34d485
Reviewed-on: https://chromium-review.googlesource.com/707149Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Commit-Queue: Ulan Degenbaev <ulan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#48395}
parent 3f02a37b
......@@ -434,9 +434,10 @@ void ConcurrentMarking::ScheduleTasks() {
task_state_[i].interrupt_request.SetValue(false);
is_pending_[i] = true;
++pending_task_count_;
Task* task = new Task(heap_->isolate(), this, &task_state_[i], i);
cancelable_id_[i] = task->id();
V8::GetCurrentPlatform()->CallOnBackgroundThread(
new Task(heap_->isolate(), this, &task_state_[i], i),
v8::Platform::kShortRunningTask);
task, v8::Platform::kShortRunningTask);
}
}
}
......@@ -452,12 +453,34 @@ void ConcurrentMarking::RescheduleTasksIfNeeded() {
}
}
void ConcurrentMarking::WaitForTasks() {
if (!FLAG_concurrent_marking) return;
base::LockGuard<base::Mutex> guard(&pending_lock_);
while (pending_task_count_ > 0) {
pending_condition_.Wait(&pending_lock_);
}
}
void ConcurrentMarking::EnsureCompleted() {
if (!FLAG_concurrent_marking) return;
base::LockGuard<base::Mutex> guard(&pending_lock_);
CancelableTaskManager* task_manager =
heap_->isolate()->cancelable_task_manager();
for (int i = 1; i <= task_count_; i++) {
if (is_pending_[i]) {
if (task_manager->TryAbort(cancelable_id_[i]) ==
CancelableTaskManager::kTaskAborted) {
is_pending_[i] = false;
--pending_task_count_;
}
}
}
while (pending_task_count_ > 0) {
pending_condition_.Wait(&pending_lock_);
}
for (int i = 1; i <= task_count_; i++) {
DCHECK(!is_pending_[i]);
}
}
void ConcurrentMarking::FlushLiveBytes(
......
......@@ -43,6 +43,7 @@ class ConcurrentMarking {
MarkingWorklist* bailout, WeakObjects* weak_objects);
void ScheduleTasks();
void WaitForTasks();
void EnsureCompleted();
void RescheduleTasksIfNeeded();
// Flushes the local live bytes into the given marking state.
......@@ -82,6 +83,7 @@ class ConcurrentMarking {
base::ConditionVariable pending_condition_;
int pending_task_count_;
bool is_pending_[kMaxTasks + 1];
CancelableTaskManager::Id cancelable_id_[kMaxTasks + 1];
int task_count_;
};
......
......@@ -43,6 +43,7 @@ TEST(ConcurrentMarking) {
new ConcurrentMarking(heap, &shared, &bailout, &weak_objects);
PublishSegment(&shared, heap->undefined_value());
concurrent_marking->ScheduleTasks();
concurrent_marking->WaitForTasks();
concurrent_marking->EnsureCompleted();
delete concurrent_marking;
}
......@@ -64,9 +65,11 @@ TEST(ConcurrentMarkingReschedule) {
new ConcurrentMarking(heap, &shared, &bailout, &weak_objects);
PublishSegment(&shared, heap->undefined_value());
concurrent_marking->ScheduleTasks();
concurrent_marking->WaitForTasks();
concurrent_marking->EnsureCompleted();
PublishSegment(&shared, heap->undefined_value());
concurrent_marking->RescheduleTasksIfNeeded();
concurrent_marking->WaitForTasks();
concurrent_marking->EnsureCompleted();
delete concurrent_marking;
}
......@@ -81,6 +84,7 @@ TEST(ConcurrentMarkingMarkedBytes) {
CcTest::CollectAllGarbage();
if (!heap->incremental_marking()->IsStopped()) return;
heap::SimulateIncrementalMarking(heap, false);
heap->concurrent_marking()->WaitForTasks();
heap->concurrent_marking()->EnsureCompleted();
CHECK_GE(heap->concurrent_marking()->TotalMarkedBytes(), root->Size());
}
......
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