| 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 #include <memory> | 5 #include <memory> |
| 6 | 6 |
| 7 #include "src/assembler-inl.h" | 7 #include "src/assembler-inl.h" |
| 8 #include "src/base/adapters.h" | 8 #include "src/base/adapters.h" |
| 9 #include "src/base/atomic-utils.h" | 9 #include "src/base/atomic-utils.h" |
| 10 #include "src/code-stubs.h" | 10 #include "src/code-stubs.h" |
| (...skipping 850 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 861 return nullptr; | 861 return nullptr; |
| 862 } | 862 } |
| 863 | 863 |
| 864 static Handle<Code> UnwrapImportWrapper(Handle<Object> import_wrapper) { | 864 static Handle<Code> UnwrapImportWrapper(Handle<Object> import_wrapper) { |
| 865 Handle<JSFunction> func = Handle<JSFunction>::cast(import_wrapper); | 865 Handle<JSFunction> func = Handle<JSFunction>::cast(import_wrapper); |
| 866 Handle<Code> export_wrapper_code = handle(func->code()); | 866 Handle<Code> export_wrapper_code = handle(func->code()); |
| 867 int mask = RelocInfo::ModeMask(RelocInfo::CODE_TARGET); | 867 int mask = RelocInfo::ModeMask(RelocInfo::CODE_TARGET); |
| 868 for (RelocIterator it(*export_wrapper_code, mask);; it.next()) { | 868 for (RelocIterator it(*export_wrapper_code, mask);; it.next()) { |
| 869 DCHECK(!it.done()); | 869 DCHECK(!it.done()); |
| 870 Code* target = Code::GetCodeFromTargetAddress(it.rinfo()->target_address()); | 870 Code* target = Code::GetCodeFromTargetAddress(it.rinfo()->target_address()); |
| 871 if (target->kind() == Code::WASM_INTERPRETER_ENTRY) { |
| 872 // Don't call the interpreter entry directly, otherwise we cannot |
| 873 // disable the breakpoint later by patching the exported code. |
| 874 return Handle<Code>::null(); |
| 875 } |
| 871 if (target->kind() != Code::WASM_FUNCTION && | 876 if (target->kind() != Code::WASM_FUNCTION && |
| 872 target->kind() != Code::WASM_TO_JS_FUNCTION) | 877 target->kind() != Code::WASM_TO_JS_FUNCTION) |
| 873 continue; | 878 continue; |
| 874 // There should only be this one call to wasm code. | 879 // There should only be this one call to wasm code. |
| 875 #ifdef DEBUG | 880 #ifdef DEBUG |
| 876 for (it.next(); !it.done(); it.next()) { | 881 for (it.next(); !it.done(); it.next()) { |
| 877 Code* code = Code::GetCodeFromTargetAddress(it.rinfo()->target_address()); | 882 Code* code = Code::GetCodeFromTargetAddress(it.rinfo()->target_address()); |
| 878 DCHECK(code->kind() != Code::WASM_FUNCTION && | 883 DCHECK(code->kind() != Code::WASM_FUNCTION && |
| 879 code->kind() != Code::WASM_TO_JS_FUNCTION); | 884 code->kind() != Code::WASM_TO_JS_FUNCTION); |
| 880 } | 885 } |
| 881 #endif | 886 #endif |
| 882 return handle(target); | 887 return handle(target); |
| 883 } | 888 } |
| 884 UNREACHABLE(); | 889 UNREACHABLE(); |
| 885 return Handle<Code>::null(); | 890 return Handle<Code>::null(); |
| 886 } | 891 } |
| 887 | 892 |
| 888 Handle<Code> CompileImportWrapper(Isolate* isolate, int index, FunctionSig* sig, | 893 Handle<Code> CompileImportWrapper(Isolate* isolate, int index, FunctionSig* sig, |
| 889 Handle<JSReceiver> target, | 894 Handle<JSReceiver> target, |
| 890 Handle<String> module_name, | 895 Handle<String> module_name, |
| 891 MaybeHandle<String> import_name, | 896 MaybeHandle<String> import_name, |
| 892 ModuleOrigin origin) { | 897 ModuleOrigin origin) { |
| 893 WasmFunction* other_func = GetWasmFunctionForImportWrapper(isolate, target); | 898 WasmFunction* other_func = GetWasmFunctionForImportWrapper(isolate, target); |
| 894 if (other_func) { | 899 if (other_func) { |
| 895 if (sig->Equals(other_func->sig)) { | 900 if (!sig->Equals(other_func->sig)) return Handle<Code>::null(); |
| 896 // Signature matched. Unwrap the JS->WASM wrapper and return the raw | 901 // Signature matched. Unwrap the JS->WASM wrapper and return the raw |
| 897 // WASM function code. | 902 // WASM function code. |
| 898 return UnwrapImportWrapper(target); | 903 Handle<Code> code = UnwrapImportWrapper(target); |
| 899 } else { | 904 // If we got no code (imported function is being debugged), fall through |
| 900 return Handle<Code>::null(); | 905 // to CompileWasmToJSWrapper. |
| 901 } | 906 if (!code.is_null()) return code; |
| 902 } else { | |
| 903 // Signature mismatch. Compile a new wrapper for the new signature. | |
| 904 return compiler::CompileWasmToJSWrapper(isolate, target, sig, index, | |
| 905 module_name, import_name, origin); | |
| 906 } | 907 } |
| 908 // No wasm function or being debugged. Compile a new wrapper for the new |
| 909 // signature. |
| 910 return compiler::CompileWasmToJSWrapper(isolate, target, sig, index, |
| 911 module_name, import_name, origin); |
| 907 } | 912 } |
| 908 | 913 |
| 909 void UpdateDispatchTablesInternal(Isolate* isolate, | 914 void UpdateDispatchTablesInternal(Isolate* isolate, |
| 910 Handle<FixedArray> dispatch_tables, int index, | 915 Handle<FixedArray> dispatch_tables, int index, |
| 911 WasmFunction* function, Handle<Code> code) { | 916 WasmFunction* function, Handle<Code> code) { |
| 912 DCHECK_EQ(0, dispatch_tables->length() % 4); | 917 DCHECK_EQ(0, dispatch_tables->length() % 4); |
| 913 for (int i = 0; i < dispatch_tables->length(); i += 4) { | 918 for (int i = 0; i < dispatch_tables->length(); i += 4) { |
| 914 int table_index = Smi::cast(dispatch_tables->get(i + 1))->value(); | 919 int table_index = Smi::cast(dispatch_tables->get(i + 1))->value(); |
| 915 Handle<FixedArray> function_table( | 920 Handle<FixedArray> function_table( |
| 916 FixedArray::cast(dispatch_tables->get(i + 2)), isolate); | 921 FixedArray::cast(dispatch_tables->get(i + 2)), isolate); |
| (...skipping 1800 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2717 Handle<String> module_property_name = | 2722 Handle<String> module_property_name = |
| 2718 isolate->factory()->InternalizeUtf8String("module"); | 2723 isolate->factory()->InternalizeUtf8String("module"); |
| 2719 Handle<String> instance_property_name = | 2724 Handle<String> instance_property_name = |
| 2720 isolate->factory()->InternalizeUtf8String("instance"); | 2725 isolate->factory()->InternalizeUtf8String("instance"); |
| 2721 JSObject::AddProperty(ret, module_property_name, module, NONE); | 2726 JSObject::AddProperty(ret, module_property_name, module, NONE); |
| 2722 JSObject::AddProperty(ret, instance_property_name, | 2727 JSObject::AddProperty(ret, instance_property_name, |
| 2723 instance_object.ToHandleChecked(), NONE); | 2728 instance_object.ToHandleChecked(), NONE); |
| 2724 | 2729 |
| 2725 ResolvePromise(isolate, promise, ret); | 2730 ResolvePromise(isolate, promise, ret); |
| 2726 } | 2731 } |
| OLD | NEW |