Bug 1379830 - stylo: Allow ServoStyleContext to participate in ArenaRefPtr; r=bholley
authorManish Goregaokar <manishearth@gmail.com>
Tue, 18 Jul 2017 16:52:41 -0700
changeset 418539 31ae02774ca909703e18c7b9f0a0f0a4f133e1ed
parent 418538 9043cd8fdee3f628f26d68ceae6c8d3de2936ffe
child 418540 f026b16bb1e8cbd8fcdd23d01d23f540e378bd27
push id7566
push usermtabara@mozilla.com
push dateWed, 02 Aug 2017 08:25:16 +0000
treeherdermozilla-beta@86913f512c3c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbholley
bugs1379830
milestone56.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 1379830 - stylo: Allow ServoStyleContext to participate in ArenaRefPtr; r=bholley MozReview-Commit-ID: 3uuokS0yAS6
layout/base/ArenaRefPtr.h
layout/base/ArenaRefPtrInlines.h
layout/base/nsPresArena.cpp
layout/base/nsPresArenaObjectList.h
--- a/layout/base/ArenaRefPtr.h
+++ b/layout/base/ArenaRefPtr.h
@@ -13,27 +13,16 @@
 
 #ifndef mozilla_ArenaRefPtr_h
 #define mozilla_ArenaRefPtr_h
 
 class nsPresArena;
 
 namespace mozilla {
 
-// Most consumers of ArenaRefPtr will unconditionally use the arena
-// However, nsStyleContext only uses the arena if it is a GeckoStyleContext
-// so we need a mechanism to override this
-template<class U>
-struct ArenaRefPtrTraits
-{
-  static bool UsesArena(U* aPtr) {
-    return true;
-  }
-};
-
 /**
  * A class for holding strong references to nsPresArena-allocated
  * objects.
  *
  * Since the arena's lifetime is not related to the refcounts
  * of the objects allocated within it, it is possible to have a strong
  * reference to an arena-allocated object that lives until the
  * destruction of the arena.  An ArenaRefPtr acts like a weak reference
@@ -149,22 +138,22 @@ private:
 
   template<typename I>
   void assignFrom(I& aPtr)
   {
     if (aPtr == mPtr) {
       return;
     }
     bool sameArena = mPtr && aPtr && mPtr->Arena() == aPtr->Arena();
-    if (mPtr && !sameArena && ArenaRefPtrTraits<T>::UsesArena(mPtr)) {
+    if (mPtr && !sameArena) {
       MOZ_ASSERT(mPtr->Arena());
       mPtr->Arena()->DeregisterArenaRefPtr(this);
     }
     mPtr = Move(aPtr);
-    if (mPtr && !sameArena && ArenaRefPtrTraits<T>::UsesArena(aPtr)) {
+    if (mPtr && !sameArena) {
       MOZ_ASSERT(mPtr->Arena());
       mPtr->Arena()->RegisterArenaRefPtr(this);
     }
   }
 
   RefPtr<T> mPtr;
 };
 
--- a/layout/base/ArenaRefPtrInlines.h
+++ b/layout/base/ArenaRefPtrInlines.h
@@ -17,38 +17,24 @@
 #include "nsStyleContext.h"
 
 namespace mozilla {
 
 template<typename T>
 void
 ArenaRefPtr<T>::AssertValidType()
 {
-#ifdef DEBUG
-  bool ok =
-#define PRES_ARENA_OBJECT_WITH_ARENAREFPTR_SUPPORT(name_) \
-    T::ArenaObjectID() == eArenaObjectID_##name_ ||
-#include "nsPresArenaObjectList.h"
-#undef PRES_ARENA_OBJECT_WITH_ARENAREFPTR_SUPPORT
-    false;
-  MOZ_ASSERT(ok, "ArenaRefPtr<T> template parameter T must be declared in "
-                 "nsPresArenaObjectList with "
-                 "PRES_ARENA_OBJECT_WITH_ARENAREFPTR_SUPPORT");
-#endif
+  // If adding new types, please update nsPresArena::ClearArenaRefPtrWithoutDeregistering
+  // as well
+  static_assert(IsSame<T, GeckoStyleContext>::value || IsSame<T, nsStyleContext>::value,
+                 "ArenaRefPtr<T> template parameter T must be declared in "
+                 "nsPresArenaObjectList and explicitly handled in"
+                 "nsPresArena.cpp");
 }
 
-template<>
-struct ArenaRefPtrTraits<nsStyleContext>
-{
-  static bool UsesArena(nsStyleContext* aPtr) {
-    MOZ_ASSERT(aPtr);
-    return aPtr->IsGecko();
-  }
-};
-
 } // namespace mozilla
 
 template<typename T>
 void
 nsPresArena::RegisterArenaRefPtr(mozilla::ArenaRefPtr<T>* aPtr)
 {
   MOZ_ASSERT(!mArenaRefPtrs.Contains(aPtr));
   mArenaRefPtrs.Put(aPtr, T::ArenaObjectID());
--- a/layout/base/nsPresArena.cpp
+++ b/layout/base/nsPresArena.cpp
@@ -11,16 +11,18 @@
 
 #include "mozilla/Poison.h"
 #include "nsDebug.h"
 #include "nsArenaMemoryStats.h"
 #include "nsPrintfCString.h"
 #include "GeckoStyleContext.h"
 #include "FrameLayerBuilder.h"
 #include "mozilla/ArrayUtils.h"
+#include "nsStyleContext.h"
+#include "nsStyleContextInlines.h"
 
 #include <inttypes.h>
 
 using namespace mozilla;
 
 nsPresArena::nsPresArena()
 {
 }
@@ -41,33 +43,22 @@ nsPresArena::~nsPresArena()
 #endif
 }
 
 /* inline */ void
 nsPresArena::ClearArenaRefPtrWithoutDeregistering(void* aPtr,
                                                   ArenaObjectID aObjectID)
 {
   switch (aObjectID) {
-#define PRES_ARENA_OBJECT_WITH_ARENAREFPTR_SUPPORT(name_)                     \
-    case eArenaObjectID_##name_:                                              \
-      static_cast<ArenaRefPtr<name_>*>(aPtr)->ClearWithoutDeregistering();    \
+    // We use ArenaRefPtr<nsStyleContext>, which can be ServoStyleContext
+    // or GeckoStyleContext. GeckoStyleContext is actually arena managed,
+    // but ServoStyleContext isn't.
+    case eArenaObjectID_GeckoStyleContext:
+      static_cast<ArenaRefPtr<nsStyleContext>*>(aPtr)->ClearWithoutDeregistering();
       return;
-#include "nsPresArenaObjectList.h"
-#undef PRES_ARENA_OBJECT_WITH_ARENAREFPTR_SUPPORT
-    default:
-      break;
-  }
-  switch (aObjectID) {
-#define PRES_ARENA_OBJECT_WITHOUT_ARENAREFPTR_SUPPORT(name_)                  \
-    case eArenaObjectID_##name_:                                              \
-      MOZ_ASSERT(false, #name_ " must be declared in nsPresArenaObjectList.h "\
-                        "with PRES_ARENA_OBJECT_SUPPORTS_ARENAREFPTR");       \
-      break;
-#include "nsPresArenaObjectList.h"
-#undef PRES_ARENA_OBJECT_WITHOUT_ARENAREFPTR_SUPPORT
     default:
       MOZ_ASSERT(false, "unexpected ArenaObjectID value");
       break;
   }
 }
 
 void
 nsPresArena::ClearArenaRefPtrs()
--- a/layout/base/nsPresArenaObjectList.h
+++ b/layout/base/nsPresArenaObjectList.h
@@ -5,73 +5,31 @@
 
 /* a list of all types that can be allocated in an nsPresArena, for
    preprocessing */
 
 #ifdef STYLE_STRUCT
 #error Sorry nsPresArenaObjectList.h needs to use STYLE_STRUCT!
 #endif
 
-#ifdef PRES_ARENA_OBJECT
-#if defined(PRES_ARENA_OBJECT_WITHOUT_ARENAREFPTR_SUPPORT) || \
-    defined(PRES_ARENA_OBJECT_WITH_ARENAREFPTR_SUPPORT)
-#error Must not define PRES_ARENA_OBJECT along with \
-       PRES_ARENA_OBJECT_WITHOUT_ARENAREFPTR_SUPPORT or \
-       PRES_ARENA_OBJECT_WITH_ARENAREFPTR_SUPPORT.
-#endif
-#define PRES_ARENA_OBJECT_WITHOUT_ARENAREFPTR_SUPPORT(name_) PRES_ARENA_OBJECT(name_)
-#define PRES_ARENA_OBJECT_WITH_ARENAREFPTR_SUPPORT(name_) PRES_ARENA_OBJECT(name_)
-#define DEFINED_PRES_ARENA_OBJECT_WITHOUT_ARENAREFPTR_SUPPORT
-#define DEFINED_PRES_ARENA_OBJECT_WITH_ARENAREFPTR_SUPPORT
-#endif
+// These are objects that can be stored in the pres arena
 
-#ifndef PRES_ARENA_OBJECT_WITHOUT_ARENAREFPTR_SUPPORT
-#define PRES_ARENA_OBJECT_WITHOUT_ARENAREFPTR_SUPPORT(name_) /* nothing */
-#define DEFINED_PRES_ARENA_OBJECT_WITHOUT_ARENAREFPTR_SUPPORT
-#endif
-
-#ifndef PRES_ARENA_OBJECT_WITH_ARENAREFPTR_SUPPORT
-#define PRES_ARENA_OBJECT_WITH_ARENAREFPTR_SUPPORT(name_) /* nothing */
-#define DEFINED_PRES_ARENA_OBJECT_WITH_ARENAREFPTR_SUPPORT
-#endif
+PRES_ARENA_OBJECT(GeckoStyleContext)
 
-// Use PRES_ARENA_OBJECT_WITHOUT_ARENAREFPTR_SUPPORT to mention an nsPresArena-
-// allocated object that does not support ArenaRefPtr, and use
-// PRES_ARENA_OBJECT_WITH_ARENAREFPTR_SUPPORT to mention one that does.
-//
-// All PRES_ARENA_OBJECT_WITH_ARENAREFPTR_SUPPORT classes must be #included into
-// nsPresArena.cpp.
-//
-// Files including nsPresArenaObjectList.h can either define one or both
-// of PRES_ARENA_OBJECT_{WITH,WITHOUT}_ARENAREFPTR_SUPPORT to capture those
-// classes separately, or PRES_ARENA_OBJECT to capture all nsPresArena-
-// allocated classes.
-
-PRES_ARENA_OBJECT_WITHOUT_ARENAREFPTR_SUPPORT(nsLineBox)
-PRES_ARENA_OBJECT_WITHOUT_ARENAREFPTR_SUPPORT(nsRuleNode)
-PRES_ARENA_OBJECT_WITH_ARENAREFPTR_SUPPORT(GeckoStyleContext)
-PRES_ARENA_OBJECT_WITHOUT_ARENAREFPTR_SUPPORT(DisplayItemData)
-PRES_ARENA_OBJECT_WITHOUT_ARENAREFPTR_SUPPORT(nsInheritedStyleData)
-PRES_ARENA_OBJECT_WITHOUT_ARENAREFPTR_SUPPORT(nsResetStyleData)
-PRES_ARENA_OBJECT_WITHOUT_ARENAREFPTR_SUPPORT(nsConditionalResetStyleData)
-PRES_ARENA_OBJECT_WITHOUT_ARENAREFPTR_SUPPORT(nsConditionalResetStyleDataEntry)
-PRES_ARENA_OBJECT_WITHOUT_ARENAREFPTR_SUPPORT(nsFrameList)
-PRES_ARENA_OBJECT_WITHOUT_ARENAREFPTR_SUPPORT(CustomCounterStyle)
-PRES_ARENA_OBJECT_WITHOUT_ARENAREFPTR_SUPPORT(DependentBuiltinCounterStyle)
-PRES_ARENA_OBJECT_WITHOUT_ARENAREFPTR_SUPPORT(nsCallbackEventRequest)
-PRES_ARENA_OBJECT_WITHOUT_ARENAREFPTR_SUPPORT(nsIntervalSet_Interval)
-PRES_ARENA_OBJECT_WITHOUT_ARENAREFPTR_SUPPORT(CellData)
-PRES_ARENA_OBJECT_WITHOUT_ARENAREFPTR_SUPPORT(BCCellData)
+PRES_ARENA_OBJECT(nsLineBox)
+PRES_ARENA_OBJECT(nsRuleNode)
+PRES_ARENA_OBJECT(DisplayItemData)
+PRES_ARENA_OBJECT(nsInheritedStyleData)
+PRES_ARENA_OBJECT(nsResetStyleData)
+PRES_ARENA_OBJECT(nsConditionalResetStyleData)
+PRES_ARENA_OBJECT(nsConditionalResetStyleDataEntry)
+PRES_ARENA_OBJECT(nsFrameList)
+PRES_ARENA_OBJECT(CustomCounterStyle)
+PRES_ARENA_OBJECT(DependentBuiltinCounterStyle)
+PRES_ARENA_OBJECT(nsCallbackEventRequest)
+PRES_ARENA_OBJECT(nsIntervalSet_Interval)
+PRES_ARENA_OBJECT(CellData)
+PRES_ARENA_OBJECT(BCCellData)
 
 #define STYLE_STRUCT(name_, checkdata_cb_) \
-  PRES_ARENA_OBJECT_WITHOUT_ARENAREFPTR_SUPPORT(nsStyle##name_)
+  PRES_ARENA_OBJECT(nsStyle##name_)
 #include "nsStyleStructList.h"
 #undef STYLE_STRUCT
-
-#ifdef DEFINED_PRES_ARENA_OBJECT_WITHOUT_ARENAREFPTR_SUPPORT
-#undef PRES_ARENA_OBJECT_WITHOUT_ARENAREFPTR_SUPPORT
-#undef DEFINED_PRES_ARENA_OBJECT_WITHOUT_ARENAREFPTR_SUPPORT
-#endif
-
-#ifdef DEFINED_PRES_ARENA_OBJECT_WITH_ARENAREFPTR_SUPPORT
-#undef PRES_ARENA_OBJECT_WITH_ARENAREFPTR_SUPPORT
-#undef DEFINED_PRES_ARENA_OBJECT_WITH_ARENAREFPTR_SUPPORT
-#endif