Bug 1508873 - part 1 - statically assert alignment for hashtable entries; r=luke
authorNathan Froyd <froydnj@mozilla.com>
Thu, 13 Dec 2018 12:21:19 -0500
changeset 450391 ff944ef6b8a4bf09a8a8083ee7bf7dfa964e75b0
parent 450390 526d733d3c622f4c698a5960398098ad3905e814
child 450392 20d92a98e3a37f3fd5a58717f28567f214429b3e
push id110492
push usernfroyd@mozilla.com
push dateThu, 13 Dec 2018 17:21:43 +0000
treeherdermozilla-inbound@95e3de1d6643 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersluke
bugs1508873
milestone66.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 1508873 - part 1 - statically assert alignment for hashtable entries; r=luke We do this to make our lives easier in later patches; this check guarantees that we don't need padding between the block of cached hash values and the block of entries immediately after it.
mfbt/HashTable.h
--- a/mfbt/HashTable.h
+++ b/mfbt/HashTable.h
@@ -942,16 +942,29 @@ namespace detail {
 template <class T, class HashPolicy, class AllocPolicy>
 class HashTable;
 
 template <typename T>
 class HashTableEntry {
  private:
   using NonConstT = typename RemoveConst<T>::Type;
 
+#ifdef HAVE_64BIT_BUILD
+  static_assert(alignof(NonConstT) <= alignof(void*),
+                "cannot use over-aligned entries in mozilla::HashTable");
+#else
+  // This assertion is safe for 32-bit builds because on both Windows and Linux
+  // (including Android), the minimum alignment for allocations larger than 8
+  // bytes is 8 bytes, and the actual data for entries in our entry store is
+  // guaranteed to have that alignment as well, thanks to the power-of-two
+  // number of cached hash values stored prior to the entry data.
+  static_assert(alignof(NonConstT) <= 2 * alignof(void*),
+                "cannot use over-aligned entries in mozilla::HashTable");
+#endif
+
   static const HashNumber sFreeKey = 0;
   static const HashNumber sRemovedKey = 1;
   static const HashNumber sCollisionBit = 1;
 
   HashNumber mKeyHash = sFreeKey;
   alignas(NonConstT) unsigned char mValueData[sizeof(NonConstT)];
 
  private: