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> |
(...skipping 10 matching lines...) Expand all Loading... | |
21 namespace v8 { | 21 namespace v8 { |
22 | 22 |
23 class Platform; | 23 class Platform; |
24 enum class MemoryPressureLevel; | 24 enum class MemoryPressureLevel; |
25 | 25 |
26 namespace internal { | 26 namespace internal { |
27 | 27 |
28 class CancelableTaskManager; | 28 class CancelableTaskManager; |
29 class CompilerDispatcherJob; | 29 class CompilerDispatcherJob; |
30 class CompilerDispatcherTracer; | 30 class CompilerDispatcherTracer; |
31 class CompilationInfo; | |
32 class CompilationJob; | |
31 class Isolate; | 33 class Isolate; |
34 class ParseInfo; | |
32 class SharedFunctionInfo; | 35 class SharedFunctionInfo; |
36 class Zone; | |
33 | 37 |
34 template <typename T> | 38 template <typename T> |
35 class Handle; | 39 class Handle; |
36 | 40 |
37 // The CompilerDispatcher uses a combination of idle tasks and background tasks | 41 // The CompilerDispatcher uses a combination of idle tasks and background tasks |
38 // to parse and compile lazily parsed functions. | 42 // to parse and compile lazily parsed functions. |
39 // | 43 // |
40 // As both parsing and compilation currently requires a preparation and | 44 // As both parsing and compilation currently requires a preparation and |
41 // finalization step that happens on the main thread, every task has to be | 45 // finalization step that happens on the main thread, every task has to be |
42 // advanced during idle time first. Depending on the properties of the task, it | 46 // advanced during idle time first. Depending on the properties of the task, it |
(...skipping 18 matching lines...) Expand all Loading... | |
61 // then spins of another idle task to potentially do the final step on the main | 65 // then spins of another idle task to potentially do the final step on the main |
62 // thread. | 66 // thread. |
63 class V8_EXPORT_PRIVATE CompilerDispatcher { | 67 class V8_EXPORT_PRIVATE CompilerDispatcher { |
64 public: | 68 public: |
65 enum class BlockingBehavior { kBlock, kDontBlock }; | 69 enum class BlockingBehavior { kBlock, kDontBlock }; |
66 | 70 |
67 CompilerDispatcher(Isolate* isolate, Platform* platform, | 71 CompilerDispatcher(Isolate* isolate, Platform* platform, |
68 size_t max_stack_size); | 72 size_t max_stack_size); |
69 ~CompilerDispatcher(); | 73 ~CompilerDispatcher(); |
70 | 74 |
71 // Returns true if a job was enqueued. | 75 // Returns true if the compiler dispatcher is enabled. |
76 bool IsEnabled() const; | |
77 | |
78 // Enqueue a job for parse and compile. Returns true if a job was enqueued. | |
72 bool Enqueue(Handle<SharedFunctionInfo> function); | 79 bool Enqueue(Handle<SharedFunctionInfo> function); |
73 | 80 |
81 // Enqueue a job for compilation. Function must have already been parsed and | |
82 // analyzed and be ready for compilation. Takes ownership of |zone|, | |
83 // |parse_info|, |compile_info| and |job|. Returns true if a job was enqueued. | |
84 bool Enqueue(Zone* zone, ParseInfo* parse_info, CompilationInfo* compile_info, | |
jochen (gone - plz use gerrit)
2017/01/10 09:59:47
I wonder whether ParseInfo* and Literal* would be
rmcilroy
2017/01/12 12:31:55
I've refactored this to only need the SFI*, Litera
| |
85 CompilationJob* job); | |
86 | |
74 // Returns true if there is a pending job for the given function. | 87 // Returns true if there is a pending job for the given function. |
75 bool IsEnqueued(Handle<SharedFunctionInfo> function) const; | 88 bool IsEnqueued(Handle<SharedFunctionInfo> function) const; |
76 | 89 |
77 // Blocks until the given function is compiled (and does so as fast as | 90 // Blocks until the given function is compiled (and does so as fast as |
78 // possible). Returns true if the compile job was succesful. | 91 // possible). Returns true if the compile job was successful. |
79 bool FinishNow(Handle<SharedFunctionInfo> function); | 92 bool FinishNow(Handle<SharedFunctionInfo> function); |
80 | 93 |
94 // Blocks until all enqueued jobs have finished. | |
95 void FinishAllNow(); | |
jochen (gone - plz use gerrit)
2017/01/10 09:59:47
just for the record, I don't think we should have
rmcilroy
2017/01/12 12:31:55
Agreed, that's going to be my next CL.
| |
96 | |
81 // Aborts a given job. Blocks if requested. | 97 // Aborts a given job. Blocks if requested. |
82 void Abort(Handle<SharedFunctionInfo> function, BlockingBehavior blocking); | 98 void Abort(Handle<SharedFunctionInfo> function, BlockingBehavior blocking); |
83 | 99 |
84 // Aborts all jobs. Blocks if requested. | 100 // Aborts all jobs. Blocks if requested. |
85 void AbortAll(BlockingBehavior blocking); | 101 void AbortAll(BlockingBehavior blocking); |
86 | 102 |
87 // Memory pressure notifications from the embedder. | 103 // Memory pressure notifications from the embedder. |
88 void MemoryPressureNotification(v8::MemoryPressureLevel level, | 104 void MemoryPressureNotification(v8::MemoryPressureLevel level, |
89 bool is_isolate_locked); | 105 bool is_isolate_locked); |
90 | 106 |
91 private: | 107 private: |
92 FRIEND_TEST(CompilerDispatcherTest, IdleTaskSmallIdleTime); | 108 FRIEND_TEST(CompilerDispatcherTest, IdleTaskSmallIdleTime); |
93 FRIEND_TEST(IgnitionCompilerDispatcherTest, CompileOnBackgroundThread); | 109 FRIEND_TEST(IgnitionCompilerDispatcherTest, CompileOnBackgroundThread); |
94 FRIEND_TEST(IgnitionCompilerDispatcherTest, FinishNowWithBackgroundTask); | 110 FRIEND_TEST(IgnitionCompilerDispatcherTest, FinishNowWithBackgroundTask); |
95 FRIEND_TEST(IgnitionCompilerDispatcherTest, | 111 FRIEND_TEST(IgnitionCompilerDispatcherTest, |
96 AsyncAbortAllPendingBackgroundTask); | 112 AsyncAbortAllPendingBackgroundTask); |
97 FRIEND_TEST(IgnitionCompilerDispatcherTest, | 113 FRIEND_TEST(IgnitionCompilerDispatcherTest, |
98 AsyncAbortAllRunningBackgroundTask); | 114 AsyncAbortAllRunningBackgroundTask); |
99 FRIEND_TEST(IgnitionCompilerDispatcherTest, FinishNowDuringAbortAll); | 115 FRIEND_TEST(IgnitionCompilerDispatcherTest, FinishNowDuringAbortAll); |
100 | 116 |
101 typedef std::multimap<std::pair<int, int>, | 117 typedef std::multimap<std::pair<int, int>, |
102 std::unique_ptr<CompilerDispatcherJob>> | 118 std::unique_ptr<CompilerDispatcherJob>> |
103 JobMap; | 119 JobMap; |
104 class AbortTask; | 120 class AbortTask; |
105 class BackgroundTask; | 121 class BackgroundTask; |
106 class IdleTask; | 122 class IdleTask; |
107 | 123 |
108 void WaitForJobIfRunningOnBackground(CompilerDispatcherJob* job); | 124 void WaitForJobIfRunningOnBackground(CompilerDispatcherJob* job); |
109 bool IsEnabled() const; | |
110 void AbortInactiveJobs(); | 125 void AbortInactiveJobs(); |
126 bool CanEnqueueJobs(); | |
111 JobMap::const_iterator GetJobFor(Handle<SharedFunctionInfo> shared) const; | 127 JobMap::const_iterator GetJobFor(Handle<SharedFunctionInfo> shared) const; |
128 bool FinishNow(CompilerDispatcherJob* job); | |
112 void ConsiderJobForBackgroundProcessing(CompilerDispatcherJob* job); | 129 void ConsiderJobForBackgroundProcessing(CompilerDispatcherJob* job); |
113 void ScheduleMoreBackgroundTasksIfNeeded(); | 130 void ScheduleMoreBackgroundTasksIfNeeded(); |
114 void ScheduleIdleTaskFromAnyThread(); | 131 void ScheduleIdleTaskFromAnyThread(); |
115 void ScheduleIdleTaskIfNeeded(); | 132 void ScheduleIdleTaskIfNeeded(); |
116 void ScheduleAbortTask(); | 133 void ScheduleAbortTask(); |
117 void DoBackgroundWork(); | 134 void DoBackgroundWork(); |
118 void DoIdleWork(double deadline_in_seconds); | 135 void DoIdleWork(double deadline_in_seconds); |
119 | 136 |
120 Isolate* isolate_; | 137 Isolate* isolate_; |
121 Platform* platform_; | 138 Platform* platform_; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
162 base::AtomicValue<bool> block_for_testing_; | 179 base::AtomicValue<bool> block_for_testing_; |
163 base::Semaphore semaphore_for_testing_; | 180 base::Semaphore semaphore_for_testing_; |
164 | 181 |
165 DISALLOW_COPY_AND_ASSIGN(CompilerDispatcher); | 182 DISALLOW_COPY_AND_ASSIGN(CompilerDispatcher); |
166 }; | 183 }; |
167 | 184 |
168 } // namespace internal | 185 } // namespace internal |
169 } // namespace v8 | 186 } // namespace v8 |
170 | 187 |
171 #endif // V8_COMPILER_DISPATCHER_COMPILER_DISPATCHER_H_ | 188 #endif // V8_COMPILER_DISPATCHER_COMPILER_DISPATCHER_H_ |
OLD | NEW |