Commit 27272ab5 authored by Ben L. Titzer's avatar Ben L. Titzer Committed by Commit Bot

[wasm] Factor out instantiation code into own file

This refactoring CL moves all instantiation logic in its own file,
separating it from the module compiler.

R=ahaas@chromium.org

Change-Id: I5a721c7357022dd7bf32f776b2ab0153f7dd68fc
Reviewed-on: https://chromium-review.googlesource.com/c/1409429
Commit-Queue: Ben Titzer <titzer@chromium.org>
Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58797}
parent 138bcfc3
......@@ -2583,6 +2583,7 @@ v8_source_set("v8_base") {
"src/wasm/function-compiler.h",
"src/wasm/graph-builder-interface.cc",
"src/wasm/graph-builder-interface.h",
"src/wasm/js-to-wasm-wrapper-cache-inl.h",
"src/wasm/jump-table-assembler.cc",
"src/wasm/jump-table-assembler.h",
"src/wasm/leb-helper.h",
......@@ -2594,6 +2595,8 @@ v8_source_set("v8_base") {
"src/wasm/module-compiler.h",
"src/wasm/module-decoder.cc",
"src/wasm/module-decoder.h",
"src/wasm/module-instantiate.cc",
"src/wasm/module-instantiate.h",
"src/wasm/object-access.h",
"src/wasm/signature-map.cc",
"src/wasm/signature-map.h",
......
// Copyright 2018 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.
#ifndef V8_WASM_JS_TO_WASM_WRAPPER_CACHE_INL_H_
#define V8_WASM_JS_TO_WASM_WRAPPER_CACHE_INL_H_
#include "src/compiler/wasm-compiler.h"
#include "src/counters.h"
#include "src/wasm/value-type.h"
#include "src/wasm/wasm-code-manager.h"
namespace v8 {
namespace internal {
namespace wasm {
class JSToWasmWrapperCache {
public:
Handle<Code> GetOrCompileJSToWasmWrapper(Isolate* isolate, FunctionSig* sig,
bool is_import) {
std::pair<bool, FunctionSig> key(is_import, *sig);
Handle<Code>& cached = cache_[key];
if (cached.is_null()) {
cached = compiler::CompileJSToWasmWrapper(isolate, sig, is_import)
.ToHandleChecked();
}
return cached;
}
private:
// We generate different code for calling imports than calling wasm functions
// in this module. Both are cached separately.
using CacheKey = std::pair<bool, FunctionSig>;
std::unordered_map<CacheKey, Handle<Code>, base::hash<CacheKey>> cache_;
};
} // namespace wasm
} // namespace internal
} // namespace v8
#endif // V8_WASM_JS_TO_WASM_WRAPPER_CACHE_INL_H_
This diff is collapsed.
......@@ -42,10 +42,10 @@ std::unique_ptr<NativeModule> CompileToNativeModule(
std::shared_ptr<const WasmModule> module, const ModuleWireBytes& wire_bytes,
Handle<FixedArray>* export_wrappers_out);
MaybeHandle<WasmInstanceObject> InstantiateToInstanceObject(
Isolate* isolate, ErrorThrower* thrower,
Handle<WasmModuleObject> module_object, MaybeHandle<JSReceiver> imports,
MaybeHandle<JSArrayBuffer> memory);
void CompileNativeModuleWithExplicitBoundsChecks(Isolate* isolate,
ErrorThrower* thrower,
const WasmModule* wasm_module,
NativeModule* native_module);
V8_EXPORT_PRIVATE
void CompileJsToWasmWrappers(Isolate* isolate, const WasmModule* module,
......
This diff is collapsed.
// Copyright 2019 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.
#ifndef V8_WASM_MODULE_INSTANTIATE_H_
#define V8_WASM_MODULE_INSTANTIATE_H_
namespace v8 {
namespace internal {
class Isolate;
class JSArrayBuffer;
class JSReceiver;
class WasmModuleObject;
class WasmInstanceObject;
template <typename T>
class Handle;
template <typename T>
class MaybeHandle;
namespace wasm {
class ErrorThrower;
MaybeHandle<WasmInstanceObject> InstantiateToInstanceObject(
Isolate* isolate, ErrorThrower* thrower,
Handle<WasmModuleObject> module_object, MaybeHandle<JSReceiver> imports,
MaybeHandle<JSArrayBuffer> memory);
} // namespace wasm
} // namespace internal
} // namespace v8
#endif // V8_WASM_MODULE_INSTANTIATE_H_
......@@ -12,6 +12,7 @@
#include "src/wasm/function-compiler.h"
#include "src/wasm/module-compiler.h"
#include "src/wasm/module-decoder.h"
#include "src/wasm/module-instantiate.h"
#include "src/wasm/streaming-decoder.h"
#include "src/wasm/wasm-objects-inl.h"
......
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