diff --git a/js/public/RootingAPI.h b/js/public/RootingAPI.h index fe08687cfdb4..c283fd698426 100644 --- a/js/public/RootingAPI.h +++ b/js/public/RootingAPI.h @@ -925,22 +925,15 @@ enum class AutoGCRooterKind : uint8_t { Limit }; -namespace detail { -// Dummy type to store root list entry pointers as. This code does not just use -// the actual type, because then eg JSObject* and JSFunction* would be assumed -// to never alias but they do (they are stored in the same list). Also, do not -// use `void*` so that `Rooted` is a compile error. -struct RootListEntry; -} // namespace detail - +// Our instantiations of Rooted and PersistentRooted require an +// instantiation of MapTypeToRootKind. template <> -struct MapTypeToRootKind { +struct MapTypeToRootKind { static const RootKind kind = RootKind::Traceable; }; using RootedListHeads = - mozilla::EnumeratedArray*>; + mozilla::EnumeratedArray*>; using AutoRooterListHeads = mozilla::EnumeratedArray> { inline void registerWithRootLists(RootedListHeads& roots) { this->stack = &roots[JS::MapTypeToRootKind::kind]; this->prev = *stack; - *stack = reinterpret_cast*>(this); + *stack = reinterpret_cast*>(this); } inline RootedListHeads& rootLists(RootingContext* cx) { @@ -1130,8 +1123,7 @@ class MOZ_RAII Rooted : public js::RootedBase> { } ~Rooted() { - MOZ_ASSERT(*stack == - reinterpret_cast*>(this)); + MOZ_ASSERT(*stack == reinterpret_cast*>(this)); *stack = prev; } @@ -1163,12 +1155,12 @@ class MOZ_RAII Rooted : public js::RootedBase> { private: /* - * These need to be templated on RootListEntry* to avoid aliasing issues - * between, for example, Rooted and Rooted, which use - * the same stack head pointer for different classes. + * These need to be templated on void* to avoid aliasing issues between, for + * example, Rooted and Rooted, which use the same + * stack head pointer for different classes. */ - Rooted** stack; - Rooted* prev; + Rooted** stack; + Rooted* prev; Ptr ptr; @@ -1297,13 +1289,11 @@ inline MutableHandle::MutableHandle(PersistentRooted* root) { ptr = root->address(); } -JS_PUBLIC_API void AddPersistentRoot( - RootingContext* cx, RootKind kind, - PersistentRooted* root); +JS_PUBLIC_API void AddPersistentRoot(RootingContext* cx, RootKind kind, + PersistentRooted* root); -JS_PUBLIC_API void AddPersistentRoot( - JSRuntime* rt, RootKind kind, - PersistentRooted* root); +JS_PUBLIC_API void AddPersistentRoot(JSRuntime* rt, RootKind kind, + PersistentRooted* root); /** * A copyable, assignable global GC root type with arbitrary lifetime, an @@ -1352,17 +1342,15 @@ class PersistentRooted void registerWithRootLists(RootingContext* cx) { MOZ_ASSERT(!initialized()); JS::RootKind kind = JS::MapTypeToRootKind::kind; - AddPersistentRoot( - cx, kind, - reinterpret_cast*>(this)); + AddPersistentRoot(cx, kind, + reinterpret_cast*>(this)); } void registerWithRootLists(JSRuntime* rt) { MOZ_ASSERT(!initialized()); JS::RootKind kind = JS::MapTypeToRootKind::kind; - AddPersistentRoot( - rt, kind, - reinterpret_cast*>(this)); + AddPersistentRoot(rt, kind, + reinterpret_cast*>(this)); } public: diff --git a/js/src/gc/RootMarking.cpp b/js/src/gc/RootMarking.cpp index 9403ec4c8240..4e10c3ef5864 100644 --- a/js/src/gc/RootMarking.cpp +++ b/js/src/gc/RootMarking.cpp @@ -75,9 +75,9 @@ inline void JS::PersistentRooted::trace(JSTracer* trc, const char* name) { } template -static inline void TraceExactStackRootList( - JSTracer* trc, JS::Rooted* listHead, - const char* name) { +static inline void TraceExactStackRootList(JSTracer* trc, + JS::Rooted* listHead, + const char* name) { auto* typedList = reinterpret_cast*>(listHead); for (JS::Rooted* root = typedList; root; root = root->previous()) { root->trace(trc, name); @@ -112,8 +112,7 @@ static void TraceExactStackRoots(JSContext* cx, JSTracer* trc) { template static inline void TracePersistentRootedList( - JSTracer* trc, - LinkedList>& list, + JSTracer* trc, LinkedList>& list, const char* name) { auto& typedList = reinterpret_cast>&>(list); for (PersistentRooted* root : typedList) { @@ -145,7 +144,7 @@ static void TracePersistentRooted(JSRuntime* rt, JSTracer* trc) { template static void FinishPersistentRootedChain( - LinkedList>& listArg) { + LinkedList>& listArg) { auto& list = reinterpret_cast>&>(listArg); while (!list.isEmpty()) { list.getFirst()->reset(); @@ -635,15 +634,13 @@ void GCRuntime::resetBufferedGrayRoots() { } } -JS_PUBLIC_API void JS::AddPersistentRoot( - JS::RootingContext* cx, RootKind kind, - PersistentRooted* root) { +JS_PUBLIC_API void JS::AddPersistentRoot(JS::RootingContext* cx, RootKind kind, + PersistentRooted* root) { static_cast(cx)->runtime()->heapRoots.ref()[kind].insertBack( root); } -JS_PUBLIC_API void JS::AddPersistentRoot( - JSRuntime* rt, RootKind kind, - PersistentRooted* root) { +JS_PUBLIC_API void JS::AddPersistentRoot(JSRuntime* rt, RootKind kind, + PersistentRooted* root) { rt->heapRoots.ref()[kind].insertBack(root); } diff --git a/js/src/vm/Runtime.h b/js/src/vm/Runtime.h index 60cd256645cd..b8d280ee83d9 100644 --- a/js/src/vm/Runtime.h +++ b/js/src/vm/Runtime.h @@ -394,7 +394,7 @@ struct JSRuntime { // Heap GC roots for PersistentRooted pointers. js::MainThreadData>>> + mozilla::LinkedList>>> heapRoots; void tracePersistentRoots(JSTracer* trc);