 Chromium Code Reviews
 Chromium Code Reviews Issue 2717973003:
  [wasm] Exit loop once wasm code in JS_TO_WASM is found  (Closed)
    
  
    Issue 2717973003:
  [wasm] Exit loop once wasm code in JS_TO_WASM is found  (Closed) 
  | 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 842 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 853 if (func->code()->kind() == Code::JS_TO_WASM_FUNCTION) { | 853 if (func->code()->kind() == Code::JS_TO_WASM_FUNCTION) { | 
| 854 auto exported = Handle<WasmExportedFunction>::cast(func); | 854 auto exported = Handle<WasmExportedFunction>::cast(func); | 
| 855 Handle<WasmInstanceObject> other_instance(exported->instance(), isolate); | 855 Handle<WasmInstanceObject> other_instance(exported->instance(), isolate); | 
| 856 int func_index = exported->function_index(); | 856 int func_index = exported->function_index(); | 
| 857 return &other_instance->module()->functions[func_index]; | 857 return &other_instance->module()->functions[func_index]; | 
| 858 } | 858 } | 
| 859 } | 859 } | 
| 860 return nullptr; | 860 return nullptr; | 
| 861 } | 861 } | 
| 862 | 862 | 
| 863 static Handle<Code> UnwrapImportWrapper(Handle<Object> target) { | 863 Code* UnwrapImportWrapper(Object* target) { | 
| 
titzer
2017/02/28 15:07:31
I think it'd be better if you left this as using h
 
titzer
2017/02/28 15:07:31
any reason for dropping the static qualifier?
 
Clemens Hammacher
2017/02/28 15:14:52
No, this is a mistake. This CL (https://codereview
 
Clemens Hammacher
2017/03/01 15:31:15
Done.
 | |
| 864 Handle<JSFunction> func = Handle<JSFunction>::cast(target); | 864 JSFunction* func = JSFunction::cast(target); | 
| 865 Handle<Code> export_wrapper_code = handle(func->code()); | 865 Handle<Code> export_wrapper_code = handle(func->code()); | 
| 866 int found = 0; | |
| 867 int mask = RelocInfo::ModeMask(RelocInfo::CODE_TARGET); | 866 int mask = RelocInfo::ModeMask(RelocInfo::CODE_TARGET); | 
| 868 Handle<Code> code; | 867 Handle<Code> code; | 
| 869 for (RelocIterator it(*export_wrapper_code, mask); !it.done(); it.next()) { | 868 for (RelocIterator it(*export_wrapper_code, mask);; it.next()) { | 
| 870 RelocInfo* rinfo = it.rinfo(); | 869 DCHECK(!it.done()); | 
| 871 Address target_address = rinfo->target_address(); | 870 Code* target = Code::GetCodeFromTargetAddress(it.rinfo()->target_address()); | 
| 872 Code* target = Code::GetCodeFromTargetAddress(target_address); | 871 if (target->kind() != Code::WASM_FUNCTION && | 
| 873 if (target->kind() == Code::WASM_FUNCTION || | 872 target->kind() != Code::WASM_TO_JS_FUNCTION) | 
| 
ahaas
2017/02/28 18:40:35
What is the reason why code->builtin_index() != Bu
 
Clemens Hammacher
2017/03/01 15:31:14
The import wrapper we are unwrapping here belongs
 | |
| 874 target->kind() == Code::WASM_TO_JS_FUNCTION) { | 873 continue; | 
| 875 ++found; | 874 // There should only be this one call to wasm code. | 
| 876 code = handle(target); | 875 #ifdef DEBUG | 
| 876 for (it.next(); !it.done(); it.next()) { | |
| 877 Code* code = Code::GetCodeFromTargetAddress(it.rinfo()->target_address()); | |
| 878 DCHECK(code->kind() != Code::WASM_FUNCTION && | |
| 879 code->kind() != Code::WASM_TO_JS_FUNCTION); | |
| 877 } | 880 } | 
| 881 #endif | |
| 882 return target; | |
| 878 } | 883 } | 
| 879 DCHECK_EQ(1, found); | 884 UNREACHABLE(); | 
| 880 return code; | 885 return nullptr; | 
| 881 } | 886 } | 
| 882 | 887 | 
| 883 static Handle<Code> CompileImportWrapper(Isolate* isolate, int index, | 888 static Handle<Code> CompileImportWrapper(Isolate* isolate, int index, | 
| 884 FunctionSig* sig, | 889 FunctionSig* sig, | 
| 885 Handle<JSReceiver> target, | 890 Handle<JSReceiver> target, | 
| 886 Handle<String> module_name, | 891 Handle<String> module_name, | 
| 887 MaybeHandle<String> import_name, | 892 MaybeHandle<String> import_name, | 
| 888 ModuleOrigin origin) { | 893 ModuleOrigin origin) { | 
| 889 WasmFunction* other_func = GetWasmFunctionForImportWrapper(isolate, target); | 894 WasmFunction* other_func = GetWasmFunctionForImportWrapper(isolate, target); | 
| 890 if (other_func) { | 895 if (other_func) { | 
| 891 if (sig->Equals(other_func->sig)) { | 896 if (sig->Equals(other_func->sig)) { | 
| 892 // Signature matched. Unwrap the JS->WASM wrapper and return the raw | 897 // Signature matched. Unwrap the JS->WASM wrapper and return the raw | 
| 893 // WASM function code. | 898 // WASM function code. | 
| 894 return UnwrapImportWrapper(target); | 899 return handle(UnwrapImportWrapper(*target), isolate); | 
| 895 } else { | 900 } else { | 
| 896 return Handle<Code>::null(); | 901 return Handle<Code>::null(); | 
| 897 } | 902 } | 
| 898 } else { | 903 } else { | 
| 899 // Signature mismatch. Compile a new wrapper for the new signature. | 904 // Signature mismatch. Compile a new wrapper for the new signature. | 
| 900 return compiler::CompileWasmToJSWrapper(isolate, target, sig, index, | 905 return compiler::CompileWasmToJSWrapper(isolate, target, sig, index, | 
| 901 module_name, import_name, origin); | 906 module_name, import_name, origin); | 
| 902 } | 907 } | 
| 903 } | 908 } | 
| 904 | 909 | 
| (...skipping 29 matching lines...) Expand all Loading... | |
| 934 void wasm::UpdateDispatchTables(Isolate* isolate, | 939 void wasm::UpdateDispatchTables(Isolate* isolate, | 
| 935 Handle<FixedArray> dispatch_tables, int index, | 940 Handle<FixedArray> dispatch_tables, int index, | 
| 936 Handle<JSFunction> function) { | 941 Handle<JSFunction> function) { | 
| 937 if (function.is_null()) { | 942 if (function.is_null()) { | 
| 938 UpdateDispatchTablesInternal(isolate, dispatch_tables, index, nullptr, | 943 UpdateDispatchTablesInternal(isolate, dispatch_tables, index, nullptr, | 
| 939 Handle<Code>::null()); | 944 Handle<Code>::null()); | 
| 940 } else { | 945 } else { | 
| 941 UpdateDispatchTablesInternal( | 946 UpdateDispatchTablesInternal( | 
| 942 isolate, dispatch_tables, index, | 947 isolate, dispatch_tables, index, | 
| 943 GetWasmFunctionForImportWrapper(isolate, function), | 948 GetWasmFunctionForImportWrapper(isolate, function), | 
| 944 UnwrapImportWrapper(function)); | 949 handle(UnwrapImportWrapper(*function), isolate)); | 
| 945 } | 950 } | 
| 946 } | 951 } | 
| 947 | 952 | 
| 948 // A helper class to simplify instantiating a module from a compiled module. | 953 // A helper class to simplify instantiating a module from a compiled module. | 
| 949 // It closes over the {Isolate}, the {ErrorThrower}, the {WasmCompiledModule}, | 954 // It closes over the {Isolate}, the {ErrorThrower}, the {WasmCompiledModule}, | 
| 950 // etc. | 955 // etc. | 
| 951 class InstantiationHelper { | 956 class InstantiationHelper { | 
| 952 public: | 957 public: | 
| 953 InstantiationHelper(Isolate* isolate, ErrorThrower* thrower, | 958 InstantiationHelper(Isolate* isolate, ErrorThrower* thrower, | 
| 954 Handle<WasmModuleObject> module_object, | 959 Handle<WasmModuleObject> module_object, | 
| (...skipping 621 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1576 if (!val->IsJSFunction()) continue; | 1581 if (!val->IsJSFunction()) continue; | 
| 1577 WasmFunction* function = | 1582 WasmFunction* function = | 
| 1578 GetWasmFunctionForImportWrapper(isolate_, val); | 1583 GetWasmFunctionForImportWrapper(isolate_, val); | 
| 1579 if (function == nullptr) { | 1584 if (function == nullptr) { | 
| 1580 thrower_->LinkError("table import %d[%d] is not a WASM function", | 1585 thrower_->LinkError("table import %d[%d] is not a WASM function", | 
| 1581 index, i); | 1586 index, i); | 
| 1582 return -1; | 1587 return -1; | 
| 1583 } | 1588 } | 
| 1584 int sig_index = table.map.FindOrInsert(function->sig); | 1589 int sig_index = table.map.FindOrInsert(function->sig); | 
| 1585 table_instance.signature_table->set(i, Smi::FromInt(sig_index)); | 1590 table_instance.signature_table->set(i, Smi::FromInt(sig_index)); | 
| 1586 table_instance.function_table->set(i, *UnwrapImportWrapper(val)); | 1591 table_instance.function_table->set(i, UnwrapImportWrapper(*val)); | 
| 1587 } | 1592 } | 
| 1588 | 1593 | 
| 1589 num_imported_tables++; | 1594 num_imported_tables++; | 
| 1590 break; | 1595 break; | 
| 1591 } | 1596 } | 
| 1592 case kExternalMemory: { | 1597 case kExternalMemory: { | 
| 1593 // Validation should have failed if more than one memory object was | 1598 // Validation should have failed if more than one memory object was | 
| 1594 // provided. | 1599 // provided. | 
| 1595 DCHECK(!instance->has_memory_object()); | 1600 DCHECK(!instance->has_memory_object()); | 
| 1596 if (!WasmJs::IsWasmMemoryObject(isolate_, value)) { | 1601 if (!WasmJs::IsWasmMemoryObject(isolate_, value)) { | 
| (...skipping 1113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2710 Handle<String> module_property_name = | 2715 Handle<String> module_property_name = | 
| 2711 isolate->factory()->InternalizeUtf8String("module"); | 2716 isolate->factory()->InternalizeUtf8String("module"); | 
| 2712 Handle<String> instance_property_name = | 2717 Handle<String> instance_property_name = | 
| 2713 isolate->factory()->InternalizeUtf8String("instance"); | 2718 isolate->factory()->InternalizeUtf8String("instance"); | 
| 2714 JSObject::AddProperty(ret, module_property_name, module, NONE); | 2719 JSObject::AddProperty(ret, module_property_name, module, NONE); | 
| 2715 JSObject::AddProperty(ret, instance_property_name, | 2720 JSObject::AddProperty(ret, instance_property_name, | 
| 2716 instance_object.ToHandleChecked(), NONE); | 2721 instance_object.ToHandleChecked(), NONE); | 
| 2717 | 2722 | 
| 2718 ResolvePromise(isolate, promise, ret); | 2723 ResolvePromise(isolate, promise, ret); | 
| 2719 } | 2724 } | 
| OLD | NEW |