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 FunctionLiteral; | |
32 class Isolate; | 31 class Isolate; |
33 class SharedFunctionInfo; | 32 class SharedFunctionInfo; |
34 | 33 |
35 template <typename T> | 34 template <typename T> |
36 class Handle; | 35 class Handle; |
37 | 36 |
38 // The CompilerDispatcher uses a combination of idle tasks and background tasks | 37 // The CompilerDispatcher uses a combination of idle tasks and background tasks |
39 // to parse and compile lazily parsed functions. | 38 // to parse and compile lazily parsed functions. |
40 // | 39 // |
41 // As both parsing and compilation currently requires a preparation and | 40 // As both parsing and compilation currently requires a preparation and |
(...skipping 20 matching lines...) Expand all Loading... |
62 // then spins of another idle task to potentially do the final step on the main | 61 // then spins of another idle task to potentially do the final step on the main |
63 // thread. | 62 // thread. |
64 class V8_EXPORT_PRIVATE CompilerDispatcher { | 63 class V8_EXPORT_PRIVATE CompilerDispatcher { |
65 public: | 64 public: |
66 enum class BlockingBehavior { kBlock, kDontBlock }; | 65 enum class BlockingBehavior { kBlock, kDontBlock }; |
67 | 66 |
68 CompilerDispatcher(Isolate* isolate, Platform* platform, | 67 CompilerDispatcher(Isolate* isolate, Platform* platform, |
69 size_t max_stack_size); | 68 size_t max_stack_size); |
70 ~CompilerDispatcher(); | 69 ~CompilerDispatcher(); |
71 | 70 |
72 // Returns true if the compiler dispatcher is enabled. | 71 // Returns true if a job was enqueued. |
73 bool IsEnabled() const; | |
74 | |
75 // Enqueue a job for parse and compile. Returns true if a job was enqueued. | |
76 bool Enqueue(Handle<SharedFunctionInfo> function); | 72 bool Enqueue(Handle<SharedFunctionInfo> function); |
77 | 73 |
78 // Like Enqueue, but also advances the job so that it can potentially | 74 // Like Enqueue, but also advances the job so that it can potentially |
79 // continue running on a background thread (if at all possible). Returns | 75 // continue running on a background thread (if at all possible). Returns |
80 // true if the job was enqueued. | 76 // true if the job was enqueued. |
81 bool EnqueueAndStep(Handle<SharedFunctionInfo> function); | 77 bool EnqueueAndStep(Handle<SharedFunctionInfo> function); |
82 | 78 |
83 // Enqueue a job for compilation. Function must have already been parsed and | |
84 // analyzed and be ready for compilation. Returns true if a job was enqueued. | |
85 bool Enqueue(Handle<SharedFunctionInfo> function, FunctionLiteral* literal); | |
86 | |
87 // Like Enqueue, but also advances the job so that it can potentially | |
88 // continue running on a background thread (if at all possible). Returns | |
89 // true if the job was enqueued. | |
90 bool EnqueueAndStep(Handle<SharedFunctionInfo> function, | |
91 FunctionLiteral* literal); | |
92 | |
93 // Returns true if there is a pending job for the given function. | 79 // Returns true if there is a pending job for the given function. |
94 bool IsEnqueued(Handle<SharedFunctionInfo> function) const; | 80 bool IsEnqueued(Handle<SharedFunctionInfo> function) const; |
95 | 81 |
96 // Blocks until the given function is compiled (and does so as fast as | 82 // Blocks until the given function is compiled (and does so as fast as |
97 // possible). Returns true if the compile job was successful. | 83 // possible). Returns true if the compile job was succesful. |
98 bool FinishNow(Handle<SharedFunctionInfo> function); | 84 bool FinishNow(Handle<SharedFunctionInfo> function); |
99 | 85 |
100 // Blocks until all enqueued jobs have finished. Returns true if all the | |
101 // compile jobs were successful. | |
102 bool FinishAllNow(); | |
103 | |
104 // Aborts a given job. Blocks if requested. | 86 // Aborts a given job. Blocks if requested. |
105 void Abort(Handle<SharedFunctionInfo> function, BlockingBehavior blocking); | 87 void Abort(Handle<SharedFunctionInfo> function, BlockingBehavior blocking); |
106 | 88 |
107 // Aborts all jobs. Blocks if requested. | 89 // Aborts all jobs. Blocks if requested. |
108 void AbortAll(BlockingBehavior blocking); | 90 void AbortAll(BlockingBehavior blocking); |
109 | 91 |
110 // Memory pressure notifications from the embedder. | 92 // Memory pressure notifications from the embedder. |
111 void MemoryPressureNotification(v8::MemoryPressureLevel level, | 93 void MemoryPressureNotification(v8::MemoryPressureLevel level, |
112 bool is_isolate_locked); | 94 bool is_isolate_locked); |
113 | 95 |
114 private: | 96 private: |
115 FRIEND_TEST(CompilerDispatcherTest, EnqueueAndStep); | 97 FRIEND_TEST(CompilerDispatcherTest, EnqueueAndStep); |
116 FRIEND_TEST(CompilerDispatcherTest, EnqueueParsed); | |
117 FRIEND_TEST(CompilerDispatcherTest, EnqueueAndStepParsed); | |
118 FRIEND_TEST(CompilerDispatcherTest, IdleTaskSmallIdleTime); | 98 FRIEND_TEST(CompilerDispatcherTest, IdleTaskSmallIdleTime); |
119 FRIEND_TEST(CompilerDispatcherTest, CompileOnBackgroundThread); | 99 FRIEND_TEST(CompilerDispatcherTest, CompileOnBackgroundThread); |
120 FRIEND_TEST(CompilerDispatcherTest, FinishNowWithBackgroundTask); | 100 FRIEND_TEST(CompilerDispatcherTest, FinishNowWithBackgroundTask); |
121 FRIEND_TEST(CompilerDispatcherTest, AsyncAbortAllPendingBackgroundTask); | 101 FRIEND_TEST(CompilerDispatcherTest, AsyncAbortAllPendingBackgroundTask); |
122 FRIEND_TEST(CompilerDispatcherTest, AsyncAbortAllRunningBackgroundTask); | 102 FRIEND_TEST(CompilerDispatcherTest, AsyncAbortAllRunningBackgroundTask); |
123 FRIEND_TEST(CompilerDispatcherTest, FinishNowDuringAbortAll); | 103 FRIEND_TEST(CompilerDispatcherTest, FinishNowDuringAbortAll); |
124 | 104 |
125 typedef std::multimap<std::pair<int, int>, | 105 typedef std::multimap<std::pair<int, int>, |
126 std::unique_ptr<CompilerDispatcherJob>> | 106 std::unique_ptr<CompilerDispatcherJob>> |
127 JobMap; | 107 JobMap; |
128 class AbortTask; | 108 class AbortTask; |
129 class BackgroundTask; | 109 class BackgroundTask; |
130 class IdleTask; | 110 class IdleTask; |
131 | 111 |
132 void WaitForJobIfRunningOnBackground(CompilerDispatcherJob* job); | 112 void WaitForJobIfRunningOnBackground(CompilerDispatcherJob* job); |
| 113 bool IsEnabled() const; |
133 void AbortInactiveJobs(); | 114 void AbortInactiveJobs(); |
134 bool CanEnqueue(Handle<SharedFunctionInfo> function); | |
135 JobMap::const_iterator GetJobFor(Handle<SharedFunctionInfo> shared) const; | 115 JobMap::const_iterator GetJobFor(Handle<SharedFunctionInfo> shared) const; |
136 bool FinishNow(CompilerDispatcherJob* job); | |
137 void ConsiderJobForBackgroundProcessing(CompilerDispatcherJob* job); | 116 void ConsiderJobForBackgroundProcessing(CompilerDispatcherJob* job); |
138 void ScheduleMoreBackgroundTasksIfNeeded(); | 117 void ScheduleMoreBackgroundTasksIfNeeded(); |
139 void ScheduleIdleTaskFromAnyThread(); | 118 void ScheduleIdleTaskFromAnyThread(); |
140 void ScheduleIdleTaskIfNeeded(); | 119 void ScheduleIdleTaskIfNeeded(); |
141 void ScheduleAbortTask(); | 120 void ScheduleAbortTask(); |
142 void DoBackgroundWork(); | 121 void DoBackgroundWork(); |
143 void DoIdleWork(double deadline_in_seconds); | 122 void DoIdleWork(double deadline_in_seconds); |
144 | 123 |
145 Isolate* isolate_; | 124 Isolate* isolate_; |
146 Platform* platform_; | 125 Platform* platform_; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 base::AtomicValue<bool> block_for_testing_; | 166 base::AtomicValue<bool> block_for_testing_; |
188 base::Semaphore semaphore_for_testing_; | 167 base::Semaphore semaphore_for_testing_; |
189 | 168 |
190 DISALLOW_COPY_AND_ASSIGN(CompilerDispatcher); | 169 DISALLOW_COPY_AND_ASSIGN(CompilerDispatcher); |
191 }; | 170 }; |
192 | 171 |
193 } // namespace internal | 172 } // namespace internal |
194 } // namespace v8 | 173 } // namespace v8 |
195 | 174 |
196 #endif // V8_COMPILER_DISPATCHER_COMPILER_DISPATCHER_H_ | 175 #endif // V8_COMPILER_DISPATCHER_COMPILER_DISPATCHER_H_ |
OLD | NEW |