Chromium Code Reviews| 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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 62 | 62 |
| 63 base::RandomNumberGenerator* random_number_generator_ = nullptr; | 63 base::RandomNumberGenerator* random_number_generator_ = nullptr; |
| 64 std::vector<std::unique_ptr<compiler::WasmCompilationUnit>> schedule_; | 64 std::vector<std::unique_ptr<compiler::WasmCompilationUnit>> schedule_; |
| 65 const size_t max_memory_; | 65 const size_t max_memory_; |
| 66 bool throttle_ = false; | 66 bool throttle_ = false; |
| 67 base::AtomicNumber<size_t> allocated_memory_{0}; | 67 base::AtomicNumber<size_t> allocated_memory_{0}; |
| 68 }; | 68 }; |
| 69 | 69 |
| 70 Isolate* isolate_; | 70 Isolate* isolate_; |
| 71 std::unique_ptr<WasmModule> module_; | 71 std::unique_ptr<WasmModule> module_; |
| 72 std::shared_ptr<Counters> counters_shared_; | 72 const std::shared_ptr<Counters> counters_shared_; |
| 73 Counters* counters_; | |
| 74 bool is_sync_; | 73 bool is_sync_; |
| 75 std::vector<std::unique_ptr<compiler::WasmCompilationUnit>> | 74 std::vector<std::unique_ptr<compiler::WasmCompilationUnit>> |
| 76 compilation_units_; | 75 compilation_units_; |
| 77 CodeGenerationSchedule executed_units_; | 76 CodeGenerationSchedule executed_units_; |
| 78 base::Mutex result_mutex_; | 77 base::Mutex result_mutex_; |
| 79 base::AtomicNumber<size_t> next_unit_; | 78 base::AtomicNumber<size_t> next_unit_; |
| 80 const size_t num_background_tasks_; | 79 const size_t num_background_tasks_; |
| 81 // This flag should only be set while holding result_mutex_. | 80 // This flag should only be set while holding result_mutex_. |
| 82 bool finisher_is_running_ = false; | 81 bool finisher_is_running_ = false; |
| 83 CancelableTaskManager background_task_manager_; | 82 CancelableTaskManager background_task_manager_; |
| 84 | 83 |
| 84 Counters* counters() const { return counters_shared_.get(); } | |
|
Mircea Trofin
2017/06/22 18:42:24
for consistency, should this have the "shared" wor
kschimpf
2017/06/22 20:38:31
This is an artifact that we used to have both fiel
| |
| 85 | |
| 85 // Run by each compilation task and by the main thread. The | 86 // Run by each compilation task and by the main thread. The |
| 86 // no_finisher_callback is called within the result_mutex_ lock when no | 87 // no_finisher_callback is called within the result_mutex_ lock when no |
| 87 // finishing task is running, i.e. when the finisher_is_running_ flag is not | 88 // finishing task is running, i.e. when the finisher_is_running_ flag is not |
| 88 // set. | 89 // set. |
| 89 bool FetchAndExecuteCompilationUnit( | 90 bool FetchAndExecuteCompilationUnit( |
| 90 std::function<void()> no_finisher_callback = [] {}); | 91 std::function<void()> no_finisher_callback = [] {}); |
| 91 | 92 |
| 92 void CompileAndSchedule(size_t index); | 93 void CompileAndSchedule(size_t index); |
| 93 bool GetNextUncompiledFunctionId(size_t* index); | 94 bool GetNextUncompiledFunctionId(size_t* index); |
| 94 void OnBackgroundTaskStopped(); | 95 void OnBackgroundTaskStopped(); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 171 // Represents the initialized state of a table. | 172 // Represents the initialized state of a table. |
| 172 struct TableInstance { | 173 struct TableInstance { |
| 173 Handle<WasmTableObject> table_object; // WebAssembly.Table instance | 174 Handle<WasmTableObject> table_object; // WebAssembly.Table instance |
| 174 Handle<FixedArray> js_wrappers; // JSFunctions exported | 175 Handle<FixedArray> js_wrappers; // JSFunctions exported |
| 175 Handle<FixedArray> function_table; // internal code array | 176 Handle<FixedArray> function_table; // internal code array |
| 176 Handle<FixedArray> signature_table; // internal sig array | 177 Handle<FixedArray> signature_table; // internal sig array |
| 177 }; | 178 }; |
| 178 | 179 |
| 179 Isolate* isolate_; | 180 Isolate* isolate_; |
| 180 WasmModule* const module_; | 181 WasmModule* const module_; |
| 181 std::shared_ptr<Counters> counters_shared_; | 182 const std::shared_ptr<Counters> counters_shared_; |
| 182 Counters* counters_; | |
| 183 ErrorThrower* thrower_; | 183 ErrorThrower* thrower_; |
| 184 Handle<WasmModuleObject> module_object_; | 184 Handle<WasmModuleObject> module_object_; |
| 185 Handle<JSReceiver> ffi_; // TODO(titzer): Use MaybeHandle | 185 Handle<JSReceiver> ffi_; // TODO(titzer): Use MaybeHandle |
| 186 Handle<JSArrayBuffer> memory_; // TODO(titzer): Use MaybeHandle | 186 Handle<JSArrayBuffer> memory_; // TODO(titzer): Use MaybeHandle |
| 187 Handle<JSArrayBuffer> globals_; | 187 Handle<JSArrayBuffer> globals_; |
| 188 Handle<WasmCompiledModule> compiled_module_; | 188 Handle<WasmCompiledModule> compiled_module_; |
| 189 std::vector<TableInstance> table_instances_; | 189 std::vector<TableInstance> table_instances_; |
| 190 std::vector<Handle<JSFunction>> js_wrappers_; | 190 std::vector<Handle<JSFunction>> js_wrappers_; |
| 191 JSToWasmWrapperCache js_to_wasm_cache_; | 191 JSToWasmWrapperCache js_to_wasm_cache_; |
| 192 WeakCallbackInfo<void>::Callback instance_finalizer_callback_; | 192 WeakCallbackInfo<void>::Callback instance_finalizer_callback_; |
| 193 | 193 |
| 194 Counters* counters() const { return counters_shared_.get(); } | |
| 195 | |
| 194 // Helper routines to print out errors with imports. | 196 // Helper routines to print out errors with imports. |
| 195 #define ERROR_THROWER_WITH_MESSAGE(TYPE) \ | 197 #define ERROR_THROWER_WITH_MESSAGE(TYPE) \ |
| 196 void Report##TYPE(const char* error, uint32_t index, \ | 198 void Report##TYPE(const char* error, uint32_t index, \ |
| 197 Handle<String> module_name, Handle<String> import_name) { \ | 199 Handle<String> module_name, Handle<String> import_name) { \ |
| 198 thrower_->TYPE("Import #%d module=\"%.*s\" function=\"%.*s\" error: %s", \ | 200 thrower_->TYPE("Import #%d module=\"%.*s\" function=\"%.*s\" error: %s", \ |
| 199 index, module_name->length(), \ | 201 index, module_name->length(), \ |
| 200 module_name->ToCString().get(), import_name->length(), \ | 202 module_name->ToCString().get(), import_name->length(), \ |
| 201 import_name->ToCString().get(), error); \ | 203 import_name->ToCString().get(), error); \ |
| 202 } \ | 204 } \ |
| 203 \ | 205 \ |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 289 class DecodeFail; | 291 class DecodeFail; |
| 290 class PrepareAndStartCompile; | 292 class PrepareAndStartCompile; |
| 291 class ExecuteAndFinishCompilationUnits; | 293 class ExecuteAndFinishCompilationUnits; |
| 292 class WaitForBackgroundTasks; | 294 class WaitForBackgroundTasks; |
| 293 class FinishCompilationUnits; | 295 class FinishCompilationUnits; |
| 294 class FinishCompile; | 296 class FinishCompile; |
| 295 class CompileWrappers; | 297 class CompileWrappers; |
| 296 class FinishModule; | 298 class FinishModule; |
| 297 | 299 |
| 298 Isolate* isolate_; | 300 Isolate* isolate_; |
| 299 std::shared_ptr<Counters> counters_shared_; | 301 const std::shared_ptr<Counters> counters_shared_; |
| 300 Counters* counters_; | |
| 301 std::unique_ptr<byte[]> bytes_copy_; | 302 std::unique_ptr<byte[]> bytes_copy_; |
| 302 ModuleWireBytes wire_bytes_; | 303 ModuleWireBytes wire_bytes_; |
| 303 Handle<Context> context_; | 304 Handle<Context> context_; |
| 304 Handle<JSPromise> module_promise_; | 305 Handle<JSPromise> module_promise_; |
| 305 std::unique_ptr<ModuleCompiler> compiler_; | 306 std::unique_ptr<ModuleCompiler> compiler_; |
| 306 std::unique_ptr<ModuleBytesEnv> module_bytes_env_; | 307 std::unique_ptr<ModuleBytesEnv> module_bytes_env_; |
| 307 | 308 |
| 308 std::vector<DeferredHandles*> deferred_handles_; | 309 std::vector<DeferredHandles*> deferred_handles_; |
| 309 Handle<WasmModuleObject> module_object_; | 310 Handle<WasmModuleObject> module_object_; |
| 310 Handle<FixedArray> function_tables_; | 311 Handle<FixedArray> function_tables_; |
| 311 Handle<FixedArray> signature_tables_; | 312 Handle<FixedArray> signature_tables_; |
| 312 Handle<WasmCompiledModule> compiled_module_; | 313 Handle<WasmCompiledModule> compiled_module_; |
| 313 Handle<FixedArray> code_table_; | 314 Handle<FixedArray> code_table_; |
| 314 std::unique_ptr<WasmInstance> temp_instance_ = nullptr; | 315 std::unique_ptr<WasmInstance> temp_instance_ = nullptr; |
| 315 size_t outstanding_units_ = 0; | 316 size_t outstanding_units_ = 0; |
| 316 std::unique_ptr<CompileStep> step_; | 317 std::unique_ptr<CompileStep> step_; |
| 317 CancelableTaskManager background_task_manager_; | 318 CancelableTaskManager background_task_manager_; |
| 318 #if DEBUG | 319 #if DEBUG |
| 319 // Counts the number of pending foreground tasks. | 320 // Counts the number of pending foreground tasks. |
| 320 int32_t num_pending_foreground_tasks_ = 0; | 321 int32_t num_pending_foreground_tasks_ = 0; |
| 321 #endif | 322 #endif |
| 322 | 323 |
| 324 Counters* counters() const { return counters_shared_.get(); } | |
| 325 | |
| 323 void ReopenHandlesInDeferredScope(); | 326 void ReopenHandlesInDeferredScope(); |
| 324 | 327 |
| 325 void AsyncCompileFailed(ErrorThrower& thrower); | 328 void AsyncCompileFailed(ErrorThrower& thrower); |
| 326 | 329 |
| 327 void AsyncCompileSucceeded(Handle<Object> result); | 330 void AsyncCompileSucceeded(Handle<Object> result); |
| 328 | 331 |
| 329 template <typename Task, typename... Args> | 332 template <typename Task, typename... Args> |
| 330 void DoSync(Args&&... args); | 333 void DoSync(Args&&... args); |
| 331 | 334 |
| 332 void StartForegroundTask(); | 335 void StartForegroundTask(); |
| 333 | 336 |
| 334 void StartBackgroundTask(); | 337 void StartBackgroundTask(); |
| 335 | 338 |
| 336 template <typename Task, typename... Args> | 339 template <typename Task, typename... Args> |
| 337 void DoAsync(Args&&... args); | 340 void DoAsync(Args&&... args); |
| 338 }; | 341 }; |
| 339 | 342 |
| 340 } // namespace wasm | 343 } // namespace wasm |
| 341 } // namespace internal | 344 } // namespace internal |
| 342 } // namespace v8 | 345 } // namespace v8 |
| 343 | 346 |
| 344 #endif // V8_WASM_MODULE_COMPILER_H_ | 347 #endif // V8_WASM_MODULE_COMPILER_H_ |
| OLD | NEW |