Commit 21255208 authored by bradnelson's avatar bradnelson Committed by Commit bot

[wasm][asm.js] Adding timing info message about asm.js

Adding timing info going to the console about asm.js

Rename ConvertAsmToWasm -> CompileAsmViaWasm, to be more precise.
Add enum for wasm data elements.

BUG=v8:4203
R=titzer@chromium.org,yangguo@chromium.org

Review-Url: https://codereview.chromium.org/2577453003
Cr-Commit-Position: refs/heads/master@{#41695}
parent 33480daa
......@@ -31,6 +31,15 @@ namespace v8 {
namespace internal {
namespace {
enum WasmDataEntries {
kWasmDataCompiledModule,
kWasmDataForeignGlobals,
kWasmDataUsesArray,
kWasmDataScript,
kWasmDataScriptPosition,
kWasmDataEntryCount,
};
Handle<i::Object> StdlibMathMember(i::Isolate* isolate,
Handle<JSReceiver> stdlib,
Handle<Name> name) {
......@@ -151,8 +160,10 @@ bool IsStdlibMemberValid(i::Isolate* isolate, Handle<JSReceiver> stdlib,
} // namespace
MaybeHandle<FixedArray> AsmJs::ConvertAsmToWasm(ParseInfo* info) {
MaybeHandle<FixedArray> AsmJs::CompileAsmViaWasm(ParseInfo* info) {
ErrorThrower thrower(info->isolate(), "Asm.js -> WebAssembly conversion");
base::ElapsedTimer asm_wasm_timer;
asm_wasm_timer.Start();
wasm::AsmWasmBuilder builder(info->isolate(), info->zone(),
info->ast_value_factory(), info->script(),
info->literal());
......@@ -165,14 +176,19 @@ MaybeHandle<FixedArray> AsmJs::ConvertAsmToWasm(ParseInfo* info) {
builder.typer()->error_message());
return MaybeHandle<FixedArray>();
}
double asm_wasm_time = asm_wasm_timer.Elapsed().InMillisecondsF();
wasm::ZoneBuffer* module = asm_wasm_result.module_bytes;
wasm::ZoneBuffer* asm_offsets = asm_wasm_result.asm_offset_table;
base::ElapsedTimer compile_timer;
compile_timer.Start();
MaybeHandle<JSObject> compiled = wasm::CreateModuleObjectFromBytes(
info->isolate(), module->begin(), module->end(), &thrower,
internal::wasm::kAsmJsOrigin, info->script(), asm_offsets->begin(),
asm_offsets->end());
DCHECK(!compiled.is_null());
double compile_time = compile_timer.Elapsed().InMillisecondsF();
wasm::AsmTyper::StdlibSet uses = builder.typer()->StdlibUses();
Handle<FixedArray> uses_array =
......@@ -182,16 +198,37 @@ MaybeHandle<FixedArray> AsmJs::ConvertAsmToWasm(ParseInfo* info) {
uses_array->set(count++, Smi::FromInt(i));
}
Handle<FixedArray> result = info->isolate()->factory()->NewFixedArray(3);
result->set(0, *compiled.ToHandleChecked());
result->set(1, *foreign_globals);
result->set(2, *uses_array);
Handle<FixedArray> result =
info->isolate()->factory()->NewFixedArray(kWasmDataEntryCount);
result->set(kWasmDataCompiledModule, *compiled.ToHandleChecked());
result->set(kWasmDataForeignGlobals, *foreign_globals);
result->set(kWasmDataUsesArray, *uses_array);
result->set(kWasmDataScript, *info->script());
result->set(kWasmDataScriptPosition,
Smi::FromInt(info->literal()->position()));
MessageLocation location(info->script(), info->literal()->position(),
info->literal()->position());
char text[100];
int length = base::OS::SNPrintF(text, arraysize(text),
"asm->wasm: %0.3f ms, compile: %0.3f ms",
asm_wasm_time, compile_time);
DCHECK_NE(-1, length);
USE(length);
Handle<String> stext(info->isolate()->factory()->InternalizeUtf8String(text));
Handle<JSMessageObject> message = MessageHandler::MakeMessageObject(
info->isolate(), MessageTemplate::kAsmJsCompiled, &location, stext,
Handle<JSArray>::null());
message->set_error_level(v8::Isolate::kMessageInfo);
MessageHandler::ReportMessage(info->isolate(), &location, message);
return result;
}
bool AsmJs::IsStdlibValid(i::Isolate* isolate, Handle<FixedArray> wasm_data,
Handle<JSReceiver> stdlib) {
i::Handle<i::FixedArray> uses(i::FixedArray::cast(wasm_data->get(2)));
i::Handle<i::FixedArray> uses(
i::FixedArray::cast(wasm_data->get(kWasmDataUsesArray)));
for (int i = 0; i < uses->length(); ++i) {
if (!IsStdlibMemberValid(isolate, stdlib,
uses->GetValueChecked<i::Object>(isolate, i))) {
......@@ -205,9 +242,12 @@ MaybeHandle<Object> AsmJs::InstantiateAsmWasm(i::Isolate* isolate,
Handle<FixedArray> wasm_data,
Handle<JSArrayBuffer> memory,
Handle<JSReceiver> foreign) {
i::Handle<i::JSObject> module(i::JSObject::cast(wasm_data->get(0)));
base::ElapsedTimer instantiate_timer;
instantiate_timer.Start();
i::Handle<i::JSObject> module(
i::JSObject::cast(wasm_data->get(kWasmDataCompiledModule)));
i::Handle<i::FixedArray> foreign_globals(
i::FixedArray::cast(wasm_data->get(1)));
i::FixedArray::cast(wasm_data->get(kWasmDataForeignGlobals)));
ErrorThrower thrower(isolate, "Asm.js -> WebAssembly instantiation");
......@@ -259,6 +299,26 @@ MaybeHandle<Object> AsmJs::InstantiateAsmWasm(i::Isolate* isolate,
!single_function.ToHandleChecked()->IsUndefined(isolate)) {
return single_function;
}
i::Handle<i::Script> script(i::Script::cast(wasm_data->get(kWasmDataScript)));
int32_t position = 0;
if (!wasm_data->get(kWasmDataScriptPosition)->ToInt32(&position)) {
UNREACHABLE();
}
MessageLocation location(script, position, position);
char text[50];
int length =
base::OS::SNPrintF(text, arraysize(text), "%0.3f ms",
instantiate_timer.Elapsed().InMillisecondsF());
DCHECK_NE(-1, length);
USE(length);
Handle<String> stext(isolate->factory()->InternalizeUtf8String(text));
Handle<JSMessageObject> message = MessageHandler::MakeMessageObject(
isolate, MessageTemplate::kAsmJsInstantiated, &location, stext,
Handle<JSArray>::null());
message->set_error_level(v8::Isolate::kMessageInfo);
MessageHandler::ReportMessage(isolate, &location, message);
return module_object;
}
......
......@@ -16,7 +16,7 @@ class ParseInfo;
// Interface to compile and instantiate for asmjs.
class AsmJs {
public:
static MaybeHandle<FixedArray> ConvertAsmToWasm(ParseInfo* info);
static MaybeHandle<FixedArray> CompileAsmViaWasm(ParseInfo* info);
static bool IsStdlibValid(Isolate* isolate, Handle<FixedArray> wasm_data,
Handle<JSReceiver> stdlib);
static MaybeHandle<Object> InstantiateAsmWasm(Isolate* isolate,
......
......@@ -430,7 +430,7 @@ bool GenerateUnoptimizedCode(CompilationInfo* info) {
!info->shared_info()->is_asm_wasm_broken() && !info->is_debug()) {
EnsureFeedbackMetadata(info);
MaybeHandle<FixedArray> wasm_data;
wasm_data = AsmJs::ConvertAsmToWasm(info->parse_info());
wasm_data = AsmJs::CompileAsmViaWasm(info->parse_info());
if (!wasm_data.is_null()) {
info->shared_info()->set_asm_wasm_data(*wasm_data.ToHandleChecked());
info->SetCode(info->isolate()->builtins()->InstantiateAsmJs());
......
......@@ -669,8 +669,10 @@ class ErrorUtils : public AllStatic {
T(WasmTrapFuncSigMismatch, "function signature mismatch") \
T(WasmTrapInvalidIndex, "invalid index into function table") \
T(WasmTrapTypeError, "invalid type") \
/* Asm.js validation warnings */ \
/* Asm.js validation related */ \
T(AsmJsInvalid, "Invalid asm.js: %") \
T(AsmJsCompiled, "Converted asm.js to WebAssembly: %") \
T(AsmJsInstantiated, "Instantiated asm.js: %") \
/* DataCloneError messages */ \
T(DataCloneError, "% could not be cloned.") \
T(DataCloneErrorNeuteredArrayBuffer, \
......
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