| 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 <utility> | 11 #include <utility> |
| 11 | 12 |
| 12 #include "src/base/macros.h" | 13 #include "src/base/macros.h" |
| 14 #include "src/base/platform/condition-variable.h" |
| 15 #include "src/base/platform/mutex.h" |
| 13 #include "src/globals.h" | 16 #include "src/globals.h" |
| 14 #include "testing/gtest/include/gtest/gtest_prod.h" | 17 #include "testing/gtest/include/gtest/gtest_prod.h" |
| 15 | 18 |
| 16 namespace v8 { | 19 namespace v8 { |
| 17 | 20 |
| 18 class Platform; | 21 class Platform; |
| 19 | 22 |
| 20 namespace internal { | 23 namespace internal { |
| 21 | 24 |
| 25 class CancelableTaskManager; |
| 22 class CompilerDispatcherJob; | 26 class CompilerDispatcherJob; |
| 23 class CompilerDispatcherTracer; | 27 class CompilerDispatcherTracer; |
| 24 class Isolate; | 28 class Isolate; |
| 25 class SharedFunctionInfo; | 29 class SharedFunctionInfo; |
| 26 | 30 |
| 27 template <typename T> | 31 template <typename T> |
| 28 class Handle; | 32 class Handle; |
| 29 | 33 |
| 30 // The CompilerDispatcher uses a combination of idle tasks and background tasks | 34 // The CompilerDispatcher uses a combination of idle tasks and background tasks |
| 31 // to parse and compile lazily parsed functions. | 35 // to parse and compile lazily parsed functions. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 48 bool FinishNow(Handle<SharedFunctionInfo> function); | 52 bool FinishNow(Handle<SharedFunctionInfo> function); |
| 49 | 53 |
| 50 // Aborts a given job. Blocks if requested. | 54 // Aborts a given job. Blocks if requested. |
| 51 void Abort(Handle<SharedFunctionInfo> function, BlockingBehavior blocking); | 55 void Abort(Handle<SharedFunctionInfo> function, BlockingBehavior blocking); |
| 52 | 56 |
| 53 // Aborts all jobs. Blocks if requested. | 57 // Aborts all jobs. Blocks if requested. |
| 54 void AbortAll(BlockingBehavior blocking); | 58 void AbortAll(BlockingBehavior blocking); |
| 55 | 59 |
| 56 private: | 60 private: |
| 57 FRIEND_TEST(CompilerDispatcherTest, IdleTaskSmallIdleTime); | 61 FRIEND_TEST(CompilerDispatcherTest, IdleTaskSmallIdleTime); |
| 62 FRIEND_TEST(IgnitionCompilerDispatcherTest, CompileOnBackgroundThread); |
| 63 FRIEND_TEST(IgnitionCompilerDispatcherTest, FinishNowWithBackgroundTask); |
| 58 | 64 |
| 59 typedef std::multimap<std::pair<int, int>, | 65 typedef std::multimap<std::pair<int, int>, |
| 60 std::unique_ptr<CompilerDispatcherJob>> | 66 std::unique_ptr<CompilerDispatcherJob>> |
| 61 JobMap; | 67 JobMap; |
| 68 class BackgroundTask; |
| 62 class IdleTask; | 69 class IdleTask; |
| 63 | 70 |
| 71 void WaitForJobIfRunningOnBackground(CompilerDispatcherJob* job); |
| 64 bool IsEnabled() const; | 72 bool IsEnabled() const; |
| 65 JobMap::const_iterator GetJobFor(Handle<SharedFunctionInfo> shared) const; | 73 JobMap::const_iterator GetJobFor(Handle<SharedFunctionInfo> shared) const; |
| 74 void ConsiderJobForBackgroundProcessing(CompilerDispatcherJob* job); |
| 75 void ScheduleMoreBackgroundTasksIfNeeded(); |
| 76 void ScheduleIdleTaskFromAnyThread(); |
| 66 void ScheduleIdleTaskIfNeeded(); | 77 void ScheduleIdleTaskIfNeeded(); |
| 78 void DoBackgroundWork(); |
| 67 void DoIdleWork(double deadline_in_seconds); | 79 void DoIdleWork(double deadline_in_seconds); |
| 68 | 80 |
| 69 Isolate* isolate_; | 81 Isolate* isolate_; |
| 70 Platform* platform_; | 82 Platform* platform_; |
| 71 size_t max_stack_size_; | 83 size_t max_stack_size_; |
| 72 std::unique_ptr<CompilerDispatcherTracer> tracer_; | 84 std::unique_ptr<CompilerDispatcherTracer> tracer_; |
| 73 | 85 |
| 74 bool idle_task_scheduled_; | 86 std::unique_ptr<CancelableTaskManager> task_manager_; |
| 75 | 87 |
| 76 // Mapping from (script id, function literal id) to job. We use a multimap, | 88 // Mapping from (script id, function literal id) to job. We use a multimap, |
| 77 // as script id is not necessarily unique. | 89 // as script id is not necessarily unique. |
| 78 JobMap jobs_; | 90 JobMap jobs_; |
| 79 | 91 |
| 92 // The following members can be accessed from any thread. Methods need to hold |
| 93 // the mutex |mutex_| while accessing them. |
| 94 base::Mutex mutex_; |
| 95 |
| 96 bool idle_task_scheduled_; |
| 97 |
| 98 // Number of currently scheduled BackgroundTask objects. |
| 99 size_t num_scheduled_background_tasks_; |
| 100 |
| 101 // The set of CompilerDispatcherJobs that can be advanced on any thread. |
| 102 std::unordered_set<CompilerDispatcherJob*> pending_background_jobs_; |
| 103 |
| 104 // The set of CompilerDispatcherJobs currently processed on background |
| 105 // threads. |
| 106 std::unordered_set<CompilerDispatcherJob*> running_background_jobs_; |
| 107 |
| 108 // If not nullptr, then the main thread waits for the task processing |
| 109 // this job, and blocks on the ConditionVariable main_thread_blocking_signal_. |
| 110 CompilerDispatcherJob* main_thread_blocking_on_job_; |
| 111 base::ConditionVariable main_thread_blocking_signal_; |
| 112 |
| 80 DISALLOW_COPY_AND_ASSIGN(CompilerDispatcher); | 113 DISALLOW_COPY_AND_ASSIGN(CompilerDispatcher); |
| 81 }; | 114 }; |
| 82 | 115 |
| 83 } // namespace internal | 116 } // namespace internal |
| 84 } // namespace v8 | 117 } // namespace v8 |
| 85 | 118 |
| 86 #endif // V8_COMPILER_DISPATCHER_COMPILER_DISPATCHER_H_ | 119 #endif // V8_COMPILER_DISPATCHER_COMPILER_DISPATCHER_H_ |
| OLD | NEW |