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 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 #define WCM_WEAK_LINK(TYPE, NAME) \ | 393 #define WCM_WEAK_LINK(TYPE, NAME) \ |
394 WCM_OBJECT_OR_WEAK(WeakCell, weak_##NAME, kID_##NAME); \ | 394 WCM_OBJECT_OR_WEAK(WeakCell, weak_##NAME, kID_##NAME); \ |
395 \ | 395 \ |
396 Handle<TYPE> NAME() const { \ | 396 Handle<TYPE> NAME() const { \ |
397 return handle(TYPE::cast(weak_##NAME()->value())); \ | 397 return handle(TYPE::cast(weak_##NAME()->value())); \ |
398 } | 398 } |
399 | 399 |
400 #define CORE_WCM_PROPERTY_TABLE(MACRO) \ | 400 #define CORE_WCM_PROPERTY_TABLE(MACRO) \ |
401 MACRO(OBJECT, FixedArray, code_table) \ | 401 MACRO(OBJECT, FixedArray, code_table) \ |
402 MACRO(OBJECT, Foreign, module_wrapper) \ | 402 MACRO(OBJECT, Foreign, module_wrapper) \ |
| 403 /* For debugging: */ \ |
403 MACRO(OBJECT, SeqOneByteString, module_bytes) \ | 404 MACRO(OBJECT, SeqOneByteString, module_bytes) \ |
404 MACRO(OBJECT, Script, asm_js_script) \ | 405 MACRO(OBJECT, Script, script) \ |
| 406 MACRO(OBJECT, ByteArray, asm_js_offset_tables) \ |
| 407 /* End of debugging stuff. */ \ |
405 MACRO(OBJECT, FixedArray, function_tables) \ | 408 MACRO(OBJECT, FixedArray, function_tables) \ |
406 MACRO(OBJECT, FixedArray, empty_function_tables) \ | 409 MACRO(OBJECT, FixedArray, empty_function_tables) \ |
407 MACRO(OBJECT, ByteArray, asm_js_offset_tables) \ | |
408 MACRO(OBJECT, JSArrayBuffer, memory) \ | 410 MACRO(OBJECT, JSArrayBuffer, memory) \ |
409 MACRO(SMALL_NUMBER, uint32_t, min_mem_pages) \ | 411 MACRO(SMALL_NUMBER, uint32_t, min_mem_pages) \ |
410 MACRO(SMALL_NUMBER, uint32_t, max_mem_pages) \ | 412 MACRO(SMALL_NUMBER, uint32_t, max_mem_pages) \ |
411 MACRO(WEAK_LINK, WasmCompiledModule, next_instance) \ | 413 MACRO(WEAK_LINK, WasmCompiledModule, next_instance) \ |
412 MACRO(WEAK_LINK, WasmCompiledModule, prev_instance) \ | 414 MACRO(WEAK_LINK, WasmCompiledModule, prev_instance) \ |
413 MACRO(WEAK_LINK, JSObject, owning_instance) \ | 415 MACRO(WEAK_LINK, JSObject, owning_instance) \ |
414 MACRO(WEAK_LINK, JSObject, wasm_module) | 416 MACRO(WEAK_LINK, JSObject, wasm_module) |
415 | 417 |
416 #if DEBUG | 418 #if DEBUG |
417 #define DEBUG_ONLY_TABLE(MACRO) MACRO(SMALL_NUMBER, uint32_t, instance_id) | 419 #define DEBUG_ONLY_TABLE(MACRO) MACRO(SMALL_NUMBER, uint32_t, instance_id) |
(...skipping 30 matching lines...) Expand all Loading... |
448 | 450 |
449 uint32_t mem_size() const { | 451 uint32_t mem_size() const { |
450 return has_memory() ? memory()->byte_length()->Number() | 452 return has_memory() ? memory()->byte_length()->Number() |
451 : default_mem_size(); | 453 : default_mem_size(); |
452 } | 454 } |
453 | 455 |
454 uint32_t default_mem_size() const { | 456 uint32_t default_mem_size() const { |
455 return min_mem_pages() * WasmModule::kPageSize; | 457 return min_mem_pages() * WasmModule::kPageSize; |
456 } | 458 } |
457 | 459 |
| 460 WasmModule* cpp_module() const { |
| 461 return Handle<WasmModuleWrapper>::cast(module_wrapper())->get(); |
| 462 } |
| 463 |
458 #define DECLARATION(KIND, TYPE, NAME) WCM_##KIND(TYPE, NAME) | 464 #define DECLARATION(KIND, TYPE, NAME) WCM_##KIND(TYPE, NAME) |
459 WCM_PROPERTY_TABLE(DECLARATION) | 465 WCM_PROPERTY_TABLE(DECLARATION) |
460 #undef DECLARATION | 466 #undef DECLARATION |
461 | 467 |
462 static bool IsWasmCompiledModule(Object* obj); | 468 static bool IsWasmCompiledModule(Object* obj); |
463 | 469 |
464 void PrintInstancesChain(); | 470 void PrintInstancesChain(); |
465 | 471 |
466 static void RecreateModuleWrapper(Isolate* isolate, | 472 static void RecreateModuleWrapper(Isolate* isolate, |
467 Handle<FixedArray> compiled_module); | 473 Handle<FixedArray> compiled_module); |
468 | 474 |
469 private: | 475 private: |
470 void InitId(); | 476 void InitId(); |
471 | 477 |
472 DISALLOW_IMPLICIT_CONSTRUCTORS(WasmCompiledModule); | 478 DISALLOW_IMPLICIT_CONSTRUCTORS(WasmCompiledModule); |
473 }; | 479 }; |
474 | 480 |
475 // Extract a function name from the given wasm object. | 481 // Extract a function name from the given compiled wasm module. |
476 // Returns "<WASM UNNAMED>" if the function is unnamed or the name is not a | 482 // Returns "<WASM UNNAMED>" if no compiled module is passed, the function is |
477 // valid UTF-8 string. | 483 // unnamed or the name is not a valid UTF-8 string. |
478 Handle<String> GetWasmFunctionName(Isolate* isolate, Handle<Object> wasm, | 484 // TODO(5620): Fix interface once we always get a compiled module. |
| 485 Handle<String> GetWasmFunctionName(Isolate* isolate, |
| 486 Handle<Object> compiled_module_or_undef, |
479 uint32_t func_index); | 487 uint32_t func_index); |
480 | 488 |
481 // Extract a function name from the given wasm object. | 489 // Extract a function name from the given compiled wasm module. |
482 // Returns a null handle if the function is unnamed or the name is not a valid | 490 // Returns a null handle if the function is unnamed or the name is not a valid |
483 // UTF-8 string. | 491 // UTF-8 string. |
484 Handle<Object> GetWasmFunctionNameOrNull(Isolate* isolate, Handle<Object> wasm, | 492 Handle<Object> GetWasmFunctionNameOrNull( |
485 uint32_t func_index); | 493 Isolate* isolate, Handle<WasmCompiledModule> compiled_module, |
| 494 uint32_t func_index); |
486 | 495 |
487 // Return the binary source bytes of a wasm module. | 496 // Return the binary source bytes of a wasm module. |
488 Handle<SeqOneByteString> GetWasmBytes(Handle<JSObject> wasm); | 497 Handle<SeqOneByteString> GetWasmBytes(Handle<JSObject> wasm); |
489 | 498 |
490 // Get the debug info associated with the given wasm object. | 499 // Get the debug info associated with the given wasm object. |
491 // If no debug info exists yet, it is created automatically. | 500 // If no debug info exists yet, it is created automatically. |
492 Handle<WasmDebugInfo> GetDebugInfo(Handle<JSObject> wasm); | 501 Handle<WasmDebugInfo> GetDebugInfo(Handle<JSObject> wasm); |
493 | 502 |
494 // Return the number of functions in the given wasm object. | 503 // Return the number of functions in the given wasm object. |
495 int GetNumberOfFunctions(Handle<JSObject> wasm); | 504 int GetNumberOfFunctions(Handle<JSObject> wasm); |
(...skipping 11 matching lines...) Expand all Loading... |
507 // special marker as internal field, which will definitely never occur anywhere | 516 // special marker as internal field, which will definitely never occur anywhere |
508 // else. | 517 // else. |
509 bool IsWasmInstance(Object* instance); | 518 bool IsWasmInstance(Object* instance); |
510 | 519 |
511 // Return the compiled module object for this WASM instance. | 520 // Return the compiled module object for this WASM instance. |
512 WasmCompiledModule* GetCompiledModule(Object* wasm_instance); | 521 WasmCompiledModule* GetCompiledModule(Object* wasm_instance); |
513 | 522 |
514 // Check whether the wasm module was generated from asm.js code. | 523 // Check whether the wasm module was generated from asm.js code. |
515 bool WasmIsAsmJs(Object* instance, Isolate* isolate); | 524 bool WasmIsAsmJs(Object* instance, Isolate* isolate); |
516 | 525 |
517 // Get the script for the asm.js origin of the wasm module. | 526 // Get the script of the wasm module. If the origin of the module is asm.js, the |
518 Handle<Script> GetAsmWasmScript(Handle<JSObject> instance); | 527 // returned Script will be a JavaScript Script of Script::TYPE_NORMAL, otherwise |
| 528 // it's of type TYPE_WASM. |
| 529 Handle<Script> GetScript(Handle<JSObject> instance); |
519 | 530 |
520 // Get the asm.js source position for the given byte offset in the given | 531 // Get the asm.js source position for the given byte offset in the given |
521 // function. | 532 // function. |
522 int GetAsmWasmSourcePosition(Handle<JSObject> instance, int func_index, | 533 int GetAsmWasmSourcePosition(Handle<JSObject> instance, int func_index, |
523 int byte_offset); | 534 int byte_offset); |
524 | 535 |
525 // Constructs a single function table as a FixedArray of double size, | 536 // Constructs a single function table as a FixedArray of double size, |
526 // populating it with function signature indices and function indices. | 537 // populating it with function signature indices and function indices. |
527 Handle<FixedArray> BuildFunctionTable(Isolate* isolate, uint32_t index, | 538 Handle<FixedArray> BuildFunctionTable(Isolate* isolate, uint32_t index, |
528 const WasmModule* module); | 539 const WasmModule* module); |
(...skipping 10 matching lines...) Expand all Loading... |
539 V8_EXPORT_PRIVATE MaybeHandle<JSObject> CreateModuleObjectFromBytes( | 550 V8_EXPORT_PRIVATE MaybeHandle<JSObject> CreateModuleObjectFromBytes( |
540 Isolate* isolate, const byte* start, const byte* end, ErrorThrower* thrower, | 551 Isolate* isolate, const byte* start, const byte* end, ErrorThrower* thrower, |
541 ModuleOrigin origin, Handle<Script> asm_js_script, | 552 ModuleOrigin origin, Handle<Script> asm_js_script, |
542 const byte* asm_offset_tables_start, const byte* asm_offset_tables_end); | 553 const byte* asm_offset_tables_start, const byte* asm_offset_tables_end); |
543 | 554 |
544 V8_EXPORT_PRIVATE bool ValidateModuleBytes(Isolate* isolate, const byte* start, | 555 V8_EXPORT_PRIVATE bool ValidateModuleBytes(Isolate* isolate, const byte* start, |
545 const byte* end, | 556 const byte* end, |
546 ErrorThrower* thrower, | 557 ErrorThrower* thrower, |
547 ModuleOrigin origin); | 558 ModuleOrigin origin); |
548 | 559 |
549 // Get the number of imported functions for a WASM instance. | 560 // Get the offset of the code of a function within a module. |
550 int GetNumImportedFunctions(Handle<JSObject> instance); | 561 int GetFunctionCodeOffset(Handle<WasmCompiledModule> compiled_module, |
| 562 int func_index); |
| 563 |
| 564 // Translate from byte offset in the module to function number and byte offset |
| 565 // within that function, encoded as line and column in the position info. |
| 566 bool GetPositionInfo(Handle<WasmCompiledModule> compiled_module, |
| 567 uint32_t position, Script::PositionInfo* info); |
551 | 568 |
552 // Assumed to be called with a code object associated to a wasm module instance. | 569 // Assumed to be called with a code object associated to a wasm module instance. |
553 // Intended to be called from runtime functions. | 570 // Intended to be called from runtime functions. |
554 // Returns nullptr on failing to get owning instance. | 571 // Returns nullptr on failing to get owning instance. |
555 Object* GetOwningWasmInstance(Code* code); | 572 Object* GetOwningWasmInstance(Code* code); |
556 | 573 |
557 MaybeHandle<JSArrayBuffer> GetInstanceMemory(Isolate* isolate, | 574 MaybeHandle<JSArrayBuffer> GetInstanceMemory(Isolate* isolate, |
558 Handle<JSObject> instance); | 575 Handle<JSObject> instance); |
559 | 576 |
560 int32_t GetInstanceMemorySize(Isolate* isolate, Handle<JSObject> instance); | 577 int32_t GetInstanceMemorySize(Isolate* isolate, Handle<JSObject> instance); |
(...skipping 10 matching lines...) Expand all Loading... |
571 int instance_count); | 588 int instance_count); |
572 void ValidateModuleState(Isolate* isolate, Handle<JSObject> wasm_module); | 589 void ValidateModuleState(Isolate* isolate, Handle<JSObject> wasm_module); |
573 void ValidateOrphanedInstance(Isolate* isolate, Handle<JSObject> instance); | 590 void ValidateOrphanedInstance(Isolate* isolate, Handle<JSObject> instance); |
574 | 591 |
575 } // namespace testing | 592 } // namespace testing |
576 } // namespace wasm | 593 } // namespace wasm |
577 } // namespace internal | 594 } // namespace internal |
578 } // namespace v8 | 595 } // namespace v8 |
579 | 596 |
580 #endif // V8_WASM_MODULE_H_ | 597 #endif // V8_WASM_MODULE_H_ |
OLD | NEW |