[wasm] Hide SyncValidate() behind WasmEngine interface.

This is the first in a series of CLs that will separate the JS API
from the implementation of WebAssembly by bottlenecking interactions
through the WasmEngine. In the long run, the JS API and much of V8
should rely only on the WasmEngine interface, which will represent
the "public interface" for embedding WebAssembly.

Next: hide compilation-related methods behind WasmEngine.
Bug: v8:7316
Change-Id: I93404f0dc8a201ae99d30b4c1ca34606e3dddbca
Reviewed-on: https://chromium-review.googlesource.com/868590
Commit-Queue: Ben Titzer <titzer@chromium.org>
Reviewed-by: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#50660}
This commit is contained in:
Ben L. Titzer 2018-01-17 15:46:27 +01:00 committed by Commit Bot
parent 06f0365165
commit 84326fc49b
8 changed files with 34 additions and 17 deletions

View File

@ -2136,6 +2136,7 @@ v8_source_set("v8_base") {
"src/wasm/wasm-code-wrapper.h",
"src/wasm/wasm-constants.h",
"src/wasm/wasm-debug.cc",
"src/wasm/wasm-engine.cc",
"src/wasm/wasm-engine.h",
"src/wasm/wasm-external-refs.cc",
"src/wasm/wasm-external-refs.h",

View File

@ -1486,6 +1486,7 @@
'wasm/wasm-code-wrapper.h',
'wasm/wasm-constants.h',
'wasm/wasm-debug.cc',
'wasm/wasm-engine.cc',
'wasm/wasm-engine.h',
'wasm/wasm-external-refs.cc',
'wasm/wasm-external-refs.h',

View File

@ -533,13 +533,6 @@ class SetOfNativeModuleModificationScopes final {
} // namespace
bool SyncValidate(Isolate* isolate, const ModuleWireBytes& bytes) {
if (bytes.start() == nullptr || bytes.length() == 0) return false;
ModuleResult result = SyncDecodeWasmModule(isolate, bytes.start(),
bytes.end(), true, kWasmOrigin);
return result.ok();
}
MaybeHandle<WasmModuleObject> SyncCompileTranslatedAsmJs(
Isolate* isolate, ErrorThrower* thrower, const ModuleWireBytes& bytes,
Handle<Script> asm_js_script,

View File

@ -23,9 +23,6 @@ namespace wasm {
class ModuleCompiler;
class WasmCode;
V8_EXPORT_PRIVATE bool SyncValidate(Isolate* isolate,
const ModuleWireBytes& bytes);
V8_EXPORT_PRIVATE MaybeHandle<WasmModuleObject> SyncCompileTranslatedAsmJs(
Isolate* isolate, ErrorThrower* thrower, const ModuleWireBytes& bytes,
Handle<Script> asm_js_script, Vector<const byte> asm_js_offset_table_bytes);

23
src/wasm/wasm-engine.cc Normal file
View File

@ -0,0 +1,23 @@
// 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.
#include "src/wasm/wasm-engine.h"
#include "src/objects-inl.h"
#include "src/wasm/module-compiler.h"
namespace v8 {
namespace internal {
namespace wasm {
bool WasmEngine::SyncValidate(Isolate* isolate, const ModuleWireBytes& bytes) {
// TODO(titzer): remove dependency on the isolate.
if (bytes.start() == nullptr || bytes.length() == 0) return false;
ModuleResult result = SyncDecodeWasmModule(isolate, bytes.start(),
bytes.end(), true, kWasmOrigin);
return result.ok();
}
} // namespace wasm
} // namespace internal
} // namespace v8

View File

@ -18,11 +18,13 @@ namespace wasm {
// The central data structure that represents an engine instance capable of
// loading, instantiating, and executing WASM code.
class WasmEngine {
class V8_EXPORT_PRIVATE WasmEngine {
public:
explicit WasmEngine(std::unique_ptr<WasmCodeManager> code_manager)
: code_manager_(std::move(code_manager)) {}
bool SyncValidate(Isolate* isolate, const ModuleWireBytes& bytes);
CompilationManager* compilation_manager() { return &compilation_manager_; }
WasmCodeManager* code_manager() const { return code_manager_.get(); }

View File

@ -17,13 +17,11 @@
#include "src/parsing/parse-info.h"
#include "src/trap-handler/trap-handler.h"
#include "src/wasm/module-compiler.h"
#include "src/wasm/module-decoder.h"
#include "src/wasm/wasm-api.h"
#include "src/wasm/wasm-engine.h"
#include "src/wasm/wasm-limits.h"
#include "src/wasm/wasm-memory.h"
#include "src/wasm/wasm-module.h"
#include "src/wasm/wasm-objects-inl.h"
#include "src/wasm/wasm-result.h"
using v8::internal::wasm::ErrorThrower;
@ -195,10 +193,10 @@ void WebAssemblyValidate(const v8::FunctionCallbackInfo<v8::Value>& args) {
memcpy(copy.get(), bytes.start(), bytes.length());
i::wasm::ModuleWireBytes bytes_copy(copy.get(),
copy.get() + bytes.length());
validated = i::wasm::SyncValidate(i_isolate, bytes_copy);
validated = i_isolate->wasm_engine()->SyncValidate(i_isolate, bytes_copy);
} else {
// The wire bytes are not shared, OK to use them directly.
validated = i::wasm::SyncValidate(i_isolate, bytes);
validated = i_isolate->wasm_engine()->SyncValidate(i_isolate, bytes);
}
return_value.Set(Boolean::New(isolate, validated));

View File

@ -9,6 +9,7 @@
#include "src/objects-inl.h"
#include "src/wasm/module-compiler.h"
#include "src/wasm/wasm-api.h"
#include "src/wasm/wasm-engine.h"
#include "src/wasm/wasm-module-builder.h"
#include "src/wasm/wasm-module.h"
#include "src/zone/accounting-allocator.h"
@ -248,7 +249,8 @@ int WasmExecutionFuzzer::FuzzWasmModule(const uint8_t* data, size_t size,
GenerateTestCase(i_isolate, wire_bytes, compiles);
}
bool validates = SyncValidate(i_isolate, wire_bytes);
bool validates =
i_isolate->wasm_engine()->SyncValidate(i_isolate, wire_bytes);
CHECK_EQ(compiles, validates);
CHECK_IMPLIES(require_valid, validates);