Commit 3a9e4d80 authored by Michael Starzinger's avatar Michael Starzinger Committed by Commit Bot

[asm.js] Cleanup asm.js instantiation API.

This refactors the {AsmJs} methods used for instantiating an asm.js
module to only use one single entry point. It is in preparation to
validate the "memory" argument as well.

R=clemensh@chromium.org
BUG=chromium:715505

Change-Id: I5e26fcf46f98c053080c70b26c0f562afc7f794a
Reviewed-on: https://chromium-review.googlesource.com/488226
Commit-Queue: Michael Starzinger <mstarzinger@chromium.org>
Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#44922}
parent 216e677a
...@@ -63,12 +63,8 @@ Handle<Object> StdlibMathMember(Isolate* isolate, Handle<JSReceiver> stdlib, ...@@ -63,12 +63,8 @@ Handle<Object> StdlibMathMember(Isolate* isolate, Handle<JSReceiver> stdlib,
} }
bool IsStdlibMemberValid(Isolate* isolate, Handle<JSReceiver> stdlib, bool IsStdlibMemberValid(Isolate* isolate, Handle<JSReceiver> stdlib,
Handle<Object> member_id) { wasm::AsmTyper::StandardMember member) {
int32_t member_kind; switch (member) {
if (!member_id->ToInt32(&member_kind)) {
UNREACHABLE();
}
switch (static_cast<wasm::AsmTyper::StandardMember>(member_kind)) {
case wasm::AsmTyper::StandardMember::kNone: case wasm::AsmTyper::StandardMember::kNone:
case wasm::AsmTyper::StandardMember::kModule: case wasm::AsmTyper::StandardMember::kModule:
case wasm::AsmTyper::StandardMember::kStdlib: case wasm::AsmTyper::StandardMember::kStdlib:
...@@ -286,29 +282,30 @@ MaybeHandle<FixedArray> AsmJs::CompileAsmViaWasm(CompilationInfo* info) { ...@@ -286,29 +282,30 @@ MaybeHandle<FixedArray> AsmJs::CompileAsmViaWasm(CompilationInfo* info) {
return result; return result;
} }
bool AsmJs::IsStdlibValid(Isolate* isolate, Handle<FixedArray> wasm_data,
Handle<JSReceiver> stdlib) {
Handle<FixedArray> uses(FixedArray::cast(wasm_data->get(kWasmDataUsesArray)));
for (int i = 0; i < uses->length(); ++i) {
if (!IsStdlibMemberValid(isolate, stdlib,
uses->GetValueChecked<Object>(isolate, i))) {
return false;
}
}
return true;
}
MaybeHandle<Object> AsmJs::InstantiateAsmWasm(Isolate* isolate, MaybeHandle<Object> AsmJs::InstantiateAsmWasm(Isolate* isolate,
Handle<FixedArray> wasm_data, Handle<FixedArray> wasm_data,
Handle<JSArrayBuffer> memory, Handle<JSReceiver> stdlib,
Handle<JSReceiver> foreign) { Handle<JSReceiver> foreign,
Handle<JSArrayBuffer> memory) {
base::ElapsedTimer instantiate_timer; base::ElapsedTimer instantiate_timer;
instantiate_timer.Start(); instantiate_timer.Start();
Handle<FixedArray> stdlib_uses(
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<FixedArray> foreign_globals( Handle<FixedArray> foreign_globals(
FixedArray::cast(wasm_data->get(kWasmDataForeignGlobals))); FixedArray::cast(wasm_data->get(kWasmDataForeignGlobals)));
// Check that all used stdlib members are valid.
for (int i = 0; i < stdlib_uses->length(); ++i) {
int member_id = Smi::cast(stdlib_uses->get(i))->value();
wasm::AsmTyper::StandardMember member =
static_cast<wasm::AsmTyper::StandardMember>(member_id);
if (!IsStdlibMemberValid(isolate, stdlib, member)) {
return MaybeHandle<Object>();
}
}
// Create the ffi object for foreign functions {"": foreign}. // Create the ffi object for foreign functions {"": foreign}.
Handle<JSObject> ffi_object; Handle<JSObject> ffi_object;
if (!foreign.is_null()) { if (!foreign.is_null()) {
......
...@@ -13,18 +13,18 @@ namespace internal { ...@@ -13,18 +13,18 @@ namespace internal {
class CompilationInfo; class CompilationInfo;
class JSArrayBuffer; class JSArrayBuffer;
// Interface to compile and instantiate for asmjs. // Interface to compile and instantiate for asm.js modules.
class AsmJs { class AsmJs {
public: public:
static MaybeHandle<FixedArray> CompileAsmViaWasm(CompilationInfo* info); static MaybeHandle<FixedArray> CompileAsmViaWasm(CompilationInfo* info);
static bool IsStdlibValid(Isolate* isolate, Handle<FixedArray> wasm_data,
Handle<JSReceiver> stdlib);
static MaybeHandle<Object> InstantiateAsmWasm(Isolate* isolate, static MaybeHandle<Object> InstantiateAsmWasm(Isolate* isolate,
Handle<FixedArray> wasm_data, Handle<FixedArray> wasm_data,
Handle<JSArrayBuffer> memory, Handle<JSReceiver> stdlib,
Handle<JSReceiver> foreign); Handle<JSReceiver> foreign,
Handle<JSArrayBuffer> memory);
}; };
} // namespace internal } // namespace internal
} // namespace v8 } // namespace v8
#endif
#endif // V8_ASMJS_ASM_JS_H_
...@@ -85,12 +85,10 @@ RUNTIME_FUNCTION(Runtime_InstantiateAsmJs) { ...@@ -85,12 +85,10 @@ RUNTIME_FUNCTION(Runtime_InstantiateAsmJs) {
if (args[3]->IsJSArrayBuffer()) { if (args[3]->IsJSArrayBuffer()) {
memory = args.at<JSArrayBuffer>(3); memory = args.at<JSArrayBuffer>(3);
} }
if (function->shared()->HasAsmWasmData() && if (function->shared()->HasAsmWasmData()) {
AsmJs::IsStdlibValid(isolate, handle(function->shared()->asm_wasm_data()), Handle<FixedArray> data(function->shared()->asm_wasm_data());
stdlib)) { MaybeHandle<Object> result =
MaybeHandle<Object> result; AsmJs::InstantiateAsmWasm(isolate, data, stdlib, foreign, memory);
result = AsmJs::InstantiateAsmWasm(
isolate, handle(function->shared()->asm_wasm_data()), memory, foreign);
if (!result.is_null()) { if (!result.is_null()) {
return *result.ToHandleChecked(); return *result.ToHandleChecked();
} }
......
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