From eff749c61254c56a23846d85265ceddf1571bf9e Mon Sep 17 00:00:00 2001 From: Terrence Cole Date: Mon, 28 Dec 2015 10:11:40 -0800 Subject: [PATCH] Bug 1234862 - Part 1: Rename GCMethods to BarrierMethods; r=sfink --HG-- extra : rebase_source : a773cf25e8e9986a154b8a8b0d04c6b9267545b8 --- dom/xbl/nsXBLMaybeCompiled.h | 22 +++++++----- js/public/Debug.h | 2 +- js/public/Id.h | 7 +++- js/public/RootingAPI.h | 34 +++++++++++-------- js/public/Value.h | 7 ++-- js/src/gc/Barrier.cpp | 8 ++--- js/src/gc/Barrier.h | 66 ++++++++++++++++++------------------ js/src/gc/Marking.cpp | 8 ++--- js/src/vm/Interpreter.cpp | 4 +-- js/src/vm/TaggedProto.cpp | 11 +++--- js/src/vm/TaggedProto.h | 6 ++-- 11 files changed, 96 insertions(+), 79 deletions(-) diff --git a/dom/xbl/nsXBLMaybeCompiled.h b/dom/xbl/nsXBLMaybeCompiled.h index e478a3a23fd4..63c1b24ce607 100644 --- a/dom/xbl/nsXBLMaybeCompiled.h +++ b/dom/xbl/nsXBLMaybeCompiled.h @@ -79,18 +79,22 @@ private: JSObject* mCompiled; }; - friend struct js::GCMethods>; + friend struct js::BarrierMethods>; }; /* Add support for JS::Heap. */ namespace js { template -struct GCMethods > +struct GCPolicy> { - typedef struct GCMethods Base; - static nsXBLMaybeCompiled initial() { return nsXBLMaybeCompiled(); } +}; + +template +struct BarrierMethods> +{ + typedef struct BarrierMethods Base; static void postBarrier(nsXBLMaybeCompiled* functionp, nsXBLMaybeCompiled prev, @@ -109,14 +113,14 @@ struct GCMethods > }; template -class HeapBase > +class HeapBase> { - const JS::Heap >& wrapper() const { - return *static_cast >*>(this); + const JS::Heap>& wrapper() const { + return *static_cast>*>(this); } - JS::Heap >& wrapper() { - return *static_cast >*>(this); + JS::Heap>& wrapper() { + return *static_cast>*>(this); } const nsXBLMaybeCompiled* extract() const { diff --git a/js/public/Debug.h b/js/public/Debug.h index aefe40b603e6..9fc2c03f93d9 100644 --- a/js/public/Debug.h +++ b/js/public/Debug.h @@ -150,7 +150,7 @@ class Builder { // A rooted reference to our value. PersistentRooted value; - BuiltThing(JSContext* cx, Builder& owner_, T value_ = js::GCMethods::initial()) + BuiltThing(JSContext* cx, Builder& owner_, T value_ = js::GCPolicy::initial()) : owner(owner_), value(cx, value_) { owner.assertBuilt(value_); diff --git a/js/public/Id.h b/js/public/Id.h index d5ddef9bab94..bb3c58124483 100644 --- a/js/public/Id.h +++ b/js/public/Id.h @@ -169,9 +169,14 @@ extern JS_PUBLIC_DATA(const JS::HandleId) JSID_EMPTYHANDLE; namespace js { template <> -struct GCMethods +struct GCPolicy { static jsid initial() { return JSID_VOID; } +}; + +template <> +struct BarrierMethods +{ static void postBarrier(jsid* idp, jsid prev, jsid next) {} }; diff --git a/js/public/RootingAPI.h b/js/public/RootingAPI.h index 4e925cba0475..4a22b70c1863 100644 --- a/js/public/RootingAPI.h +++ b/js/public/RootingAPI.h @@ -105,7 +105,11 @@ namespace js { template -struct GCMethods { +struct BarrierMethods { +}; + +template +struct GCPolicy { static T initial() { return T(); } }; @@ -221,7 +225,7 @@ class Heap : public js::HeapBase Heap() { static_assert(sizeof(T) == sizeof(Heap), "Heap must be binary compatible with T."); - init(js::GCMethods::initial()); + init(js::GCPolicy::initial()); } explicit Heap(T p) { init(p); } @@ -234,7 +238,7 @@ class Heap : public js::HeapBase explicit Heap(const Heap& p) { init(p.ptr); } ~Heap() { - post(ptr, js::GCMethods::initial()); + post(ptr, js::GCPolicy::initial()); } DECLARE_POINTER_CONSTREF_OPS(T); @@ -258,7 +262,7 @@ class Heap : public js::HeapBase private: void init(T newPtr) { ptr = newPtr; - post(js::GCMethods::initial(), ptr); + post(js::GCPolicy::initial(), ptr); } void set(T newPtr) { @@ -268,7 +272,7 @@ class Heap : public js::HeapBase } void post(const T& prev, const T& next) { - js::GCMethods::postBarrier(&ptr, prev, next); + js::BarrierMethods::postBarrier(&ptr, prev, next); } enum { @@ -527,7 +531,7 @@ struct RootKind }; template -struct GCMethods +struct BarrierMethods { static T* initial() { return nullptr; } static void postBarrier(T** vp, T* prev, T* next) { @@ -538,7 +542,7 @@ struct GCMethods }; template <> -struct GCMethods +struct BarrierMethods { static JSObject* initial() { return nullptr; } static gc::Cell* asGCThingOrNull(JSObject* v) { @@ -553,7 +557,7 @@ struct GCMethods }; template <> -struct GCMethods +struct BarrierMethods { static JSFunction* initial() { return nullptr; } static void postBarrier(JSFunction** vp, JSFunction* prev, JSFunction* next) { @@ -703,7 +707,7 @@ class MOZ_RAII Rooted : public js::RootedBase public: template explicit Rooted(const RootingContext& cx) - : ptr(js::GCMethods::initial()) + : ptr(js::GCPolicy::initial()) { registerWithRootLists(js::RootListsForRootingContext(cx)); } @@ -808,7 +812,7 @@ class MOZ_RAII FakeRooted : public RootedBase { public: template - explicit FakeRooted(CX* cx) : ptr(GCMethods::initial()) {} + explicit FakeRooted(CX* cx) : ptr(GCPolicy::initial()) {} template FakeRooted(CX* cx, T initial) : ptr(initial) {} @@ -1025,11 +1029,11 @@ class PersistentRooted : public js::PersistentRootedBase, } public: - PersistentRooted() : ptr(js::GCMethods::initial()) {} + PersistentRooted() : ptr(js::GCPolicy::initial()) {} template explicit PersistentRooted(const RootingContext& cx) - : ptr(js::GCMethods::initial()) + : ptr(js::GCPolicy::initial()) { registerWithRootLists(js::RootListsForRootingContext(cx)); } @@ -1062,7 +1066,7 @@ class PersistentRooted : public js::PersistentRootedBase, template void init(const RootingContext& cx) { - init(cx, js::GCMethods::initial()); + init(cx, js::GCPolicy::initial()); } template @@ -1073,7 +1077,7 @@ class PersistentRooted : public js::PersistentRootedBase, void reset() { if (initialized()) { - set(js::GCMethods::initial()); + set(js::GCPolicy::initial()); ListBase::remove(); } } @@ -1162,7 +1166,7 @@ CallTraceCallbackOnNonHeap(T* v, const TraceCallbacks& aCallbacks, const char* a { static_assert(sizeof(T) == sizeof(JS::Heap), "T and Heap must be compatible."); MOZ_ASSERT(v); - mozilla::DebugOnly cell = GCMethods::asGCThingOrNull(*v); + mozilla::DebugOnly cell = BarrierMethods::asGCThingOrNull(*v); MOZ_ASSERT(cell); MOZ_ASSERT(!IsInsideNursery(cell)); JS::Heap* asHeapT = reinterpret_cast*>(v); diff --git a/js/public/Value.h b/js/public/Value.h index 20a441ad3264..15d4eb4b94c9 100644 --- a/js/public/Value.h +++ b/js/public/Value.h @@ -1699,14 +1699,15 @@ JS_PUBLIC_API(void) HeapValuePostBarrier(Value* valuep, const Value& prev, const namespace js { -template <> struct GCMethods +template <> +struct GCPolicy { static JS::Value initial() { return JS::UndefinedValue(); } }; -template <> struct GCMethods +template <> +struct BarrierMethods { - static JS::Value initial() { return JS::UndefinedValue(); } static gc::Cell* asGCThingOrNull(const JS::Value& v) { return v.isMarkable() ? v.toGCThing() : nullptr; } diff --git a/js/src/gc/Barrier.cpp b/js/src/gc/Barrier.cpp index 699bc3aec21f..f2b007e65f49 100644 --- a/js/src/gc/Barrier.cpp +++ b/js/src/gc/Barrier.cpp @@ -90,7 +90,7 @@ template void ReadBarrierFunctor::operator()(T* t) { - InternalGCMethods::readBarrier(t); + InternalBarrierMethods::readBarrier(t); } template void ReadBarrierFunctor::operator()(JS::Symbol*); template void ReadBarrierFunctor::operator()(JSObject*); @@ -101,7 +101,7 @@ template void PreBarrierFunctor::operator()(T* t) { - InternalGCMethods::preBarrier(t); + InternalBarrierMethods::preBarrier(t); } template void PreBarrierFunctor::operator()(JS::Symbol*); template void PreBarrierFunctor::operator()(JSObject*); @@ -170,12 +170,12 @@ JS_PUBLIC_API(void) JS::HeapObjectPostBarrier(JSObject** objp, JSObject* prev, JSObject* next) { MOZ_ASSERT(objp); - js::InternalGCMethods::postBarrier(objp, prev, next); + js::InternalBarrierMethods::postBarrier(objp, prev, next); } JS_PUBLIC_API(void) JS::HeapValuePostBarrier(JS::Value* valuep, const Value& prev, const Value& next) { MOZ_ASSERT(valuep); - js::InternalGCMethods::postBarrier(valuep, prev, next); + js::InternalBarrierMethods::postBarrier(valuep, prev, next); } diff --git a/js/src/gc/Barrier.h b/js/src/gc/Barrier.h index a2131f03f2de..3124d8d1a63e 100644 --- a/js/src/gc/Barrier.h +++ b/js/src/gc/Barrier.h @@ -156,23 +156,23 @@ * via: * * WriteBarrieredBase::pre - * -> InternalGCMethods::preBarrier + * -> InternalBarrierMethods::preBarrier * -> T::writeBarrierPre - * -> InternalGCMethods::preBarrier - * -> InternalGCMethods::preBarrier - * -> InternalGCMethods::preBarrier + * -> InternalBarrierMethods::preBarrier + * -> InternalBarrierMethods::preBarrier + * -> InternalBarrierMethods::preBarrier * -> T::writeBarrierPre * * HeapPtr::post and RelocatablePtr::post - * -> InternalGCMethods::postBarrier + * -> InternalBarrierMethods::postBarrier * -> T::writeBarrierPost - * -> InternalGCMethods::postBarrier + * -> InternalBarrierMethods::postBarrier * -> StoreBuffer::put * * These classes are designed to be used by the internals of the JS engine. * Barriers designed to be used externally are provided in js/RootingAPI.h. * These external barriers call into the same post-barrier implementations at - * InternalGCMethods::post via an indirect call to Heap(.+)Barrier. + * InternalBarrierMethods::post via an indirect call to Heap(.+)Barrier. */ class JSAtom; @@ -240,10 +240,10 @@ void MarkIdForBarrier(JSTracer* trc, jsid* idp, const char* name); } // namespace gc template -struct InternalGCMethods {}; +struct InternalBarrierMethods {}; template -struct InternalGCMethods +struct InternalBarrierMethods { static bool isMarkable(T* v) { return v != nullptr; } @@ -265,7 +265,7 @@ template struct ReadBarrierFunctor : public VoidDefaultAdaptor { }; template <> -struct InternalGCMethods +struct InternalBarrierMethods { static bool isMarkable(Value v) { return v.isMarkable(); } static bool isMarkableTaggedPointer(Value v) { return isMarkable(v); } @@ -301,7 +301,7 @@ struct InternalGCMethods }; template <> -struct InternalGCMethods +struct InternalBarrierMethods { static bool isMarkable(jsid id) { return JSID_IS_STRING(id) || JSID_IS_SYMBOL(id); } static bool isMarkableTaggedPointer(jsid id) { return isMarkable(id); } @@ -368,11 +368,11 @@ class WriteBarrieredBase : public BarrieredBase void unsafeSet(T v) { this->value = v; } // For users who need to manually barrier the raw types. - static void writeBarrierPre(const T& v) { InternalGCMethods::preBarrier(v); } + static void writeBarrierPre(const T& v) { InternalBarrierMethods::preBarrier(v); } protected: - void pre() { InternalGCMethods::preBarrier(this->value); } - void post(T prev, T next) { InternalGCMethods::postBarrier(&this->value, prev, next); } + void pre() { InternalBarrierMethods::preBarrier(this->value); } + void post(T prev, T next) { InternalBarrierMethods::postBarrier(&this->value, prev, next); } }; /* @@ -385,7 +385,7 @@ template class PreBarriered : public WriteBarrieredBase { public: - PreBarriered() : WriteBarrieredBase(GCMethods::initial()) {} + PreBarriered() : WriteBarrieredBase(GCPolicy::initial()) {} /* * Allow implicit construction for use in generic contexts, such as DebuggerWeakMap::markKeys. */ @@ -430,12 +430,12 @@ template class HeapPtr : public WriteBarrieredBase { public: - HeapPtr() : WriteBarrieredBase(GCMethods::initial()) {} + HeapPtr() : WriteBarrieredBase(GCPolicy::initial()) {} explicit HeapPtr(T v) : WriteBarrieredBase(v) { - this->post(GCMethods::initial(), v); + this->post(GCPolicy::initial(), v); } explicit HeapPtr(const HeapPtr& v) : WriteBarrieredBase(v) { - this->post(GCMethods::initial(), v); + this->post(GCPolicy::initial(), v); } #ifdef DEBUG ~HeapPtr() { @@ -447,7 +447,7 @@ class HeapPtr : public WriteBarrieredBase void init(T v) { this->value = v; - this->post(GCMethods::initial(), v); + this->post(GCPolicy::initial(), v); } DECLARE_POINTER_ASSIGN_OPS(HeapPtr, T); @@ -482,11 +482,11 @@ template class RelocatablePtr : public WriteBarrieredBase { public: - RelocatablePtr() : WriteBarrieredBase(GCMethods::initial()) {} + RelocatablePtr() : WriteBarrieredBase(GCPolicy::initial()) {} // Implicitly adding barriers is a reasonable default. MOZ_IMPLICIT RelocatablePtr(const T& v) : WriteBarrieredBase(v) { - this->post(GCMethods::initial(), this->value); + this->post(GCPolicy::initial(), this->value); } /* @@ -496,17 +496,17 @@ class RelocatablePtr : public WriteBarrieredBase * simply omit the rvalue variant. */ MOZ_IMPLICIT RelocatablePtr(const RelocatablePtr& v) : WriteBarrieredBase(v) { - this->post(GCMethods::initial(), this->value); + this->post(GCPolicy::initial(), this->value); } ~RelocatablePtr() { this->pre(); - this->post(this->value, GCMethods::initial()); + this->post(this->value, GCPolicy::initial()); } void init(T v) { this->value = v; - this->post(GCMethods::initial(), this->value); + this->post(GCPolicy::initial(), this->value); } DECLARE_POINTER_ASSIGN_OPS(RelocatablePtr, T); @@ -540,8 +540,8 @@ class ReadBarrieredBase : public BarrieredBase explicit ReadBarrieredBase(T v) : BarrieredBase(v) {} protected: - void read() const { InternalGCMethods::readBarrier(this->value); } - void post(T prev, T next) { InternalGCMethods::postBarrier(&this->value, prev, next); } + void read() const { InternalBarrierMethods::readBarrier(this->value); } + void post(T prev, T next) { InternalBarrierMethods::postBarrier(&this->value, prev, next); } }; // Incremental GC requires that weak pointers have read barriers. This is mostly @@ -561,16 +561,16 @@ template class ReadBarriered : public ReadBarrieredBase { public: - ReadBarriered() : ReadBarrieredBase(GCMethods::initial()) {} + ReadBarriered() : ReadBarrieredBase(GCPolicy::initial()) {} // It is okay to add barriers implicitly. MOZ_IMPLICIT ReadBarriered(const T& v) : ReadBarrieredBase(v) { - this->post(GCMethods::initial(), v); + this->post(GCPolicy::initial(), v); } // Copy is creating a new edge, so we must read barrier the source edge. explicit ReadBarriered(const ReadBarriered& v) : ReadBarrieredBase(v) { - this->post(GCMethods::initial(), v.get()); + this->post(GCPolicy::initial(), v.get()); } // Move retains the lifetime status of the source edge, so does not fire @@ -578,11 +578,11 @@ class ReadBarriered : public ReadBarrieredBase ReadBarriered(ReadBarriered&& v) : ReadBarrieredBase(mozilla::Forward>(v)) { - this->post(GCMethods::initial(), v.value); + this->post(GCPolicy::initial(), v.value); } ~ReadBarriered() { - this->post(this->value, GCMethods::initial()); + this->post(this->value, GCPolicy::initial()); } ReadBarriered& operator=(const ReadBarriered& v) { @@ -593,8 +593,8 @@ class ReadBarriered : public ReadBarrieredBase } const T get() const { - if (!InternalGCMethods::isMarkable(this->value)) - return GCMethods::initial(); + if (!InternalBarrierMethods::isMarkable(this->value)) + return GCPolicy::initial(); this->read(); return this->value; } diff --git a/js/src/gc/Marking.cpp b/js/src/gc/Marking.cpp index d0833d5d1de0..786852d739c9 100644 --- a/js/src/gc/Marking.cpp +++ b/js/src/gc/Marking.cpp @@ -403,7 +403,7 @@ JS_PUBLIC_API(void) JS::TraceEdge(JSTracer* trc, JS::Heap* thingp, const char* name) { MOZ_ASSERT(thingp); - if (InternalGCMethods::isMarkable(thingp->get())) + if (InternalBarrierMethods::isMarkable(thingp->get())) DispatchToTracer(trc, ConvertToBase(thingp->unsafeGet()), name); } @@ -463,7 +463,7 @@ void js::TraceNullableRoot(JSTracer* trc, T* thingp, const char* name) { AssertRootMarkingPhase(trc); - if (InternalGCMethods::isMarkableTaggedPointer(*thingp)) + if (InternalBarrierMethods::isMarkableTaggedPointer(*thingp)) DispatchToTracer(trc, ConvertToBase(thingp), name); } @@ -488,7 +488,7 @@ js::TraceRange(JSTracer* trc, size_t len, WriteBarrieredBase* vec, const char { JS::AutoTracingIndex index(trc); for (auto i : MakeRange(len)) { - if (InternalGCMethods::isMarkable(vec[i].get())) + if (InternalBarrierMethods::isMarkable(vec[i].get())) DispatchToTracer(trc, ConvertToBase(vec[i].unsafeUnbarrieredForTracing()), name); ++index; } @@ -501,7 +501,7 @@ js::TraceRootRange(JSTracer* trc, size_t len, T* vec, const char* name) AssertRootMarkingPhase(trc); JS::AutoTracingIndex index(trc); for (auto i : MakeRange(len)) { - if (InternalGCMethods::isMarkable(vec[i])) + if (InternalBarrierMethods::isMarkable(vec[i])) DispatchToTracer(trc, ConvertToBase(&vec[i]), name); ++index; } diff --git a/js/src/vm/Interpreter.cpp b/js/src/vm/Interpreter.cpp index 95136e46b239..bfdbcc8aa979 100644 --- a/js/src/vm/Interpreter.cpp +++ b/js/src/vm/Interpreter.cpp @@ -1482,11 +1482,11 @@ class ReservedRooted : public ReservedRootedBase } explicit ReservedRooted(Rooted* root) : savedRoot(root) { - *root = js::GCMethods::initial(); + *root = js::GCPolicy::initial(); } ~ReservedRooted() { - *savedRoot = js::GCMethods::initial(); + *savedRoot = js::GCPolicy::initial(); } void set(const T& p) const { *savedRoot = p; } diff --git a/js/src/vm/TaggedProto.cpp b/js/src/vm/TaggedProto.cpp index f00f07d31c93..725c3bc64e0d 100644 --- a/js/src/vm/TaggedProto.cpp +++ b/js/src/vm/TaggedProto.cpp @@ -14,18 +14,19 @@ namespace js { /* static */ void -InternalGCMethods::preBarrier(TaggedProto& proto) +InternalBarrierMethods::preBarrier(TaggedProto& proto) { - InternalGCMethods::preBarrier(proto.toObjectOrNull()); + InternalBarrierMethods::preBarrier(proto.toObjectOrNull()); } /* static */ void -InternalGCMethods::postBarrier(TaggedProto* vp, TaggedProto prev, TaggedProto next) +InternalBarrierMethods::postBarrier(TaggedProto* vp, TaggedProto prev, + TaggedProto next) { JSObject* prevObj = prev.isObject() ? prev.toObject() : nullptr; JSObject* nextObj = next.isObject() ? next.toObject() : nullptr; - InternalGCMethods::postBarrier(reinterpret_cast(vp), prevObj, - nextObj); + InternalBarrierMethods::postBarrier(reinterpret_cast(vp), prevObj, + nextObj); } } // namespace js diff --git a/js/src/vm/TaggedProto.h b/js/src/vm/TaggedProto.h index 72538802535e..412961a08bdf 100644 --- a/js/src/vm/TaggedProto.h +++ b/js/src/vm/TaggedProto.h @@ -52,12 +52,14 @@ class TaggedProto : public JS::Traceable JSObject* proto; }; -template <> struct GCMethods +template <> +struct GCPolicy { static TaggedProto initial() { return TaggedProto(); } }; -template <> struct InternalGCMethods +template <> +struct InternalBarrierMethods { static void preBarrier(TaggedProto& proto);