Loading js/src/builtin/MapObject.cpp +1 −3 Original line number Diff line number Diff line Loading @@ -11,15 +11,13 @@ #include "jsobj.h" #include "ds/OrderedHashTable.h" #include "gc/Marking.h" #include "js/Utility.h" #include "vm/GlobalObject.h" #include "vm/Interpreter.h" #include "vm/SelfHosting.h" #include "vm/Symbol.h" #include "jsobjinlines.h" #include "gc/Marking-inl.h" #include "vm/Interpreter-inl.h" #include "vm/NativeObject-inl.h" Loading js/src/gc/Marking-inl.h 0 → 100644 +128 −0 Original line number Diff line number Diff line /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- * vim: set ts=8 sts=4 et sw=4 tw=99: * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #ifndef gc_Marking_inl_h #define gc_Marking_inl_h #include "gc/Marking.h" #include "gc/RelocationOverlay.h" namespace js { namespace gc { template <typename T> struct MightBeForwarded { static_assert(mozilla::IsBaseOf<Cell, T>::value, "T must derive from Cell"); static_assert(!mozilla::IsSame<Cell, T>::value && !mozilla::IsSame<TenuredCell, T>::value, "T must not be Cell or TenuredCell"); static const bool value = mozilla::IsBaseOf<JSObject, T>::value || mozilla::IsBaseOf<Shape, T>::value || mozilla::IsBaseOf<BaseShape, T>::value || mozilla::IsBaseOf<JSString, T>::value || mozilla::IsBaseOf<JSScript, T>::value || mozilla::IsBaseOf<js::LazyScript, T>::value || mozilla::IsBaseOf<js::Scope, T>::value || mozilla::IsBaseOf<js::RegExpShared, T>::value; }; template <typename T> inline bool IsForwarded(T* t) { RelocationOverlay* overlay = RelocationOverlay::fromCell(t); if (!MightBeForwarded<T>::value) { MOZ_ASSERT(!overlay->isForwarded()); return false; } return overlay->isForwarded(); } struct IsForwardedFunctor : public BoolDefaultAdaptor<Value, false> { template <typename T> bool operator()(T* t) { return IsForwarded(t); } }; inline bool IsForwarded(const JS::Value& value) { return DispatchTyped(IsForwardedFunctor(), value); } template <typename T> inline T* Forwarded(T* t) { RelocationOverlay* overlay = RelocationOverlay::fromCell(t); MOZ_ASSERT(overlay->isForwarded()); return reinterpret_cast<T*>(overlay->forwardingAddress()); } struct ForwardedFunctor : public IdentityDefaultAdaptor<Value> { template <typename T> inline Value operator()(T* t) { return js::gc::RewrapTaggedPointer<Value, T>::wrap(Forwarded(t)); } }; inline Value Forwarded(const JS::Value& value) { return DispatchTyped(ForwardedFunctor(), value); } template <typename T> inline T MaybeForwarded(T t) { if (IsForwarded(t)) t = Forwarded(t); MakeAccessibleAfterMovingGC(t); return t; } #ifdef JSGC_HASH_TABLE_CHECKS template <typename T> inline bool IsGCThingValidAfterMovingGC(T* t) { return !IsInsideNursery(t) && !RelocationOverlay::isCellForwarded(t); } template <typename T> inline void CheckGCThingAfterMovingGC(T* t) { if (t) MOZ_RELEASE_ASSERT(IsGCThingValidAfterMovingGC(t)); } template <typename T> inline void CheckGCThingAfterMovingGC(const ReadBarriered<T*>& t) { CheckGCThingAfterMovingGC(t.unbarrieredGet()); } struct CheckValueAfterMovingGCFunctor : public VoidDefaultAdaptor<Value> { template <typename T> void operator()(T* t) { CheckGCThingAfterMovingGC(t); } }; inline void CheckValueAfterMovingGC(const JS::Value& value) { DispatchTyped(CheckValueAfterMovingGCFunctor(), value); } #endif // JSGC_HASH_TABLE_CHECKS } /* namespace gc */ } /* namespace js */ #endif // gc_Marking_inl_h js/src/gc/Marking.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -4,7 +4,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "gc/Marking.h" #include "gc/Marking-inl.h" #include "mozilla/DebugOnly.h" #include "mozilla/IntegerRange.h" Loading js/src/gc/Marking.h +55 −0 Original line number Diff line number Diff line Loading @@ -4,6 +4,11 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ /* * Marking and sweeping APIs for use by implementations of different GC cell * kinds. */ #ifndef gc_Marking_h #define gc_Marking_h Loading Loading @@ -142,6 +147,56 @@ template<typename T> void CheckTracedThing(JSTracer* trc, T thing); namespace gc { // Functions for checking and updating GC thing pointers that might have been // moved by compacting GC. Overloads are also provided that work with Values. // // IsForwarded - check whether a pointer refers to an GC thing that has been // moved. // // Forwarded - return a pointer to the new location of a GC thing given a // pointer to old location. // // MaybeForwarded - used before dereferencing a pointer that may refer to a // moved GC thing without updating it. For JSObjects this will // also update the object's shape pointer if it has been moved // to allow slots to be accessed. template <typename T> inline bool IsForwarded(T* t); inline bool IsForwarded(const JS::Value& value); template <typename T> inline T* Forwarded(T* t); inline Value Forwarded(const JS::Value& value); template <typename T> inline T MaybeForwarded(T t); inline void MakeAccessibleAfterMovingGC(void* anyp) {} inline void MakeAccessibleAfterMovingGC(JSObject* obj); // Defined in jsobjinlines.h. #ifdef JSGC_HASH_TABLE_CHECKS template <typename T> inline bool IsGCThingValidAfterMovingGC(T* t); template <typename T> inline void CheckGCThingAfterMovingGC(T* t); template <typename T> inline void CheckGCThingAfterMovingGC(const ReadBarriered<T*>& t); inline void CheckValueAfterMovingGC(const JS::Value& value); #endif // JSGC_HASH_TABLE_CHECKS } /* namespace gc */ } /* namespace js */ #endif /* gc_Marking_h */ js/src/gc/Nursery.cpp +1 −2 Original line number Diff line number Diff line Loading @@ -29,8 +29,7 @@ #include "vm/TypedArrayObject.h" #include "vm/TypeInference.h" #include "jsobjinlines.h" #include "gc/Marking-inl.h" #include "vm/NativeObject-inl.h" using namespace js; Loading Loading
js/src/builtin/MapObject.cpp +1 −3 Original line number Diff line number Diff line Loading @@ -11,15 +11,13 @@ #include "jsobj.h" #include "ds/OrderedHashTable.h" #include "gc/Marking.h" #include "js/Utility.h" #include "vm/GlobalObject.h" #include "vm/Interpreter.h" #include "vm/SelfHosting.h" #include "vm/Symbol.h" #include "jsobjinlines.h" #include "gc/Marking-inl.h" #include "vm/Interpreter-inl.h" #include "vm/NativeObject-inl.h" Loading
js/src/gc/Marking-inl.h 0 → 100644 +128 −0 Original line number Diff line number Diff line /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- * vim: set ts=8 sts=4 et sw=4 tw=99: * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #ifndef gc_Marking_inl_h #define gc_Marking_inl_h #include "gc/Marking.h" #include "gc/RelocationOverlay.h" namespace js { namespace gc { template <typename T> struct MightBeForwarded { static_assert(mozilla::IsBaseOf<Cell, T>::value, "T must derive from Cell"); static_assert(!mozilla::IsSame<Cell, T>::value && !mozilla::IsSame<TenuredCell, T>::value, "T must not be Cell or TenuredCell"); static const bool value = mozilla::IsBaseOf<JSObject, T>::value || mozilla::IsBaseOf<Shape, T>::value || mozilla::IsBaseOf<BaseShape, T>::value || mozilla::IsBaseOf<JSString, T>::value || mozilla::IsBaseOf<JSScript, T>::value || mozilla::IsBaseOf<js::LazyScript, T>::value || mozilla::IsBaseOf<js::Scope, T>::value || mozilla::IsBaseOf<js::RegExpShared, T>::value; }; template <typename T> inline bool IsForwarded(T* t) { RelocationOverlay* overlay = RelocationOverlay::fromCell(t); if (!MightBeForwarded<T>::value) { MOZ_ASSERT(!overlay->isForwarded()); return false; } return overlay->isForwarded(); } struct IsForwardedFunctor : public BoolDefaultAdaptor<Value, false> { template <typename T> bool operator()(T* t) { return IsForwarded(t); } }; inline bool IsForwarded(const JS::Value& value) { return DispatchTyped(IsForwardedFunctor(), value); } template <typename T> inline T* Forwarded(T* t) { RelocationOverlay* overlay = RelocationOverlay::fromCell(t); MOZ_ASSERT(overlay->isForwarded()); return reinterpret_cast<T*>(overlay->forwardingAddress()); } struct ForwardedFunctor : public IdentityDefaultAdaptor<Value> { template <typename T> inline Value operator()(T* t) { return js::gc::RewrapTaggedPointer<Value, T>::wrap(Forwarded(t)); } }; inline Value Forwarded(const JS::Value& value) { return DispatchTyped(ForwardedFunctor(), value); } template <typename T> inline T MaybeForwarded(T t) { if (IsForwarded(t)) t = Forwarded(t); MakeAccessibleAfterMovingGC(t); return t; } #ifdef JSGC_HASH_TABLE_CHECKS template <typename T> inline bool IsGCThingValidAfterMovingGC(T* t) { return !IsInsideNursery(t) && !RelocationOverlay::isCellForwarded(t); } template <typename T> inline void CheckGCThingAfterMovingGC(T* t) { if (t) MOZ_RELEASE_ASSERT(IsGCThingValidAfterMovingGC(t)); } template <typename T> inline void CheckGCThingAfterMovingGC(const ReadBarriered<T*>& t) { CheckGCThingAfterMovingGC(t.unbarrieredGet()); } struct CheckValueAfterMovingGCFunctor : public VoidDefaultAdaptor<Value> { template <typename T> void operator()(T* t) { CheckGCThingAfterMovingGC(t); } }; inline void CheckValueAfterMovingGC(const JS::Value& value) { DispatchTyped(CheckValueAfterMovingGCFunctor(), value); } #endif // JSGC_HASH_TABLE_CHECKS } /* namespace gc */ } /* namespace js */ #endif // gc_Marking_inl_h
js/src/gc/Marking.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -4,7 +4,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "gc/Marking.h" #include "gc/Marking-inl.h" #include "mozilla/DebugOnly.h" #include "mozilla/IntegerRange.h" Loading
js/src/gc/Marking.h +55 −0 Original line number Diff line number Diff line Loading @@ -4,6 +4,11 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ /* * Marking and sweeping APIs for use by implementations of different GC cell * kinds. */ #ifndef gc_Marking_h #define gc_Marking_h Loading Loading @@ -142,6 +147,56 @@ template<typename T> void CheckTracedThing(JSTracer* trc, T thing); namespace gc { // Functions for checking and updating GC thing pointers that might have been // moved by compacting GC. Overloads are also provided that work with Values. // // IsForwarded - check whether a pointer refers to an GC thing that has been // moved. // // Forwarded - return a pointer to the new location of a GC thing given a // pointer to old location. // // MaybeForwarded - used before dereferencing a pointer that may refer to a // moved GC thing without updating it. For JSObjects this will // also update the object's shape pointer if it has been moved // to allow slots to be accessed. template <typename T> inline bool IsForwarded(T* t); inline bool IsForwarded(const JS::Value& value); template <typename T> inline T* Forwarded(T* t); inline Value Forwarded(const JS::Value& value); template <typename T> inline T MaybeForwarded(T t); inline void MakeAccessibleAfterMovingGC(void* anyp) {} inline void MakeAccessibleAfterMovingGC(JSObject* obj); // Defined in jsobjinlines.h. #ifdef JSGC_HASH_TABLE_CHECKS template <typename T> inline bool IsGCThingValidAfterMovingGC(T* t); template <typename T> inline void CheckGCThingAfterMovingGC(T* t); template <typename T> inline void CheckGCThingAfterMovingGC(const ReadBarriered<T*>& t); inline void CheckValueAfterMovingGC(const JS::Value& value); #endif // JSGC_HASH_TABLE_CHECKS } /* namespace gc */ } /* namespace js */ #endif /* gc_Marking_h */
js/src/gc/Nursery.cpp +1 −2 Original line number Diff line number Diff line Loading @@ -29,8 +29,7 @@ #include "vm/TypedArrayObject.h" #include "vm/TypeInference.h" #include "jsobjinlines.h" #include "gc/Marking-inl.h" #include "vm/NativeObject-inl.h" using namespace js; Loading