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

Unified Diff: src/wasm/wasm-module.cc

Issue 2205973003: [wasm] Serialization/Deserialization of compiled module (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: fix silly bug Created 4 years, 4 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/wasm/wasm-module.cc
diff --git a/src/wasm/wasm-module.cc b/src/wasm/wasm-module.cc
index fdec11b33fb572aac5fbc42a3145cef376484fd3..0a2cf51a9fa28b3ab9c77ace6039a44cc635dc4e 100644
--- a/src/wasm/wasm-module.cc
+++ b/src/wasm/wasm-module.cc
@@ -5,12 +5,14 @@
#include <memory>
#include "src/base/atomic-utils.h"
+#include "src/code-stubs.h"
+
#include "src/macro-assembler.h"
#include "src/objects.h"
#include "src/property-descriptor.h"
-#include "src/v8.h"
-
#include "src/simulator.h"
+#include "src/snapshot/snapshot.h"
+#include "src/v8.h"
#include "src/wasm/ast-decoder.h"
#include "src/wasm/module-decoder.h"
@@ -21,6 +23,11 @@
#include "src/compiler/wasm-compiler.h"
+// DELETE THESE 2:
+#include "src/snapshot/code-serializer.h"
+#include "src/snapshot/deserializer.h"
Yang 2016/08/05 15:39:28 Should this be removed?
Mircea Trofin 2016/08/06 00:31:39 Done.
+//
+
namespace v8 {
namespace internal {
namespace wasm {
@@ -1517,6 +1524,50 @@ int GetNumberOfFunctions(JSObject* wasm) {
return ByteArray::cast(func_names_obj)->get_int(0);
}
+ScriptData* SerializeWasmCompiledModule(Isolate* isolate,
+ Handle<FixedArray> compiled_module) {
+ CodeSerializer cs(isolate, 0);
+ cs.reference_map()->AddAttachedReference(*isolate->native_context());
Yang 2016/08/05 12:04:17 Can we put all this into src/snapshot in a new sub
Mircea Trofin 2016/08/05 15:01:29 Knowing we need to attach the native context is sp
Yang 2016/08/05 15:39:28 Same thing can be said for CodeSerializer::Seriali
Mircea Trofin 2016/08/06 00:31:39 Done. I was a bit concerned that the serializer w
+ ScriptData* data = cs.Serialize(compiled_module);
+ return data;
+}
+
+MaybeHandle<FixedArray> DeserializeWasmCompiledModule(Isolate* isolate,
+ ScriptData* data) {
+ SanityCheckResult sanity_check_result = CHECK_SUCCESS;
+ MaybeHandle<FixedArray> nothing;
+ const SerializedCodeData scd = SerializedCodeData::FromCachedData(
+ isolate, data, 0, &sanity_check_result);
+
+ if (sanity_check_result != SanityCheckResult::CHECK_SUCCESS) {
+ return nothing;
+ }
+
+ Deserializer deserializer(&scd, true);
+ deserializer.AddAttachedObject(isolate->native_context());
+
+ Vector<const uint32_t> stub_keys = scd.CodeStubKeys();
+ for (int i = 0; i < stub_keys.length(); ++i) {
+ deserializer.AddAttachedObject(
+ CodeStub::GetCode(isolate, stub_keys[i]).ToHandleChecked());
+ }
+
+ MaybeHandle<HeapObject> obj = deserializer.DeserializeObject(isolate);
+ if (obj.is_null() || !obj.ToHandleChecked()->IsFixedArray()) return nothing;
+ return Handle<FixedArray>::cast(obj.ToHandleChecked());
+}
+
+Handle<JSObject> CreateCompiledModuleObject(
+ Isolate* isolate, Handle<FixedArray> compiled_module) {
+ Handle<JSFunction> module_cons(
+ isolate->native_context()->wasm_module_constructor());
+ Handle<JSObject> module_obj = isolate->factory()->NewJSObject(module_cons);
+ module_obj->SetInternalField(0, *compiled_module);
+ Handle<Symbol> module_sym(isolate->native_context()->wasm_module_sym());
+ Object::SetProperty(module_obj, module_sym, module_obj, STRICT).Check();
+ return module_obj;
+}
+
namespace testing {
int32_t CompileAndRunWasmModule(Isolate* isolate, const byte* module_start,

Powered by Google App Engine
This is Rietveld 408576698