Commit 6f838195 authored by Clemens Backes's avatar Clemens Backes Committed by Commit Bot

[wasm] Remove obsolete --no-wasm-shared-code flag

The flag is enabled since M-70, and we do not use the previous
behaviour anywhere. Hence, remove the flag and clean up some API code.
In particular, the concept of {TransferrableModule} is not needed any
more, we can just use {CompiledWasmModule}.

R=mstarzinger@chromium.org, adamk@chromium.org

Bug: v8:9810
Change-Id: I9b3aa4972277a9262b58da70b141e90d1de31f35
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1847366
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Reviewed-by: 's avatarAdam Klein <adamk@chromium.org>
Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#64209}
parent 991a000f
......@@ -4635,47 +4635,38 @@ class V8_EXPORT CompiledWasmModule {
// An instance of WebAssembly.Module.
class V8_EXPORT WasmModuleObject : public Object {
public:
WasmModuleObject() = delete;
/**
* An opaque, native heap object for transferring wasm modules. It
* supports move semantics, and does not support copy semantics.
* TODO(wasm): Merge this with CompiledWasmModule once code sharing is always
* enabled.
*/
class TransferrableModule final {
public:
TransferrableModule(TransferrableModule&& src) = default;
TransferrableModule(const TransferrableModule& src) = delete;
TransferrableModule& operator=(TransferrableModule&& src) = default;
TransferrableModule& operator=(const TransferrableModule& src) = delete;
private:
typedef std::shared_ptr<internal::wasm::NativeModule> SharedModule;
friend class WasmModuleObject;
explicit TransferrableModule(SharedModule shared_module)
: shared_module_(std::move(shared_module)) {}
TransferrableModule(OwnedBuffer serialized, OwnedBuffer bytes)
: serialized_(std::move(serialized)), wire_bytes_(std::move(bytes)) {}
SharedModule shared_module_;
OwnedBuffer serialized_ = {nullptr, 0};
OwnedBuffer wire_bytes_ = {nullptr, 0};
};
using TransferrableModule V8_DEPRECATE_SOON(
"Use CompiledWasmModule directly") = CompiledWasmModule;
/**
* Get an in-memory, non-persistable, and context-independent (meaning,
* suitable for transfer to another Isolate and Context) representation
* of this wasm compiled module.
*/
V8_DEPRECATE_SOON("Use GetCompiledModule")
TransferrableModule GetTransferrableModule();
/**
* Efficiently re-create a WasmModuleObject, without recompiling, from
* a TransferrableModule.
*/
V8_DEPRECATE_SOON("Use FromCompiledModule")
static MaybeLocal<WasmModuleObject> FromTransferrableModule(
Isolate* isolate, const TransferrableModule&);
/**
* Efficiently re-create a WasmModuleObject, without recompiling, from
* a CompiledWasmModule.
*/
static MaybeLocal<WasmModuleObject> FromCompiledModule(
Isolate* isolate, const CompiledWasmModule&);
/**
* Get the compiled module for this module object. The compiled module can be
* shared by several module objects.
......@@ -4698,11 +4689,7 @@ class V8_EXPORT WasmModuleObject : public Object {
static MaybeLocal<WasmModuleObject> Compile(Isolate* isolate,
const uint8_t* start,
size_t length);
static MemorySpan<const uint8_t> AsReference(const OwnedBuffer& buff) {
return {buff.buffer.get(), buff.size};
}
WasmModuleObject();
static void CheckCast(Value* obj);
};
......
......@@ -7089,21 +7089,7 @@ MemorySpan<const uint8_t> CompiledWasmModule::GetWireBytesRef() {
WasmModuleObject::TransferrableModule
WasmModuleObject::GetTransferrableModule() {
if (i::FLAG_wasm_shared_code) {
i::Handle<i::WasmModuleObject> obj =
i::Handle<i::WasmModuleObject>::cast(Utils::OpenHandle(this));
return TransferrableModule(obj->shared_native_module());
} else {
CompiledWasmModule compiled_module = GetCompiledModule();
OwnedBuffer serialized_module = compiled_module.Serialize();
MemorySpan<const uint8_t> wire_bytes_ref =
compiled_module.GetWireBytesRef();
size_t wire_size = wire_bytes_ref.size();
std::unique_ptr<uint8_t[]> wire_bytes_copy(new uint8_t[wire_size]);
memcpy(wire_bytes_copy.get(), wire_bytes_ref.data(), wire_size);
return TransferrableModule(std::move(serialized_module),
{std::move(wire_bytes_copy), wire_size});
}
return GetCompiledModule();
}
CompiledWasmModule WasmModuleObject::GetCompiledModule() {
......@@ -7115,17 +7101,17 @@ CompiledWasmModule WasmModuleObject::GetCompiledModule() {
MaybeLocal<WasmModuleObject> WasmModuleObject::FromTransferrableModule(
Isolate* isolate,
const WasmModuleObject::TransferrableModule& transferrable_module) {
if (i::FLAG_wasm_shared_code) {
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
i::Handle<i::WasmModuleObject> module_object =
i_isolate->wasm_engine()->ImportNativeModule(
i_isolate, transferrable_module.shared_module_);
return Local<WasmModuleObject>::Cast(
Utils::ToLocal(i::Handle<i::JSObject>::cast(module_object)));
} else {
return Deserialize(isolate, AsReference(transferrable_module.serialized_),
AsReference(transferrable_module.wire_bytes_));
}
return FromCompiledModule(isolate, transferrable_module);
}
MaybeLocal<WasmModuleObject> WasmModuleObject::FromCompiledModule(
Isolate* isolate, const CompiledWasmModule& compiled_module) {
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
i::Handle<i::WasmModuleObject> module_object =
i_isolate->wasm_engine()->ImportNativeModule(
i_isolate, Utils::Open(compiled_module));
return Local<WasmModuleObject>::Cast(
Utils::ToLocal(i::Handle<i::JSObject>::cast(module_object)));
}
MaybeLocal<WasmModuleObject> WasmModuleObject::Deserialize(
......
......@@ -276,6 +276,11 @@ class Utils {
return CompiledWasmModule{std::move(native_module)};
}
static inline const std::shared_ptr<i::wasm::NativeModule>& Open(
const CompiledWasmModule& compiled_module) {
return compiled_module.native_module_;
}
private:
static void ReportApiFailure(const char* location, const char* message);
};
......
......@@ -3329,7 +3329,7 @@ class Serializer : public ValueSerializer::Delegate {
size_t index = wasm_modules_.size();
wasm_modules_.emplace_back(isolate_, module);
data_->transferrable_modules_.push_back(module->GetTransferrableModule());
data_->compiled_wasm_modules_.push_back(module->GetCompiledModule());
return Just<uint32_t>(static_cast<uint32_t>(index));
}
......@@ -3455,11 +3455,9 @@ class Deserializer : public ValueDeserializer::Delegate {
MaybeLocal<WasmModuleObject> GetWasmModuleFromId(
Isolate* isolate, uint32_t transfer_id) override {
DCHECK_NOT_NULL(data_);
if (transfer_id < data_->transferrable_modules().size()) {
return WasmModuleObject::FromTransferrableModule(
isolate_, data_->transferrable_modules().at(transfer_id));
}
return MaybeLocal<WasmModuleObject>();
if (transfer_id >= data_->compiled_wasm_modules().size()) return {};
return WasmModuleObject::FromCompiledModule(
isolate_, data_->compiled_wasm_modules().at(transfer_id));
}
private:
......
......@@ -123,9 +123,8 @@ class SerializationData {
const std::vector<std::shared_ptr<v8::BackingStore>>& sab_backing_stores() {
return sab_backing_stores_;
}
const std::vector<WasmModuleObject::TransferrableModule>&
transferrable_modules() {
return transferrable_modules_;
const std::vector<CompiledWasmModule>& compiled_wasm_modules() {
return compiled_wasm_modules_;
}
private:
......@@ -137,7 +136,7 @@ class SerializationData {
size_t size_;
std::vector<std::shared_ptr<v8::BackingStore>> backing_stores_;
std::vector<std::shared_ptr<v8::BackingStore>> sab_backing_stores_;
std::vector<WasmModuleObject::TransferrableModule> transferrable_modules_;
std::vector<CompiledWasmModule> compiled_wasm_modules_;
private:
friend class Serializer;
......
......@@ -730,9 +730,6 @@ DEFINE_BOOL(wasm_math_intrinsics, true,
DEFINE_BOOL(wasm_shared_engine, true,
"shares one wasm engine between all isolates within a process")
DEFINE_IMPLICATION(future, wasm_shared_engine)
DEFINE_BOOL(wasm_shared_code, true,
"shares code underlying a wasm module when it is transferred")
DEFINE_IMPLICATION(future, wasm_shared_code)
DEFINE_BOOL(wasm_trap_handler, true,
"use signal handlers to catch out of bounds memory access in wasm"
" (currently Linux x86_64 only)")
......
......@@ -1793,7 +1793,7 @@ WasmCode* WasmCodeManager::LookupCode(Address pc) const {
}
// TODO(v8:7424): Code protection scopes are not yet supported with shared code
// enabled and need to be revisited to work with --wasm-shared-code as well.
// enabled and need to be revisited.
NativeModuleModificationScope::NativeModuleModificationScope(
NativeModule* native_module)
: native_module_(native_module) {
......
......@@ -271,9 +271,8 @@ TEST(BlockWasmCodeGenAtDeserialization) {
Cleanup();
}
namespace {
void TestTransferrableWasmModules(bool should_share) {
UNINITIALIZED_TEST(CompiledWasmModulesTransfer) {
FlagScope<bool> flag_scope_engine(&FLAG_wasm_shared_engine, true);
i::wasm::WasmEngine::InitializeOncePerProcess();
v8::internal::AccountingAllocator allocator;
Zone zone(&allocator, ZONE_NAME);
......@@ -284,7 +283,7 @@ void TestTransferrableWasmModules(bool should_share) {
v8::Isolate::CreateParams create_params;
create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
v8::Isolate* from_isolate = v8::Isolate::New(create_params);
std::vector<v8::WasmModuleObject::TransferrableModule> store;
std::vector<v8::CompiledWasmModule> store;
std::shared_ptr<NativeModule> original_native_module;
{
v8::HandleScope scope(from_isolate);
......@@ -292,7 +291,7 @@ void TestTransferrableWasmModules(bool should_share) {
Isolate* from_i_isolate = reinterpret_cast<Isolate*>(from_isolate);
testing::SetupIsolateForWasmModule(from_i_isolate);
ErrorThrower thrower(from_i_isolate, "TestTransferrableWasmModules");
ErrorThrower thrower(from_i_isolate, "TestCompiledWasmModulesTransfer");
auto enabled_features = WasmFeaturesFromIsolate(from_i_isolate);
MaybeHandle<WasmModuleObject> maybe_module_object =
from_i_isolate->wasm_engine()->SyncCompile(
......@@ -303,7 +302,7 @@ void TestTransferrableWasmModules(bool should_share) {
v8::Local<v8::WasmModuleObject> v8_module =
v8::Local<v8::WasmModuleObject>::Cast(
v8::Utils::ToLocal(Handle<JSObject>::cast(module_object)));
store.push_back(v8_module->GetTransferrableModule());
store.push_back(v8_module->GetCompiledModule());
original_native_module = module_object->shared_native_module();
}
......@@ -314,14 +313,13 @@ void TestTransferrableWasmModules(bool should_share) {
LocalContext env(to_isolate);
v8::MaybeLocal<v8::WasmModuleObject> transferred_module =
v8::WasmModuleObject::FromTransferrableModule(to_isolate, store[0]);
v8::WasmModuleObject::FromCompiledModule(to_isolate, store[0]);
CHECK(!transferred_module.IsEmpty());
Handle<WasmModuleObject> module_object = Handle<WasmModuleObject>::cast(
v8::Utils::OpenHandle(*transferred_module.ToLocalChecked()));
std::shared_ptr<NativeModule> transferred_native_module =
module_object->shared_native_module();
bool is_sharing = (original_native_module == transferred_native_module);
CHECK_EQ(should_share, is_sharing);
CHECK_EQ(original_native_module, transferred_native_module);
}
to_isolate->Dispose();
}
......@@ -329,19 +327,6 @@ void TestTransferrableWasmModules(bool should_share) {
from_isolate->Dispose();
}
} // namespace
UNINITIALIZED_TEST(TransferrableWasmModulesCloned) {
FlagScope<bool> flag_scope_code(&FLAG_wasm_shared_code, false);
TestTransferrableWasmModules(false);
}
UNINITIALIZED_TEST(TransferrableWasmModulesShared) {
FlagScope<bool> flag_scope_engine(&FLAG_wasm_shared_engine, true);
FlagScope<bool> flag_scope_code(&FLAG_wasm_shared_code, true);
TestTransferrableWasmModules(true);
}
#undef EMIT_CODE_WITH_END
} // namespace test_wasm_serialization
......
......@@ -2509,35 +2509,32 @@ class ValueSerializerTestWithWasm : public ValueSerializerTest {
class SerializeToTransfer : public ValueSerializer::Delegate {
public:
SerializeToTransfer(
std::vector<WasmModuleObject::TransferrableModule>* modules)
explicit SerializeToTransfer(std::vector<CompiledWasmModule>* modules)
: modules_(modules) {}
Maybe<uint32_t> GetWasmModuleTransferId(
Isolate* isolate, Local<WasmModuleObject> module) override {
modules_->push_back(module->GetTransferrableModule());
modules_->push_back(module->GetCompiledModule());
return Just(static_cast<uint32_t>(modules_->size()) - 1);
}
void ThrowDataCloneError(Local<String> message) override { UNREACHABLE(); }
private:
std::vector<WasmModuleObject::TransferrableModule>* modules_;
std::vector<CompiledWasmModule>* modules_;
};
class DeserializeFromTransfer : public ValueDeserializer::Delegate {
public:
DeserializeFromTransfer(
std::vector<WasmModuleObject::TransferrableModule>* modules)
explicit DeserializeFromTransfer(std::vector<CompiledWasmModule>* modules)
: modules_(modules) {}
MaybeLocal<WasmModuleObject> GetWasmModuleFromId(Isolate* isolate,
uint32_t id) override {
return WasmModuleObject::FromTransferrableModule(isolate,
modules_->at(id));
return WasmModuleObject::FromCompiledModule(isolate, modules_->at(id));
}
private:
std::vector<WasmModuleObject::TransferrableModule>* modules_;
std::vector<CompiledWasmModule>* modules_;
};
ValueSerializer::Delegate* GetSerializerDelegate() override {
......@@ -2617,7 +2614,7 @@ class ValueSerializerTestWithWasm : public ValueSerializerTest {
private:
static bool g_saved_flag;
std::vector<WasmModuleObject::TransferrableModule> transfer_modules_;
std::vector<CompiledWasmModule> transfer_modules_;
SerializeToTransfer serialize_delegate_;
DeserializeFromTransfer deserialize_delegate_;
ValueSerializer::Delegate* current_serializer_delegate_ = nullptr;
......
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