5 #ifndef V8_COMPILER_DISPATCHER_COMPILER_DISPATCHER_H_ 6 #define V8_COMPILER_DISPATCHER_COMPILER_DISPATCHER_H_ 11 #include <unordered_set> 14 #include "src/base/atomic-utils.h" 15 #include "src/base/macros.h" 16 #include "src/base/optional.h" 17 #include "src/base/platform/condition-variable.h" 18 #include "src/base/platform/mutex.h" 19 #include "src/base/platform/semaphore.h" 20 #include "src/globals.h" 21 #include "src/identity-map.h" 22 #include "src/maybe-handles.h" 23 #include "testing/gtest/include/gtest/gtest_prod.h" 28 enum class MemoryPressureLevel;
33 class AstValueFactory;
34 class BackgroundCompileTask;
35 class CancelableTaskManager;
36 class UnoptimizedCompileJob;
37 class CompilerDispatcherTracer;
38 class DeferredHandles;
39 class FunctionLiteral;
42 class SharedFunctionInfo;
44 class WorkerThreadRuntimeCallStats;
81 size_t max_stack_size);
85 bool IsEnabled()
const;
95 bool IsEnqueued(
JobId job_id)
const;
105 void AbortJob(
JobId job_id);
111 FRIEND_TEST(CompilerDispatcherTest, IdleTaskNoIdleTime);
112 FRIEND_TEST(CompilerDispatcherTest, IdleTaskSmallIdleTime);
113 FRIEND_TEST(CompilerDispatcherTest, FinishNowWithWorkerTask);
114 FRIEND_TEST(CompilerDispatcherTest, AbortJobNotStarted);
115 FRIEND_TEST(CompilerDispatcherTest, AbortJobAlreadyStarted);
116 FRIEND_TEST(CompilerDispatcherTest, AsyncAbortAllPendingWorkerTask);
117 FRIEND_TEST(CompilerDispatcherTest, AsyncAbortAllRunningWorkerTask);
118 FRIEND_TEST(CompilerDispatcherTest, CompileMultipleOnBackgroundThread);
124 bool IsReadyToFinalize(
const base::MutexGuard&) {
125 return has_run && (!
function.is_null() || aborted);
129 base::MutexGuard lock(mutex);
130 return IsReadyToFinalize(lock);
133 std::unique_ptr<BackgroundCompileTask> task;
139 typedef std::map<JobId, std::unique_ptr<Job>> JobMap;
142 void WaitForJobIfRunningOnBackground(Job* job);
144 void ScheduleMoreWorkerTasksIfNeeded();
145 void ScheduleIdleTaskFromAnyThread(
const base::MutexGuard&);
146 void DoBackgroundWork();
147 void DoIdleWork(
double deadline_in_seconds);
149 JobMap::const_iterator InsertJob(std::unique_ptr<Job> job);
151 JobMap::const_iterator RemoveJob(JobMap::const_iterator job);
157 std::shared_ptr<v8::TaskRunner> taskrunner_;
159 size_t max_stack_size_;
162 bool trace_compiler_dispatcher_;
164 std::unique_ptr<CancelableTaskManager> task_manager_;
181 bool idle_task_scheduled_;
184 int num_worker_tasks_;
187 std::unordered_set<Job*> pending_background_jobs_;
190 std::unordered_set<Job*> running_background_jobs_;
194 Job* main_thread_blocking_on_job_;
207 #endif // V8_COMPILER_DISPATCHER_COMPILER_DISPATCHER_H_