[wasm] Rename the APIs that unwrap exports from other instances.

The renames capture what the item being unwrapped is - it's always
a js-to-wasm wrapper, which is more closely captured by "export" rather
than "import".

Bug: 
Change-Id: Iffc3d8cb9037afc2d32885301fd13fc12b8277ce
Reviewed-on: https://chromium-review.googlesource.com/648005
Reviewed-by: Clemens Hammacher <clemensh@chromium.org>
Commit-Queue: Mircea Trofin <mtrofin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47827}
This commit is contained in:
Mircea Trofin 2017-09-05 08:50:14 -07:00 committed by Commit Bot
parent 30f08f39f9
commit e11cee846f
3 changed files with 26 additions and 21 deletions

View File

@ -491,11 +491,11 @@ bool in_bounds(uint32_t offset, uint32_t size, uint32_t upper) {
using WasmInstanceMap =
IdentityMap<Handle<WasmInstanceObject>, FreeStoreAllocationPolicy>;
Handle<Code> UnwrapOrCompileImportWrapper(
Handle<Code> UnwrapExportOrCompileImportWrapper(
Isolate* isolate, int index, FunctionSig* sig, Handle<JSReceiver> target,
Handle<String> module_name, MaybeHandle<String> import_name,
ModuleOrigin origin, WasmInstanceMap* imported_instances) {
WasmFunction* other_func = GetWasmFunctionForImportWrapper(isolate, target);
WasmFunction* other_func = GetWasmFunctionForExport(isolate, target);
if (other_func) {
if (!sig->Equals(other_func->sig)) return Handle<Code>::null();
// Signature matched. Unwrap the import wrapper and return the raw wasm
@ -504,7 +504,7 @@ Handle<Code> UnwrapOrCompileImportWrapper(
Handle<WasmInstanceObject> imported_instance(
Handle<WasmExportedFunction>::cast(target)->instance(), isolate);
imported_instances->Set(imported_instance, imported_instance);
return UnwrapImportWrapper(target);
return UnwrapExportWrapper(Handle<JSFunction>::cast(target));
}
// No wasm function or being debugged. Compile a new wrapper for the new
// signature.
@ -1335,17 +1335,17 @@ int InstanceBuilder::ProcessImports(Handle<FixedArray> code_table,
return -1;
}
Handle<Code> import_wrapper = UnwrapOrCompileImportWrapper(
Handle<Code> import_code = UnwrapExportOrCompileImportWrapper(
isolate_, index, module_->functions[import.index].sig,
Handle<JSReceiver>::cast(value), module_name, import_name,
module_->origin(), &imported_wasm_instances);
if (import_wrapper.is_null()) {
if (import_code.is_null()) {
ReportLinkError("imported function does not match the expected type",
index, module_name, import_name);
return -1;
}
code_table->set(num_imported_functions, *import_wrapper);
RecordStats(*import_wrapper, counters());
code_table->set(num_imported_functions, *import_code);
RecordStats(*import_code, counters());
num_imported_functions++;
break;
}
@ -1403,8 +1403,7 @@ int InstanceBuilder::ProcessImports(Handle<FixedArray> code_table,
for (int i = 0; i < table_size; ++i) {
Handle<Object> val(table_instance.js_wrappers->get(i), isolate_);
if (!val->IsJSFunction()) continue;
WasmFunction* function =
GetWasmFunctionForImportWrapper(isolate_, val);
WasmFunction* function = GetWasmFunctionForExport(isolate_, val);
if (function == nullptr) {
thrower_->LinkError("table import %d[%d] is not a wasm function",
index, i);
@ -1412,7 +1411,8 @@ int InstanceBuilder::ProcessImports(Handle<FixedArray> code_table,
}
int sig_index = table.map.FindOrInsert(function->sig);
table_instance.signature_table->set(i, Smi::FromInt(sig_index));
table_instance.function_table->set(i, *UnwrapImportWrapper(val));
table_instance.function_table->set(
i, *UnwrapExportWrapper(Handle<JSFunction>::cast(val)));
}
num_imported_tables++;

View File

@ -367,8 +367,8 @@ WasmInstanceObject* GetOwningWasmInstance(Code* code) {
WasmModule::WasmModule(std::unique_ptr<Zone> owned)
: signature_zone(std::move(owned)) {}
WasmFunction* GetWasmFunctionForImportWrapper(Isolate* isolate,
Handle<Object> target) {
WasmFunction* GetWasmFunctionForExport(Isolate* isolate,
Handle<Object> target) {
if (target->IsJSFunction()) {
Handle<JSFunction> func = Handle<JSFunction>::cast(target);
if (func->code()->kind() == Code::JS_TO_WASM_FUNCTION) {
@ -381,9 +381,9 @@ WasmFunction* GetWasmFunctionForImportWrapper(Isolate* isolate,
return nullptr;
}
Handle<Code> UnwrapImportWrapper(Handle<Object> import_wrapper) {
Handle<JSFunction> func = Handle<JSFunction>::cast(import_wrapper);
Handle<Code> export_wrapper_code = handle(func->code());
Handle<Code> UnwrapExportWrapper(Handle<JSFunction> export_wrapper) {
Handle<Code> export_wrapper_code = handle(export_wrapper->code());
DCHECK_EQ(export_wrapper_code->kind(), Code::JS_TO_WASM_FUNCTION);
int mask = RelocInfo::ModeMask(RelocInfo::CODE_TARGET);
for (RelocIterator it(*export_wrapper_code, mask);; it.next()) {
DCHECK(!it.done());
@ -447,11 +447,14 @@ void TableSet(ErrorThrower* thrower, Isolate* isolate,
WasmFunction* wasm_function = nullptr;
Handle<Code> code = Handle<Code>::null();
Handle<Object> value = handle(isolate->heap()->null_value());
Handle<Object> value = isolate->factory()->null_value();
if (!function.is_null()) {
wasm_function = GetWasmFunctionForImportWrapper(isolate, function);
code = UnwrapImportWrapper(function);
wasm_function = GetWasmFunctionForExport(isolate, function);
// The verification that {function} is an export was done
// by the caller.
DCHECK_NOT_NULL(wasm_function);
code = UnwrapExportWrapper(function);
value = Handle<Object>::cast(function);
}

View File

@ -339,12 +339,14 @@ void DetachWebAssemblyMemoryBuffer(Isolate* isolate,
Handle<JSArrayBuffer> buffer,
bool free_memory);
// If the target is an export wrapper, return the {WasmFunction*} corresponding
// to the wrapped wasm function; in all other cases, return nullptr.
// The returned pointer is owned by the wasm instance target belongs to. The
// result is alive as long as the instance exists.
WasmFunction* GetWasmFunctionForImportWrapper(Isolate* isolate,
Handle<Object> target);
WasmFunction* GetWasmFunctionForExport(Isolate* isolate, Handle<Object> target);
Handle<Code> UnwrapImportWrapper(Handle<Object> import_wrapper);
// {export_wrapper} is known to be an export.
Handle<Code> UnwrapExportWrapper(Handle<JSFunction> export_wrapper);
void TableSet(ErrorThrower* thrower, Isolate* isolate,
Handle<WasmTableObject> table, int64_t index,