| 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 <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "src/base/macros.h" | 12 #include "src/base/macros.h" |
| 13 #include "src/globals.h" | 13 #include "src/globals.h" |
| 14 | 14 |
| 15 namespace v8 { | 15 namespace v8 { |
| 16 |
| 17 class Platform; |
| 18 |
| 16 namespace internal { | 19 namespace internal { |
| 17 | 20 |
| 18 class CompilerDispatcherJob; | 21 class CompilerDispatcherJob; |
| 19 class CompilerDispatcherTracer; | 22 class CompilerDispatcherTracer; |
| 20 class Isolate; | 23 class Isolate; |
| 21 class SharedFunctionInfo; | 24 class SharedFunctionInfo; |
| 22 | 25 |
| 23 template <typename T> | 26 template <typename T> |
| 24 class Handle; | 27 class Handle; |
| 25 | 28 |
| 26 class V8_EXPORT_PRIVATE CompilerDispatcher { | 29 class V8_EXPORT_PRIVATE CompilerDispatcher { |
| 27 public: | 30 public: |
| 28 enum class BlockingBehavior { kBlock, kDontBlock }; | 31 enum class BlockingBehavior { kBlock, kDontBlock }; |
| 29 | 32 |
| 30 CompilerDispatcher(Isolate* isolate, size_t max_stack_size); | 33 CompilerDispatcher(Isolate* isolate, Platform* platform, |
| 34 size_t max_stack_size); |
| 31 ~CompilerDispatcher(); | 35 ~CompilerDispatcher(); |
| 32 | 36 |
| 33 // Returns true if a job was enqueued. | 37 // Returns true if a job was enqueued. |
| 34 bool Enqueue(Handle<SharedFunctionInfo> function); | 38 bool Enqueue(Handle<SharedFunctionInfo> function); |
| 35 | 39 |
| 36 // Returns true if there is a pending job for the given function. | 40 // Returns true if there is a pending job for the given function. |
| 37 bool IsEnqueued(Handle<SharedFunctionInfo> function) const; | 41 bool IsEnqueued(Handle<SharedFunctionInfo> function) const; |
| 38 | 42 |
| 39 // Blocks until the given function is compiled (and does so as fast as | 43 // Blocks until the given function is compiled (and does so as fast as |
| 40 // possible). Returns true if the compile job was succesful. | 44 // possible). Returns true if the compile job was succesful. |
| 41 bool FinishNow(Handle<SharedFunctionInfo> function); | 45 bool FinishNow(Handle<SharedFunctionInfo> function); |
| 42 | 46 |
| 43 // Aborts a given job. Blocks if requested. | 47 // Aborts a given job. Blocks if requested. |
| 44 void Abort(Handle<SharedFunctionInfo> function, BlockingBehavior blocking); | 48 void Abort(Handle<SharedFunctionInfo> function, BlockingBehavior blocking); |
| 45 | 49 |
| 46 // Aborts all jobs. Blocks if requested. | 50 // Aborts all jobs. Blocks if requested. |
| 47 void AbortAll(BlockingBehavior blocking); | 51 void AbortAll(BlockingBehavior blocking); |
| 48 | 52 |
| 49 private: | 53 private: |
| 50 typedef std::multimap<std::pair<int, int>, | 54 typedef std::multimap<std::pair<int, int>, |
| 51 std::unique_ptr<CompilerDispatcherJob>> | 55 std::unique_ptr<CompilerDispatcherJob>> |
| 52 JobMap; | 56 JobMap; |
| 57 class IdleTask; |
| 58 |
| 53 JobMap::const_iterator GetJobFor(Handle<SharedFunctionInfo> shared) const; | 59 JobMap::const_iterator GetJobFor(Handle<SharedFunctionInfo> shared) const; |
| 60 void ScheduleIdleTaskIfNeeded(); |
| 61 void DoIdleWork(double deadline_in_seconds); |
| 54 | 62 |
| 55 Isolate* isolate_; | 63 Isolate* isolate_; |
| 64 Platform* platform_; |
| 56 size_t max_stack_size_; | 65 size_t max_stack_size_; |
| 57 std::unique_ptr<CompilerDispatcherTracer> tracer_; | 66 std::unique_ptr<CompilerDispatcherTracer> tracer_; |
| 58 | 67 |
| 68 bool idle_task_scheduled_; |
| 69 |
| 59 // Mapping from (script id, function literal id) to job. We use a multimap, | 70 // Mapping from (script id, function literal id) to job. We use a multimap, |
| 60 // as script id is not necessarily unique. | 71 // as script id is not necessarily unique. |
| 61 JobMap jobs_; | 72 JobMap jobs_; |
| 62 | 73 |
| 63 DISALLOW_COPY_AND_ASSIGN(CompilerDispatcher); | 74 DISALLOW_COPY_AND_ASSIGN(CompilerDispatcher); |
| 64 }; | 75 }; |
| 65 | 76 |
| 66 } // namespace internal | 77 } // namespace internal |
| 67 } // namespace v8 | 78 } // namespace v8 |
| 68 | 79 |
| 69 #endif // V8_COMPILER_DISPATCHER_COMPILER_DISPATCHER_H_ | 80 #endif // V8_COMPILER_DISPATCHER_COMPILER_DISPATCHER_H_ |
| OLD | NEW |