OLD | NEW |
1 // Copyright 2017 the V8 project authors. All rights reserved. | 1 // Copyright 2017 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_WASM_MODULE_COMPILER_H_ | 5 #ifndef V8_WASM_MODULE_COMPILER_H_ |
6 #define V8_WASM_MODULE_COMPILER_H_ | 6 #define V8_WASM_MODULE_COMPILER_H_ |
7 | 7 |
8 #include <functional> | 8 #include <functional> |
9 | 9 |
10 #include "src/base/atomic-utils.h" | 10 #include "src/base/atomic-utils.h" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 | 52 |
53 private: | 53 private: |
54 size_t GetRandomIndexInSchedule(); | 54 size_t GetRandomIndexInSchedule(); |
55 | 55 |
56 base::RandomNumberGenerator* random_number_generator_ = nullptr; | 56 base::RandomNumberGenerator* random_number_generator_ = nullptr; |
57 std::vector<std::unique_ptr<compiler::WasmCompilationUnit>> schedule_; | 57 std::vector<std::unique_ptr<compiler::WasmCompilationUnit>> schedule_; |
58 }; | 58 }; |
59 | 59 |
60 Isolate* isolate_; | 60 Isolate* isolate_; |
61 std::unique_ptr<WasmModule> module_; | 61 std::unique_ptr<WasmModule> module_; |
62 std::shared_ptr<Counters> counters_shared_; | 62 const std::shared_ptr<Counters> counters_shared_; |
63 Counters* counters_; | |
64 bool is_sync_; | 63 bool is_sync_; |
65 std::vector<std::unique_ptr<compiler::WasmCompilationUnit>> | 64 std::vector<std::unique_ptr<compiler::WasmCompilationUnit>> |
66 compilation_units_; | 65 compilation_units_; |
67 CodeGenerationSchedule executed_units_; | 66 CodeGenerationSchedule executed_units_; |
68 base::Mutex result_mutex_; | 67 base::Mutex result_mutex_; |
69 base::AtomicNumber<size_t> next_unit_; | 68 base::AtomicNumber<size_t> next_unit_; |
70 size_t num_background_tasks_ = 0; | 69 size_t num_background_tasks_ = 0; |
71 // This flag should only be set while holding result_mutex_. | 70 // This flag should only be set while holding result_mutex_. |
72 bool finisher_is_running_ = false; | 71 bool finisher_is_running_ = false; |
73 | 72 |
| 73 Counters* counters() const { return counters_shared_.get(); } |
| 74 |
74 // Run by each compilation task and by the main thread. The | 75 // Run by each compilation task and by the main thread. The |
75 // no_finisher_callback is called within the result_mutex_ lock when no | 76 // no_finisher_callback is called within the result_mutex_ lock when no |
76 // finishing task is running, i.e. when the finisher_is_running_ flag is not | 77 // finishing task is running, i.e. when the finisher_is_running_ flag is not |
77 // set. | 78 // set. |
78 bool FetchAndExecuteCompilationUnit( | 79 bool FetchAndExecuteCompilationUnit( |
79 std::function<void()> no_finisher_callback = [] {}); | 80 std::function<void()> no_finisher_callback = [] {}); |
80 | 81 |
81 size_t InitializeParallelCompilation( | 82 size_t InitializeParallelCompilation( |
82 const std::vector<WasmFunction>& functions, ModuleBytesEnv& module_env); | 83 const std::vector<WasmFunction>& functions, ModuleBytesEnv& module_env); |
83 | 84 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 // Represents the initialized state of a table. | 150 // Represents the initialized state of a table. |
150 struct TableInstance { | 151 struct TableInstance { |
151 Handle<WasmTableObject> table_object; // WebAssembly.Table instance | 152 Handle<WasmTableObject> table_object; // WebAssembly.Table instance |
152 Handle<FixedArray> js_wrappers; // JSFunctions exported | 153 Handle<FixedArray> js_wrappers; // JSFunctions exported |
153 Handle<FixedArray> function_table; // internal code array | 154 Handle<FixedArray> function_table; // internal code array |
154 Handle<FixedArray> signature_table; // internal sig array | 155 Handle<FixedArray> signature_table; // internal sig array |
155 }; | 156 }; |
156 | 157 |
157 Isolate* isolate_; | 158 Isolate* isolate_; |
158 WasmModule* const module_; | 159 WasmModule* const module_; |
159 std::shared_ptr<Counters> counters_shared_; | 160 const std::shared_ptr<Counters> counters_shared_; |
160 Counters* counters_; | |
161 ErrorThrower* thrower_; | 161 ErrorThrower* thrower_; |
162 Handle<WasmModuleObject> module_object_; | 162 Handle<WasmModuleObject> module_object_; |
163 Handle<JSReceiver> ffi_; // TODO(titzer): Use MaybeHandle | 163 Handle<JSReceiver> ffi_; // TODO(titzer): Use MaybeHandle |
164 Handle<JSArrayBuffer> memory_; // TODO(titzer): Use MaybeHandle | 164 Handle<JSArrayBuffer> memory_; // TODO(titzer): Use MaybeHandle |
165 Handle<JSArrayBuffer> globals_; | 165 Handle<JSArrayBuffer> globals_; |
166 Handle<WasmCompiledModule> compiled_module_; | 166 Handle<WasmCompiledModule> compiled_module_; |
167 std::vector<TableInstance> table_instances_; | 167 std::vector<TableInstance> table_instances_; |
168 std::vector<Handle<JSFunction>> js_wrappers_; | 168 std::vector<Handle<JSFunction>> js_wrappers_; |
169 JSToWasmWrapperCache js_to_wasm_cache_; | 169 JSToWasmWrapperCache js_to_wasm_cache_; |
170 WeakCallbackInfo<void>::Callback instance_finalizer_callback_; | 170 WeakCallbackInfo<void>::Callback instance_finalizer_callback_; |
171 | 171 |
| 172 Counters* counters() const { return counters_shared_.get(); } |
| 173 |
172 // Helper routines to print out errors with imports. | 174 // Helper routines to print out errors with imports. |
173 #define ERROR_THROWER_WITH_MESSAGE(TYPE) \ | 175 #define ERROR_THROWER_WITH_MESSAGE(TYPE) \ |
174 void Report##TYPE(const char* error, uint32_t index, \ | 176 void Report##TYPE(const char* error, uint32_t index, \ |
175 Handle<String> module_name, Handle<String> import_name) { \ | 177 Handle<String> module_name, Handle<String> import_name) { \ |
176 thrower_->TYPE("Import #%d module=\"%.*s\" function=\"%.*s\" error: %s", \ | 178 thrower_->TYPE("Import #%d module=\"%.*s\" function=\"%.*s\" error: %s", \ |
177 index, module_name->length(), \ | 179 index, module_name->length(), \ |
178 module_name->ToCString().get(), import_name->length(), \ | 180 module_name->ToCString().get(), import_name->length(), \ |
179 import_name->ToCString().get(), error); \ | 181 import_name->ToCString().get(), error); \ |
180 } \ | 182 } \ |
181 \ | 183 \ |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 explicit AsyncCompileJob(Isolate* isolate, std::unique_ptr<byte[]> bytes_copy, | 255 explicit AsyncCompileJob(Isolate* isolate, std::unique_ptr<byte[]> bytes_copy, |
254 size_t length, Handle<Context> context, | 256 size_t length, Handle<Context> context, |
255 Handle<JSPromise> promise); | 257 Handle<JSPromise> promise); |
256 | 258 |
257 void Start(); | 259 void Start(); |
258 | 260 |
259 ~AsyncCompileJob(); | 261 ~AsyncCompileJob(); |
260 | 262 |
261 private: | 263 private: |
262 Isolate* isolate_; | 264 Isolate* isolate_; |
263 std::shared_ptr<Counters> counters_shared_; | 265 const std::shared_ptr<Counters> counters_shared_; |
264 Counters* counters_; | |
265 std::unique_ptr<byte[]> bytes_copy_; | 266 std::unique_ptr<byte[]> bytes_copy_; |
266 ModuleWireBytes wire_bytes_; | 267 ModuleWireBytes wire_bytes_; |
267 Handle<Context> context_; | 268 Handle<Context> context_; |
268 Handle<JSPromise> module_promise_; | 269 Handle<JSPromise> module_promise_; |
269 std::unique_ptr<ModuleCompiler> compiler_; | 270 std::unique_ptr<ModuleCompiler> compiler_; |
270 std::unique_ptr<ModuleBytesEnv> module_bytes_env_; | 271 std::unique_ptr<ModuleBytesEnv> module_bytes_env_; |
271 | 272 |
272 bool failed_ = false; | 273 bool failed_ = false; |
273 std::vector<DeferredHandles*> deferred_handles_; | 274 std::vector<DeferredHandles*> deferred_handles_; |
274 Handle<WasmModuleObject> module_object_; | 275 Handle<WasmModuleObject> module_object_; |
275 Handle<FixedArray> function_tables_; | 276 Handle<FixedArray> function_tables_; |
276 Handle<FixedArray> signature_tables_; | 277 Handle<FixedArray> signature_tables_; |
277 Handle<WasmCompiledModule> compiled_module_; | 278 Handle<WasmCompiledModule> compiled_module_; |
278 Handle<FixedArray> code_table_; | 279 Handle<FixedArray> code_table_; |
279 std::unique_ptr<WasmInstance> temp_instance_ = nullptr; | 280 std::unique_ptr<WasmInstance> temp_instance_ = nullptr; |
280 size_t outstanding_units_ = 0; | 281 size_t outstanding_units_ = 0; |
281 size_t num_background_tasks_ = 0; | 282 size_t num_background_tasks_ = 0; |
282 | 283 |
| 284 Counters* counters() const { return counters_shared_.get(); } |
| 285 |
283 void ReopenHandlesInDeferredScope(); | 286 void ReopenHandlesInDeferredScope(); |
284 | 287 |
285 void AsyncCompileFailed(ErrorThrower& thrower); | 288 void AsyncCompileFailed(ErrorThrower& thrower); |
286 | 289 |
287 void AsyncCompileSucceeded(Handle<Object> result); | 290 void AsyncCompileSucceeded(Handle<Object> result); |
288 | 291 |
289 template <typename Task, typename... Args> | 292 template <typename Task, typename... Args> |
290 void DoSync(Args&&... args); | 293 void DoSync(Args&&... args); |
291 | 294 |
292 template <typename Task, typename... Args> | 295 template <typename Task, typename... Args> |
(...skipping 12 matching lines...) Expand all Loading... |
305 class FinishCompile; | 308 class FinishCompile; |
306 class CompileWrappers; | 309 class CompileWrappers; |
307 class FinishModule; | 310 class FinishModule; |
308 }; | 311 }; |
309 | 312 |
310 } // namespace wasm | 313 } // namespace wasm |
311 } // namespace internal | 314 } // namespace internal |
312 } // namespace v8 | 315 } // namespace v8 |
313 | 316 |
314 #endif // V8_WASM_MODULE_COMPILER_H_ | 317 #endif // V8_WASM_MODULE_COMPILER_H_ |
OLD | NEW |