Commit f0e07e4b authored by Deepti Gandluri's avatar Deepti Gandluri Committed by Commit Bot

[wasm] Remove redundant table size relocation

BUG=chromium:752423

Change-Id: Ifea2fba7e002cb88dd6e53170fe98d3fd4af686a
Reviewed-on: https://chromium-review.googlesource.com/609445
Commit-Queue: Deepti Gandluri <gdeepti@chromium.org>
Reviewed-by: 's avatarBen Titzer <titzer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47527}
parent dc26486c
......@@ -1364,7 +1364,7 @@ int InstanceBuilder::ProcessImports(Handle<FixedArray> code_table,
}
if (imported_maximum_size > table.maximum_size) {
thrower_->LinkError(
"memory import %d has a larger maximum size %" PRIx64
" table import %d has a larger maximum size %" PRIx64
" than the module's declared maximum %u",
index, imported_maximum_size, table.maximum_size);
return -1;
......@@ -1767,13 +1767,6 @@ void InstanceBuilder::InitializeTables(
// uninitialized entries will always fail the signature check.
table_instance.signature_table->set(i, Smi::FromInt(kInvalidSigIndex));
}
} else {
// Table is imported, patch table bounds check
DCHECK(table_size <= table_instance.function_table->length());
if (table_size < table_instance.function_table->length()) {
code_specialization->PatchTableSize(
table_size, table_instance.function_table->length());
}
}
int int_index = static_cast<int>(index);
......
......@@ -141,7 +141,7 @@ function js_div(a, b) { return (a / b) | 0; }
let main = i2.exports.main;
for (var j = 0; j < i; j++) {
assertThrows(() => main(0, j));
assertTraps(kTrapFuncSigMismatch, () => main(0, j));
assertSame(null, table.get(j));
}
......@@ -207,7 +207,7 @@ function js_div(a, b) { return (a / b) | 0; }
let main = i2.exports.main;
for (var j = 0; j < i; j++) {
assertThrows(() => main(0, j));
assertTraps(kTrapFuncSigMismatch, () => main(0, j));
assertSame(null, table.get(j));
}
......@@ -335,11 +335,10 @@ function js_div(a, b) { return (a / b) | 0; }
assertEquals(22, i1.exports.main(1));
assertEquals(22, i2.exports.main(1));
assertThrows(() => i1.exports.main(2));
assertThrows(() => i2.exports.main(2));
assertThrows(() => i1.exports.main(3));
assertThrows(() => i2.exports.main(3));
assertTraps(kTrapFuncSigMismatch, () => i1.exports.main(2));
assertTraps(kTrapFuncSigMismatch, () => i2.exports.main(2));
assertTraps(kTrapFuncInvalid, () => i1.exports.main(3));
assertTraps(kTrapFuncInvalid, () => i2.exports.main(3));
})();
(function MismatchedTableSize() {
......@@ -388,14 +387,14 @@ function js_div(a, b) { return (a / b) | 0; }
assertEquals(i, table.length);
for (var j = 0; j < i; j++) table.set(j, null);
for (var j = 0; j < i; j++) assertEquals(null, table.get(j));
assertThrows(() => table.set(i, null));
assertThrows(() => table.get(i));
assertThrows(() => table.set(i, null), RangeError);
assertThrows(() => table.get(i), RangeError);
assertEquals(i, table.grow(5));
}
assertEquals(30, table.length);
assertThrows(() => table.grow(1));
assertThrows(() => table.set(kMaxSize, null));
assertThrows(() => table.get(kMaxSize));
assertThrows(() => table.grow(1), RangeError);
assertThrows(() => table.set(kMaxSize, null), RangeError);
assertThrows(() => table.get(kMaxSize), RangeError);
})();
(function CumulativeGrowTest() {
......@@ -456,7 +455,7 @@ function js_div(a, b) { return (a / b) | 0; }
assertEquals("function", typeof func);
assertSame(new_func, table.get(j));
}
assertThrows(() => table.grow(11));
assertThrows(() => table.grow(11), RangeError);
})();
......@@ -467,15 +466,15 @@ function js_div(a, b) { return (a / b) | 0; }
// initial size is too large
assertThrows(() => builder.instantiate({t: {t: new WebAssembly.Table(
{element: "anyfunc", initial: 3, maximum: 3})}}));
{element: "anyfunc", initial: 3, maximum: 3})}}), WebAssembly.LinkError);
// maximum size is too large
assertThrows(() => builder.instantiate({t: {t: new WebAssembly.Table(
{element: "anyfunc", initial: 1, maximum: 4})}}));
{element: "anyfunc", initial: 1, maximum: 4})}}), WebAssembly.LinkError);
// no maximum
assertThrows(() => builder.instantiate({t: {t: new WebAssembly.Table(
{element: "anyfunc", initial: 1})}}));
{element: "anyfunc", initial: 1})}}), WebAssembly.LinkError);
})();
(function TableImportLargerThanCompiled() {
......@@ -489,7 +488,7 @@ function js_div(a, b) { return (a / b) | 0; }
let instance = new WebAssembly.Instance(module, {x: {base: 1, table: table}});
for (var i = 0; i < kInitSize; ++i) table.set(i, null);
for (var i = 0; i < kInitSize; ++i) assertEquals(null, table.get(i));
assertThrows(() => table.set(kInitSize, null));
assertThrows(() => table.set(kInitSize, null), RangeError);
})();
(function ModulesShareTableAndGrow() {
......@@ -515,13 +514,13 @@ function js_div(a, b) { return (a / b) | 0; }
for (var i = 0; i < kInitSize; ++i) table.set(i, null);
for (var i = 0; i < kInitSize; ++i) assertEquals(null, table.get(i));
assertThrows(() => table.set(kInitSize, null));
assertThrows(() => table.set(kInitSize, null), RangeError);
assertEquals(kInitSize, table.grow(5));
for (var i = 0; i < 2*kInitSize; ++i) table.set(i, null);
for (var i = 0; i < 2*kInitSize; ++i) assertEquals(null, table.get(i));
assertThrows(() => table.set(2*kInitSize, null));
assertThrows(() => table.set(2*kInitSize, null), RangeError);
// Try to grow past imported maximum
assertThrows(() => table.grow(21));
assertThrows(() => table.grow(21), RangeError);
})();
(function MultipleElementSegments() {
......@@ -602,3 +601,67 @@ function js_div(a, b) { return (a / b) | 0; }
() => instance0.exports.main(0), WebAssembly.RuntimeError,
/signature mismatch/);
})();
(function ModulesInstancesSharedTableBoundsCheck() {
print("ModulesInstancesSharedTableBoundsCheck");
let table = new WebAssembly.Table({element: "anyfunc",
initial: 1, maximum:1000000});
function CallModuleBuilder() {
var builder = new WasmModuleBuilder();
builder.addType(kSig_i_v);
builder.addType(kSig_v_v);
let index_i_ii = builder.addType(kSig_i_ii);
let index_i_i = builder.addType(kSig_i_i);
builder.addImportedTable("x", "table", 1, 10000000);
builder.addFunction("add", index_i_ii)
.addBody([
kExprGetLocal, 0,
kExprGetLocal, 1,
kExprI32Add]);
builder.addFunction("main", index_i_i)
.addBody([
kExprI32Const, 5,
kExprI32Const, 5,
kExprGetLocal, 0,
kExprCallIndirect, index_i_ii, kTableZero])
.exportAs("main");
builder.addFunctionTableInit(0, false, [0], true);
return new WebAssembly.Module(builder.toBuffer());
}
var instances = [], modules = [];
modules[0] = CallModuleBuilder();
modules[1] = CallModuleBuilder();
// Modules[0] shared by instances[0..2], modules[1] shared by instances[3, 4]
instances[0] = new WebAssembly.Instance(modules[0], {x: {table:table}});
instances[1] = new WebAssembly.Instance(modules[0], {x: {table:table}});
instances[2] = new WebAssembly.Instance(modules[0], {x: {table:table}});
instances[3] = new WebAssembly.Instance(modules[1], {x: {table:table}});
instances[4] = new WebAssembly.Instance(modules[1], {x: {table:table}});
function VerifyTableBoundsCheck(size) {
print("Verifying bounds for size = " + size);
assertEquals(size, table.length);
for (let i = 0; i < 5; i++) {
// Sanity check for indirect call
assertEquals(10, instances[i].exports.main(0));
// Bounds check at different out of bounds indices
assertInvalidFunction = function(s) {
assertThrows(
() => instances[i].exports.main(s), WebAssembly.RuntimeError,
/invalid function/);
}
assertInvalidFunction(size);
assertInvalidFunction(size + 1);
assertInvalidFunction(size + 1000);
assertInvalidFunction(2 * size);
}
}
for (let i = 0; i < 4; i++) {
VerifyTableBoundsCheck(99900 * i + 1);
table.grow(99900);
}
})();
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