Commit 59e87d64 authored by Andreas Haas's avatar Andreas Haas Committed by Commit Bot

[wasm] Remove mjsunit/wasm/test-import-export-wrapper

The test required a special runtime function, which did not work in
general but only in the context of that one test. After an offline
discussion we decided that what the test is testing is not worth a
runtime function, since we would also see in other tests if something
goes wrong.

R=clemensh@chromium.org

Bug: v8:7403
Change-Id: I129a189a9df299d409a4a555eae28783e47b97d1
Reviewed-on: https://chromium-review.googlesource.com/901284Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Commit-Queue: Andreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#51095}
parent b17a1679
...@@ -470,121 +470,6 @@ RUNTIME_FUNCTION(Runtime_ClearFunctionFeedback) { ...@@ -470,121 +470,6 @@ RUNTIME_FUNCTION(Runtime_ClearFunctionFeedback) {
return isolate->heap()->undefined_value(); return isolate->heap()->undefined_value();
} }
RUNTIME_FUNCTION(Runtime_CheckWasmWrapperElision) {
// This only supports the case where the function being exported
// calls an intermediate function, and the intermediate function
// calls exactly one imported function
HandleScope scope(isolate);
CHECK_EQ(args.length(), 2);
// It takes two parameters, the first one is the JSFunction,
// The second one is the type
CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0);
// If type is 0, it means that it is supposed to be a direct call into a wasm
// function.
// If type is 1, it means that it is supposed to have wrappers.
CONVERT_ARG_HANDLE_CHECKED(Smi, type, 1);
Handle<Code> export_code = handle(function->code());
CHECK(export_code->kind() == Code::JS_TO_WASM_FUNCTION);
int const mask =
RelocInfo::ModeMask(FLAG_wasm_jit_to_native ? RelocInfo::JS_TO_WASM_CALL
: RelocInfo::CODE_TARGET);
// check the type of the $export_fct
wasm::WasmCode* export_fct = nullptr;
Handle<Code> export_fct_handle;
wasm::WasmCode* intermediate_fct = nullptr;
Handle<Code> intermediate_fct_handle;
int count = 0;
for (RelocIterator it(*export_code, mask); !it.done(); it.next()) {
RelocInfo* rinfo = it.rinfo();
Address target_address = FLAG_wasm_jit_to_native
? rinfo->js_to_wasm_address()
: rinfo->target_address();
if (FLAG_wasm_jit_to_native) {
wasm::WasmCode* target =
isolate->wasm_engine()->code_manager()->LookupCode(target_address);
if (target->kind() == wasm::WasmCode::kFunction) {
++count;
export_fct = target;
}
} else {
Code* target = Code::GetCodeFromTargetAddress(target_address);
if (target->kind() == Code::WASM_FUNCTION) {
++count;
export_fct_handle = handle(target);
}
}
}
CHECK_EQ(count, 1);
// check the type of the intermediate_fct
count = 0;
if (FLAG_wasm_jit_to_native) {
for (RelocIterator it(export_fct->instructions(), export_fct->reloc_info(),
export_fct->constant_pool(),
RelocInfo::ModeMask(RelocInfo::WASM_CALL));
!it.done(); it.next()) {
RelocInfo* rinfo = it.rinfo();
Address target_address = rinfo->target_address();
wasm::WasmCode* target =
isolate->wasm_engine()->code_manager()->LookupCode(target_address);
if (target->kind() == wasm::WasmCode::kFunction) {
++count;
intermediate_fct = target;
}
}
} else {
count = 0;
for (RelocIterator it(*export_fct_handle, mask); !it.done(); it.next()) {
RelocInfo* rinfo = it.rinfo();
Address target_address = rinfo->target_address();
Code* target = Code::GetCodeFromTargetAddress(target_address);
if (target->kind() == Code::WASM_FUNCTION) {
++count;
intermediate_fct_handle = handle(target);
}
}
}
CHECK_EQ(count, 1);
// Check the type of the imported exported function, it should be also a wasm
// function in our case.
CHECK(type->value() == 0 || type->value() == 1);
count = 0;
if (FLAG_wasm_jit_to_native) {
wasm::WasmCode::Kind target_kind = type->value() == 0
? wasm::WasmCode::kWasmToWasmWrapper
: wasm::WasmCode::kWasmToJsWrapper;
for (RelocIterator it(intermediate_fct->instructions(),
intermediate_fct->reloc_info(),
intermediate_fct->constant_pool(),
RelocInfo::ModeMask(RelocInfo::WASM_CALL));
!it.done(); it.next()) {
RelocInfo* rinfo = it.rinfo();
Address target_address = rinfo->target_address();
wasm::WasmCode* target =
isolate->wasm_engine()->code_manager()->LookupCode(target_address);
if (target->kind() == target_kind) {
++count;
}
}
} else {
Code::Kind target_kind = type->value() == 0 ? Code::WASM_TO_WASM_FUNCTION
: Code::WASM_TO_JS_FUNCTION;
count = 0;
for (RelocIterator it(*intermediate_fct_handle, mask); !it.done();
it.next()) {
RelocInfo* rinfo = it.rinfo();
Address target_address = rinfo->target_address();
Code* target = Code::GetCodeFromTargetAddress(target_address);
if (target->kind() == target_kind) {
++count;
}
}
}
CHECK_LE(count, 1);
return isolate->heap()->ToBoolean(count == 1);
}
RUNTIME_FUNCTION(Runtime_SetWasmCompileControls) { RUNTIME_FUNCTION(Runtime_SetWasmCompileControls) {
HandleScope scope(isolate); HandleScope scope(isolate);
v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate); v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate);
......
...@@ -557,7 +557,6 @@ namespace internal { ...@@ -557,7 +557,6 @@ namespace internal {
#define FOR_EACH_INTRINSIC_TEST(F) \ #define FOR_EACH_INTRINSIC_TEST(F) \
F(Abort, 1, 1) \ F(Abort, 1, 1) \
F(AbortJS, 1, 1) \ F(AbortJS, 1, 1) \
F(CheckWasmWrapperElision, 2, 1) \
F(ClearFunctionFeedback, 1, 1) \ F(ClearFunctionFeedback, 1, 1) \
F(CompleteInobjectSlackTracking, 1, 1) \ F(CompleteInobjectSlackTracking, 1, 1) \
F(ConstructConsString, 2, 1) \ F(ConstructConsString, 2, 1) \
......
// Copyright 2016 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --expose-wasm --allow-natives-syntax
load("test/mjsunit/wasm/wasm-constants.js");
load("test/mjsunit/wasm/wasm-module-builder.js");
var expect_elison = 0;
var expect_no_elison = 1;
// function calls stack: first_export -> first_func -> first_import ->
// second_export -> second_import
// In this case, first_import and second_export have same signature,
// So that wrappers will be removed
(function TestWasmWrapperElision() {
var imported = function (a) {
return a;
};
var second_module = new WasmModuleBuilder();
var sig_index = second_module.addType(kSig_i_i);
second_module
.addImport("import_module_2", "import_name_2", sig_index);
second_module
.addFunction("second_export", sig_index)
.addBody([
kExprGetLocal, 0,
kExprCallFunction, 0,
kExprReturn
])
.exportFunc();
var first_module = new WasmModuleBuilder();
var sig_index = first_module.addType(kSig_i_i);
first_module
.addImport("import_module_1", "import_name_1", sig_index);
first_module
.addFunction("first_export", sig_index)
.addBody([
kExprGetLocal, 0,
kExprCallFunction, 2,
kExprReturn
])
.exportFunc();
first_module
.addFunction("first_func", sig_index)
.addBody([
kExprI32Const, 1,
kExprGetLocal, 0,
kExprI32Add,
kExprCallFunction, 0,
kExprReturn
]);
var f = second_module
.instantiate({import_module_2: {import_name_2: imported}})
.exports.second_export;
var the_export = first_module
.instantiate({import_module_1: {import_name_1: f}})
.exports.first_export;
assertEquals(the_export(2), 3);
assertEquals(the_export(-1), 0);
assertEquals(the_export(0), 1);
assertEquals(the_export(5.5), 6);
assertEquals(%CheckWasmWrapperElision(the_export, expect_elison), true);
})();
// Function calls stack: first_export -> first_func -> first_import ->
// second_export -> second_import
// In this test, first_import and second_export have the same signature, and
// therefore the wrappers will be removed. If the wrappers are not removed, then
// the test crashes because of the int64 parameter, which is not allowed in the
// wrappers.
(function TestWasmWrapperElisionInt64() {
var imported = function (a) {
return a;
};
var second_module = new WasmModuleBuilder();
var sig_index1 = second_module.addType(kSig_i_i);
var sig_index_ll = second_module.addType(kSig_l_l);
second_module
.addImport("import_module_2", "import_name_2", sig_index1);
second_module
.addFunction("second_export", sig_index_ll)
.addBody([
kExprGetLocal, 0,
kExprI32ConvertI64,
kExprCallFunction, 0,
kExprI64SConvertI32,
kExprReturn
])
.exportFunc();
var first_module = new WasmModuleBuilder();
var sig_index = first_module.addType(kSig_i_v);
var sig_index_ll = first_module.addType(kSig_l_l);
first_module
.addImport("import_module_1", "import_name_1", sig_index_ll);
first_module
.addFunction("first_export", sig_index)
.addBody([
kExprI64Const, 2,
kExprCallFunction, 2,
kExprI32ConvertI64,
kExprReturn
])
.exportFunc();
first_module
.addFunction("first_func", sig_index_ll)
.addBody([
kExprI64Const, 1,
kExprGetLocal, 0,
kExprI64Add,
kExprCallFunction, 0,
kExprReturn
]);
var f = second_module
.instantiate({import_module_2: {import_name_2: imported}})
.exports.second_export;
var the_export = first_module
.instantiate({import_module_1: {import_name_1: f}})
.exports.first_export;
assertEquals(the_export(), 3);
})();
// function calls stack: first_export -> first_func -> first_import ->
// second_export -> second_import
// In this case, second_export has fewer params than first_import,
// so instantiation should fail.
assertThrows(function TestWasmWrapperNoElisionLessParams() {
var imported = function (a) {
return a;
};
var second_module = new WasmModuleBuilder();
var sig_index_1 = second_module.addType(kSig_i_i);
second_module
.addImport("import_module_2", "import_name_2", sig_index_1);
second_module
.addFunction("second_export", sig_index_1)
.addBody([
kExprGetLocal, 0,
kExprCallFunction, 0,
kExprReturn
])
.exportFunc();
var first_module = new WasmModuleBuilder();
var sig_index_2 = first_module.addType(kSig_i_ii);
first_module
.addImport("import_module_1", "import_name_1", sig_index_2);
first_module
.addFunction("first_export", sig_index_2)
.addBody([
kExprGetLocal, 0,
kExprGetLocal, 1,
kExprCallFunction, 2,
kExprReturn
])
.exportFunc();
first_module
.addFunction("first_func", sig_index_2)
.addBody([
kExprGetLocal, 0,
kExprGetLocal, 1,
kExprCallFunction, 0,
kExprReturn
]);
var f = second_module
.instantiate({import_module_2: {import_name_2: imported}})
.exports.second_export;
var the_export = first_module
.instantiate({import_module_1: {import_name_1: f}})
.exports.first_export;
assertEquals(the_export(4, 5), 4);
assertEquals(the_export(-1, 4), -1);
assertEquals(the_export(0, 2), 0);
assertEquals(the_export(9.9, 4.3), 9);
assertEquals(%CheckWasmWrapperElision(the_export, expect_no_elison), true);
});
// function calls stack: first_export -> first_func -> first_import ->
// second_export -> second_import
// In this case, second_export has more params than first_import,
// so instantiation should fail.
assertThrows(function TestWasmWrapperNoElisionMoreParams() {
var imported = function (a, b, c) {
return a+b+c;
};
var second_module = new WasmModuleBuilder();
var sig_index_3 = second_module.addType(kSig_i_iii);
second_module
.addImport("import_module_2", "import_name_2", sig_index_3);
second_module
.addFunction("second_export", sig_index_3)
.addBody([
kExprGetLocal, 0,
kExprGetLocal, 1,
kExprGetLocal, 2,
kExprCallFunction, 0,
kExprReturn
])
.exportFunc();
var first_module = new WasmModuleBuilder();
var sig_index_2 = first_module.addType(kSig_i_ii);
first_module
.addImport("import_module_1", "import_name_1", sig_index_2);
first_module
.addFunction("first_export", sig_index_2)
.addBody([
kExprGetLocal, 0,
kExprGetLocal, 1,
kExprCallFunction, 2,
kExprReturn
])
.exportFunc();
first_module
.addFunction("first_func", sig_index_2)
.addBody([
kExprGetLocal, 0,
kExprGetLocal, 1,
kExprCallFunction, 0,
kExprReturn
]);
var f = second_module
.instantiate({import_module_2: {import_name_2: imported}})
.exports.second_export;
var the_export = first_module
.instantiate({import_module_1: {import_name_1: f}})
.exports.first_export;
assertEquals(the_export(5, 6), 11);
assertEquals(the_export(-1, -4), -5);
assertEquals(the_export(0, 0), 0);
assertEquals(the_export(1.1, 2.7), 3);
assertEquals(%CheckWasmWrapperElision(the_export, expect_no_elison), true);
});
// function calls stack: first_export -> first_func -> first_import ->
// second_export -> second_import
// In this case, second_export has different params type with first_import,
// so instantiation should fail.
assertThrows(function TestWasmWrapperNoElisionTypeMismatch() {
var imported = function (a, b) {
return a+b;
};
var second_module = new WasmModuleBuilder();
var sig_index_2 = second_module.addType(kSig_d_dd);
second_module
.addImport("import_module_2", "import_name_2", sig_index_2);
second_module
.addFunction("second_export", sig_index_2)
.addBody([
kExprGetLocal, 0,
kExprGetLocal, 1,
kExprCallFunction, 0,
kExprReturn
])
.exportFunc();
var first_module = new WasmModuleBuilder();
var sig_index_2 = first_module.addType(kSig_i_ii);
first_module
.addImport("import_module_1", "import_name_1", sig_index_2);
first_module
.addFunction("first_export", sig_index_2)
.addBody([
kExprGetLocal, 0,
kExprGetLocal, 1,
kExprCallFunction, 2,
kExprReturn
])
.exportFunc();
first_module
.addFunction("first_func", sig_index_2)
.addBody([
kExprGetLocal, 0,
kExprGetLocal, 1,
kExprCallFunction, 0,
kExprReturn
]);
var f = second_module
.instantiate({import_module_2: {import_name_2: imported}})
.exports.second_export;
var the_export = first_module
.instantiate({import_module_1: {import_name_1: f}})
.exports.first_export;
assertEquals(the_export(2.8, 9.1), 11);
assertEquals(the_export(-1.7, -2.5), -3);
assertEquals(the_export(0.0, 0.0), 0);
assertEquals(the_export(2, -2), 0);
assertEquals(%CheckWasmWrapperElision(the_export, expect_no_elison), true);
});
(function TestSimpleI64Ret() {
var builder = new WasmModuleBuilder();
builder.addFunction("exp", kSig_l_v)
.addBody([
kExprI64Const, 23
])
.exportFunc();
var exported = builder.instantiate().exports.exp;
var builder = new WasmModuleBuilder();
builder.addImport("imp", "func", kSig_l_v);
builder.addFunction("main", kSig_i_v)
.addBody([
kExprCallFunction, 0,
kExprI32ConvertI64
])
.exportFunc();
var instance = builder.instantiate({imp: {func: exported}});
assertEquals(23, instance.exports.main());
})();
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment