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

Unified Diff: src/runtime/runtime-test.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/runtime/runtime-test.cc
diff --git a/src/runtime/runtime-test.cc b/src/runtime/runtime-test.cc
index 2232b190599a2b1a3025ea72bb44ef23596130ce..b317bb38056740aa0951895726d0de060d7db48a 100644
--- a/src/runtime/runtime-test.cc
+++ b/src/runtime/runtime-test.cc
@@ -12,6 +12,7 @@
#include "src/full-codegen/full-codegen.h"
#include "src/isolate-inl.h"
#include "src/snapshot/natives.h"
+#include "src/wasm/wasm-module.h"
namespace v8 {
namespace internal {
@@ -578,6 +579,43 @@ RUNTIME_FUNCTION(Runtime_SpeciesProtector) {
return isolate->heap()->ToBoolean(isolate->IsArraySpeciesLookupChainIntact());
}
+// Take a compiled wasm module, serialize it and copy the buffer into an array
+// buffer, which is then returned.
+RUNTIME_FUNCTION(Runtime_SerializeWasmModule) {
+ HandleScope shs(isolate);
+ DCHECK(args.length() == 1);
+ CONVERT_ARG_HANDLE_CHECKED(JSObject, module_obj, 0);
+
+ Handle<FixedArray> orig =
+ handle(FixedArray::cast(module_obj->GetInternalField(0)));
+ std::unique_ptr<ScriptData> data = std::unique_ptr<ScriptData>(
+ wasm::SerializeWasmCompiledModule(isolate, orig));
+ void* buff = isolate->array_buffer_allocator()->Allocate(data->length());
+ Handle<JSArrayBuffer> ret = isolate->factory()->NewJSArrayBuffer();
+ JSArrayBuffer::Setup(ret, isolate, false, buff, data->length());
+ memcpy(buff, data->data(), data->length());
+ return *ret;
+}
+
+// Take an array buffer and attempt to reconstruct a compiled wasm module.
+// Return undefined if unsuccessful.
+RUNTIME_FUNCTION(Runtime_DeserializeWasmModule) {
+ HandleScope shs(isolate);
+ DCHECK(args.length() == 1);
+ CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, buffer, 0);
+
+ Address mem_start = static_cast<Address>(buffer->backing_store());
+ int mem_size = static_cast<int>(buffer->byte_length()->Number());
+
+ ScriptData sc(mem_start, mem_size);
+ MaybeHandle<FixedArray> maybe_compiled_module =
+ wasm::DeserializeWasmCompiledModule(isolate, &sc);
+ Handle<FixedArray> compiled_module;
+ if (!maybe_compiled_module.ToHandle(&compiled_module)) {
+ return isolate->heap()->undefined_value();
+ }
+ return *wasm::CreateCompiledModuleObject(isolate, compiled_module);
+}
} // namespace internal
} // namespace v8

Powered by Google App Engine
This is Rietveld 408576698