Bug 712289. Make sure that alignment requirements agree for js::Value and jsval_layout. r=luke
authorBoris Zbarsky <bzbarsky@mit.edu>
Sat, 14 Jan 2012 23:39:32 -0500
changeset 85763 b4195741db430f6ef949926ae0efe8902baae27e
parent 85762 5e6e63f3aed889ec7474ab688856c0418aba3e3a
child 85764 1b67951de0a28eb0f308fdd1061a02a48c07c767
push id805
push userakeybl@mozilla.com
push dateWed, 01 Feb 2012 18:17:35 +0000
treeherdermozilla-aurora@6fb3bf232436 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersluke
bugs712289
milestone12.0a1
Bug 712289. Make sure that alignment requirements agree for js::Value and jsval_layout. r=luke
js/src/jsapi.h
js/src/jsval.h
--- a/js/src/jsapi.h
+++ b/js/src/jsapi.h
@@ -645,17 +645,17 @@ class Value
         JS_STATIC_ASSERT(sizeof(JSValueTag) == 4);
         JS_STATIC_ASSERT(sizeof(JSBool) == 4);
         JS_STATIC_ASSERT(sizeof(JSWhyMagic) <= 4);
         JS_STATIC_ASSERT(sizeof(Value) == 8);
     }
 
     friend jsval_layout (::JSVAL_TO_IMPL)(Value);
     friend Value (::IMPL_TO_JSVAL)(jsval_layout l);
-} JSVAL_ALIGNMENT;
+};
 
 inline bool
 IsPoisonedValue(const Value &v)
 {
     if (v.isString())
         return IsPoisonedPtr(v.toString());
     if (v.isObject())
         return IsPoisonedPtr(&v.toObject());
@@ -1052,16 +1052,21 @@ JSVAL_TO_IMPL(jsval v)
 static JS_ALWAYS_INLINE jsval
 IMPL_TO_JSVAL(jsval_layout l)
 {
     JS::Value v;
     v.data = l;
     return v;
 }
 
+#ifdef DEBUG
+struct JSValueAlignmentTester { char c; JS::Value v; };
+JS_STATIC_ASSERT(sizeof(JSValueAlignmentTester) == 16);
+#endif /* DEBUG */
+
 #else  /* defined(__cplusplus) */
 
 /*
  * For SpiderMonkey C clients, there is no JS::Value class, only the
  * traditional jsval with the traditional JSVAL_* operations. Since
  * SpiderMonkey itself is always compiled as C++, this relies on the binary
  * compatibility of jsval_layout and JS::Value (statically asserted below).
  */
@@ -1076,16 +1081,21 @@ JSVAL_TO_IMPL(jsval v)
 static JS_ALWAYS_INLINE jsval
 IMPL_TO_JSVAL(jsval_layout l)
 {
     return l;
 }
 
 #endif  /* defined(__cplusplus) */
 
+#ifdef DEBUG
+typedef struct { char c; jsval_layout l; } JSLayoutAlignmentTester;
+JS_STATIC_ASSERT(sizeof(JSLayoutAlignmentTester) == 16);
+#endif /* DEBUG */
+
 JS_STATIC_ASSERT(sizeof(jsval_layout) == sizeof(jsval));
 
 /************************************************************************/
 
 /* JSClass operation signatures. */
 
 /*
  * Add, delete, or get a property named by id in obj.  Note the jsid id
--- a/js/src/jsval.h
+++ b/js/src/jsval.h
@@ -305,17 +305,17 @@ typedef union jsval_layout
             void           *ptr;
             JSWhyMagic     why;
             size_t         word;
         } payload;
         JSValueTag tag;
     } s;
     double asDouble;
     void *asPtr;
-} jsval_layout;
+} JSVAL_ALIGNMENT jsval_layout;
 # elif JS_BITS_PER_WORD == 64
 typedef union jsval_layout
 {
     uint64_t asBits;
 #if (!defined(_WIN64) && defined(__cplusplus))
     /* MSVC does not pack these correctly :-( */
     struct {
         uint64_t           payload47 : 47;
@@ -327,17 +327,17 @@ typedef union jsval_layout
             int32_t        i32;
             uint32_t       u32;
             JSWhyMagic     why;
         } payload;
     } s;
     double asDouble;
     void *asPtr;
     size_t asWord;
-} jsval_layout;
+} JSVAL_ALIGNMENT jsval_layout;
 # endif  /* JS_BITS_PER_WORD */
 #else   /* defined(IS_LITTLE_ENDIAN) */
 # if JS_BITS_PER_WORD == 32
 typedef union jsval_layout
 {
     uint64_t asBits;
     struct {
         JSValueTag tag;
@@ -349,17 +349,17 @@ typedef union jsval_layout
             JSObject       *obj;
             void           *ptr;
             JSWhyMagic     why;
             size_t         word;
         } payload;
     } s;
     double asDouble;
     void *asPtr;
-} jsval_layout;
+} JSVAL_ALIGNMENT jsval_layout;
 # elif JS_BITS_PER_WORD == 64
 typedef union jsval_layout
 {
     uint64_t asBits;
     struct {
         JSValueTag         tag : 17;
         uint64_t           payload47 : 47;
     } debugView;
@@ -369,17 +369,17 @@ typedef union jsval_layout
             int32_t        i32;
             uint32_t       u32;
             JSWhyMagic     why;
         } payload;
     } s;
     double asDouble;
     void *asPtr;
     size_t asWord;
-} jsval_layout;
+} JSVAL_ALIGNMENT jsval_layout;
 # endif /* JS_BITS_PER_WORD */
 #endif  /* defined(IS_LITTLE_ENDIAN) */
 
 JS_STATIC_ASSERT(sizeof(jsval_layout) == 8);
 
 #if JS_BITS_PER_WORD == 32
 
 /*