From c459d8ea5d402c702948c860d9497b2230ff7e8a Mon Sep 17 00:00:00 2001 From: Michaƫl Zasso Date: Tue, 21 Mar 2017 10:16:54 +0100 Subject: deps: update V8 to 5.7.492.69 PR-URL: https://github.com/nodejs/node/pull/11752 Reviewed-By: Ben Noordhuis Reviewed-By: Franziska Hinkelmann --- deps/v8/src/asmjs/OWNERS | 1 + deps/v8/src/asmjs/asm-js.cc | 129 ++++++++-- deps/v8/src/asmjs/asm-js.h | 4 +- deps/v8/src/asmjs/asm-typer.cc | 407 +++++++++++++++++------------ deps/v8/src/asmjs/asm-typer.h | 80 +++++- deps/v8/src/asmjs/asm-types.cc | 1 + deps/v8/src/asmjs/asm-wasm-builder.cc | 465 ++++++++++++++++++++++------------ deps/v8/src/asmjs/asm-wasm-builder.h | 14 +- 8 files changed, 735 insertions(+), 366 deletions(-) (limited to 'deps/v8/src/asmjs') diff --git a/deps/v8/src/asmjs/OWNERS b/deps/v8/src/asmjs/OWNERS index 78e688d86e..b994be3e17 100644 --- a/deps/v8/src/asmjs/OWNERS +++ b/deps/v8/src/asmjs/OWNERS @@ -4,6 +4,7 @@ set noparent ahaas@chromium.org bradnelson@chromium.org +clemensh@chromium.org jpp@chromium.org mtrofin@chromium.org rossberg@chromium.org diff --git a/deps/v8/src/asmjs/asm-js.cc b/deps/v8/src/asmjs/asm-js.cc index 13f936d0b5..b4026b0b19 100644 --- a/deps/v8/src/asmjs/asm-js.cc +++ b/deps/v8/src/asmjs/asm-js.cc @@ -9,6 +9,7 @@ #include "src/asmjs/asm-typer.h" #include "src/asmjs/asm-wasm-builder.h" #include "src/assert-scope.h" +#include "src/compilation-info.h" #include "src/execution.h" #include "src/factory.h" #include "src/handles.h" @@ -31,6 +32,15 @@ namespace v8 { namespace internal { namespace { +enum WasmDataEntries { + kWasmDataCompiledModule, + kWasmDataForeignGlobals, + kWasmDataUsesArray, + kWasmDataScript, + kWasmDataScriptPosition, + kWasmDataEntryCount, +}; + Handle StdlibMathMember(i::Isolate* isolate, Handle stdlib, Handle name) { @@ -151,29 +161,38 @@ bool IsStdlibMemberValid(i::Isolate* isolate, Handle stdlib, } // namespace -MaybeHandle AsmJs::ConvertAsmToWasm(ParseInfo* info) { +MaybeHandle AsmJs::CompileAsmViaWasm(CompilationInfo* info) { ErrorThrower thrower(info->isolate(), "Asm.js -> WebAssembly conversion"); - wasm::AsmTyper typer(info->isolate(), info->zone(), *(info->script()), - info->literal()); - if (!typer.Validate()) { + base::ElapsedTimer asm_wasm_timer; + asm_wasm_timer.Start(); + wasm::AsmWasmBuilder builder(info); + Handle foreign_globals; + auto asm_wasm_result = builder.Run(&foreign_globals); + if (!asm_wasm_result.success) { DCHECK(!info->isolate()->has_pending_exception()); - PrintF("Validation of asm.js module failed: %s", typer.error_message()); + if (!FLAG_suppress_asm_messages) { + MessageHandler::ReportMessage(info->isolate(), + builder.typer()->message_location(), + builder.typer()->error_message()); + } return MaybeHandle(); } - v8::internal::wasm::AsmWasmBuilder builder(info->isolate(), info->zone(), - info->literal(), &typer); - i::Handle foreign_globals; - auto asm_wasm_result = builder.Run(&foreign_globals); + 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; + Vector asm_offsets_vec(asm_offsets->begin(), + static_cast(asm_offsets->size())); - i::MaybeHandle compiled = wasm::CreateModuleObjectFromBytes( + base::ElapsedTimer compile_timer; + compile_timer.Start(); + MaybeHandle compiled = wasm::CreateModuleObjectFromBytes( info->isolate(), module->begin(), module->end(), &thrower, - internal::wasm::kAsmJsOrigin, info->script(), asm_offsets->begin(), - asm_offsets->end()); + internal::wasm::kAsmJsOrigin, info->script(), asm_offsets_vec); DCHECK(!compiled.is_null()); + double compile_time = compile_timer.Elapsed().InMillisecondsF(); - wasm::AsmTyper::StdlibSet uses = typer.StdlibUses(); + wasm::AsmTyper::StdlibSet uses = builder.typer()->StdlibUses(); Handle uses_array = info->isolate()->factory()->NewFixedArray(static_cast(uses.size())); int count = 0; @@ -181,16 +200,45 @@ MaybeHandle AsmJs::ConvertAsmToWasm(ParseInfo* info) { uses_array->set(count++, Smi::FromInt(i)); } - Handle result = info->isolate()->factory()->NewFixedArray(3); - result->set(0, *compiled.ToHandleChecked()); - result->set(1, *foreign_globals); - result->set(2, *uses_array); + Handle 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; + if (FLAG_predictable) { + length = base::OS::SNPrintF(text, arraysize(text), "success"); + } else { + length = + base::OS::SNPrintF(text, arraysize(text), + "success, asm->wasm: %0.3f ms, compile: %0.3f ms", + asm_wasm_time, compile_time); + } + DCHECK_NE(-1, length); + USE(length); + Handle stext(info->isolate()->factory()->InternalizeUtf8String(text)); + Handle message = MessageHandler::MakeMessageObject( + info->isolate(), MessageTemplate::kAsmJsCompiled, &location, stext, + Handle::null()); + message->set_error_level(v8::Isolate::kMessageInfo); + if (!FLAG_suppress_asm_messages && FLAG_trace_asm_time) { + MessageHandler::ReportMessage(info->isolate(), &location, message); + } + return result; } bool AsmJs::IsStdlibValid(i::Isolate* isolate, Handle wasm_data, Handle stdlib) { - i::Handle uses(i::FixedArray::cast(wasm_data->get(2))); + i::Handle uses( + i::FixedArray::cast(wasm_data->get(kWasmDataUsesArray))); for (int i = 0; i < uses->length(); ++i) { if (!IsStdlibMemberValid(isolate, stdlib, uses->GetValueChecked(isolate, i))) { @@ -204,14 +252,27 @@ MaybeHandle AsmJs::InstantiateAsmWasm(i::Isolate* isolate, Handle wasm_data, Handle memory, Handle foreign) { - i::Handle module(i::JSObject::cast(wasm_data->get(0))); + base::ElapsedTimer instantiate_timer; + instantiate_timer.Start(); + i::Handle module( + i::WasmModuleObject::cast(wasm_data->get(kWasmDataCompiledModule))); i::Handle foreign_globals( - i::FixedArray::cast(wasm_data->get(1))); + i::FixedArray::cast(wasm_data->get(kWasmDataForeignGlobals))); ErrorThrower thrower(isolate, "Asm.js -> WebAssembly instantiation"); + // Create the ffi object for foreign functions {"": foreign}. + Handle ffi_object; + if (!foreign.is_null()) { + Handle object_function = Handle( + isolate->native_context()->object_function(), isolate); + ffi_object = isolate->factory()->NewJSObject(object_function); + JSObject::AddProperty(ffi_object, isolate->factory()->empty_string(), + foreign, NONE); + } + i::MaybeHandle maybe_module_object = - i::wasm::WasmModule::Instantiate(isolate, &thrower, module, foreign, + i::wasm::WasmModule::Instantiate(isolate, &thrower, module, ffi_object, memory); if (maybe_module_object.is_null()) { return MaybeHandle(); @@ -258,6 +319,32 @@ MaybeHandle AsmJs::InstantiateAsmWasm(i::Isolate* isolate, !single_function.ToHandleChecked()->IsUndefined(isolate)) { return single_function; } + + i::Handle 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; + if (FLAG_predictable) { + length = base::OS::SNPrintF(text, arraysize(text), "success"); + } else { + length = base::OS::SNPrintF(text, arraysize(text), "success, %0.3f ms", + instantiate_timer.Elapsed().InMillisecondsF()); + } + DCHECK_NE(-1, length); + USE(length); + Handle stext(isolate->factory()->InternalizeUtf8String(text)); + Handle message = MessageHandler::MakeMessageObject( + isolate, MessageTemplate::kAsmJsInstantiated, &location, stext, + Handle::null()); + message->set_error_level(v8::Isolate::kMessageInfo); + if (!FLAG_suppress_asm_messages && FLAG_trace_asm_time) { + MessageHandler::ReportMessage(isolate, &location, message); + } + return module_object; } diff --git a/deps/v8/src/asmjs/asm-js.h b/deps/v8/src/asmjs/asm-js.h index a2c5cec280..a7795dc541 100644 --- a/deps/v8/src/asmjs/asm-js.h +++ b/deps/v8/src/asmjs/asm-js.h @@ -10,13 +10,13 @@ namespace v8 { namespace internal { +class CompilationInfo; class JSArrayBuffer; -class ParseInfo; // Interface to compile and instantiate for asmjs. class AsmJs { public: - static MaybeHandle ConvertAsmToWasm(ParseInfo* info); + static MaybeHandle CompileAsmViaWasm(CompilationInfo* info); static bool IsStdlibValid(Isolate* isolate, Handle wasm_data, Handle stdlib); static MaybeHandle InstantiateAsmWasm(Isolate* isolate, diff --git a/deps/v8/src/asmjs/asm-typer.cc b/deps/v8/src/asmjs/asm-typer.cc index 55b5fc70d8..2389551872 100644 --- a/deps/v8/src/asmjs/asm-typer.cc +++ b/deps/v8/src/asmjs/asm-typer.cc @@ -9,6 +9,7 @@ #include #include +#include "include/v8.h" #include "src/v8.h" #include "src/asmjs/asm-types.h" @@ -17,18 +18,33 @@ #include "src/base/bits.h" #include "src/codegen.h" #include "src/globals.h" +#include "src/messages.h" #include "src/utils.h" +#include "src/vector.h" + +#define FAIL_LOCATION_RAW(location, msg) \ + do { \ + Handle message( \ + isolate_->factory()->InternalizeOneByteString(msg)); \ + error_message_ = MessageHandler::MakeMessageObject( \ + isolate_, MessageTemplate::kAsmJsInvalid, (location), message, \ + Handle::null()); \ + error_message_->set_error_level(v8::Isolate::kMessageWarning); \ + message_location_ = *(location); \ + return AsmType::None(); \ + } while (false) -#define FAIL(node, msg) \ - do { \ - int line = node->position() == kNoSourcePosition \ - ? -1 \ - : script_->GetLineNumber(node->position()); \ - base::OS::SNPrintF(error_message_, sizeof(error_message_), \ - "asm: line %d: %s\n", line + 1, msg); \ - return AsmType::None(); \ +#define FAIL_RAW(node, msg) \ + do { \ + MessageLocation location(script_, node->position(), node->position()); \ + FAIL_LOCATION_RAW(&location, msg); \ } while (false) +#define FAIL_LOCATION(location, msg) \ + FAIL_LOCATION_RAW(location, STATIC_CHAR_VECTOR(msg)) + +#define FAIL(node, msg) FAIL_RAW(node, STATIC_CHAR_VECTOR(msg)) + #define RECURSE(call) \ do { \ if (GetCurrentStackPosition() < stack_limit_) { \ @@ -90,6 +106,53 @@ Statement* AsmTyper::FlattenedStatements::Next() { } } +// ---------------------------------------------------------------------------- +// Implementation of AsmTyper::SourceLayoutTracker + +bool AsmTyper::SourceLayoutTracker::IsValid() const { + const Section* kAllSections[] = {&use_asm_, &globals_, &functions_, &tables_, + &exports_}; + for (size_t ii = 0; ii < arraysize(kAllSections); ++ii) { + const auto& curr_section = *kAllSections[ii]; + for (size_t jj = ii + 1; jj < arraysize(kAllSections); ++jj) { + if (curr_section.IsPrecededBy(*kAllSections[jj])) { + return false; + } + } + } + return true; +} + +void AsmTyper::SourceLayoutTracker::Section::AddNewElement( + const AstNode& node) { + const int node_pos = node.position(); + if (start_ == kNoSourcePosition) { + start_ = node_pos; + } else { + start_ = std::min(start_, node_pos); + } + if (end_ == kNoSourcePosition) { + end_ = node_pos; + } else { + end_ = std::max(end_, node_pos); + } +} + +bool AsmTyper::SourceLayoutTracker::Section::IsPrecededBy( + const Section& other) const { + if (start_ == kNoSourcePosition) { + DCHECK_EQ(end_, kNoSourcePosition); + return false; + } + if (other.start_ == kNoSourcePosition) { + DCHECK_EQ(other.end_, kNoSourcePosition); + return false; + } + DCHECK_LE(start_, end_); + DCHECK_LE(other.start_, other.end_); + return other.start_ <= end_; +} + // ---------------------------------------------------------------------------- // Implementation of AsmTyper::VariableInfo @@ -112,16 +175,16 @@ AsmTyper::VariableInfo* AsmTyper::VariableInfo::Clone(Zone* zone) const { return new_var_info; } -void AsmTyper::VariableInfo::FirstForwardUseIs(VariableProxy* var) { - DCHECK(first_forward_use_ == nullptr); +void AsmTyper::VariableInfo::SetFirstForwardUse( + const MessageLocation& source_location) { missing_definition_ = true; - first_forward_use_ = var; + source_location_ = source_location; } // ---------------------------------------------------------------------------- // Implementation of AsmTyper -AsmTyper::AsmTyper(Isolate* isolate, Zone* zone, Script* script, +AsmTyper::AsmTyper(Isolate* isolate, Zone* zone, Handle