From 5de4722278e6a89c787e2ae951d9c2a0fb4a9ef8 Mon Sep 17 00:00:00 2001 From: mtrofin Date: Mon, 8 Aug 2016 11:18:59 -0700 Subject: [PATCH] [wasm] external serialization APIs V8 APIs for wasm serialization/deserialization. BUG=v8:5072 Review-Url: https://codereview.chromium.org/2226753002 Cr-Commit-Position: refs/heads/master@{#38455} --- include/v8.h | 1 + src/api.cc | 3 +++ src/objects-inl.h | 6 ++++++ src/objects.cc | 12 ++++++++++++ src/objects.h | 20 ++++++++++++++++++++ 5 files changed, 42 insertions(+) diff --git a/include/v8.h b/include/v8.h index 05fa0cf6fa..3fc062a38b 100644 --- a/include/v8.h +++ b/include/v8.h @@ -1952,6 +1952,7 @@ class V8_EXPORT Value : public Data { */ bool IsProxy() const; + bool IsWebAssemblyCompiledModule() const; V8_WARN_UNUSED_RESULT MaybeLocal ToBoolean( Local context) const; diff --git a/src/api.cc b/src/api.cc index fd70187a2c..02c36ffa11 100644 --- a/src/api.cc +++ b/src/api.cc @@ -2958,6 +2958,9 @@ bool Value::IsNumber() const { bool Value::IsProxy() const { return Utils::OpenHandle(this)->IsJSProxy(); } +bool Value::IsWebAssemblyCompiledModule() const { + return Utils::OpenHandle(this)->IsWebAssemblyCompiledModule(); +} #define VALUE_IS_SPECIFIC_TYPE(Type, Class) \ bool Value::Is##Type() const { \ diff --git a/src/objects-inl.h b/src/objects-inl.h index fe4438d246..2b0b271af3 100644 --- a/src/objects-inl.h +++ b/src/objects-inl.h @@ -143,6 +143,12 @@ bool HeapObject::IsFixedArrayBase() const { return IsFixedArray() || IsFixedDoubleArray() || IsFixedTypedArrayBase(); } +bool HeapObject::IsWebAssemblyCompiledModule() const { + if (!IsJSObject()) return false; + return GetIsolate()->native_context()->wasm_module_constructor() == + this->map()->GetConstructor(); +} + bool HeapObject::IsFixedArray() const { InstanceType instance_type = map()->instance_type(); return instance_type == FIXED_ARRAY_TYPE || diff --git a/src/objects.cc b/src/objects.cc index e2b3615df1..844c56b58d 100644 --- a/src/objects.cc +++ b/src/objects.cc @@ -58,6 +58,7 @@ #include "src/string-search.h" #include "src/string-stream.h" #include "src/utils.h" +#include "src/wasm/wasm-module.h" #include "src/zone.h" #ifdef ENABLE_DISASSEMBLER @@ -19006,6 +19007,17 @@ Handle JSTypedArray::GetBuffer() { return MaterializeArrayBuffer(self); } +std::pair, size_t> +WebAssemblyCompiledModule::Serialize() { + // TODO(mtrofin): tie to the internal serialization API + return {std::unique_ptr(), 0}; +} + +MaybeHandle WebAssemblyCompiledModule::Deserialize( + Isolate* isolate, const byte* data, size_t size) { + // TODO(mtrofin): tie to the internal serialization API + return MaybeHandle(); +} Handle PropertyCell::InvalidateEntry( Handle dictionary, int entry) { diff --git a/src/objects.h b/src/objects.h index 2a248b7d91..d16c7dd0da 100644 --- a/src/objects.h +++ b/src/objects.h @@ -1002,6 +1002,7 @@ template inline bool Is(Object* obj); V(JSWeakMap) \ V(JSWeakSet) \ V(JSRegExp) \ + V(WebAssemblyCompiledModule) \ V(HashTable) \ V(Dictionary) \ V(UnseededNumberDictionary) \ @@ -8149,6 +8150,25 @@ class JSMessageObject: public JSObject { kSize> BodyDescriptor; }; +// A compiled web assembly module. +class WebAssemblyCompiledModule : public JSObject { + public: + // Serialize the compiled module. The returned buffer is owned by + // the caller, who may simply leave the return value drop out of + // scope, once done processing the bytes. + // TODO(mtrofin): to avoid increased memory pressure, we should + // explore a caller-provided segmented memory design. + std::pair, size_t> Serialize(); + + // Deserialize a compiled module. The buffer is owned by the caller and may + // be released after deserialization returns. + static MaybeHandle Deserialize(Isolate* isolate, + const byte* data, + size_t size); + + private: + DISALLOW_IMPLICIT_CONSTRUCTORS(WebAssemblyCompiledModule); +}; // Regular expressions // The regular expression holds a single reference to a FixedArray in