OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 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 #ifndef V8_COMPILER_DISPATCHER_COMPILER_DISPATCHER_H_ | 5 #ifndef V8_COMPILER_DISPATCHER_COMPILER_DISPATCHER_H_ |
6 #define V8_COMPILER_DISPATCHER_COMPILER_DISPATCHER_H_ | 6 #define V8_COMPILER_DISPATCHER_COMPILER_DISPATCHER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <memory> | 9 #include <memory> |
10 #include <unordered_set> | 10 #include <unordered_set> |
11 #include <utility> | 11 #include <utility> |
12 | 12 |
| 13 #include "src/base/atomic-utils.h" |
13 #include "src/base/macros.h" | 14 #include "src/base/macros.h" |
14 #include "src/base/platform/condition-variable.h" | 15 #include "src/base/platform/condition-variable.h" |
15 #include "src/base/platform/mutex.h" | 16 #include "src/base/platform/mutex.h" |
| 17 #include "src/base/platform/semaphore.h" |
16 #include "src/globals.h" | 18 #include "src/globals.h" |
17 #include "testing/gtest/include/gtest/gtest_prod.h" | 19 #include "testing/gtest/include/gtest/gtest_prod.h" |
18 | 20 |
19 namespace v8 { | 21 namespace v8 { |
20 | 22 |
21 class Platform; | 23 class Platform; |
22 | 24 |
23 namespace internal { | 25 namespace internal { |
24 | 26 |
25 class CancelableTaskManager; | 27 class CancelableTaskManager; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 // Aborts a given job. Blocks if requested. | 80 // Aborts a given job. Blocks if requested. |
79 void Abort(Handle<SharedFunctionInfo> function, BlockingBehavior blocking); | 81 void Abort(Handle<SharedFunctionInfo> function, BlockingBehavior blocking); |
80 | 82 |
81 // Aborts all jobs. Blocks if requested. | 83 // Aborts all jobs. Blocks if requested. |
82 void AbortAll(BlockingBehavior blocking); | 84 void AbortAll(BlockingBehavior blocking); |
83 | 85 |
84 private: | 86 private: |
85 FRIEND_TEST(CompilerDispatcherTest, IdleTaskSmallIdleTime); | 87 FRIEND_TEST(CompilerDispatcherTest, IdleTaskSmallIdleTime); |
86 FRIEND_TEST(IgnitionCompilerDispatcherTest, CompileOnBackgroundThread); | 88 FRIEND_TEST(IgnitionCompilerDispatcherTest, CompileOnBackgroundThread); |
87 FRIEND_TEST(IgnitionCompilerDispatcherTest, FinishNowWithBackgroundTask); | 89 FRIEND_TEST(IgnitionCompilerDispatcherTest, FinishNowWithBackgroundTask); |
| 90 FRIEND_TEST(IgnitionCompilerDispatcherTest, |
| 91 AsyncAbortAllPendingBackgroundTask); |
| 92 FRIEND_TEST(IgnitionCompilerDispatcherTest, |
| 93 AsyncAbortAllRunningBackgroundTask); |
| 94 FRIEND_TEST(IgnitionCompilerDispatcherTest, FinishNowDuringAbortAll); |
88 | 95 |
89 typedef std::multimap<std::pair<int, int>, | 96 typedef std::multimap<std::pair<int, int>, |
90 std::unique_ptr<CompilerDispatcherJob>> | 97 std::unique_ptr<CompilerDispatcherJob>> |
91 JobMap; | 98 JobMap; |
| 99 class AbortTask; |
92 class BackgroundTask; | 100 class BackgroundTask; |
93 class IdleTask; | 101 class IdleTask; |
94 | 102 |
95 void WaitForJobIfRunningOnBackground(CompilerDispatcherJob* job); | 103 void WaitForJobIfRunningOnBackground(CompilerDispatcherJob* job); |
96 bool IsEnabled() const; | 104 bool IsEnabled() const; |
| 105 void AbortInactiveJobs(); |
97 JobMap::const_iterator GetJobFor(Handle<SharedFunctionInfo> shared) const; | 106 JobMap::const_iterator GetJobFor(Handle<SharedFunctionInfo> shared) const; |
98 void ConsiderJobForBackgroundProcessing(CompilerDispatcherJob* job); | 107 void ConsiderJobForBackgroundProcessing(CompilerDispatcherJob* job); |
99 void ScheduleMoreBackgroundTasksIfNeeded(); | 108 void ScheduleMoreBackgroundTasksIfNeeded(); |
100 void ScheduleIdleTaskFromAnyThread(); | 109 void ScheduleIdleTaskFromAnyThread(); |
101 void ScheduleIdleTaskIfNeeded(); | 110 void ScheduleIdleTaskIfNeeded(); |
| 111 void ScheduleAbortTask(); |
102 void DoBackgroundWork(); | 112 void DoBackgroundWork(); |
103 void DoIdleWork(double deadline_in_seconds); | 113 void DoIdleWork(double deadline_in_seconds); |
104 | 114 |
105 Isolate* isolate_; | 115 Isolate* isolate_; |
106 Platform* platform_; | 116 Platform* platform_; |
107 size_t max_stack_size_; | 117 size_t max_stack_size_; |
108 std::unique_ptr<CompilerDispatcherTracer> tracer_; | 118 std::unique_ptr<CompilerDispatcherTracer> tracer_; |
109 | 119 |
110 std::unique_ptr<CancelableTaskManager> task_manager_; | 120 std::unique_ptr<CancelableTaskManager> task_manager_; |
111 | 121 |
112 // Mapping from (script id, function literal id) to job. We use a multimap, | 122 // Mapping from (script id, function literal id) to job. We use a multimap, |
113 // as script id is not necessarily unique. | 123 // as script id is not necessarily unique. |
114 JobMap jobs_; | 124 JobMap jobs_; |
115 | 125 |
116 // The following members can be accessed from any thread. Methods need to hold | 126 // The following members can be accessed from any thread. Methods need to hold |
117 // the mutex |mutex_| while accessing them. | 127 // the mutex |mutex_| while accessing them. |
118 base::Mutex mutex_; | 128 base::Mutex mutex_; |
119 | 129 |
| 130 // True if the dispatcher is in the process of aborting running tasks. |
| 131 bool abort_; |
| 132 |
120 bool idle_task_scheduled_; | 133 bool idle_task_scheduled_; |
121 | 134 |
122 // Number of currently scheduled BackgroundTask objects. | 135 // Number of currently scheduled BackgroundTask objects. |
123 size_t num_scheduled_background_tasks_; | 136 size_t num_scheduled_background_tasks_; |
124 | 137 |
125 // The set of CompilerDispatcherJobs that can be advanced on any thread. | 138 // The set of CompilerDispatcherJobs that can be advanced on any thread. |
126 std::unordered_set<CompilerDispatcherJob*> pending_background_jobs_; | 139 std::unordered_set<CompilerDispatcherJob*> pending_background_jobs_; |
127 | 140 |
128 // The set of CompilerDispatcherJobs currently processed on background | 141 // The set of CompilerDispatcherJobs currently processed on background |
129 // threads. | 142 // threads. |
130 std::unordered_set<CompilerDispatcherJob*> running_background_jobs_; | 143 std::unordered_set<CompilerDispatcherJob*> running_background_jobs_; |
131 | 144 |
132 // If not nullptr, then the main thread waits for the task processing | 145 // If not nullptr, then the main thread waits for the task processing |
133 // this job, and blocks on the ConditionVariable main_thread_blocking_signal_. | 146 // this job, and blocks on the ConditionVariable main_thread_blocking_signal_. |
134 CompilerDispatcherJob* main_thread_blocking_on_job_; | 147 CompilerDispatcherJob* main_thread_blocking_on_job_; |
135 base::ConditionVariable main_thread_blocking_signal_; | 148 base::ConditionVariable main_thread_blocking_signal_; |
136 | 149 |
| 150 // Test support. |
| 151 base::AtomicValue<bool> block_for_testing_; |
| 152 base::Semaphore semaphore_for_testing_; |
| 153 |
137 DISALLOW_COPY_AND_ASSIGN(CompilerDispatcher); | 154 DISALLOW_COPY_AND_ASSIGN(CompilerDispatcher); |
138 }; | 155 }; |
139 | 156 |
140 } // namespace internal | 157 } // namespace internal |
141 } // namespace v8 | 158 } // namespace v8 |
142 | 159 |
143 #endif // V8_COMPILER_DISPATCHER_COMPILER_DISPATCHER_H_ | 160 #endif // V8_COMPILER_DISPATCHER_COMPILER_DISPATCHER_H_ |
OLD | NEW |