Bug 1532946 - Tidy allocation functions by renaming overloads for object and string allocation r=sfink

This commit is contained in:
Jon Coppeard 2019-03-06 11:23:08 +00:00
Родитель aa5c7c415a
Коммит abb2fb97f8
11 изменённых файлов: 60 добавлений и 58 удалений

Просмотреть файл

@ -2317,7 +2317,7 @@ bool TypedObject::construct(JSContext* cx, unsigned int argc, Value* vp) {
MOZ_ASSERT(::IsTypedObjectClass(clasp));
JSObject* obj =
js::Allocate<JSObject>(cx, kind, /* nDynamicSlots = */ 0, heap, clasp);
js::AllocateObject(cx, kind, /* nDynamicSlots = */ 0, heap, clasp);
if (!obj) {
return cx->alreadyReportedOOM();
}

Просмотреть файл

@ -25,11 +25,9 @@
using namespace js;
using namespace gc;
template <typename T, AllowGC allowGC /* = CanGC */>
JSObject* js::Allocate(JSContext* cx, AllocKind kind, size_t nDynamicSlots,
InitialHeap heap, const Class* clasp) {
static_assert(mozilla::IsConvertible<T*, JSObject*>::value,
"must be JSObject derived");
template <AllowGC allowGC /* = CanGC */>
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<allowGC>(cx, kind, thingSize,
nDynamicSlots);
}
template JSObject* js::Allocate<JSObject, NoGC>(JSContext* cx,
gc::AllocKind kind,
size_t nDynamicSlots,
gc::InitialHeap heap,
const Class* clasp);
template JSObject* js::Allocate<JSObject, CanGC>(JSContext* cx,
gc::AllocKind kind,
size_t nDynamicSlots,
gc::InitialHeap heap,
const Class* clasp);
template JSObject* js::AllocateObject<NoGC>(JSContext* cx,
gc::AllocKind kind,
size_t nDynamicSlots,
gc::InitialHeap heap,
const Class* clasp);
template JSObject* js::AllocateObject<CanGC>(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 <typename StringAllocT, AllowGC allowGC /* = CanGC */>
StringAllocT* js::AllocateString(JSContext* cx, InitialHeap heap) {
StringAllocT* js::AllocateStringImpl(JSContext* cx, InitialHeap heap) {
static_assert(mozilla::IsConvertible<StringAllocT*, JSString*>::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<type, NoGC>(JSContext * cx, \
InitialHeap heap); \
template type* js::AllocateString<type, CanGC>(JSContext * cx, \
InitialHeap heap);
template type* js::AllocateStringImpl<type, NoGC>(JSContext * cx, \
InitialHeap heap); \
template type* js::AllocateStringImpl<type, CanGC>(JSContext * cx, \
InitialHeap heap);
FOR_EACH_NURSERY_STRING_ALLOCKIND(DECL_ALLOCATOR_INSTANCES)
#undef DECL_ALLOCATOR_INSTANCES

Просмотреть файл

@ -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 <typename T, AllowGC allowGC = CanGC>
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 <typename, AllowGC allowGC = CanGC>
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 <AllowGC allowGC = CanGC>
JSObject* AllocateObject(JSContext* cx, gc::AllocKind kind, size_t nDynamicSlots,
gc::InitialHeap heap, const Class* clasp);
// Internal function used for nursery-allocatable strings.
template <typename StringAllocT, AllowGC allowGC = CanGC>
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 <typename StringT, AllowGC allowGC = CanGC>
StringT* Allocate(JSContext* cx, gc::InitialHeap heap) {
return static_cast<StringT*>(js::AllocateString<JSString, allowGC>(cx, heap));
StringT* AllocateString(JSContext* cx, gc::InitialHeap heap) {
return static_cast<StringT*>(AllocateStringImpl<JSString, allowGC>(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<JSFatInlineString, CanGC>(
inline JSFatInlineString* AllocateString<JSFatInlineString, CanGC>(
JSContext* cx, gc::InitialHeap heap) {
return static_cast<JSFatInlineString*>(
js::AllocateString<JSFatInlineString, CanGC>(cx, heap));
js::AllocateStringImpl<JSFatInlineString, CanGC>(cx, heap));
}
template <>
inline JSFatInlineString* Allocate<JSFatInlineString, NoGC>(
inline JSFatInlineString* AllocateString<JSFatInlineString, NoGC>(
JSContext* cx, gc::InitialHeap heap) {
return static_cast<JSFatInlineString*>(
js::AllocateString<JSFatInlineString, NoGC>(cx, heap));
js::AllocateStringImpl<JSFatInlineString, NoGC>(cx, heap));
}
} // namespace js

Просмотреть файл

@ -2402,12 +2402,12 @@ void CreateDependentString::generate(MacroAssembler& masm,
static void* AllocateString(JSContext* cx) {
AutoUnsafeCallWithABI unsafe;
return js::Allocate<JSString, NoGC>(cx, js::gc::TenuredHeap);
return js::AllocateString<JSString, NoGC>(cx, js::gc::TenuredHeap);
}
static void* AllocateFatInlineString(JSContext* cx) {
AutoUnsafeCallWithABI unsafe;
return js::Allocate<JSFatInlineString, NoGC>(cx, js::gc::TenuredHeap);
return js::AllocateString<JSFatInlineString, NoGC>(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<JSObject, NoGC>(cx, kind, nDynamicSlots, gc::DefaultHeap,
&ArrayObject::class_);
return js::AllocateObject<NoGC>(cx, kind, nDynamicSlots, gc::DefaultHeap,
&ArrayObject::class_);
}
static void CreateMatchResultFallback(MacroAssembler& masm, Register object,

Просмотреть файл

@ -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<JSObject>(cx, kind, nDynamicSlots, heap, clasp);
JSObject* obj = js::AllocateObject(cx, kind, nDynamicSlots, heap, clasp);
if (!obj) {
return nullptr;
}

Просмотреть файл

@ -73,8 +73,8 @@ inline NativeObject* NewObjectCache::newObjectFromHit(JSContext* cx,
}
NativeObject* obj = static_cast<NativeObject*>(
Allocate<JSObject, NoGC>(cx, entry->kind,
/* nDynamicSlots = */ 0, heap, group->clasp()));
AllocateObject<NoGC>(cx, entry->kind, /* nDynamicSlots = */ 0,
heap, group->clasp()));
if (!obj) {
return nullptr;
}

Просмотреть файл

@ -113,8 +113,7 @@ inline JSFunction* CloneFunctionObjectIfNotSingleton(
MOZ_ASSERT(dynamicSlotsCount(shape->numFixedSlots(), shape->slotSpan(),
clasp) == NumDynamicSlots);
JSObject* obj =
js::Allocate<JSObject>(cx, kind, NumDynamicSlots, heap, clasp);
JSObject* obj = js::AllocateObject(cx, kind, NumDynamicSlots, heap, clasp);
if (!obj) {
return cx->alreadyReportedOOM();
}

Просмотреть файл

@ -488,7 +488,7 @@ inline bool NativeObject::isInWholeCellBuffer() const {
size_t nDynamicSlots =
dynamicSlotsCount(shape->numFixedSlots(), shape->slotSpan(), clasp);
JSObject* obj = js::Allocate<JSObject>(cx, kind, nDynamicSlots, heap, clasp);
JSObject* obj = js::AllocateObject(cx, kind, nDynamicSlots, heap, clasp);
if (!obj) {
return cx->alreadyReportedOOM();
}

Просмотреть файл

@ -187,8 +187,8 @@ void ProxyObject::nuke() {
gc::InitialHeap heap = GetInitialHeap(newKind, group);
debugCheckNewObject(group, shape, allocKind, heap);
JSObject* obj = js::Allocate<JSObject>(cx, allocKind, /* nDynamicSlots = */ 0,
heap, clasp);
JSObject* obj = js::AllocateObject(cx, allocKind, /* nDynamicSlots = */ 0,
heap, clasp);
if (!obj) {
return cx->alreadyReportedOOM();
}

Просмотреть файл

@ -159,7 +159,7 @@ MOZ_ALWAYS_INLINE JSRope* JSRope::new_(
if (!validateLength(cx, length)) {
return nullptr;
}
JSRope* str = js::Allocate<JSRope, allowGC>(cx, heap);
JSRope* str = js::AllocateString<JSRope, allowGC>(cx, heap);
if (!str) {
return nullptr;
}
@ -220,7 +220,7 @@ MOZ_ALWAYS_INLINE JSLinearString* JSDependentString::new_(
}
JSDependentString* str =
js::Allocate<JSDependentString, js::NoGC>(cx, js::gc::DefaultHeap);
js::AllocateString<JSDependentString, js::NoGC>(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<JSDependentString>(cx, js::gc::DefaultHeap);
str = js::AllocateString<JSDependentString>(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<js::NormalAtom, allowGC>(cx);
} else {
str = js::Allocate<JSFlatString, allowGC>(cx, js::gc::DefaultHeap);
str = js::AllocateString<JSFlatString, allowGC>(cx, js::gc::DefaultHeap);
}
if (!str) {
return nullptr;
@ -308,7 +308,7 @@ MOZ_ALWAYS_INLINE JSThinInlineString* JSThinInlineString::new_(JSContext* cx) {
return (JSThinInlineString*)(js::Allocate<js::NormalAtom, allowGC>(cx));
}
return js::Allocate<JSThinInlineString, allowGC>(cx, js::gc::DefaultHeap);
return js::AllocateString<JSThinInlineString, allowGC>(cx, js::gc::DefaultHeap);
}
template <js::AllowGC allowGC>
@ -317,7 +317,7 @@ MOZ_ALWAYS_INLINE JSFatInlineString* JSFatInlineString::new_(JSContext* cx) {
return (JSFatInlineString*)(js::Allocate<js::FatInlineAtom, allowGC>(cx));
}
return js::Allocate<JSFatInlineString, allowGC>(cx, js::gc::DefaultHeap);
return js::AllocateString<JSFatInlineString, allowGC>(cx, js::gc::DefaultHeap);
}
template <>

Просмотреть файл

@ -846,7 +846,7 @@ NativeObject* UnboxedPlainObject::convertToNative(JSContext* cx,
debugCheckNewObject(group, /* shape = */ nullptr, kind, heap);
JSObject* obj =
js::Allocate<JSObject>(cx, kind, /* nDynamicSlots = */ 0, heap, clasp);
js::AllocateObject(cx, kind, /* nDynamicSlots = */ 0, heap, clasp);
if (!obj) {
return cx->alreadyReportedOOM();
}