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