Bug 1731218 - Part 1: Rename rooting API base classes to 'Operations' in prepartion for adding base classes r=sfink
authorJon Coppeard <jcoppeard@mozilla.com>
Tue, 21 Sep 2021 11:17:49 +0000
changeset 592638 b45dc61300b183efa0f6bcf19bf0f0a431f4d958
parent 592637 5c9145f71f553a5d739ce32abde81d2e7479ee15
child 592639 bc5898ff5c3d4311adba5cdc7c35dc753d127a89
push id150104
push userjcoppeard@mozilla.com
push dateTue, 21 Sep 2021 11:20:42 +0000
treeherderautoland@f76391987517 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssfink
bugs1731218
milestone94.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 1731218 - Part 1: Rename rooting API base classes to 'Operations' in prepartion for adding base classes r=sfink These are really mixins used to add public methods based on the type and don't need to the base of an inheritance tree. Differential Revision: https://phabricator.services.mozilla.com/D125950
js/public/RootingAPI.h
js/public/Value.h
js/src/gc/MaybeRooted.h
js/src/vm/Interpreter.cpp
js/src/vm/JSObject.h
--- a/js/public/RootingAPI.h
+++ b/js/public/RootingAPI.h
@@ -120,26 +120,27 @@ struct BarrierMethods {};
 template <typename Element, typename Wrapper>
 class WrappedPtrOperations {};
 
 template <typename Element, typename Wrapper>
 class MutableWrappedPtrOperations
     : public WrappedPtrOperations<Element, Wrapper> {};
 
 template <typename T, typename Wrapper>
-class RootedBase : public MutableWrappedPtrOperations<T, Wrapper> {};
+class RootedOperations : public MutableWrappedPtrOperations<T, Wrapper> {};
+
+template <typename T, typename Wrapper>
+class HandleOperations : public WrappedPtrOperations<T, Wrapper> {};
 
 template <typename T, typename Wrapper>
-class HandleBase : public WrappedPtrOperations<T, Wrapper> {};
+class MutableHandleOperations : public MutableWrappedPtrOperations<T, Wrapper> {
+};
 
 template <typename T, typename Wrapper>
-class MutableHandleBase : public MutableWrappedPtrOperations<T, Wrapper> {};
-
-template <typename T, typename Wrapper>
-class HeapBase : public MutableWrappedPtrOperations<T, Wrapper> {};
+class HeapOperations : public MutableWrappedPtrOperations<T, Wrapper> {};
 
 // Cannot use FOR_EACH_HEAP_ABLE_GC_POINTER_TYPE, as this would import too many
 // macros into scope
 template <typename T>
 struct IsHeapConstructibleType {
   static constexpr bool value = false;
 };
 #define DECLARE_IS_HEAP_CONSTRUCTIBLE_TYPE(T) \
@@ -284,17 +285,17 @@ inline void AssertGCThingIsNotNurseryAll
  * keep the pointed-to GC thing alive.
  *
  * Heap<T> objects should only be used on the heap. GC references stored on the
  * C/C++ stack must use Rooted/Handle/MutableHandle instead.
  *
  * Type T must be a public GC pointer type.
  */
 template <typename T>
-class MOZ_NON_MEMMOVABLE Heap : public js::HeapBase<T, Heap<T>> {
+class MOZ_NON_MEMMOVABLE Heap : public js::HeapOperations<T, Heap<T>> {
   // Please note: this can actually also be used by nsXBLMaybeCompiled<T>, for
   // legacy reasons.
   static_assert(js::IsHeapConstructibleType<T>::value,
                 "Type T must be a public GC pointer type");
 
  public:
   using ElementType = T;
 
@@ -444,17 +445,17 @@ inline void AssertObjectIsNotGray(const 
  * The considerations to keep in mind when using a TenuredHeap<T> vs a normal
  * Heap<T> are:
  *
  *  - It is invalid for a TenuredHeap<T> to refer to a non-tenured thing.
  *  - It is however valid for a Heap<T> to refer to a tenured thing.
  *  - It is not possible to store flag bits in a Heap<T>.
  */
 template <typename T>
-class TenuredHeap : public js::HeapBase<T, TenuredHeap<T>> {
+class TenuredHeap : public js::HeapOperations<T, TenuredHeap<T>> {
  public:
   using ElementType = T;
 
   TenuredHeap() : bits(0) {
     static_assert(sizeof(T) == sizeof(TenuredHeap<T>),
                   "TenuredHeap<T> must be binary compatible with T.");
   }
   explicit TenuredHeap(T p) : bits(0) { setPtr(p); }
@@ -564,20 +565,20 @@ template <typename T>
 class PersistentRooted;
 
 /**
  * Reference to a T that has been rooted elsewhere. This is most useful
  * as a parameter type, which guarantees that the T lvalue is properly
  * rooted. See "Move GC Stack Rooting" above.
  *
  * If you want to add additional methods to Handle for a specific
- * specialization, define a HandleBase<T> specialization containing them.
+ * specialization, define a HandleOperations<T> specialization containing them.
  */
 template <typename T>
-class MOZ_NONHEAP_CLASS Handle : public js::HandleBase<T, Handle<T>> {
+class MOZ_NONHEAP_CLASS Handle : public js::HandleOperations<T, Handle<T>> {
   friend class MutableHandle<T>;
 
  public:
   using ElementType = T;
 
   Handle(const Handle<T>&) = default;
 
   /* Creates a handle from a handle of a type convertible to T. */
@@ -662,22 +663,22 @@ struct DefineComparisonOps<Handle<T>> : 
 
 }  // namespace detail
 
 /**
  * Similar to a handle, but the underlying storage can be changed. This is
  * useful for outparams.
  *
  * If you want to add additional methods to MutableHandle for a specific
- * specialization, define a MutableHandleBase<T> specialization containing
+ * specialization, define a MutableHandleOperations<T> specialization containing
  * them.
  */
 template <typename T>
 class MOZ_STACK_CLASS MutableHandle
-    : public js::MutableHandleBase<T, MutableHandle<T>> {
+    : public js::MutableHandleOperations<T, MutableHandle<T>> {
  public:
   using ElementType = T;
 
   inline MOZ_IMPLICIT MutableHandle(Rooted<T>* root);
   inline MOZ_IMPLICIT MutableHandle(PersistentRooted<T>* root);
 
  private:
   // Disallow nullptr for overloading purposes.
@@ -1098,20 +1099,20 @@ using RootedPtrTraits =
 } /* namespace detail */
 
 /**
  * Local variable of type T whose value is always rooted. This is typically
  * used for local variables, or for non-rooted values being passed to a
  * function that requires a handle, e.g. Foo(Root<T>(cx, x)).
  *
  * If you want to add additional methods to Rooted for a specific
- * specialization, define a RootedBase<T> specialization containing them.
+ * specialization, define a RootedOperations<T> specialization containing them.
  */
 template <typename T>
-class MOZ_RAII Rooted : public js::RootedBase<T, Rooted<T>> {
+class MOZ_RAII Rooted : public js::RootedOperations<T, Rooted<T>> {
   using Ptr = detail::RootedPtr<T>;
   using PtrTraits = detail::RootedPtrTraits<T>;
 
   inline void registerWithRootLists(RootedListHeads& roots) {
     this->stack = &roots[JS::MapTypeToRootKind<T>::kind];
     this->prev = *stack;
     *stack = reinterpret_cast<Rooted<detail::RootListEntry*>*>(this);
   }
@@ -1261,17 +1262,17 @@ inline ProfilingStack* GetContextProfili
  *
  * Given a Rooted<JSObject*> obj, one can view
  *   Handle<StringObject*> h = obj.as<StringObject*>();
  * as an optimization of
  *   Rooted<StringObject*> rooted(cx, &obj->as<StringObject*>());
  *   Handle<StringObject*> h = rooted;
  */
 template <typename Container>
-class RootedBase<JSObject*, Container>
+class RootedOperations<JSObject*, Container>
     : public MutableWrappedPtrOperations<JSObject*, Container> {
  public:
   template <class U>
   JS::Handle<U*> as() const;
 };
 
 /**
  * Augment the generic Handle<T> interface when T = JSObject* with
@@ -1279,17 +1280,17 @@ class RootedBase<JSObject*, Container>
  *
  * Given a Handle<JSObject*> obj, one can view
  *   Handle<StringObject*> h = obj.as<StringObject*>();
  * as an optimization of
  *   Rooted<StringObject*> rooted(cx, &obj->as<StringObject*>());
  *   Handle<StringObject*> h = rooted;
  */
 template <typename Container>
-class HandleBase<JSObject*, Container>
+class HandleOperations<JSObject*, Container>
     : public WrappedPtrOperations<JSObject*, Container> {
  public:
   template <class U>
   JS::Handle<U*> as() const;
 };
 
 } /* namespace js */
 
@@ -1371,17 +1372,17 @@ JS_PUBLIC_API void AddPersistentRoot(
  * Firefox is owned by some JS object or another, so using PersistentRooted in
  * such objects would introduce leaks. For these kinds of edges, Heap<T> or
  * TenuredHeap<T> would be better types. It's up to the implementor of the type
  * containing Heap<T> or TenuredHeap<T> members to make sure their referents get
  * marked when the object itself is marked.
  */
 template <typename T>
 class PersistentRooted
-    : public js::RootedBase<T, PersistentRooted<T>>,
+    : public js::RootedOperations<T, PersistentRooted<T>>,
       private mozilla::LinkedListElement<PersistentRooted<T>> {
   using ListBase = mozilla::LinkedListElement<PersistentRooted<T>>;
   using Ptr = detail::RootedPtr<T>;
   using PtrTraits = detail::RootedPtrTraits<T>;
 
   friend class mozilla::LinkedList<PersistentRooted>;
   friend class mozilla::LinkedListElement<PersistentRooted>;
 
--- a/js/public/Value.h
+++ b/js/public/Value.h
@@ -1212,17 +1212,17 @@ class MutableWrappedPtrOperations<JS::Va
   }
 };
 
 /*
  * Augment the generic Heap<T> interface when T = Value with
  * type-querying, value-extracting, and mutating operations.
  */
 template <typename Wrapper>
-class HeapBase<JS::Value, Wrapper>
+class HeapOperations<JS::Value, Wrapper>
     : public MutableWrappedPtrOperations<JS::Value, Wrapper> {};
 
 MOZ_HAVE_NORETURN MOZ_COLD MOZ_NEVER_INLINE void ReportBadValueTypeAndCrash(
     const JS::Value& val);
 
 // If the Value is a GC pointer type, call |f| with the pointer cast to that
 // type and return the result wrapped in a Maybe, otherwise return None().
 template <typename F>
--- a/js/src/gc/MaybeRooted.h
+++ b/js/src/gc/MaybeRooted.h
@@ -23,17 +23,17 @@
 
 namespace js {
 
 /**
  * Interface substitute for Rooted<T> which does not root the variable's
  * memory.
  */
 template <typename T>
-class MOZ_RAII FakeRooted : public RootedBase<T, FakeRooted<T>> {
+class MOZ_RAII FakeRooted : public RootedOperations<T, FakeRooted<T>> {
  public:
   using ElementType = T;
 
   explicit FakeRooted(JSContext* cx) : ptr(JS::SafelyInitialized<T>()) {}
 
   FakeRooted(JSContext* cx, T initial) : ptr(initial) {}
 
   DECLARE_POINTER_CONSTREF_OPS(T);
@@ -67,17 +67,17 @@ struct DefineComparisonOps<js::FakeRoote
 namespace js {
 
 /**
  * Interface substitute for MutableHandle<T> which is not required to point to
  * rooted memory.
  */
 template <typename T>
 class FakeMutableHandle
-    : public js::MutableHandleBase<T, FakeMutableHandle<T>> {
+    : public js::MutableHandleOperations<T, FakeMutableHandle<T>> {
  public:
   using ElementType = T;
 
   MOZ_IMPLICIT FakeMutableHandle(T* t) : ptr(t) {}
 
   MOZ_IMPLICIT FakeMutableHandle(FakeRooted<T>* root) : ptr(root->address()) {}
 
   void set(const T& v) { *ptr = v; }
--- a/js/src/vm/Interpreter.cpp
+++ b/js/src/vm/Interpreter.cpp
@@ -1788,17 +1788,17 @@ static MOZ_ALWAYS_INLINE void InitElemAr
  * upon entry. ReservedRooted "borrows" a reserved Rooted variable and uses it
  * within a local scope, resetting the value to nullptr (or the appropriate
  * equivalent for T) at scope end. This avoids inserting/removing the Rooted
  * from the rooter list, while preventing stale values from being kept alive
  * unnecessarily.
  */
 
 template <typename T>
-class ReservedRooted : public RootedBase<T, ReservedRooted<T>> {
+class ReservedRooted : public RootedOperations<T, ReservedRooted<T>> {
   Rooted<T>* savedRoot;
 
  public:
   ReservedRooted(Rooted<T>* root, const T& ptr) : savedRoot(root) {
     *root = ptr;
   }
 
   explicit ReservedRooted(Rooted<T>* root) : savedRoot(root) {
--- a/js/src/vm/JSObject.h
+++ b/js/src/vm/JSObject.h
@@ -559,27 +559,27 @@ class JSObject
 
 template <>
 inline bool JSObject::is<JSObject>() const {
   return true;
 }
 
 template <typename Wrapper>
 template <typename U>
-MOZ_ALWAYS_INLINE JS::Handle<U*> js::RootedBase<JSObject*, Wrapper>::as()
+MOZ_ALWAYS_INLINE JS::Handle<U*> js::RootedOperations<JSObject*, Wrapper>::as()
     const {
   const Wrapper& self = *static_cast<const Wrapper*>(this);
   MOZ_ASSERT(self->template is<U>());
   return Handle<U*>::fromMarkedLocation(
       reinterpret_cast<U* const*>(self.address()));
 }
 
 template <typename Wrapper>
 template <class U>
-MOZ_ALWAYS_INLINE JS::Handle<U*> js::HandleBase<JSObject*, Wrapper>::as()
+MOZ_ALWAYS_INLINE JS::Handle<U*> js::HandleOperations<JSObject*, Wrapper>::as()
     const {
   const JS::Handle<JSObject*>& self =
       *static_cast<const JS::Handle<JSObject*>*>(this);
   MOZ_ASSERT(self->template is<U>());
   return Handle<U*>::fromMarkedLocation(
       reinterpret_cast<U* const*>(self.address()));
 }