Commit 30e4ba6d authored by Clemens Backes's avatar Clemens Backes Committed by Commit Bot

[wasm] Remove serialization of WasmModuleObject

Serialization of WasmModuleObject was our first implementation for
postMessage, and was used for IndexedDB. IndexedDB support is removed
since a long time, and postMessage works by just messaging an identifier
and reusing the underlying NativeModule when receiving this.
Thus the logic to serialize the actual code is unused, and thus should
be removed together with all tests.

R=ahaas@chromium.org

Bug: v8:10146
Change-Id: I599296736dabd486c45ced2b6e5996e490fa40c8
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2013110Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#65922}
parent 7b79a02d
......@@ -144,11 +144,6 @@ enum class SerializationTag : uint8_t {
kArrayBufferView = 'V',
// Shared array buffer. transferID:uint32_t
kSharedArrayBuffer = 'u',
// Compiled WebAssembly module. encodingType:(one-byte tag).
// If encodingType == 'y' (raw bytes):
// wasmWireByteLength:uint32_t, then raw data
// compiledDataLength:uint32_t, then raw data
kWasmModule = 'W',
// A wasm module object transfer. next value is its index.
kWasmModuleTransfer = 'w',
// The delegate is responsible for processing all following data.
......@@ -210,10 +205,6 @@ enum class ArrayBufferViewTag : uint8_t {
kDataView = '?',
};
enum class WasmEncodingTag : uint8_t {
kRawBytes = 'y',
};
// Sub-tags only meaningful for error serialization.
enum class ErrorTag : uint8_t {
// The error is a EvalError. No accompanying data.
......@@ -982,42 +973,22 @@ Maybe<bool> ValueSerializer::WriteJSError(Handle<JSObject> error) {
}
Maybe<bool> ValueSerializer::WriteWasmModule(Handle<WasmModuleObject> object) {
if (delegate_ != nullptr) {
// TODO(titzer): introduce a Utils::ToLocal for WasmModuleObject.
Maybe<uint32_t> transfer_id = delegate_->GetWasmModuleTransferId(
reinterpret_cast<v8::Isolate*>(isolate_),
v8::Local<v8::WasmModuleObject>::Cast(
Utils::ToLocal(Handle<JSObject>::cast(object))));
RETURN_VALUE_IF_SCHEDULED_EXCEPTION(isolate_, Nothing<bool>());
uint32_t id = 0;
if (transfer_id.To(&id)) {
WriteTag(SerializationTag::kWasmModuleTransfer);
WriteVarint<uint32_t>(id);
return Just(true);
}
}
WasmEncodingTag encoding_tag = WasmEncodingTag::kRawBytes;
WriteTag(SerializationTag::kWasmModule);
WriteRawBytes(&encoding_tag, sizeof(encoding_tag));
wasm::NativeModule* native_module = object->native_module();
Vector<const uint8_t> wire_bytes = native_module->wire_bytes();
WriteVarint<uint32_t>(static_cast<uint32_t>(wire_bytes.size()));
uint8_t* destination;
if (ReserveRawBytes(wire_bytes.size()).To(&destination)) {
memcpy(destination, wire_bytes.begin(), wire_bytes.size());
if (delegate_ == nullptr) {
ThrowDataCloneError(MessageTemplate::kDataCloneError, object);
return Nothing<bool>();
}
wasm::WasmSerializer wasm_serializer(native_module);
size_t module_size = wasm_serializer.GetSerializedNativeModuleSize();
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_serializer.SerializeNativeModule({module_buffer, module_size})) {
return Nothing<bool>();
}
// TODO(titzer): introduce a Utils::ToLocal for WasmModuleObject.
Maybe<uint32_t> transfer_id = delegate_->GetWasmModuleTransferId(
reinterpret_cast<v8::Isolate*>(isolate_),
v8::Local<v8::WasmModuleObject>::Cast(
Utils::ToLocal(Handle<JSObject>::cast(object))));
RETURN_VALUE_IF_SCHEDULED_EXCEPTION(isolate_, Nothing<bool>());
uint32_t id = 0;
if (transfer_id.To(&id)) {
WriteTag(SerializationTag::kWasmModuleTransfer);
WriteVarint<uint32_t>(id);
return Just(true);
}
return ThrowIfOutOfMemory();
}
......@@ -1359,8 +1330,6 @@ MaybeHandle<Object> ValueDeserializer::ReadObjectInternal() {
}
case SerializationTag::kError:
return ReadJSError();
case SerializationTag::kWasmModule:
return ReadWasmModule();
case SerializationTag::kWasmModuleTransfer:
return ReadWasmModuleTransfer();
case SerializationTag::kWasmMemoryTransfer:
......@@ -1966,56 +1935,6 @@ MaybeHandle<JSObject> ValueDeserializer::ReadWasmModuleTransfer() {
return module;
}
MaybeHandle<JSObject> ValueDeserializer::ReadWasmModule() {
auto enabled_features = wasm::WasmFeatures::FromIsolate(isolate_);
if ((FLAG_wasm_disable_structured_cloning &&
!enabled_features.has_threads()) ||
!expect_inline_wasm()) {
return MaybeHandle<JSObject>();
}
Vector<const uint8_t> encoding_tag;
if (!ReadRawBytes(sizeof(WasmEncodingTag)).To(&encoding_tag) ||
encoding_tag[0] != static_cast<uint8_t>(WasmEncodingTag::kRawBytes)) {
return MaybeHandle<JSObject>();
}
// Extract the data from the buffer: wasm wire bytes, followed by V8 compiled
// script data.
static_assert(sizeof(int) <= sizeof(uint32_t),
"max int must fit in uint32_t");
const uint32_t max_valid_size = std::numeric_limits<int>::max();
uint32_t wire_bytes_length = 0;
Vector<const uint8_t> wire_bytes;
uint32_t compiled_bytes_length = 0;
Vector<const uint8_t> compiled_bytes;
if (!ReadVarint<uint32_t>().To(&wire_bytes_length) ||
wire_bytes_length > max_valid_size ||
!ReadRawBytes(wire_bytes_length).To(&wire_bytes) ||
!ReadVarint<uint32_t>().To(&compiled_bytes_length) ||
compiled_bytes_length > max_valid_size ||
!ReadRawBytes(compiled_bytes_length).To(&compiled_bytes)) {
return MaybeHandle<JSObject>();
}
// Try to deserialize the compiled module first.
MaybeHandle<WasmModuleObject> result =
wasm::DeserializeNativeModule(isolate_, compiled_bytes, wire_bytes, {});
if (result.is_null()) {
wasm::ErrorThrower thrower(isolate_, "ValueDeserializer::ReadWasmModule");
// TODO(titzer): are the current features appropriate for deserializing?
auto enabled_features = wasm::WasmFeatures::FromIsolate(isolate_);
result = isolate_->wasm_engine()->SyncCompile(
isolate_, enabled_features, &thrower,
wasm::ModuleWireBytes(wire_bytes));
}
uint32_t id = next_id_++;
if (!result.is_null()) {
AddObjectWithID(id, result.ToHandleChecked());
}
return result;
}
MaybeHandle<WasmMemoryObject> ValueDeserializer::ReadWasmMemory() {
uint32_t id = next_id_++;
......
......@@ -276,7 +276,6 @@ class ValueDeserializer {
MaybeHandle<JSArrayBufferView> ReadJSArrayBufferView(
Handle<JSArrayBuffer> buffer) V8_WARN_UNUSED_RESULT;
MaybeHandle<Object> ReadJSError() V8_WARN_UNUSED_RESULT;
MaybeHandle<JSObject> ReadWasmModule() V8_WARN_UNUSED_RESULT;
MaybeHandle<JSObject> ReadWasmModuleTransfer() V8_WARN_UNUSED_RESULT;
MaybeHandle<WasmMemoryObject> ReadWasmMemory() V8_WARN_UNUSED_RESULT;
MaybeHandle<JSObject> ReadHostObject() V8_WARN_UNUSED_RESULT;
......
......@@ -2682,15 +2682,6 @@ TEST_F(ValueSerializerTestWithWasm, RoundtripWasmTransfer) {
ExpectPass();
}
TEST_F(ValueSerializerTestWithWasm, RountripWasmInline) {
SetExpectInlineWasm(true);
ExpectPass();
}
TEST_F(ValueSerializerTestWithWasm, CannotDeserializeWasmInlineData) {
ExpectFail();
}
TEST_F(ValueSerializerTestWithWasm, CannotTransferWasmWhenExpectingInline) {
EnableTransferSerialization();
SetExpectInlineWasm(true);
......@@ -2705,13 +2696,6 @@ TEST_F(ValueSerializerTestWithWasm, ComplexObjectDuplicateTransfer) {
ExpectScriptTrue("result.mod1 === result.mod2");
}
TEST_F(ValueSerializerTestWithWasm, ComplexObjectDuplicateInline) {
SetExpectInlineWasm(true);
Local<Value> value = RoundTripTest(GetComplexObjectWithDuplicate());
VerifyComplexObject(value);
ExpectScriptTrue("result.mod1 === result.mod2");
}
TEST_F(ValueSerializerTestWithWasm, ComplexObjectWithManyTransfer) {
EnableTransferSerialization();
EnableTransferDeserialization();
......@@ -2720,13 +2704,6 @@ TEST_F(ValueSerializerTestWithWasm, ComplexObjectWithManyTransfer) {
ExpectScriptTrue("result.mod1 != result.mod2");
}
TEST_F(ValueSerializerTestWithWasm, ComplexObjectWithManyInline) {
SetExpectInlineWasm(true);
Local<Value> value = RoundTripTest(GetComplexObjectWithMany());
VerifyComplexObject(value);
ExpectScriptTrue("result.mod1 != result.mod2");
}
// As produced around Chrome 56.
const unsigned char kSerializedIncrementerWasm[] = {
0xFF, 0x09, 0x3F, 0x00, 0x57, 0x79, 0x2D, 0x00, 0x61, 0x73, 0x6D, 0x0D,
......
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