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 #include <src/wasm/module-compiler.h> | 5 #include <src/wasm/module-compiler.h> |
6 | 6 |
7 #include <atomic> | 7 #include <atomic> |
8 | 8 |
9 #include "src/asmjs/asm-js.h" | 9 #include "src/asmjs/asm-js.h" |
10 #include "src/assembler-inl.h" | 10 #include "src/assembler-inl.h" |
(...skipping 1004 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1015 | 1015 |
1016 //-------------------------------------------------------------------------- | 1016 //-------------------------------------------------------------------------- |
1017 // Set up the exports object for the new instance. | 1017 // Set up the exports object for the new instance. |
1018 //-------------------------------------------------------------------------- | 1018 //-------------------------------------------------------------------------- |
1019 ProcessExports(code_table, instance, compiled_module_); | 1019 ProcessExports(code_table, instance, compiled_module_); |
1020 if (thrower_->error()) return {}; | 1020 if (thrower_->error()) return {}; |
1021 | 1021 |
1022 //-------------------------------------------------------------------------- | 1022 //-------------------------------------------------------------------------- |
1023 // Add instance to Memory object | 1023 // Add instance to Memory object |
1024 //-------------------------------------------------------------------------- | 1024 //-------------------------------------------------------------------------- |
1025 DCHECK(wasm::IsWasmInstance(*instance)); | 1025 DCHECK(instance->IsWasmInstanceObject()); |
1026 if (instance->has_memory_object()) { | 1026 if (instance->has_memory_object()) { |
1027 instance->memory_object()->AddInstance(isolate_, instance); | 1027 instance->memory_object()->AddInstance(isolate_, instance); |
1028 } | 1028 } |
1029 | 1029 |
1030 //-------------------------------------------------------------------------- | 1030 //-------------------------------------------------------------------------- |
1031 // Initialize the indirect function tables. | 1031 // Initialize the indirect function tables. |
1032 //-------------------------------------------------------------------------- | 1032 //-------------------------------------------------------------------------- |
1033 if (function_table_count > 0) LoadTableSegments(code_table, instance); | 1033 if (function_table_count > 0) LoadTableSegments(code_table, instance); |
1034 | 1034 |
1035 // Patch all code with the relocations registered in code_specialization. | 1035 // Patch all code with the relocations registered in code_specialization. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1067 // Publish the new instance to the instances chain. | 1067 // Publish the new instance to the instances chain. |
1068 { | 1068 { |
1069 DisallowHeapAllocation no_gc; | 1069 DisallowHeapAllocation no_gc; |
1070 if (!link_to_original.is_null()) { | 1070 if (!link_to_original.is_null()) { |
1071 compiled_module_->set_weak_next_instance( | 1071 compiled_module_->set_weak_next_instance( |
1072 link_to_original.ToHandleChecked()); | 1072 link_to_original.ToHandleChecked()); |
1073 original.ToHandleChecked()->set_weak_prev_instance(link_to_clone); | 1073 original.ToHandleChecked()->set_weak_prev_instance(link_to_clone); |
1074 compiled_module_->set_weak_wasm_module( | 1074 compiled_module_->set_weak_wasm_module( |
1075 original.ToHandleChecked()->weak_wasm_module()); | 1075 original.ToHandleChecked()->weak_wasm_module()); |
1076 } | 1076 } |
1077 module_object_->SetEmbedderField(0, *compiled_module_); | 1077 module_object_->set_compiled_module(*compiled_module_); |
1078 compiled_module_->set_weak_owning_instance(link_to_owning_instance); | 1078 compiled_module_->set_weak_owning_instance(link_to_owning_instance); |
1079 GlobalHandles::MakeWeak( | 1079 GlobalHandles::MakeWeak( |
1080 global_handle.location(), global_handle.location(), | 1080 global_handle.location(), global_handle.location(), |
1081 instance_finalizer_callback_, v8::WeakCallbackType::kFinalizer); | 1081 instance_finalizer_callback_, v8::WeakCallbackType::kFinalizer); |
1082 } | 1082 } |
1083 } | 1083 } |
1084 | 1084 |
1085 //-------------------------------------------------------------------------- | 1085 //-------------------------------------------------------------------------- |
1086 // Debugging support. | 1086 // Debugging support. |
1087 //-------------------------------------------------------------------------- | 1087 //-------------------------------------------------------------------------- |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1391 // provided. | 1391 // provided. |
1392 DCHECK(!instance->has_memory_object()); | 1392 DCHECK(!instance->has_memory_object()); |
1393 if (!WasmJs::IsWasmMemoryObject(isolate_, value)) { | 1393 if (!WasmJs::IsWasmMemoryObject(isolate_, value)) { |
1394 ReportLinkError("memory import must be a WebAssembly.Memory object", | 1394 ReportLinkError("memory import must be a WebAssembly.Memory object", |
1395 index, module_name, import_name); | 1395 index, module_name, import_name); |
1396 return -1; | 1396 return -1; |
1397 } | 1397 } |
1398 auto memory = Handle<WasmMemoryObject>::cast(value); | 1398 auto memory = Handle<WasmMemoryObject>::cast(value); |
1399 DCHECK(WasmJs::IsWasmMemoryObject(isolate_, memory)); | 1399 DCHECK(WasmJs::IsWasmMemoryObject(isolate_, memory)); |
1400 instance->set_memory_object(*memory); | 1400 instance->set_memory_object(*memory); |
1401 memory_ = Handle<JSArrayBuffer>(memory->buffer(), isolate_); | 1401 memory_ = Handle<JSArrayBuffer>(memory->array_buffer(), isolate_); |
1402 uint32_t imported_cur_pages = static_cast<uint32_t>( | 1402 uint32_t imported_cur_pages = static_cast<uint32_t>( |
1403 memory_->byte_length()->Number() / WasmModule::kPageSize); | 1403 memory_->byte_length()->Number() / WasmModule::kPageSize); |
1404 if (imported_cur_pages < module_->min_mem_pages) { | 1404 if (imported_cur_pages < module_->min_mem_pages) { |
1405 thrower_->LinkError( | 1405 thrower_->LinkError( |
1406 "memory import %d is smaller than maximum %u, got %u", index, | 1406 "memory import %d is smaller than maximum %u, got %u", index, |
1407 module_->min_mem_pages, imported_cur_pages); | 1407 module_->min_mem_pages, imported_cur_pages); |
1408 } | 1408 } |
1409 int32_t imported_max_pages = memory->maximum_pages(); | 1409 int32_t imported_max_pages = memory->maximum_pages(); |
1410 if (module_->has_max_mem) { | 1410 if (module_->has_max_mem) { |
1411 if (imported_max_pages < 0) { | 1411 if (imported_max_pages < 0) { |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1661 memory_object = WasmMemoryObject::New( | 1661 memory_object = WasmMemoryObject::New( |
1662 isolate_, | 1662 isolate_, |
1663 (instance->has_memory_buffer()) | 1663 (instance->has_memory_buffer()) |
1664 ? handle(instance->memory_buffer()) | 1664 ? handle(instance->memory_buffer()) |
1665 : Handle<JSArrayBuffer>::null(), | 1665 : Handle<JSArrayBuffer>::null(), |
1666 (module_->max_mem_pages != 0) ? module_->max_mem_pages : -1); | 1666 (module_->max_mem_pages != 0) ? module_->max_mem_pages : -1); |
1667 instance->set_memory_object(*memory_object); | 1667 instance->set_memory_object(*memory_object); |
1668 } else { | 1668 } else { |
1669 memory_object = | 1669 memory_object = |
1670 Handle<WasmMemoryObject>(instance->memory_object(), isolate_); | 1670 Handle<WasmMemoryObject>(instance->memory_object(), isolate_); |
1671 DCHECK(WasmJs::IsWasmMemoryObject(isolate_, memory_object)); | |
1672 memory_object->ResetInstancesLink(isolate_); | 1671 memory_object->ResetInstancesLink(isolate_); |
1673 } | 1672 } |
1674 | 1673 |
1675 desc.set_value(memory_object); | 1674 desc.set_value(memory_object); |
1676 break; | 1675 break; |
1677 } | 1676 } |
1678 case kExternalGlobal: { | 1677 case kExternalGlobal: { |
1679 // Export the value of the global variable as a number. | 1678 // Export the value of the global variable as a number. |
1680 WasmGlobal& global = module_->globals[exp.index]; | 1679 WasmGlobal& global = module_->globals[exp.index]; |
1681 double num = 0; | 1680 double num = 0; |
(...skipping 674 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2356 HandleScope scope(job_->isolate_); | 2355 HandleScope scope(job_->isolate_); |
2357 Handle<WasmModuleObject> result = | 2356 Handle<WasmModuleObject> result = |
2358 WasmModuleObject::New(job_->isolate_, job_->compiled_module_); | 2357 WasmModuleObject::New(job_->isolate_, job_->compiled_module_); |
2359 // {job_} is deleted in AsyncCompileSucceeded, therefore the {return}. | 2358 // {job_} is deleted in AsyncCompileSucceeded, therefore the {return}. |
2360 return job_->AsyncCompileSucceeded(result); | 2359 return job_->AsyncCompileSucceeded(result); |
2361 } | 2360 } |
2362 }; | 2361 }; |
2363 } // namespace wasm | 2362 } // namespace wasm |
2364 } // namespace internal | 2363 } // namespace internal |
2365 } // namespace v8 | 2364 } // namespace v8 |
OLD | NEW |