| OLD | NEW |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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_H_ | 5 #ifndef V8_WASM_MODULE_H_ |
| 6 #define V8_WASM_MODULE_H_ | 6 #define V8_WASM_MODULE_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "src/api.h" | 10 #include "src/api.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 namespace internal { | 21 namespace internal { |
| 22 | 22 |
| 23 class WasmCompiledModule; | 23 class WasmCompiledModule; |
| 24 class WasmDebugInfo; | 24 class WasmDebugInfo; |
| 25 class WasmModuleObject; | 25 class WasmModuleObject; |
| 26 class WasmInstanceObject; | 26 class WasmInstanceObject; |
| 27 class WasmMemoryObject; | 27 class WasmMemoryObject; |
| 28 | 28 |
| 29 namespace compiler { | 29 namespace compiler { |
| 30 class CallDescriptor; | 30 class CallDescriptor; |
| 31 class WasmCompilationUnit; | |
| 32 } | 31 } |
| 33 | 32 |
| 34 namespace wasm { | 33 namespace wasm { |
| 35 class ErrorThrower; | 34 class ErrorThrower; |
| 36 | 35 |
| 37 const uint32_t kWasmMagic = 0x6d736100; | 36 const uint32_t kWasmMagic = 0x6d736100; |
| 38 const uint32_t kWasmVersion = 0x01; | 37 const uint32_t kWasmVersion = 0x01; |
| 39 // Legacy version supported for short transitionary period. | 38 // Legacy version supported for short transitionary period. |
| 40 const uint32_t kWasmLegacyVersion = 0x0d; | 39 const uint32_t kWasmLegacyVersion = 0x0d; |
| 41 | 40 |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 // invalid-semaphore error in the compilation tasks. | 209 // invalid-semaphore error in the compilation tasks. |
| 211 // TODO(wasm): Move this semaphore back to CompileInParallel when the try bots | 210 // TODO(wasm): Move this semaphore back to CompileInParallel when the try bots |
| 212 // switch to libc-2.21 or higher. | 211 // switch to libc-2.21 or higher. |
| 213 std::unique_ptr<base::Semaphore> pending_tasks; | 212 std::unique_ptr<base::Semaphore> pending_tasks; |
| 214 | 213 |
| 215 WasmModule() : WasmModule(nullptr) {} | 214 WasmModule() : WasmModule(nullptr) {} |
| 216 WasmModule(Zone* owned_zone); | 215 WasmModule(Zone* owned_zone); |
| 217 ~WasmModule() { | 216 ~WasmModule() { |
| 218 if (owned_zone) delete owned_zone; | 217 if (owned_zone) delete owned_zone; |
| 219 } | 218 } |
| 220 | |
| 221 // Creates a new instantiation of the module in the given isolate. | |
| 222 static MaybeHandle<WasmInstanceObject> Instantiate( | |
| 223 Isolate* isolate, ErrorThrower* thrower, | |
| 224 Handle<WasmModuleObject> wasm_module, Handle<JSReceiver> ffi, | |
| 225 Handle<JSArrayBuffer> memory = Handle<JSArrayBuffer>::null()); | |
| 226 | |
| 227 MaybeHandle<WasmCompiledModule> CompileFunctions( | |
| 228 Isolate* isolate, Handle<Managed<WasmModule>> module_wrapper, | |
| 229 ErrorThrower* thrower, const ModuleWireBytes& wire_bytes, | |
| 230 Handle<Script> asm_js_script, | |
| 231 Vector<const byte> asm_js_offset_table_bytes) const; | |
| 232 }; | 219 }; |
| 233 | 220 |
| 234 typedef Managed<WasmModule> WasmModuleWrapper; | 221 typedef Managed<WasmModule> WasmModuleWrapper; |
| 235 | 222 |
| 236 // An instantiated WASM module, including memory, function table, etc. | 223 // An instantiated WASM module, including memory, function table, etc. |
| 237 struct WasmInstance { | 224 struct WasmInstance { |
| 238 const WasmModule* module; // static representation of the module. | 225 const WasmModule* module; // static representation of the module. |
| 239 // -- Heap allocated -------------------------------------------------------- | 226 // -- Heap allocated -------------------------------------------------------- |
| 240 Handle<Context> context; // JavaScript native context. | 227 Handle<Context> context; // JavaScript native context. |
| 241 std::vector<Handle<FixedArray>> function_tables; // indirect function tables. | 228 std::vector<Handle<FixedArray>> function_tables; // indirect function tables. |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 return &module->function_tables[index]; | 339 return &module->function_tables[index]; |
| 353 } | 340 } |
| 354 | 341 |
| 355 bool asm_js() { return module->origin == kAsmJsOrigin; } | 342 bool asm_js() { return module->origin == kAsmJsOrigin; } |
| 356 | 343 |
| 357 Handle<Code> GetFunctionCode(uint32_t index) { | 344 Handle<Code> GetFunctionCode(uint32_t index) { |
| 358 DCHECK_NOT_NULL(instance); | 345 DCHECK_NOT_NULL(instance); |
| 359 return instance->function_code[index]; | 346 return instance->function_code[index]; |
| 360 } | 347 } |
| 361 | 348 |
| 349 // TODO(titzer): move these into src/compiler/wasm-compiler.cc |
| 362 static compiler::CallDescriptor* GetWasmCallDescriptor(Zone* zone, | 350 static compiler::CallDescriptor* GetWasmCallDescriptor(Zone* zone, |
| 363 FunctionSig* sig); | 351 FunctionSig* sig); |
| 364 static compiler::CallDescriptor* GetI32WasmCallDescriptor( | 352 static compiler::CallDescriptor* GetI32WasmCallDescriptor( |
| 365 Zone* zone, compiler::CallDescriptor* descriptor); | 353 Zone* zone, compiler::CallDescriptor* descriptor); |
| 366 static compiler::CallDescriptor* GetI32WasmCallDescriptorForSimd( | 354 static compiler::CallDescriptor* GetI32WasmCallDescriptorForSimd( |
| 367 Zone* zone, compiler::CallDescriptor* descriptor); | 355 Zone* zone, compiler::CallDescriptor* descriptor); |
| 368 }; | 356 }; |
| 369 | 357 |
| 370 // A ModuleEnv together with ModuleWireBytes. | 358 // A ModuleEnv together with ModuleWireBytes. |
| 371 struct ModuleBytesEnv { | 359 struct ModuleBytesEnv { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 Handle<Context> context); | 406 Handle<Context> context); |
| 419 | 407 |
| 420 V8_EXPORT_PRIVATE Handle<JSArray> GetImports(Isolate* isolate, | 408 V8_EXPORT_PRIVATE Handle<JSArray> GetImports(Isolate* isolate, |
| 421 Handle<WasmModuleObject> module); | 409 Handle<WasmModuleObject> module); |
| 422 V8_EXPORT_PRIVATE Handle<JSArray> GetExports(Isolate* isolate, | 410 V8_EXPORT_PRIVATE Handle<JSArray> GetExports(Isolate* isolate, |
| 423 Handle<WasmModuleObject> module); | 411 Handle<WasmModuleObject> module); |
| 424 V8_EXPORT_PRIVATE Handle<JSArray> GetCustomSections( | 412 V8_EXPORT_PRIVATE Handle<JSArray> GetCustomSections( |
| 425 Isolate* isolate, Handle<WasmModuleObject> module, Handle<String> name, | 413 Isolate* isolate, Handle<WasmModuleObject> module, Handle<String> name, |
| 426 ErrorThrower* thrower); | 414 ErrorThrower* thrower); |
| 427 | 415 |
| 428 V8_EXPORT_PRIVATE bool ValidateModuleBytes(Isolate* isolate, const byte* start, | |
| 429 const byte* end, | |
| 430 ErrorThrower* thrower, | |
| 431 ModuleOrigin origin); | |
| 432 | |
| 433 // Get the offset of the code of a function within a module. | 416 // Get the offset of the code of a function within a module. |
| 434 int GetFunctionCodeOffset(Handle<WasmCompiledModule> compiled_module, | 417 int GetFunctionCodeOffset(Handle<WasmCompiledModule> compiled_module, |
| 435 int func_index); | 418 int func_index); |
| 436 | 419 |
| 437 // Assumed to be called with a code object associated to a wasm module instance. | 420 // Assumed to be called with a code object associated to a wasm module instance. |
| 438 // Intended to be called from runtime functions. | 421 // Intended to be called from runtime functions. |
| 439 // Returns nullptr on failing to get owning instance. | 422 // Returns nullptr on failing to get owning instance. |
| 440 WasmInstanceObject* GetOwningWasmInstance(Code* code); | 423 WasmInstanceObject* GetOwningWasmInstance(Code* code); |
| 441 | 424 |
| 442 MaybeHandle<JSArrayBuffer> GetInstanceMemory( | 425 MaybeHandle<JSArrayBuffer> GetInstanceMemory( |
| (...skipping 14 matching lines...) Expand all Loading... |
| 457 | 440 |
| 458 int32_t GrowMemory(Isolate* isolate, Handle<WasmInstanceObject> instance, | 441 int32_t GrowMemory(Isolate* isolate, Handle<WasmInstanceObject> instance, |
| 459 uint32_t pages); | 442 uint32_t pages); |
| 460 | 443 |
| 461 void UpdateDispatchTables(Isolate* isolate, Handle<FixedArray> dispatch_tables, | 444 void UpdateDispatchTables(Isolate* isolate, Handle<FixedArray> dispatch_tables, |
| 462 int index, Handle<JSFunction> js_function); | 445 int index, Handle<JSFunction> js_function); |
| 463 | 446 |
| 464 void GrowDispatchTables(Isolate* isolate, Handle<FixedArray> dispatch_tables, | 447 void GrowDispatchTables(Isolate* isolate, Handle<FixedArray> dispatch_tables, |
| 465 uint32_t old_size, uint32_t count); | 448 uint32_t old_size, uint32_t count); |
| 466 | 449 |
| 450 //============================================================================ |
| 451 //== Compilation and instantiation =========================================== |
| 452 //============================================================================ |
| 453 V8_EXPORT_PRIVATE bool SyncValidate(Isolate* isolate, ErrorThrower* thrower, |
| 454 const ModuleWireBytes& bytes); |
| 455 |
| 456 V8_EXPORT_PRIVATE MaybeHandle<WasmModuleObject> SyncCompileTranslatedAsmJs( |
| 457 Isolate* isolate, ErrorThrower* thrower, const ModuleWireBytes& bytes, |
| 458 Handle<Script> asm_js_script, Vector<const byte> asm_js_offset_table_bytes); |
| 459 |
| 460 V8_EXPORT_PRIVATE MaybeHandle<WasmModuleObject> SyncCompile( |
| 461 Isolate* isolate, ErrorThrower* thrower, const ModuleWireBytes& bytes); |
| 462 |
| 463 V8_EXPORT_PRIVATE MaybeHandle<WasmInstanceObject> SyncInstantiate( |
| 464 Isolate* isolate, ErrorThrower* thrower, |
| 465 Handle<WasmModuleObject> module_object, MaybeHandle<JSReceiver> imports, |
| 466 MaybeHandle<JSArrayBuffer> memory); |
| 467 |
| 468 V8_EXPORT_PRIVATE void AsyncCompile(Isolate* isolate, Handle<JSPromise> promise, |
| 469 const ModuleWireBytes& bytes); |
| 470 |
| 471 V8_EXPORT_PRIVATE void AsyncInstantiate(Isolate* isolate, |
| 472 Handle<JSPromise> promise, |
| 473 Handle<WasmModuleObject> module_object, |
| 474 MaybeHandle<JSReceiver> imports); |
| 475 |
| 476 V8_EXPORT_PRIVATE void AsyncCompileAndInstantiate( |
| 477 Isolate* isolate, Handle<JSPromise> promise, const ModuleWireBytes& bytes, |
| 478 MaybeHandle<JSReceiver> imports); |
| 479 |
| 467 namespace testing { | 480 namespace testing { |
| 468 | |
| 469 void ValidateInstancesChain(Isolate* isolate, | 481 void ValidateInstancesChain(Isolate* isolate, |
| 470 Handle<WasmModuleObject> module_obj, | 482 Handle<WasmModuleObject> module_obj, |
| 471 int instance_count); | 483 int instance_count); |
| 472 void ValidateModuleState(Isolate* isolate, Handle<WasmModuleObject> module_obj); | 484 void ValidateModuleState(Isolate* isolate, Handle<WasmModuleObject> module_obj); |
| 473 void ValidateOrphanedInstance(Isolate* isolate, | 485 void ValidateOrphanedInstance(Isolate* isolate, |
| 474 Handle<WasmInstanceObject> instance); | 486 Handle<WasmInstanceObject> instance); |
| 475 | |
| 476 } // namespace testing | 487 } // namespace testing |
| 477 } // namespace wasm | 488 } // namespace wasm |
| 478 } // namespace internal | 489 } // namespace internal |
| 479 } // namespace v8 | 490 } // namespace v8 |
| 480 | 491 |
| 481 #endif // V8_WASM_MODULE_H_ | 492 #endif // V8_WASM_MODULE_H_ |
| OLD | NEW |