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 <functional> | |
8 #include <map> | 9 #include <map> |
9 #include <memory> | 10 #include <memory> |
11 #include <unordered_set> | |
10 #include <utility> | 12 #include <utility> |
11 | 13 |
14 #include "src/base/functional.h" | |
12 #include "src/base/macros.h" | 15 #include "src/base/macros.h" |
13 #include "src/globals.h" | 16 #include "src/globals.h" |
17 #include "testing/gtest/include/gtest/gtest_prod.h" | |
14 | 18 |
15 namespace v8 { | 19 namespace v8 { |
20 | |
21 class Platform; | |
22 | |
16 namespace internal { | 23 namespace internal { |
17 | 24 |
18 class CompilerDispatcherJob; | 25 class CompilerDispatcherJob; |
19 class CompilerDispatcherTracer; | 26 class CompilerDispatcherTracer; |
20 class Isolate; | 27 class Isolate; |
21 class SharedFunctionInfo; | 28 class SharedFunctionInfo; |
22 | 29 |
23 template <typename T> | 30 template <typename T> |
24 class Handle; | 31 class Handle; |
25 | 32 |
26 class V8_EXPORT_PRIVATE CompilerDispatcher { | 33 class V8_EXPORT_PRIVATE CompilerDispatcher { |
27 public: | 34 public: |
28 enum class BlockingBehavior { kBlock, kDontBlock }; | 35 enum class BlockingBehavior { kBlock, kDontBlock }; |
29 | 36 |
30 CompilerDispatcher(Isolate* isolate, size_t max_stack_size); | 37 CompilerDispatcher(Isolate* isolate, Platform* platform, |
38 size_t max_stack_size); | |
31 ~CompilerDispatcher(); | 39 ~CompilerDispatcher(); |
32 | 40 |
33 // Returns true if a job was enqueued. | 41 // Returns true if a job was enqueued. |
34 bool Enqueue(Handle<SharedFunctionInfo> function); | 42 bool Enqueue(Handle<SharedFunctionInfo> function); |
35 | 43 |
36 // Returns true if there is a pending job for the given function. | 44 // Returns true if there is a pending job for the given function. |
37 bool IsEnqueued(Handle<SharedFunctionInfo> function) const; | 45 bool IsEnqueued(Handle<SharedFunctionInfo> function) const; |
38 | 46 |
39 // Blocks until the given function is compiled (and does so as fast as | 47 // Blocks until the given function is compiled (and does so as fast as |
40 // possible). Returns true if the compile job was succesful. | 48 // possible). Returns true if the compile job was succesful. |
41 bool FinishNow(Handle<SharedFunctionInfo> function); | 49 bool FinishNow(Handle<SharedFunctionInfo> function); |
42 | 50 |
43 // Aborts a given job. Blocks if requested. | 51 // Aborts a given job. Blocks if requested. |
44 void Abort(Handle<SharedFunctionInfo> function, BlockingBehavior blocking); | 52 void Abort(Handle<SharedFunctionInfo> function, BlockingBehavior blocking); |
45 | 53 |
46 // Aborts all jobs. Blocks if requested. | 54 // Aborts all jobs. Blocks if requested. |
47 void AbortAll(BlockingBehavior blocking); | 55 void AbortAll(BlockingBehavior blocking); |
48 | 56 |
49 private: | 57 private: |
58 FRIEND_TEST(CompilerDispatcherTest, IdleTaskSmallIdleTime); | |
59 | |
50 typedef std::multimap<std::pair<int, int>, | 60 typedef std::multimap<std::pair<int, int>, |
51 std::unique_ptr<CompilerDispatcherJob>> | 61 std::unique_ptr<CompilerDispatcherJob>> |
vogelheim
2016/12/15 15:24:12
nitpick: Maybe typedef std::unordered_set<JobMap::
jochen (gone - plz use gerrit)
2016/12/15 15:37:59
done
| |
52 JobMap; | 62 JobMap; |
63 class IdleTask; | |
64 struct JobIteratorHash { | |
65 public: | |
66 size_t operator()(const JobMap::const_iterator& it) const { | |
67 std::hash<int> hasher; | |
vogelheim
2016/12/15 15:24:12
Why std::hash<int>, and not v8::base::hash<int>?
jochen (gone - plz use gerrit)
2016/12/15 15:37:59
no reason, fixed
| |
68 return base::hash_combine(hasher(it->first.first), | |
69 hasher(it->first.second)); | |
70 } | |
71 }; | |
72 | |
53 JobMap::const_iterator GetJobFor(Handle<SharedFunctionInfo> shared) const; | 73 JobMap::const_iterator GetJobFor(Handle<SharedFunctionInfo> shared) const; |
74 void ScheduleIdleTaskIfNeeded(); | |
75 void DoIdleWork(double deadline_in_seconds); | |
76 void DoIdleWorkForJobSet( | |
77 double deadline_in_seconds, | |
78 std::unordered_set<JobMap::const_iterator, JobIteratorHash>* job_set); | |
79 void ClassifyJob(JobMap::const_iterator it); | |
54 | 80 |
55 Isolate* isolate_; | 81 Isolate* isolate_; |
82 Platform* platform_; | |
56 size_t max_stack_size_; | 83 size_t max_stack_size_; |
57 std::unique_ptr<CompilerDispatcherTracer> tracer_; | 84 std::unique_ptr<CompilerDispatcherTracer> tracer_; |
58 | 85 |
86 bool idle_task_scheduled_; | |
87 | |
59 // Mapping from (script id, function literal id) to job. We use a multimap, | 88 // Mapping from (script id, function literal id) to job. We use a multimap, |
60 // as script id is not necessarily unique. | 89 // as script id is not necessarily unique. |
61 JobMap jobs_; | 90 JobMap jobs_; |
62 | 91 |
92 std::unordered_set<JobMap::const_iterator, JobIteratorHash> | |
93 jobs_for_main_thread_; | |
94 std::unordered_set<JobMap::const_iterator, JobIteratorHash> | |
95 jobs_for_background_thread_; | |
96 | |
63 DISALLOW_COPY_AND_ASSIGN(CompilerDispatcher); | 97 DISALLOW_COPY_AND_ASSIGN(CompilerDispatcher); |
64 }; | 98 }; |
65 | 99 |
66 } // namespace internal | 100 } // namespace internal |
67 } // namespace v8 | 101 } // namespace v8 |
68 | 102 |
69 #endif // V8_COMPILER_DISPATCHER_COMPILER_DISPATCHER_H_ | 103 #endif // V8_COMPILER_DISPATCHER_COMPILER_DISPATCHER_H_ |
OLD | NEW |