| 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 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 return static_cast<TYPE>(Smi::cast(get(kID_##NAME))->value()); \ | 375 return static_cast<TYPE>(Smi::cast(get(kID_##NAME))->value()); \ |
| 376 } | 376 } |
| 377 | 377 |
| 378 #define WCM_WEAK_LINK(TYPE, NAME) \ | 378 #define WCM_WEAK_LINK(TYPE, NAME) \ |
| 379 WCM_OBJECT_OR_WEAK(WeakCell, weak_##NAME, kID_##NAME); \ | 379 WCM_OBJECT_OR_WEAK(WeakCell, weak_##NAME, kID_##NAME); \ |
| 380 \ | 380 \ |
| 381 Handle<TYPE> NAME() const { \ | 381 Handle<TYPE> NAME() const { \ |
| 382 return handle(TYPE::cast(weak_##NAME()->value())); \ | 382 return handle(TYPE::cast(weak_##NAME()->value())); \ |
| 383 } | 383 } |
| 384 | 384 |
| 385 #define WCM_PROPERTY_TABLE(MACRO) \ | 385 #define CORE_WCM_PROPERTY_TABLE(MACRO) \ |
| 386 MACRO(OBJECT, FixedArray, code_table) \ | 386 MACRO(OBJECT, FixedArray, code_table) \ |
| 387 MACRO(OBJECT, FixedArray, import_data) \ | 387 MACRO(OBJECT, FixedArray, import_data) \ |
| 388 MACRO(OBJECT, FixedArray, exports) \ | 388 MACRO(OBJECT, FixedArray, exports) \ |
| 389 MACRO(OBJECT, FixedArray, startup_function) \ | 389 MACRO(OBJECT, FixedArray, startup_function) \ |
| 390 MACRO(OBJECT, FixedArray, indirect_function_tables) \ | 390 MACRO(OBJECT, FixedArray, indirect_function_tables) \ |
| 391 MACRO(OBJECT, String, module_bytes) \ | 391 MACRO(OBJECT, String, module_bytes) \ |
| 392 MACRO(OBJECT, ByteArray, function_names) \ | 392 MACRO(OBJECT, ByteArray, function_names) \ |
| 393 MACRO(SMALL_NUMBER, uint32_t, min_memory_pages) \ | 393 MACRO(SMALL_NUMBER, uint32_t, min_memory_pages) \ |
| 394 MACRO(OBJECT, FixedArray, data_segments_info) \ | 394 MACRO(OBJECT, FixedArray, data_segments_info) \ |
| 395 MACRO(OBJECT, ByteArray, data_segments) \ | 395 MACRO(OBJECT, ByteArray, data_segments) \ |
| 396 MACRO(SMALL_NUMBER, uint32_t, globals_size) \ | 396 MACRO(SMALL_NUMBER, uint32_t, globals_size) \ |
| 397 MACRO(OBJECT, JSArrayBuffer, heap) \ | 397 MACRO(OBJECT, JSArrayBuffer, heap) \ |
| 398 MACRO(SMALL_NUMBER, bool, export_memory) \ | 398 MACRO(SMALL_NUMBER, bool, export_memory) \ |
| 399 MACRO(SMALL_NUMBER, ModuleOrigin, origin) \ | 399 MACRO(SMALL_NUMBER, ModuleOrigin, origin) \ |
| 400 MACRO(WEAK_LINK, WasmCompiledModule, next_instance) \ | 400 MACRO(WEAK_LINK, WasmCompiledModule, next_instance) \ |
| 401 MACRO(WEAK_LINK, WasmCompiledModule, prev_instance) \ | 401 MACRO(WEAK_LINK, WasmCompiledModule, prev_instance) \ |
| 402 MACRO(WEAK_LINK, JSObject, owning_instance) \ | 402 MACRO(WEAK_LINK, JSObject, owning_instance) \ |
| 403 MACRO(WEAK_LINK, JSObject, module_object) | 403 MACRO(WEAK_LINK, JSObject, module_object) |
| 404 | 404 |
| 405 #if DEBUG |
| 406 #define DEBUG_ONLY_TABLE(MACRO) MACRO(SMALL_NUMBER, uint32_t, instance_id) |
| 407 #else |
| 408 #define DEBUG_ONLY_TABLE(IGNORE) |
| 409 uint32_t instance_id() const { return -1; } |
| 410 #endif |
| 411 |
| 412 #define WCM_PROPERTY_TABLE(MACRO) \ |
| 413 CORE_WCM_PROPERTY_TABLE(MACRO) \ |
| 414 DEBUG_ONLY_TABLE(MACRO) |
| 415 |
| 405 private: | 416 private: |
| 406 enum PropertyIndices { | 417 enum PropertyIndices { |
| 407 #define INDICES(IGNORE1, IGNORE2, NAME) kID_##NAME, | 418 #define INDICES(IGNORE1, IGNORE2, NAME) kID_##NAME, |
| 408 WCM_PROPERTY_TABLE(INDICES) Count | 419 WCM_PROPERTY_TABLE(INDICES) Count |
| 409 #undef INDICES | 420 #undef INDICES |
| 410 }; | 421 }; |
| 411 | 422 |
| 412 public: | 423 public: |
| 413 static Handle<WasmCompiledModule> New(Isolate* isolate, | 424 static Handle<WasmCompiledModule> New(Isolate* isolate, |
| 414 uint32_t min_memory_pages, | 425 uint32_t min_memory_pages, |
| 415 uint32_t globals_size, | 426 uint32_t globals_size, |
| 416 bool export_memory, | 427 bool export_memory, |
| 417 ModuleOrigin origin); | 428 ModuleOrigin origin); |
| 418 | 429 |
| 419 static Handle<WasmCompiledModule> Clone(Isolate* isolate, | 430 static Handle<WasmCompiledModule> Clone(Isolate* isolate, |
| 420 Handle<WasmCompiledModule> module) { | 431 Handle<WasmCompiledModule> module) { |
| 421 Handle<WasmCompiledModule> ret = Handle<WasmCompiledModule>::cast( | 432 Handle<WasmCompiledModule> ret = Handle<WasmCompiledModule>::cast( |
| 422 isolate->factory()->CopyFixedArray(module)); | 433 isolate->factory()->CopyFixedArray(module)); |
| 434 ret->Init(); |
| 435 ret->reset_weak_owning_instance(); |
| 436 ret->reset_weak_next_instance(); |
| 437 ret->reset_weak_prev_instance(); |
| 423 return ret; | 438 return ret; |
| 424 } | 439 } |
| 425 | 440 |
| 426 uint32_t mem_size() const { | 441 uint32_t mem_size() const { |
| 427 DCHECK(has_heap()); | 442 DCHECK(has_heap()); |
| 428 return heap()->byte_length()->Number(); | 443 return heap()->byte_length()->Number(); |
| 429 } | 444 } |
| 430 | 445 |
| 431 uint32_t default_mem_size() const { | 446 uint32_t default_mem_size() const { |
| 432 return min_memory_pages() * WasmModule::kPageSize; | 447 return min_memory_pages() * WasmModule::kPageSize; |
| 433 } | 448 } |
| 434 | 449 |
| 435 #define DECLARATION(KIND, TYPE, NAME) WCM_##KIND(TYPE, NAME) | 450 #define DECLARATION(KIND, TYPE, NAME) WCM_##KIND(TYPE, NAME) |
| 436 WCM_PROPERTY_TABLE(DECLARATION) | 451 WCM_PROPERTY_TABLE(DECLARATION) |
| 437 #undef DECLARATION | 452 #undef DECLARATION |
| 438 | 453 |
| 454 void PrintInstancesChain(); |
| 455 |
| 439 private: | 456 private: |
| 457 #if DEBUG |
| 458 static uint32_t instance_id_counter_; |
| 459 #endif |
| 460 void Init(); |
| 461 |
| 440 DISALLOW_IMPLICIT_CONSTRUCTORS(WasmCompiledModule); | 462 DISALLOW_IMPLICIT_CONSTRUCTORS(WasmCompiledModule); |
| 441 }; | 463 }; |
| 442 | 464 |
| 443 // Extract a function name from the given wasm object. | 465 // Extract a function name from the given wasm object. |
| 444 // Returns "<WASM UNNAMED>" if the function is unnamed or the name is not a | 466 // Returns "<WASM UNNAMED>" if the function is unnamed or the name is not a |
| 445 // valid UTF-8 string. | 467 // valid UTF-8 string. |
| 446 Handle<String> GetWasmFunctionName(Isolate* isolate, Handle<Object> wasm, | 468 Handle<String> GetWasmFunctionName(Isolate* isolate, Handle<Object> wasm, |
| 447 uint32_t func_index); | 469 uint32_t func_index); |
| 448 | 470 |
| 449 // Extract a function name from the given wasm object. | 471 // Extract a function name from the given wasm object. |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 int instance_count); | 544 int instance_count); |
| 523 void ValidateModuleState(Isolate* isolate, Handle<JSObject> module_obj); | 545 void ValidateModuleState(Isolate* isolate, Handle<JSObject> module_obj); |
| 524 void ValidateOrphanedInstance(Isolate* isolate, Handle<JSObject> instance); | 546 void ValidateOrphanedInstance(Isolate* isolate, Handle<JSObject> instance); |
| 525 | 547 |
| 526 } // namespace testing | 548 } // namespace testing |
| 527 } // namespace wasm | 549 } // namespace wasm |
| 528 } // namespace internal | 550 } // namespace internal |
| 529 } // namespace v8 | 551 } // namespace v8 |
| 530 | 552 |
| 531 #endif // V8_WASM_MODULE_H_ | 553 #endif // V8_WASM_MODULE_H_ |
| OLD | NEW |