diff --git a/js/src/builtin/TypedObject.cpp b/js/src/builtin/TypedObject.cpp index 298b9f30fa1e..4d69a4378bf8 100644 --- a/js/src/builtin/TypedObject.cpp +++ b/js/src/builtin/TypedObject.cpp @@ -2317,7 +2317,7 @@ bool TypedObject::construct(JSContext* cx, unsigned int argc, Value* vp) { MOZ_ASSERT(::IsTypedObjectClass(clasp)); JSObject* obj = - js::Allocate(cx, kind, /* nDynamicSlots = */ 0, heap, clasp); + js::AllocateObject(cx, kind, /* nDynamicSlots = */ 0, heap, clasp); if (!obj) { return cx->alreadyReportedOOM(); } diff --git a/js/src/gc/Allocator.cpp b/js/src/gc/Allocator.cpp index e907aa3c5381..61e75e424252 100644 --- a/js/src/gc/Allocator.cpp +++ b/js/src/gc/Allocator.cpp @@ -25,11 +25,9 @@ using namespace js; using namespace gc; -template -JSObject* js::Allocate(JSContext* cx, AllocKind kind, size_t nDynamicSlots, - InitialHeap heap, const Class* clasp) { - static_assert(mozilla::IsConvertible::value, - "must be JSObject derived"); +template +JSObject* js::AllocateObject(JSContext* cx, AllocKind kind, size_t nDynamicSlots, + InitialHeap heap, const Class* clasp) { MOZ_ASSERT(IsObjectAllocKind(kind)); size_t thingSize = Arena::thingSize(kind); @@ -77,16 +75,16 @@ JSObject* js::Allocate(JSContext* cx, AllocKind kind, size_t nDynamicSlots, return GCRuntime::tryNewTenuredObject(cx, kind, thingSize, nDynamicSlots); } -template JSObject* js::Allocate(JSContext* cx, - gc::AllocKind kind, - size_t nDynamicSlots, - gc::InitialHeap heap, - const Class* clasp); -template JSObject* js::Allocate(JSContext* cx, - gc::AllocKind kind, - size_t nDynamicSlots, - gc::InitialHeap heap, - const Class* clasp); +template JSObject* js::AllocateObject(JSContext* cx, + gc::AllocKind kind, + size_t nDynamicSlots, + gc::InitialHeap heap, + const Class* clasp); +template JSObject* js::AllocateObject(JSContext* cx, + gc::AllocKind kind, + size_t nDynamicSlots, + gc::InitialHeap heap, + const Class* clasp); // Attempt to allocate a new JSObject out of the nursery. If there is not // enough room in the nursery or there is an OOM, this method will return @@ -177,7 +175,7 @@ JSString* GCRuntime::tryNewNurseryString(JSContext* cx, size_t thingSize, } template -StringAllocT* js::AllocateString(JSContext* cx, InitialHeap heap) { +StringAllocT* js::AllocateStringImpl(JSContext* cx, InitialHeap heap) { static_assert(mozilla::IsConvertible::value, "must be JSString derived"); @@ -224,10 +222,10 @@ StringAllocT* js::AllocateString(JSContext* cx, InitialHeap heap) { #define DECL_ALLOCATOR_INSTANCES(allocKind, traceKind, type, sizedType, \ bgfinal, nursery, compact) \ - template type* js::AllocateString(JSContext * cx, \ - InitialHeap heap); \ - template type* js::AllocateString(JSContext * cx, \ - InitialHeap heap); + template type* js::AllocateStringImpl(JSContext * cx, \ + InitialHeap heap); \ + template type* js::AllocateStringImpl(JSContext * cx, \ + InitialHeap heap); FOR_EACH_NURSERY_STRING_ALLOCKIND(DECL_ALLOCATOR_INSTANCES) #undef DECL_ALLOCATOR_INSTANCES diff --git a/js/src/gc/Allocator.h b/js/src/gc/Allocator.h index 96342bf6ea76..62e6b1b61574 100644 --- a/js/src/gc/Allocator.h +++ b/js/src/gc/Allocator.h @@ -17,47 +17,52 @@ namespace js { struct Class; -// Allocate a new GC thing. After a successful allocation the caller must -// fully initialize the thing before calling any function that can potentially -// trigger GC. This will ensure that GC tracing never sees junk values stored -// in the partially initialized thing. - +// Allocate a new GC thing that's not a JSObject or a string. +// +// After a successful allocation the caller must fully initialize the thing +// before calling any function that can potentially trigger GC. This will ensure +// that GC tracing never sees junk values stored in the partially initialized +// thing. template T* Allocate(JSContext* cx); -// Use for JSObject. A longer signature that includes additional information in -// support of various optimizations. If dynamic slots are requested they will be -// allocated and the pointer stored directly in |NativeObject::slots_|. -template -JSObject* Allocate(JSContext* cx, gc::AllocKind kind, size_t nDynamicSlots, - gc::InitialHeap heap, const Class* clasp); +// Allocate a JSObject. +// +// A longer signature that includes additional information in support of various +// optimizations. If dynamic slots are requested they will be allocated and the +// pointer stored directly in |NativeObject::slots_|. +template +JSObject* AllocateObject(JSContext* cx, gc::AllocKind kind, size_t nDynamicSlots, + gc::InitialHeap heap, const Class* clasp); // Internal function used for nursery-allocatable strings. template -StringAllocT* AllocateString(JSContext* cx, gc::InitialHeap heap); +StringAllocT* AllocateStringImpl(JSContext* cx, gc::InitialHeap heap); +// Allocate a string. +// // Use for nursery-allocatable strings. Returns a value cast to the correct // type. template -StringT* Allocate(JSContext* cx, gc::InitialHeap heap) { - return static_cast(js::AllocateString(cx, heap)); +StringT* AllocateString(JSContext* cx, gc::InitialHeap heap) { + return static_cast(AllocateStringImpl(cx, heap)); } // Specialization for JSFatInlineString that must use a different allocation // type. Note that we have to explicitly specialize for both values of AllowGC // because partial function specialization is not allowed. template <> -inline JSFatInlineString* Allocate( +inline JSFatInlineString* AllocateString( JSContext* cx, gc::InitialHeap heap) { return static_cast( - js::AllocateString(cx, heap)); + js::AllocateStringImpl(cx, heap)); } template <> -inline JSFatInlineString* Allocate( +inline JSFatInlineString* AllocateString( JSContext* cx, gc::InitialHeap heap) { return static_cast( - js::AllocateString(cx, heap)); + js::AllocateStringImpl(cx, heap)); } } // namespace js diff --git a/js/src/jit/CodeGenerator.cpp b/js/src/jit/CodeGenerator.cpp index 636a534a2a43..fcf3f6f52879 100644 --- a/js/src/jit/CodeGenerator.cpp +++ b/js/src/jit/CodeGenerator.cpp @@ -2402,12 +2402,12 @@ void CreateDependentString::generate(MacroAssembler& masm, static void* AllocateString(JSContext* cx) { AutoUnsafeCallWithABI unsafe; - return js::Allocate(cx, js::gc::TenuredHeap); + return js::AllocateString(cx, js::gc::TenuredHeap); } static void* AllocateFatInlineString(JSContext* cx) { AutoUnsafeCallWithABI unsafe; - return js::Allocate(cx, js::gc::TenuredHeap); + return js::AllocateString(cx, js::gc::TenuredHeap); } void CreateDependentString::generateFallback(MacroAssembler& masm) { @@ -2443,8 +2443,8 @@ void CreateDependentString::generateFallback(MacroAssembler& masm) { static void* CreateMatchResultFallbackFunc(JSContext* cx, gc::AllocKind kind, size_t nDynamicSlots) { AutoUnsafeCallWithABI unsafe; - return js::Allocate(cx, kind, nDynamicSlots, gc::DefaultHeap, - &ArrayObject::class_); + return js::AllocateObject(cx, kind, nDynamicSlots, gc::DefaultHeap, + &ArrayObject::class_); } static void CreateMatchResultFallback(MacroAssembler& masm, Register object, diff --git a/js/src/vm/ArrayObject-inl.h b/js/src/vm/ArrayObject-inl.h index ac3d22b21f6e..c2032395ef7d 100644 --- a/js/src/vm/ArrayObject-inl.h +++ b/js/src/vm/ArrayObject-inl.h @@ -50,7 +50,7 @@ inline void ArrayObject::setLength(JSContext* cx, uint32_t length) { MOZ_ASSERT(shape->numFixedSlots() == 0); size_t nDynamicSlots = dynamicSlotsCount(0, shape->slotSpan(), clasp); - JSObject* obj = js::Allocate(cx, kind, nDynamicSlots, heap, clasp); + JSObject* obj = js::AllocateObject(cx, kind, nDynamicSlots, heap, clasp); if (!obj) { return nullptr; } diff --git a/js/src/vm/Caches-inl.h b/js/src/vm/Caches-inl.h index 41e9a941b0d2..0d4c89938544 100644 --- a/js/src/vm/Caches-inl.h +++ b/js/src/vm/Caches-inl.h @@ -73,8 +73,8 @@ inline NativeObject* NewObjectCache::newObjectFromHit(JSContext* cx, } NativeObject* obj = static_cast( - Allocate(cx, entry->kind, - /* nDynamicSlots = */ 0, heap, group->clasp())); + AllocateObject(cx, entry->kind, /* nDynamicSlots = */ 0, + heap, group->clasp())); if (!obj) { return nullptr; } diff --git a/js/src/vm/JSFunction-inl.h b/js/src/vm/JSFunction-inl.h index 194aeef38177..97a190ad9745 100644 --- a/js/src/vm/JSFunction-inl.h +++ b/js/src/vm/JSFunction-inl.h @@ -113,8 +113,7 @@ inline JSFunction* CloneFunctionObjectIfNotSingleton( MOZ_ASSERT(dynamicSlotsCount(shape->numFixedSlots(), shape->slotSpan(), clasp) == NumDynamicSlots); - JSObject* obj = - js::Allocate(cx, kind, NumDynamicSlots, heap, clasp); + JSObject* obj = js::AllocateObject(cx, kind, NumDynamicSlots, heap, clasp); if (!obj) { return cx->alreadyReportedOOM(); } diff --git a/js/src/vm/NativeObject-inl.h b/js/src/vm/NativeObject-inl.h index 3ec0c92b2214..3a18b75383da 100644 --- a/js/src/vm/NativeObject-inl.h +++ b/js/src/vm/NativeObject-inl.h @@ -488,7 +488,7 @@ inline bool NativeObject::isInWholeCellBuffer() const { size_t nDynamicSlots = dynamicSlotsCount(shape->numFixedSlots(), shape->slotSpan(), clasp); - JSObject* obj = js::Allocate(cx, kind, nDynamicSlots, heap, clasp); + JSObject* obj = js::AllocateObject(cx, kind, nDynamicSlots, heap, clasp); if (!obj) { return cx->alreadyReportedOOM(); } diff --git a/js/src/vm/ProxyObject.cpp b/js/src/vm/ProxyObject.cpp index 80a453ac0b8a..82c51b2d5e16 100644 --- a/js/src/vm/ProxyObject.cpp +++ b/js/src/vm/ProxyObject.cpp @@ -187,8 +187,8 @@ void ProxyObject::nuke() { gc::InitialHeap heap = GetInitialHeap(newKind, group); debugCheckNewObject(group, shape, allocKind, heap); - JSObject* obj = js::Allocate(cx, allocKind, /* nDynamicSlots = */ 0, - heap, clasp); + JSObject* obj = js::AllocateObject(cx, allocKind, /* nDynamicSlots = */ 0, + heap, clasp); if (!obj) { return cx->alreadyReportedOOM(); } diff --git a/js/src/vm/StringType-inl.h b/js/src/vm/StringType-inl.h index cea1b09c1e02..369daa038efa 100644 --- a/js/src/vm/StringType-inl.h +++ b/js/src/vm/StringType-inl.h @@ -159,7 +159,7 @@ MOZ_ALWAYS_INLINE JSRope* JSRope::new_( if (!validateLength(cx, length)) { return nullptr; } - JSRope* str = js::Allocate(cx, heap); + JSRope* str = js::AllocateString(cx, heap); if (!str) { return nullptr; } @@ -220,7 +220,7 @@ MOZ_ALWAYS_INLINE JSLinearString* JSDependentString::new_( } JSDependentString* str = - js::Allocate(cx, js::gc::DefaultHeap); + js::AllocateString(cx, js::gc::DefaultHeap); if (str) { str->init(cx, baseArg, start, length); return str; @@ -228,7 +228,7 @@ MOZ_ALWAYS_INLINE JSLinearString* JSDependentString::new_( js::RootedLinearString base(cx, baseArg); - str = js::Allocate(cx, js::gc::DefaultHeap); + str = js::AllocateString(cx, js::gc::DefaultHeap); if (!str) { return nullptr; } @@ -262,7 +262,7 @@ MOZ_ALWAYS_INLINE JSFlatString* JSFlatString::new_(JSContext* cx, if (cx->zone()->isAtomsZone()) { str = js::Allocate(cx); } else { - str = js::Allocate(cx, js::gc::DefaultHeap); + str = js::AllocateString(cx, js::gc::DefaultHeap); } if (!str) { return nullptr; @@ -308,7 +308,7 @@ MOZ_ALWAYS_INLINE JSThinInlineString* JSThinInlineString::new_(JSContext* cx) { return (JSThinInlineString*)(js::Allocate(cx)); } - return js::Allocate(cx, js::gc::DefaultHeap); + return js::AllocateString(cx, js::gc::DefaultHeap); } template @@ -317,7 +317,7 @@ MOZ_ALWAYS_INLINE JSFatInlineString* JSFatInlineString::new_(JSContext* cx) { return (JSFatInlineString*)(js::Allocate(cx)); } - return js::Allocate(cx, js::gc::DefaultHeap); + return js::AllocateString(cx, js::gc::DefaultHeap); } template <> diff --git a/js/src/vm/UnboxedObject.cpp b/js/src/vm/UnboxedObject.cpp index ec7e01995b1a..81d671c7980c 100644 --- a/js/src/vm/UnboxedObject.cpp +++ b/js/src/vm/UnboxedObject.cpp @@ -846,7 +846,7 @@ NativeObject* UnboxedPlainObject::convertToNative(JSContext* cx, debugCheckNewObject(group, /* shape = */ nullptr, kind, heap); JSObject* obj = - js::Allocate(cx, kind, /* nDynamicSlots = */ 0, heap, clasp); + js::AllocateObject(cx, kind, /* nDynamicSlots = */ 0, heap, clasp); if (!obj) { return cx->alreadyReportedOOM(); }