Commit cb944691 authored by Michael Starzinger's avatar Michael Starzinger Committed by Commit Bot

[asm.js] Report module linking failures to the console.

This adds reporting of linking failures (i.e. module instantiation)
similar to the existing reporting for validation failures. Note that
the messages in question are deterministic and can be tested.

R=clemensh@chromium.org

Change-Id: Ibecebefb86f1d878f626702c05fd0cb21189dc2a
Reviewed-on: https://chromium-review.googlesource.com/507488
Commit-Queue: Michael Starzinger <mstarzinger@chromium.org>
Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Reviewed-by: 's avatarJochen Eisinger <jochen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#45421}
parent 822442f0
...@@ -157,6 +157,15 @@ void ReportInstantiationSuccess(Handle<Script> script, int position, ...@@ -157,6 +157,15 @@ void ReportInstantiationSuccess(Handle<Script> script, int position,
v8::Isolate::kMessageInfo); v8::Isolate::kMessageInfo);
} }
// Hook to report failed execution of {AsmJs::InstantiateAsmWasm} phase.
void ReportInstantiationFailure(Handle<Script> script, int position,
const char* reason) {
if (FLAG_suppress_asm_messages) return;
Vector<const char> text = CStrVector(reason);
Report(script, position, text, MessageTemplate::kAsmJsLinkingFailed,
v8::Isolate::kMessageWarning);
}
} // namespace } // namespace
MaybeHandle<FixedArray> AsmJs::CompileAsmViaWasm(CompilationInfo* info) { MaybeHandle<FixedArray> AsmJs::CompileAsmViaWasm(CompilationInfo* info) {
...@@ -256,16 +265,24 @@ MaybeHandle<Object> AsmJs::InstantiateAsmWasm(Isolate* isolate, ...@@ -256,16 +265,24 @@ MaybeHandle<Object> AsmJs::InstantiateAsmWasm(Isolate* isolate,
FixedArray::cast(wasm_data->get(kWasmDataUsesArray))); FixedArray::cast(wasm_data->get(kWasmDataUsesArray)));
Handle<WasmModuleObject> module( Handle<WasmModuleObject> module(
WasmModuleObject::cast(wasm_data->get(kWasmDataCompiledModule))); WasmModuleObject::cast(wasm_data->get(kWasmDataCompiledModule)));
Handle<Script> script(Script::cast(shared->script()));
// TODO(mstarzinger): The position currently points to the module definition
// but should instead point to the instantiation site (more intuitive).
int position = shared->start_position();
// Check that all used stdlib members are valid. // Check that all used stdlib members are valid.
bool stdlib_use_of_typed_array_present = false; bool stdlib_use_of_typed_array_present = false;
for (int i = 0; i < stdlib_uses->length(); ++i) { for (int i = 0; i < stdlib_uses->length(); ++i) {
if (stdlib.is_null()) return MaybeHandle<Object>(); if (stdlib.is_null()) {
ReportInstantiationFailure(script, position, "Requires standard library");
return MaybeHandle<Object>();
}
int member_id = Smi::cast(stdlib_uses->get(i))->value(); int member_id = Smi::cast(stdlib_uses->get(i))->value();
wasm::AsmJsParser::StandardMember member = wasm::AsmJsParser::StandardMember member =
static_cast<wasm::AsmJsParser::StandardMember>(member_id); static_cast<wasm::AsmJsParser::StandardMember>(member_id);
if (!IsStdlibMemberValid(isolate, stdlib, member, if (!IsStdlibMemberValid(isolate, stdlib, member,
&stdlib_use_of_typed_array_present)) { &stdlib_use_of_typed_array_present)) {
ReportInstantiationFailure(script, position, "Unexpected stdlib member");
return MaybeHandle<Object>(); return MaybeHandle<Object>();
} }
} }
...@@ -282,11 +299,15 @@ MaybeHandle<Object> AsmJs::InstantiateAsmWasm(Isolate* isolate, ...@@ -282,11 +299,15 @@ MaybeHandle<Object> AsmJs::InstantiateAsmWasm(Isolate* isolate,
// Check that a valid heap buffer is provided if required. // Check that a valid heap buffer is provided if required.
if (stdlib_use_of_typed_array_present) { if (stdlib_use_of_typed_array_present) {
if (memory.is_null()) return MaybeHandle<Object>(); if (memory.is_null()) {
ReportInstantiationFailure(script, position, "Requires heap buffer");
return MaybeHandle<Object>();
}
size_t size = NumberToSize(memory->byte_length()); size_t size = NumberToSize(memory->byte_length());
// TODO(mstarzinger): We currently only limit byte length of the buffer to // TODO(mstarzinger): We currently only limit byte length of the buffer to
// be a multiple of 8, we should enforce the stricter spec limits here. // be a multiple of 8, we should enforce the stricter spec limits here.
if (size % FixedTypedArrayBase::kMaxElementSize != 0) { if (size % FixedTypedArrayBase::kMaxElementSize != 0) {
ReportInstantiationFailure(script, position, "Unexpected heap size");
return MaybeHandle<Object>(); return MaybeHandle<Object>();
} }
} }
...@@ -296,13 +317,12 @@ MaybeHandle<Object> AsmJs::InstantiateAsmWasm(Isolate* isolate, ...@@ -296,13 +317,12 @@ MaybeHandle<Object> AsmJs::InstantiateAsmWasm(Isolate* isolate,
wasm::SyncInstantiate(isolate, &thrower, module, ffi_object, memory); wasm::SyncInstantiate(isolate, &thrower, module, ffi_object, memory);
if (maybe_module_object.is_null()) { if (maybe_module_object.is_null()) {
thrower.Reset(); // Ensure exceptions do not propagate. thrower.Reset(); // Ensure exceptions do not propagate.
ReportInstantiationFailure(script, position, "Internal wasm failure");
return MaybeHandle<Object>(); return MaybeHandle<Object>();
} }
DCHECK(!thrower.error()); DCHECK(!thrower.error());
Handle<Object> module_object = maybe_module_object.ToHandleChecked(); Handle<Object> module_object = maybe_module_object.ToHandleChecked();
Handle<Script> script(Script::cast(shared->script()));
int position = shared->start_position();
ReportInstantiationSuccess(script, position, ReportInstantiationSuccess(script, position,
instantiate_timer.Elapsed().InMillisecondsF()); instantiate_timer.Elapsed().InMillisecondsF());
......
...@@ -694,6 +694,7 @@ class ErrorUtils : public AllStatic { ...@@ -694,6 +694,7 @@ class ErrorUtils : public AllStatic {
T(AsmJsInvalid, "Invalid asm.js: %") \ T(AsmJsInvalid, "Invalid asm.js: %") \
T(AsmJsCompiled, "Converted asm.js to WebAssembly: %") \ T(AsmJsCompiled, "Converted asm.js to WebAssembly: %") \
T(AsmJsInstantiated, "Instantiated asm.js: %") \ T(AsmJsInstantiated, "Instantiated asm.js: %") \
T(AsmJsLinkingFailed, "Linking failure in asm.js: %") \
/* DataCloneError messages */ \ /* DataCloneError messages */ \
T(DataCloneError, "% could not be cloned.") \ T(DataCloneError, "% could not be cloned.") \
T(DataCloneErrorOutOfMemory, "Data cannot be cloned, out of memory.") \ T(DataCloneErrorOutOfMemory, "Data cannot be cloned, out of memory.") \
......
// 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: --validate-asm --no-stress-opt --no-stress-validate-asm --no-suppress-asm-messages
function Module(stdlib, foreign, heap) {
"use asm"
var a = new stdlib.Int8Array(heap);
function f() {
return a[0] | 0;
}
return { f:f };
}
Module(this, {}, new ArrayBuffer(1)).f();
# 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.
*%(basename)s:7: Linking failure in asm.js: Unexpected heap size
// 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: --validate-asm --no-stress-opt --no-stress-validate-asm --no-suppress-asm-messages
function Module(stdlib, foreign, heap) {
"use asm"
var pi = stdlib.Math.PI;
function f() {
return +pi;
}
return { f:f };
}
Module({ Math: { PI:23 }}).f();
# 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.
*%(basename)s:7: Linking failure in asm.js: Unexpected stdlib member
// 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: --validate-asm --no-stress-opt --no-stress-validate-asm --no-suppress-asm-messages
function Module(stdlib, foreign, heap) {
"use asm"
var a = new stdlib.Int8Array(heap);
function f() {
return a[0] | 0;
}
return { f:f };
}
Module(this).f();
# 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.
*%(basename)s:7: Linking failure in asm.js: Requires heap buffer
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