Commit fcfc8519 authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[wasm] Define serialization API in terms of NativeModule

For serialization, we do not need the {WasmCompiledModule}. All we need
is the {NativeModule}.

R=mstarzinger@chromium.org

Cq-Include-Trybots: luci.chromium.try:linux_chromium_rel_ng
Change-Id: Iff7dc9cde3b1ab777028dbafcc1c870e45e28a93
Reviewed-on: https://chromium-review.googlesource.com/1097480Reviewed-by: 's avatarBen Titzer <titzer@chromium.org>
Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53686}
parent 59c396a6
......@@ -7483,12 +7483,12 @@ MaybeLocal<WasmCompiledModule> WasmCompiledModule::FromTransferrableModule(
WasmCompiledModule::SerializedModule WasmCompiledModule::Serialize() {
i::Handle<i::WasmModuleObject> obj =
i::Handle<i::WasmModuleObject>::cast(Utils::OpenHandle(this));
i::Handle<i::WasmCompiledModule> compiled_part =
i::handle(i::WasmCompiledModule::cast(obj->compiled_module()));
i::wasm::NativeModule* native_module =
obj->compiled_module()->GetNativeModule();
size_t buffer_size =
i::wasm::GetSerializedNativeModuleSize(obj->GetIsolate(), compiled_part);
i::wasm::GetSerializedNativeModuleSize(obj->GetIsolate(), native_module);
std::unique_ptr<uint8_t[]> buffer(new uint8_t[buffer_size]);
if (i::wasm::SerializeNativeModule(obj->GetIsolate(), compiled_part,
if (i::wasm::SerializeNativeModule(obj->GetIsolate(), native_module,
{buffer.get(), buffer_size}))
return {std::move(buffer), buffer_size};
return {};
......
......@@ -912,16 +912,16 @@ RUNTIME_FUNCTION(Runtime_SerializeWasmModule) {
DCHECK_EQ(1, args.length());
CONVERT_ARG_HANDLE_CHECKED(WasmModuleObject, module_obj, 0);
Handle<WasmCompiledModule> compiled_module(module_obj->compiled_module(),
isolate);
wasm::NativeModule* native_module =
module_obj->compiled_module()->GetNativeModule();
size_t compiled_size =
wasm::GetSerializedNativeModuleSize(isolate, compiled_module);
wasm::GetSerializedNativeModuleSize(isolate, native_module);
void* array_data = isolate->array_buffer_allocator()->Allocate(compiled_size);
Handle<JSArrayBuffer> array_buffer = isolate->factory()->NewJSArrayBuffer();
JSArrayBuffer::Setup(array_buffer, isolate, false, array_data, compiled_size);
if (!array_data ||
!wasm::SerializeNativeModule(
isolate, compiled_module,
isolate, native_module,
{reinterpret_cast<uint8_t*>(array_data), compiled_size})) {
return isolate->heap()->undefined_value();
}
......
......@@ -887,14 +887,15 @@ Maybe<bool> ValueSerializer::WriteWasmModule(Handle<WasmModuleObject> object) {
String::WriteToFlat(*wire_bytes, destination, 0, wire_bytes_length);
}
Handle<WasmCompiledModule> compiled_part(object->compiled_module(), isolate_);
wasm::NativeModule* native_module =
object->compiled_module()->GetNativeModule();
size_t module_size =
wasm::GetSerializedNativeModuleSize(isolate_, compiled_part);
wasm::GetSerializedNativeModuleSize(isolate_, native_module);
CHECK_GE(std::numeric_limits<uint32_t>::max(), module_size);
WriteVarint<uint32_t>(static_cast<uint32_t>(module_size));
uint8_t* module_buffer;
if (ReserveRawBytes(module_size).To(&module_buffer)) {
if (!wasm::SerializeNativeModule(isolate_, compiled_part,
if (!wasm::SerializeNativeModule(isolate_, native_module,
{module_buffer, module_size})) {
return Nothing<bool>();
}
......
......@@ -395,17 +395,14 @@ bool NativeModuleSerializer::Write(Writer* writer) {
return true;
}
size_t GetSerializedNativeModuleSize(
Isolate* isolate, Handle<WasmCompiledModule> compiled_module) {
NativeModule* native_module = compiled_module->GetNativeModule();
size_t GetSerializedNativeModuleSize(Isolate* isolate,
NativeModule* native_module) {
NativeModuleSerializer serializer(isolate, native_module);
return kVersionSize + serializer.Measure();
}
bool SerializeNativeModule(Isolate* isolate,
Handle<WasmCompiledModule> compiled_module,
bool SerializeNativeModule(Isolate* isolate, NativeModule* native_module,
Vector<byte> buffer) {
NativeModule* native_module = compiled_module->GetNativeModule();
NativeModuleSerializer serializer(isolate, native_module);
size_t measured_size = kVersionSize + serializer.Measure();
if (buffer.size() < measured_size) return false;
......
......@@ -11,11 +11,10 @@ namespace v8 {
namespace internal {
namespace wasm {
size_t GetSerializedNativeModuleSize(
Isolate* isolate, Handle<WasmCompiledModule> compiled_module);
size_t GetSerializedNativeModuleSize(Isolate* isolate,
NativeModule* native_module);
bool SerializeNativeModule(Isolate* isolate,
Handle<WasmCompiledModule> compiled_module,
bool SerializeNativeModule(Isolate* isolate, NativeModule* native_module,
Vector<byte> buffer);
MaybeHandle<WasmModuleObject> DeserializeNativeModule(
......
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