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

Side by Side Diff: src/heap/concurrent-marking.cc

Issue 2728363002: [heap] Implement concurrent marking boilerplate. (Closed)
Patch Set: Add missing test file Created 3 years, 9 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
OLDNEW
(Empty)
1 // Copyright 2017 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "src/heap/concurrent-marking.h"
6
7 #include "src/heap/heap-inl.h"
8 #include "src/heap/heap.h"
9 #include "src/isolate.h"
10 #include "src/locked-queue-inl.h"
11 #include "src/v8.h"
12
13 namespace v8 {
14 namespace internal {
15
16 class ConcurrentMarking::Task : public CancelableTask {
17 public:
18 Task(Heap* heap, Queue* queue, base::Semaphore* on_finish)
19 : CancelableTask(heap->isolate()),
20 heap_(heap),
21 queue_(queue),
22 on_finish_(on_finish) {}
23
24 virtual ~Task() {}
25
26 private:
27 // v8::internal::CancelableTask overrides.
28 void RunInternal() override {
29 USE(heap_);
30 HeapObject* object;
31 while (queue_->Dequeue(&object)) {
32 // TODO(ulan): Implement actual marking.
33 }
34 on_finish_->Signal();
35 }
36
37 Heap* heap_;
38 Queue* queue_;
39 base::Semaphore* on_finish_;
40 DISALLOW_COPY_AND_ASSIGN(Task);
41 };
42
43 ConcurrentMarking::ConcurrentMarking(Heap* heap)
44 : heap_(heap), pending_tasks_(0), number_of_tasks_(0) {}
45
46 ConcurrentMarking::~ConcurrentMarking() {}
47
48 void ConcurrentMarking::EnqueueObject(HeapObject* object) {
49 queue_.Enqueue(object);
50 }
51
52 bool ConcurrentMarking::IsQueueEmpty() { return queue_.IsEmpty(); }
53
54 void ConcurrentMarking::StartMarkingTasks(int number_of_tasks) {
55 if (!FLAG_concurrent_marking) return;
56 DCHECK_EQ(0, number_of_tasks_);
57
58 number_of_tasks_ = number_of_tasks;
59 for (int i = 0; i < number_of_tasks; i++) {
60 V8::GetCurrentPlatform()->CallOnBackgroundThread(
61 new Task(heap_, &queue_, &pending_tasks_),
62 v8::Platform::kShortRunningTask);
63 }
64 }
65
66 void ConcurrentMarking::WaitForTasksToComplete() {
67 if (!FLAG_concurrent_marking) return;
68
69 CancelableTaskManager* cancelable_task_manager =
70 heap_->isolate()->cancelable_task_manager();
71 for (int i = 0; i < number_of_tasks_; i++) {
72 if (cancelable_task_manager->TryAbort(task_ids_[i]) !=
73 CancelableTaskManager::kTaskAborted) {
74 pending_tasks_.Wait();
75 }
76 }
77 number_of_tasks_ = 0;
78 }
79
80 } // namespace internal
81 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698