Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(28)

Unified Diff: src/api.cc

Issue 2395793003: [wasm] Support recompilation if deserialization fails. (Closed)
Patch Set: [wasm] recompile if needed when deserializing Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/api.cc
diff --git a/src/api.cc b/src/api.cc
index 44933b965becb813a6f0dba8e2b8785ce844bc64..eaa12318f75c488f01aa5e4297a2db78304e9ebe 100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -7184,22 +7184,49 @@ MaybeLocal<Proxy> Proxy::New(Local<Context> context, Local<Object> local_target,
RETURN_ESCAPED(result);
}
+Local<String> WasmCompiledModule::GetUncompiledBytes() {
+ i::Handle<i::JSObject> obj =
+ i::Handle<i::JSObject>::cast(Utils::OpenHandle(this));
+ i::Handle<i::wasm::WasmCompiledModule> compiled_part =
+ i::handle(i::wasm::WasmCompiledModule::cast(obj->GetInternalField(0)));
+ return Local<String>::Cast(Utils::ToLocal(compiled_part->module_bytes()));
+}
+
WasmCompiledModule::SerializedModule WasmCompiledModule::Serialize() {
+ class WasmCompiledModuleRawBytesManager {
+ public:
+ WasmCompiledModuleRawBytesManager(
+ i::Handle<i::wasm::WasmCompiledModule> wasm_module)
+ : module_(wasm_module), bytes_(wasm_module->module_bytes()) {
+ module_->reset_module_bytes();
+ }
+
+ ~WasmCompiledModuleRawBytesManager() { module_->set_module_bytes(bytes_); }
+
+ private:
+ i::Handle<i::wasm::WasmCompiledModule> module_;
+ i::Handle<i::String> bytes_;
+ };
+
i::Handle<i::JSObject> obj =
i::Handle<i::JSObject>::cast(Utils::OpenHandle(this));
- i::Handle<i::FixedArray> compiled_part =
- i::handle(i::FixedArray::cast(obj->GetInternalField(0)));
+ i::Handle<i::wasm::WasmCompiledModule> compiled_part =
+ i::handle(i::wasm::WasmCompiledModule::cast(obj->GetInternalField(0)));
+
+ WasmCompiledModuleRawBytesManager ensure_clean_serialization(compiled_part);
Yang 2016/10/06 07:35:34 what's the advantage of this over of simply take c
vogelheim 2016/10/06 10:00:50 Agree w/ Yang. Also, in case we do want to keep t
Mircea Trofin 2016/10/06 16:17:47 Initially I thought there may be error cases to de
std::unique_ptr<i::ScriptData> script_data =
i::WasmCompiledModuleSerializer::SerializeWasmModule(obj->GetIsolate(),
compiled_part);
script_data->ReleaseDataOwnership();
+
size_t size = static_cast<size_t>(script_data->length());
return {std::unique_ptr<const uint8_t[]>(script_data->data()), size};
}
-MaybeLocal<WasmCompiledModule> WasmCompiledModule::Deserialize(
+MaybeLocal<WasmCompiledModule> WasmCompiledModule::DeserializeOrCompile(
Isolate* isolate,
- const WasmCompiledModule::SerializedModule& serialized_data) {
+ const WasmCompiledModule::SerializedModule& serialized_data,
+ Local<String> uncompiled_bytes) {
int size = static_cast<int>(serialized_data.second);
i::ScriptData sc(serialized_data.first.get(), size);
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
@@ -7207,11 +7234,31 @@ MaybeLocal<WasmCompiledModule> WasmCompiledModule::Deserialize(
i::WasmCompiledModuleSerializer::DeserializeWasmModule(i_isolate, &sc);
i::Handle<i::FixedArray> compiled_part;
if (!maybe_compiled_part.ToHandle(&compiled_part)) {
- return MaybeLocal<WasmCompiledModule>();
+ return Compile(isolate, uncompiled_bytes);
}
+ i::Handle<i::wasm::WasmCompiledModule> compiled_module =
+ handle(i::wasm::WasmCompiledModule::cast(*compiled_part));
+ i::Handle<i::String> module_bytes = Utils::OpenHandle(*uncompiled_bytes);
+ compiled_module->set_module_bytes(module_bytes);
return Local<WasmCompiledModule>::Cast(
Utils::ToLocal(i::wasm::CreateCompiledModuleObject(
- i_isolate, compiled_part, i::wasm::ModuleOrigin::kWasmOrigin)));
+ i_isolate, compiled_module, i::wasm::ModuleOrigin::kWasmOrigin)));
+}
+
+MaybeLocal<WasmCompiledModule> WasmCompiledModule::Compile(
+ Isolate* isolate, Local<String> bytes) {
+ i::Handle<i::String> module_bytes = Utils::OpenHandle(*bytes);
+ i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
+ // if we cannot deserialize, we recompile
vogelheim 2016/10/06 10:00:50 Doesn't that comment belongs into DeserializeOrCom
Mircea Trofin 2016/10/06 16:17:47 yes.
+ i::wasm::ErrorThrower thrower(i_isolate, "WasmCompiledModule::Deserialize()");
+ i::SeqOneByteString* data = i::SeqOneByteString::cast(*module_bytes);
+ i::MaybeHandle<i::JSObject> maybe_compiled =
+ i::wasm::CreateModuleObjectFromBytes(
+ i_isolate, data->GetChars(), data->GetChars() + data->length(),
+ &thrower, i::wasm::ModuleOrigin::kWasmOrigin);
+ if (maybe_compiled.is_null()) return MaybeLocal<WasmCompiledModule>();
+ return Local<WasmCompiledModule>::Cast(
+ Utils::ToLocal(maybe_compiled.ToHandleChecked()));
}
// static

Powered by Google App Engine
This is Rietveld 408576698