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