Bug 1388241 - Assert that all style structs are under 504 bytes. r?bz draft
authorXidorn Quan <me@upsuper.org>
Wed, 09 Aug 2017 11:47:02 +1000
changeset 643004 f4317263288b1e27af749992c0349c83cb81d745
parent 643000 d73556bc255909dc4e4c44c89dfd4f2aa69f1caa
child 725172 1c69db88f312a69e532f851b7adbb210036dfa1b
push id72951
push userxquan@mozilla.com
push dateWed, 09 Aug 2017 05:00:06 +0000
reviewersbz
bugs1388241
milestone57.0a1
Bug 1388241 - Assert that all style structs are under 504 bytes. r?bz MozReview-Commit-ID: BiXdV0caLHV
layout/style/nsStyleStruct.cpp
--- a/layout/style/nsStyleStruct.cpp
+++ b/layout/style/nsStyleStruct.cpp
@@ -46,16 +46,26 @@ using namespace mozilla::dom;
 
 static_assert((((1 << nsStyleStructID_Length) - 1) &
                ~(NS_STYLE_INHERIT_MASK)) == 0,
               "Not enough bits in NS_STYLE_INHERIT_MASK");
 
 /* static */ const int32_t nsStyleGridLine::kMinLine;
 /* static */ const int32_t nsStyleGridLine::kMaxLine;
 
+// We set the size limit of style structs to 504 bytes so that when they
+// are allocated by Servo side with Arc, the total size doesn't exceed
+// 512 bytes, which minimizes allocator slop.
+static constexpr size_t kStyleStructSizeLimit = 504;
+#define STYLE_STRUCT(name_, checkdata_cb_) \
+  static_assert(sizeof(nsStyle##name_) <= kStyleStructSizeLimit, \
+                "nsStyle" #name_ " became larger than the size limit");
+#include "nsStyleStructList.h"
+#undef STYLE_STRUCT
+
 static bool
 DefinitelyEqualURIs(css::URLValueData* aURI1,
                     css::URLValueData* aURI2)
 {
   return aURI1 == aURI2 ||
          (aURI1 && aURI2 && aURI1->DefinitelyEqualURIs(*aURI2));
 }