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_TEST_INSPECTOR_PROTOCOL_TASK_RUNNER_H_ | 5 #ifndef V8_TEST_INSPECTOR_PROTOCOL_TASK_RUNNER_H_ |
6 #define V8_TEST_INSPECTOR_PROTOCOL_TASK_RUNNER_H_ | 6 #define V8_TEST_INSPECTOR_PROTOCOL_TASK_RUNNER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "include/v8-inspector.h" | 10 #include "include/v8-inspector.h" |
11 #include "include/v8-platform.h" | 11 #include "include/v8-platform.h" |
12 #include "include/v8.h" | 12 #include "include/v8.h" |
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/platform.h" | 15 #include "src/base/platform/platform.h" |
16 #include "src/locked-queue-inl.h" | 16 #include "src/locked-queue-inl.h" |
17 #include "src/vector.h" | 17 #include "src/vector.h" |
18 #include "test/inspector/isolate-data.h" | 18 #include "test/inspector/isolate-data.h" |
19 | 19 |
20 class TaskRunner : public v8::base::Thread { | 20 class TaskRunner : public v8::base::Thread { |
21 public: | 21 public: |
22 class Task { | 22 class Task { |
23 public: | 23 public: |
24 virtual ~Task() {} | 24 virtual ~Task() {} |
25 virtual bool is_inspector_task() = 0; | 25 virtual bool is_priority_task() = 0; |
26 void RunOnIsolate(IsolateData* data) { | 26 virtual void Run(IsolateData* data) = 0; |
27 data_ = data; | |
28 Run(); | |
29 data_ = nullptr; | |
30 } | |
31 | |
32 protected: | |
33 virtual void Run() = 0; | |
34 v8::Isolate* isolate() const { return data_->isolate(); } | |
35 IsolateData* data() const { return data_; } | |
36 | |
37 private: | |
38 IsolateData* data_ = nullptr; | |
39 }; | 27 }; |
40 | 28 |
41 TaskRunner(IsolateData::SetupGlobalTasks setup_global_tasks, | 29 TaskRunner(IsolateData::SetupGlobalTasks setup_global_tasks, |
42 bool catch_exceptions, v8::base::Semaphore* ready_semaphore, | 30 bool catch_exceptions, v8::base::Semaphore* ready_semaphore, |
43 v8::StartupData* startup_data, | 31 v8::StartupData* startup_data, bool with_inspector); |
44 IsolateData::FrontendChannel* channel); | |
45 virtual ~TaskRunner(); | 32 virtual ~TaskRunner(); |
46 IsolateData* data() const { return data_.get(); } | 33 IsolateData* data() const { return data_.get(); } |
47 | 34 |
48 // Thread implementation. | 35 // Thread implementation. |
49 void Run() override; | 36 void Run() override; |
50 | 37 |
51 // Should be called from the same thread and only from task. | 38 // Should be called from the same thread and only from task. |
52 void RunMessageLoop(bool only_protocol); | 39 void RunMessageLoop(bool only_protocol); |
53 void QuitMessageLoop(); | 40 void QuitMessageLoop(); |
54 | 41 |
55 // TaskRunner takes ownership. | 42 // TaskRunner takes ownership. |
56 void Append(Task* task); | 43 void Append(Task* task); |
57 | 44 |
58 void Terminate(); | 45 void Terminate(); |
59 | 46 |
60 private: | 47 private: |
61 Task* GetNext(bool only_protocol); | 48 Task* GetNext(bool only_protocol); |
62 v8::Isolate* isolate() const { return data_->isolate(); } | 49 v8::Isolate* isolate() const { return data_->isolate(); } |
63 | 50 |
64 IsolateData::SetupGlobalTasks setup_global_tasks_; | 51 IsolateData::SetupGlobalTasks setup_global_tasks_; |
65 v8::StartupData* startup_data_; | 52 v8::StartupData* startup_data_; |
66 IsolateData::FrontendChannel* channel_; | 53 bool with_inspector_; |
67 bool catch_exceptions_; | 54 bool catch_exceptions_; |
68 v8::base::Semaphore* ready_semaphore_; | 55 v8::base::Semaphore* ready_semaphore_; |
69 std::unique_ptr<IsolateData> data_; | 56 std::unique_ptr<IsolateData> data_; |
70 | 57 |
71 // deferred_queue_ combined with queue_ (in this order) have all tasks in the | 58 // deferred_queue_ combined with queue_ (in this order) have all tasks in the |
72 // correct order. Sometimes we skip non-protocol tasks by moving them from | 59 // correct order. Sometimes we skip non-protocol tasks by moving them from |
73 // queue_ to deferred_queue_. | 60 // queue_ to deferred_queue_. |
74 v8::internal::LockedQueue<Task*> queue_; | 61 v8::internal::LockedQueue<Task*> queue_; |
75 v8::internal::LockedQueue<Task*> deffered_queue_; | 62 v8::internal::LockedQueue<Task*> deffered_queue_; |
76 v8::base::Semaphore process_queue_semaphore_; | 63 v8::base::Semaphore process_queue_semaphore_; |
77 | 64 |
78 int nested_loop_count_; | 65 int nested_loop_count_; |
79 | 66 |
80 v8::base::AtomicNumber<int> is_terminated_; | 67 v8::base::AtomicNumber<int> is_terminated_; |
81 | 68 |
82 DISALLOW_COPY_AND_ASSIGN(TaskRunner); | 69 DISALLOW_COPY_AND_ASSIGN(TaskRunner); |
83 }; | 70 }; |
84 | 71 |
85 class AsyncTask : public TaskRunner::Task { | |
86 public: | |
87 AsyncTask(IsolateData* data, const char* task_name); | |
88 virtual ~AsyncTask() = default; | |
89 | |
90 protected: | |
91 virtual void AsyncRun() = 0; | |
92 void Run() override; | |
93 | |
94 bool instrumenting_; | |
95 }; | |
96 | |
97 class ExecuteStringTask : public AsyncTask { | |
98 public: | |
99 ExecuteStringTask(IsolateData* data, int context_group_id, | |
100 const char* task_name, | |
101 const v8::internal::Vector<uint16_t>& expression, | |
102 v8::Local<v8::String> name, | |
103 v8::Local<v8::Integer> line_offset, | |
104 v8::Local<v8::Integer> column_offset, | |
105 v8::Local<v8::Boolean> is_module); | |
106 ExecuteStringTask(const v8::internal::Vector<const char>& expression, | |
107 int context_group_id); | |
108 bool is_inspector_task() override { return false; } | |
109 | |
110 private: | |
111 void AsyncRun() override; | |
112 | |
113 v8::internal::Vector<uint16_t> expression_; | |
114 v8::internal::Vector<const char> expression_utf8_; | |
115 v8::internal::Vector<uint16_t> name_; | |
116 int32_t line_offset_ = 0; | |
117 int32_t column_offset_ = 0; | |
118 bool is_module_ = false; | |
119 int context_group_id_; | |
120 | |
121 DISALLOW_COPY_AND_ASSIGN(ExecuteStringTask); | |
122 }; | |
123 | |
124 #endif // V8_TEST_INSPECTOR_PROTOCOL_TASK_RUNNER_H_ | 72 #endif // V8_TEST_INSPECTOR_PROTOCOL_TASK_RUNNER_H_ |
OLD | NEW |