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