Bug 1467632 - Specialize ReadScalar<ExprType>. r=luke
authorLars T Hansen <lhansen@mozilla.com>
Tue, 21 Aug 2018 09:17:05 +0200
changeset 488131 aa3d1b33b0e94e6dae117d2e32e5cd007debd36a
parent 488130 a0883c99c897122286c6e1711cada83d9889e093
child 488132 e2b35cf75610a77c6470b370118cbd0517069718
push id9719
push userffxbld-merge
push dateFri, 24 Aug 2018 17:49:46 +0000
treeherdermozilla-beta@719ec98fba77 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersluke
bugs1467632
milestone63.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1467632 - Specialize ReadScalar<ExprType>. r=luke Normally ReadScalar uses memcpy from the source stream to the destination object. This is only well-defined if the destination argument is a POD type, which ExprType is not. So specialize ReadScalar for ExprType and make the memcpy target the data payload in that type instead.
js/src/wasm/WasmTypes.cpp
js/src/wasm/WasmTypes.h
--- a/js/src/wasm/WasmTypes.cpp
+++ b/js/src/wasm/WasmTypes.cpp
@@ -184,16 +184,31 @@ FuncType::serializedSize() const
 uint8_t*
 FuncType::serialize(uint8_t* cursor) const
 {
     cursor = WriteScalar<ExprType>(cursor, ret_);
     cursor = SerializePodVector(cursor, args_);
     return cursor;
 }
 
+namespace js { namespace wasm {
+
+// ExprType is not POD while ReadScalar requires POD, so specialize.
+template <>
+inline const uint8_t*
+ReadScalar<ExprType>(const uint8_t* src, ExprType* dst)
+{
+    static_assert(sizeof(PackedTypeCode) == sizeof(ExprType),
+                  "ExprType must carry only a PackedTypeCode");
+    memcpy(dst->packedPtr(), src, sizeof(PackedTypeCode));
+    return src + sizeof(*dst);
+}
+
+}}
+
 const uint8_t*
 FuncType::deserialize(const uint8_t* cursor)
 {
     (cursor = ReadScalar<ExprType>(cursor, &ret_)) &&
     (cursor = DeserializePodVector(cursor, &args_));
     return cursor;
 }
 
--- a/js/src/wasm/WasmTypes.h
+++ b/js/src/wasm/WasmTypes.h
@@ -297,16 +297,20 @@ class ExprType
     }
 
     explicit inline ExprType(const ValType& t);
 
     PackedTypeCode packed() const {
         return tc_;
     }
 
+    PackedTypeCode* packedPtr() {
+        return &tc_;
+    }
+
     Code code() const {
         return Code(UnpackTypeCodeType(tc_));
     }
 
     uint32_t refTypeIndex() const {
         return UnpackTypeCodeIndex(tc_);
     }