author | Bogdan Tara <btara@mozilla.com> |
Thu, 03 Dec 2020 07:23:55 +0200 | |
changeset 559191 | 3ad1dbbf981dfd2d7cccc6e79fe52f918311f5ae |
parent 559190 | 7fb1c4b6fba37a4d7007e0098ec1205c18f3e4b9 |
child 559192 | 6c71b9a049a323c1db4ffbeba70ec39b6b57af9b |
push id | 131993 |
push user | btara@mozilla.com |
push date | Thu, 03 Dec 2020 05:25:57 +0000 |
treeherder | autoland@3ad1dbbf981d [default view] [failures only] |
perfherder | [talos] [build metrics] [platform microbench] (compared to previous push) |
bugs | 1679736 |
milestone | 85.0a1 |
backs out | 0e35830f4a259ba3e7919543b3dd2e11f5ef1482 |
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
|
--- a/js/public/RootingAPI.h +++ b/js/public/RootingAPI.h @@ -920,32 +920,25 @@ class JS_PUBLIC_API AutoGCRooter; enum class AutoGCRooterKind : uint8_t { WrapperVector, /* js::AutoWrapperVector */ Wrapper, /* js::AutoWrapperRooter */ Custom, /* js::CustomAutoRooter */ 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<void*>` is a compile error. -struct RootListEntry; -} // namespace detail - +// Our instantiations of Rooted<void*> and PersistentRooted<void*> require an +// instantiation of MapTypeToRootKind. template <> -struct MapTypeToRootKind<detail::RootListEntry*> { +struct MapTypeToRootKind<void*> { static const RootKind kind = RootKind::Traceable; }; using RootedListHeads = - mozilla::EnumeratedArray<RootKind, RootKind::Limit, - Rooted<detail::RootListEntry*>*>; + mozilla::EnumeratedArray<RootKind, RootKind::Limit, Rooted<void*>*>; using AutoRooterListHeads = mozilla::EnumeratedArray<AutoGCRooterKind, AutoGCRooterKind::Limit, AutoGCRooter*>; // Superclass of JSContext which can be used for rooting data in use by the // current thread but that does not provide all the functions of a JSContext. class RootingContext { @@ -1075,17 +1068,17 @@ using OverloadSelector = PreferredOverlo template <typename T> class MOZ_RAII Rooted : public js::RootedBase<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); + *stack = reinterpret_cast<Rooted<void*>*>(this); } inline RootedListHeads& rootLists(RootingContext* cx) { return cx->stackRoots_; } inline RootedListHeads& rootLists(JSContext* cx) { return rootLists(RootingContext::get(cx)); } @@ -1125,18 +1118,17 @@ class MOZ_RAII Rooted : public js::Roote template <typename RootingContext, typename S> Rooted(const RootingContext& cx, S&& initial) : ptr(std::forward<S>(initial)) { MOZ_ASSERT(GCPolicy<T>::isValid(ptr)); registerWithRootLists(rootLists(cx)); } ~Rooted() { - MOZ_ASSERT(*stack == - reinterpret_cast<Rooted<detail::RootListEntry*>*>(this)); + MOZ_ASSERT(*stack == reinterpret_cast<Rooted<void*>*>(this)); *stack = prev; } Rooted<T>* previous() { return reinterpret_cast<Rooted<T>*>(prev); } /* * This method is public for Rooted so that Codegen.py can use a Rooted * interchangeably with a MutableHandleValue. @@ -1158,22 +1150,22 @@ class MOZ_RAII Rooted : public js::Roote T* address() { return PtrTraits::address(ptr); } const T* address() const { return PtrTraits::address(ptr); } void trace(JSTracer* trc, const char* name); private: /* - * These need to be templated on RootListEntry* to avoid aliasing issues - * between, for example, Rooted<JSObject*> and Rooted<JSFunction*>, 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<JSObject> and Rooted<JSFunction>, which use the same + * stack head pointer for different classes. */ - Rooted<detail::RootListEntry*>** stack; - Rooted<detail::RootListEntry*>* prev; + Rooted<void*>** stack; + Rooted<void*>* prev; Ptr ptr; Rooted(const Rooted&) = delete; } JS_HAZ_ROOTED; namespace detail { @@ -1292,23 +1284,21 @@ inline MutableHandle<T>::MutableHandle(R template <typename T> inline MutableHandle<T>::MutableHandle(PersistentRooted<T>* root) { static_assert(sizeof(MutableHandle<T>) == sizeof(T*), "MutableHandle must be binary compatible with T*."); ptr = root->address(); } -JS_PUBLIC_API void AddPersistentRoot( - RootingContext* cx, RootKind kind, - PersistentRooted<detail::RootListEntry*>* root); +JS_PUBLIC_API void AddPersistentRoot(RootingContext* cx, RootKind kind, + PersistentRooted<void*>* root); -JS_PUBLIC_API void AddPersistentRoot( - JSRuntime* rt, RootKind kind, - PersistentRooted<detail::RootListEntry*>* root); +JS_PUBLIC_API void AddPersistentRoot(JSRuntime* rt, RootKind kind, + PersistentRooted<void*>* root); /** * A copyable, assignable global GC root type with arbitrary lifetime, an * infallible constructor, and automatic unrooting on destruction. * * These roots can be used in heap-allocated data structures, so they are not * associated with any particular JSContext or stack. They are registered with * the JSRuntime itself, without locking. Initialization may take place on @@ -1347,27 +1337,25 @@ class PersistentRooted using PtrTraits = detail::RootedPtrTraits<T>; friend class mozilla::LinkedList<PersistentRooted>; friend class mozilla::LinkedListElement<PersistentRooted>; void registerWithRootLists(RootingContext* cx) { MOZ_ASSERT(!initialized()); JS::RootKind kind = JS::MapTypeToRootKind<T>::kind; - AddPersistentRoot( - cx, kind, - reinterpret_cast<JS::PersistentRooted<detail::RootListEntry*>*>(this)); + AddPersistentRoot(cx, kind, + reinterpret_cast<JS::PersistentRooted<void*>*>(this)); } void registerWithRootLists(JSRuntime* rt) { MOZ_ASSERT(!initialized()); JS::RootKind kind = JS::MapTypeToRootKind<T>::kind; - AddPersistentRoot( - rt, kind, - reinterpret_cast<JS::PersistentRooted<detail::RootListEntry*>*>(this)); + AddPersistentRoot(rt, kind, + reinterpret_cast<JS::PersistentRooted<void*>*>(this)); } public: using ElementType = T; PersistentRooted() : ptr(SafelyInitialized<T>()) {} explicit PersistentRooted(RootingContext* cx) : ptr(SafelyInitialized<T>()) {
--- a/js/src/gc/RootMarking.cpp +++ b/js/src/gc/RootMarking.cpp @@ -70,19 +70,19 @@ inline void JS::Rooted<T>::trace(JSTrace } template <typename T> inline void JS::PersistentRooted<T>::trace(JSTracer* trc, const char* name) { PtrTraits::trace(trc, &ptr, name); } template <typename T> -static inline void TraceExactStackRootList( - JSTracer* trc, JS::Rooted<JS::detail::RootListEntry*>* listHead, - const char* name) { +static inline void TraceExactStackRootList(JSTracer* trc, + JS::Rooted<void*>* listHead, + const char* name) { auto* typedList = reinterpret_cast<JS::Rooted<T>*>(listHead); for (JS::Rooted<T>* root = typedList; root; root = root->previous()) { root->trace(trc, name); } } static inline void TraceStackRoots(JSTracer* trc, JS::RootedListHeads& stackRoots) { @@ -107,18 +107,17 @@ void JS::RootingContext::traceStackRoots } static void TraceExactStackRoots(JSContext* cx, JSTracer* trc) { cx->traceStackRoots(trc); } template <typename T> static inline void TracePersistentRootedList( - JSTracer* trc, - LinkedList<PersistentRooted<JS::detail::RootListEntry*>>& list, + JSTracer* trc, LinkedList<PersistentRooted<void*>>& list, const char* name) { auto& typedList = reinterpret_cast<LinkedList<PersistentRooted<T>>&>(list); for (PersistentRooted<T>* root : typedList) { root->trace(trc, name); } } void JSRuntime::tracePersistentRoots(JSTracer* trc) { @@ -140,17 +139,17 @@ void JSRuntime::tracePersistentRoots(JST } static void TracePersistentRooted(JSRuntime* rt, JSTracer* trc) { rt->tracePersistentRoots(trc); } template <typename T> static void FinishPersistentRootedChain( - LinkedList<PersistentRooted<JS::detail::RootListEntry*>>& listArg) { + LinkedList<PersistentRooted<void*>>& listArg) { auto& list = reinterpret_cast<LinkedList<PersistentRooted<T>>&>(listArg); while (!list.isEmpty()) { list.getFirst()->reset(); } } void JSRuntime::finishPersistentRoots() { #define FINISH_ROOT_LIST(name, type, _, _1) \ @@ -630,20 +629,18 @@ void GCRuntime::resetBufferedGrayRoots() MOZ_ASSERT( grayBufferState != GrayBufferState::Okay, "Do not clear the gray buffers unless we are Failed or becoming Unused"); for (GCZonesIter zone(this); !zone.done(); zone.next()) { zone->gcGrayRoots().Clear(); } } -JS_PUBLIC_API void JS::AddPersistentRoot( - JS::RootingContext* cx, RootKind kind, - PersistentRooted<JS::detail::RootListEntry*>* root) { +JS_PUBLIC_API void JS::AddPersistentRoot(JS::RootingContext* cx, RootKind kind, + PersistentRooted<void*>* root) { static_cast<JSContext*>(cx)->runtime()->heapRoots.ref()[kind].insertBack( root); } -JS_PUBLIC_API void JS::AddPersistentRoot( - JSRuntime* rt, RootKind kind, - PersistentRooted<JS::detail::RootListEntry*>* root) { +JS_PUBLIC_API void JS::AddPersistentRoot(JSRuntime* rt, RootKind kind, + PersistentRooted<void*>* root) { rt->heapRoots.ref()[kind].insertBack(root); }
--- a/js/src/vm/Runtime.h +++ b/js/src/vm/Runtime.h @@ -389,17 +389,17 @@ struct JSRuntime { js::UnprotectedData<js::GeckoProfilerRuntime> geckoProfiler_; public: js::GeckoProfilerRuntime& geckoProfiler() { return geckoProfiler_.ref(); } // Heap GC roots for PersistentRooted pointers. js::MainThreadData<mozilla::EnumeratedArray< JS::RootKind, JS::RootKind::Limit, - mozilla::LinkedList<JS::PersistentRooted<JS::detail::RootListEntry*>>>> + mozilla::LinkedList<JS::PersistentRooted<void*>>>> heapRoots; void tracePersistentRoots(JSTracer* trc); void finishPersistentRoots(); void finishRoots(); private: