Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(876)

Side by Side Diff: src/wasm/wasm-module.cc

Issue 2806073002: [wasm] instantiate expressed in terms of compile (Closed)
Patch Set: feedback Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <memory> 5 #include <memory>
6 6
7 #include "src/assembler-inl.h" 7 #include "src/assembler-inl.h"
8 #include "src/base/adapters.h" 8 #include "src/base/adapters.h"
9 #include "src/base/atomic-utils.h" 9 #include "src/base/atomic-utils.h"
10 #include "src/code-stubs.h" 10 #include "src/code-stubs.h"
(...skipping 2585 matching lines...) Expand 10 before | Expand all | Expand 10 after
2596 MaybeHandle<WasmInstanceObject> instance_object = SyncInstantiate( 2596 MaybeHandle<WasmInstanceObject> instance_object = SyncInstantiate(
2597 isolate, &thrower, module_object, imports, Handle<JSArrayBuffer>::null()); 2597 isolate, &thrower, module_object, imports, Handle<JSArrayBuffer>::null());
2598 if (thrower.error()) { 2598 if (thrower.error()) {
2599 RejectPromise(isolate, handle(isolate->context()), &thrower, promise); 2599 RejectPromise(isolate, handle(isolate->context()), &thrower, promise);
2600 return; 2600 return;
2601 } 2601 }
2602 ResolvePromise(isolate, handle(isolate->context()), promise, 2602 ResolvePromise(isolate, handle(isolate->context()), promise,
2603 instance_object.ToHandleChecked()); 2603 instance_object.ToHandleChecked());
2604 } 2604 }
2605 2605
2606 void wasm::AsyncCompileAndInstantiate(Isolate* isolate,
2607 Handle<JSPromise> promise,
2608 const ModuleWireBytes& bytes,
2609 MaybeHandle<JSReceiver> imports) {
2610 ErrorThrower thrower(isolate, nullptr);
2611
2612 // Compile the module.
2613 MaybeHandle<WasmModuleObject> module_object =
2614 SyncCompile(isolate, &thrower, bytes);
2615 if (thrower.error()) {
2616 RejectPromise(isolate, handle(isolate->context()), &thrower, promise);
2617 return;
2618 }
2619 Handle<WasmModuleObject> module = module_object.ToHandleChecked();
2620
2621 // Instantiate the module.
2622 MaybeHandle<WasmInstanceObject> instance_object = SyncInstantiate(
2623 isolate, &thrower, module, imports, Handle<JSArrayBuffer>::null());
2624 if (thrower.error()) {
2625 RejectPromise(isolate, handle(isolate->context()), &thrower, promise);
2626 return;
2627 }
2628
2629 Handle<JSFunction> object_function =
2630 Handle<JSFunction>(isolate->native_context()->object_function(), isolate);
2631 Handle<JSObject> ret =
2632 isolate->factory()->NewJSObject(object_function, TENURED);
2633 Handle<String> module_property_name =
2634 isolate->factory()->InternalizeUtf8String("module");
2635 Handle<String> instance_property_name =
2636 isolate->factory()->InternalizeUtf8String("instance");
2637 JSObject::AddProperty(ret, module_property_name, module, NONE);
2638 JSObject::AddProperty(ret, instance_property_name,
2639 instance_object.ToHandleChecked(), NONE);
2640
2641 ResolvePromise(isolate, handle(isolate->context()), promise, ret);
2642 }
2643
2644 // Encapsulates all the state and steps of an asynchronous compilation. 2606 // Encapsulates all the state and steps of an asynchronous compilation.
2645 // An asynchronous compile job consists of a number of tasks that are executed 2607 // An asynchronous compile job consists of a number of tasks that are executed
2646 // as foreground and background tasks. Any phase that touches the V8 heap or 2608 // as foreground and background tasks. Any phase that touches the V8 heap or
2647 // allocates on the V8 heap (e.g. creating the module object) must be a 2609 // allocates on the V8 heap (e.g. creating the module object) must be a
2648 // foreground task. All other tasks (e.g. decoding and validating, the majority 2610 // foreground task. All other tasks (e.g. decoding and validating, the majority
2649 // of the work of compilation) can be background tasks. 2611 // of the work of compilation) can be background tasks.
2650 // TODO(wasm): factor out common parts of this with the synchronous pipeline. 2612 // TODO(wasm): factor out common parts of this with the synchronous pipeline.
2651 // 2613 //
2652 // Note: In predictable mode, DoSync and DoAsync execute the referenced function 2614 // Note: In predictable mode, DoSync and DoAsync execute the referenced function
2653 // immediately before returning. Thus we handle the predictable mode specially, 2615 // immediately before returning. Thus we handle the predictable mode specially,
(...skipping 666 matching lines...) Expand 10 before | Expand all | Expand 10 after
3320 callee_compiled->instruction_start()); 3282 callee_compiled->instruction_start());
3321 } 3283 }
3322 DCHECK_EQ(non_compiled_functions.size(), idx); 3284 DCHECK_EQ(non_compiled_functions.size(), idx);
3323 } 3285 }
3324 3286
3325 Code* ret = 3287 Code* ret =
3326 Code::cast(compiled_module->code_table()->get(func_to_return_idx)); 3288 Code::cast(compiled_module->code_table()->get(func_to_return_idx));
3327 DCHECK_EQ(Code::WASM_FUNCTION, ret->kind()); 3289 DCHECK_EQ(Code::WASM_FUNCTION, ret->kind());
3328 return handle(ret, isolate); 3290 return handle(ret, isolate);
3329 } 3291 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698