Commit 85b1f108 authored by mtrofin's avatar mtrofin Committed by Commit bot

Fixed accounting issues due to code table containing imports as well as wasm funcs.

Ensuring we move forward all the deferred handles, in all cases.

BUG=

Review-Url: https://codereview.chromium.org/2807013002
Cr-Commit-Position: refs/heads/master@{#44525}
parent 72d5f384
......@@ -359,7 +359,7 @@ class CompilationHelper {
compilation_units_.push_back(
new compiler::WasmCompilationUnit(isolate_, &module_env, func));
}
return num_funcs;
return funcs_to_compile;
}
void InitializeHandles() {
......@@ -625,9 +625,6 @@ class CompilationHelper {
// object.
Handle<WasmCompiledModule> compiled_module = WasmCompiledModule::New(
isolate_, shared, code_table, function_tables, signature_tables);
if (function_table_count > 0) {
compiled_module->set_function_tables(function_tables);
}
// If we created a wasm script, finish it now and make it public to the
// debugger.
......@@ -2699,6 +2696,17 @@ class AsyncCompileJob {
size_t outstanding_units_ = 0;
size_t num_background_tasks_ = 0;
void ReopenHandlesInDeferredScope() {
DeferredHandleScope deferred(isolate_);
module_wrapper_ = handle(*module_wrapper_, isolate_);
function_tables_ = handle(*function_tables_, isolate_);
signature_tables_ = handle(*signature_tables_, isolate_);
code_table_ = handle(*code_table_, isolate_);
temp_instance_->ReopenHandles(isolate_);
helper_->InitializeHandles();
deferred_handles_.push_back(deferred.Detach());
}
//==========================================================================
// Step 1: (async) Decode the module.
//==========================================================================
......@@ -2787,9 +2795,7 @@ class AsyncCompileJob {
size_t num_functions =
module_->functions.size() - module_->num_imported_functions;
if (num_functions == 0) {
DeferredHandleScope deferred(isolate_);
module_wrapper_ = handle(*module_wrapper_, isolate_);
deferred_handles_.push_back(deferred.Detach());
ReopenHandlesInDeferredScope();
// Degenerate case of an empty module.
return DoSync(&AsyncCompileJob::FinishCompile);
}
......@@ -2807,15 +2813,7 @@ class AsyncCompileJob {
module_->functions, *module_bytes_env_);
// Reopen all handles which should survive in the DeferredHandleScope.
DeferredHandleScope deferred(isolate_);
module_wrapper_ = handle(*module_wrapper_, isolate_);
function_tables_ = handle(*function_tables_, isolate_);
signature_tables_ = handle(*signature_tables_, isolate_);
code_table_ = handle(*code_table_, isolate_);
temp_instance_->ReopenHandles(isolate_);
helper_->InitializeHandles();
deferred_handles_.push_back(deferred.Detach());
ReopenHandlesInDeferredScope();
task_ids_ =
std::unique_ptr<uint32_t[]>(new uint32_t[num_background_tasks_]);
for (size_t i = 0; i < num_background_tasks_; ++i) {
......@@ -2863,7 +2861,7 @@ class AsyncCompileJob {
failed_ = true;
} else {
DCHECK(func_index >= 0);
code_table_->set(func_index + module_->num_imported_functions, *(result));
code_table_->set(func_index, *(result));
}
if (failed_ || --outstanding_units_ == 0) {
// All compilation units are done. We still need to wait for the
......
......@@ -947,6 +947,8 @@ Handle<WasmCompiledModule> WasmCompiledModule::New(
maybe_signature_tables.ToHandleChecked());
compiled_module->set_empty_function_tables(
maybe_empty_function_tables.ToHandleChecked());
compiled_module->set_function_tables(
maybe_empty_function_tables.ToHandleChecked());
}
// TODO(mtrofin): we copy these because the order of finalization isn't
// reliable, and we need these at Reset (which is called at
......
// Copyright 2017 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');
let importingModuleBinary1 = (() => {
var builder = new WasmModuleBuilder();
builder.addImport('', 'f', kSig_i_v);
return new Int8Array(builder.toBuffer());
})();
let importingModuleBinary2 = (() => {
var builder = new WasmModuleBuilder();
builder.addImport('', 'f', kSig_i_v);
builder.addFunction('g', kSig_v_v)
.addBody([kExprNop]);
return new Int8Array(builder.toBuffer());
})();
let importingModuleBinary3 = (() => {
var builder = new WasmModuleBuilder();
builder.addImport('', 'f', kSig_i_v);
builder.addImport('', 'f2', kSig_i_v);
builder.addFunction('g', kSig_v_v)
.addBody([kExprNop]);
return new Int8Array(builder.toBuffer());
})();
let importingModuleBinary4 = (() => {
var builder = new WasmModuleBuilder();
builder.addFunction('g', kSig_v_v)
.addBody([kExprNop]);
return new Int8Array(builder.toBuffer());
})();
const complexImportingModuleBinary1 = (() => {
let builder = new WasmModuleBuilder();
builder.addImport('a', 'b', kSig_v_v);
builder.addImportedMemory('c', 'd', 1);
builder.addImportedTable('e', 'f', 1);
builder.addImportedGlobal('g', '⚡', kWasmI32);
builder.addFunction('g', kSig_v_v)
.addBody([kExprNop]);
return builder.toBuffer();
})();
const complexImportingModuleBinary2 = (() => {
let builder = new WasmModuleBuilder();
builder.addImport('a', 'b', kSig_v_v);
builder.addImportedMemory('c', 'd', 1);
builder.addImportedTable('e', 'f', 1);
builder.addImportedGlobal('g', '⚡', kWasmI32);
builder.addFunction('g', kSig_v_v)
.addBody([kExprNop]);
return builder.toBuffer();
})();
var tests = [
importingModuleBinary1,
importingModuleBinary2,
importingModuleBinary3,
importingModuleBinary4,
complexImportingModuleBinary1,
complexImportingModuleBinary2
];
for (var index in tests) {
assertPromiseResult(
WebAssembly.compile(tests[index]),
m => assertTrue(m instanceof WebAssembly.Module),
assertUnreachable);
}
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