Bug 1508085 - Track the sizes of commonly used node types also in 32 bit builds, r=ehsan
authorOlli Pettay <Olli.Pettay@helsinki.fi>
Mon, 19 Nov 2018 18:33:42 +0200
changeset 503550 9cdaafe1830232918fd372a04c49026a90aee2ed
parent 503549 2971a7e2d1e70e87fc0fe42b73514243130d4531
child 503551 9d92116a6e98e57ed4be283eb13d21984db886fd
push id10290
push userffxbld-merge
push dateMon, 03 Dec 2018 16:23:23 +0000
treeherdermozilla-beta@700bed2445e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs1508085
milestone65.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 1508085 - Track the sizes of commonly used node types also in 32 bit builds, r=ehsan
dom/base/Element.cpp
--- a/dom/base/Element.cpp
+++ b/dom/base/Element.cpp
@@ -14,16 +14,17 @@
 
 #include "AnimationCommon.h"
 #include "mozilla/DebugOnly.h"
 #include "mozilla/StaticPrefs.h"
 #include "mozilla/dom/Animation.h"
 #include "mozilla/dom/Attr.h"
 #include "mozilla/dom/Flex.h"
 #include "mozilla/dom/Grid.h"
+#include "mozilla/dom/Text.h"
 #include "mozilla/gfx/Matrix.h"
 #include "nsAtom.h"
 #include "nsCSSFrameConstructor.h"
 #include "nsDOMAttributeMap.h"
 #include "nsIContentInlines.h"
 #include "mozilla/dom/NodeInfo.h"
 #include "nsIDocumentInlines.h"
 #include "mozilla/dom/DocumentTimeline.h"
@@ -154,46 +155,49 @@
 
 #include "DOMMatrix.h"
 
 using namespace mozilla;
 using namespace mozilla::dom;
 
 using mozilla::gfx::Matrix4x4;
 
+// Verify sizes of nodes. We use a template rather than a direct static
+// assert so that the error message actually displays the sizes.
+// On 32 bit systems the actual allocated size varies a bit between
+// OSes/compilers.
 //
-// Verify sizes of elements on 64-bit platforms. This should catch most memory
-// regressions, and is easy to verify locally since most developers are on
-// 64-bit machines. We use a template rather than a direct static assert so
-// that the error message actually displays the sizes.
-//
-
 // We need different numbers on certain build types to deal with the owning
 // thread pointer that comes with the non-threadsafe refcount on
-// FragmentOrElement.
+// nsIContent.
 #ifdef MOZ_THREAD_SAFETY_OWNERSHIP_CHECKS_SUPPORTED
-#define EXTRA_DOM_ELEMENT_BYTES 8
+#define EXTRA_DOM_NODE_BYTES 8
 #else
-#define EXTRA_DOM_ELEMENT_BYTES 0
+#define EXTRA_DOM_NODE_BYTES 0
 #endif
 
-#define ASSERT_ELEMENT_SIZE(type, opt_size) \
-template<int a, int b> struct Check##type##Size \
+#define ASSERT_NODE_SIZE(type, opt_size_64, opt_size_32) \
+template<int a, int sizeOn64, int sizeOn32> struct Check##type##Size \
 { \
-  static_assert(sizeof(void*) != 8 || a == b, "DOM size changed"); \
+  static_assert((sizeof(void*) == 8 && a == sizeOn64) || \
+                (sizeof(void*) == 4 && a <= sizeOn32), "DOM size changed"); \
 }; \
-Check##type##Size<sizeof(type), opt_size + EXTRA_DOM_ELEMENT_BYTES> g##type##CES;
-
-// Note that mozjemalloc uses a 16 byte quantum, so 128 is a bin/bucket size.
-ASSERT_ELEMENT_SIZE(Element, 128);
-ASSERT_ELEMENT_SIZE(HTMLDivElement, 128);
-ASSERT_ELEMENT_SIZE(HTMLSpanElement, 128);
-
-#undef ASSERT_ELEMENT_SIZE
-#undef EXTRA_DOM_ELEMENT_BYTES
+Check##type##Size<sizeof(type), \
+                  opt_size_64 + EXTRA_DOM_NODE_BYTES, \
+                  opt_size_32 + EXTRA_DOM_NODE_BYTES> g##type##CES;
+
+// Note that mozjemalloc uses a 16 byte quantum, so 64, 80 and 128 are
+// bucket sizes.
+ASSERT_NODE_SIZE(Element, 128, 80);
+ASSERT_NODE_SIZE(HTMLDivElement, 128, 80);
+ASSERT_NODE_SIZE(HTMLSpanElement, 128, 80);
+ASSERT_NODE_SIZE(Text, 120, 64);
+
+#undef ASSERT_NODE_SIZE
+#undef EXTRA_DOM_NODE_BYTES
 
 nsAtom*
 nsIContent::DoGetID() const
 {
   MOZ_ASSERT(HasID(), "Unexpected call");
   MOZ_ASSERT(IsElement(), "Only elements can have IDs");
 
   return AsElement()->GetParsedAttr(nsGkAtoms::id)->GetAtomValue();