Skip to content

Commit 10ed846

Browse files
committed
Bug 1532946 - Tidy allocation functions by renaming overloads for object and string allocation r=sfink
UltraBlame original commit: b8137cbaf9cfa4f4c45cb9bd82584b4375ba2662
1 parent da525a1 commit 10ed846

File tree

11 files changed

+52
-50
lines changed

11 files changed

+52
-50
lines changed

js/src/builtin/TypedObject.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2317,7 +2317,7 @@ bool TypedObject::construct(JSContext* cx, unsigned int argc, Value* vp) {
23172317
MOZ_ASSERT(::IsTypedObjectClass(clasp));
23182318

23192319
JSObject* obj =
2320-
js::Allocate<JSObject>(cx, kind, 0, heap, clasp);
2320+
js::AllocateObject(cx, kind, 0, heap, clasp);
23212321
if (!obj) {
23222322
return cx->alreadyReportedOOM();
23232323
}

js/src/gc/Allocator.cpp

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,9 @@
2525
using namespace js;
2626
using namespace gc;
2727

28-
template <typename T, AllowGC allowGC >
29-
JSObject* js::Allocate(JSContext* cx, AllocKind kind, size_t nDynamicSlots,
30-
InitialHeap heap, const Class* clasp) {
31-
static_assert(mozilla::IsConvertible<T*, JSObject*>::value,
32-
"must be JSObject derived");
28+
template <AllowGC allowGC >
29+
JSObject* js::AllocateObject(JSContext* cx, AllocKind kind, size_t nDynamicSlots,
30+
InitialHeap heap, const Class* clasp) {
3331
MOZ_ASSERT(IsObjectAllocKind(kind));
3432
size_t thingSize = Arena::thingSize(kind);
3533

@@ -77,16 +75,16 @@ JSObject* js::Allocate(JSContext* cx, AllocKind kind, size_t nDynamicSlots,
7775
return GCRuntime::tryNewTenuredObject<allowGC>(cx, kind, thingSize,
7876
nDynamicSlots);
7977
}
80-
template JSObject* js::Allocate<JSObject, NoGC>(JSContext* cx,
81-
gc::AllocKind kind,
82-
size_t nDynamicSlots,
83-
gc::InitialHeap heap,
84-
const Class* clasp);
85-
template JSObject* js::Allocate<JSObject, CanGC>(JSContext* cx,
86-
gc::AllocKind kind,
87-
size_t nDynamicSlots,
88-
gc::InitialHeap heap,
89-
const Class* clasp);
78+
template JSObject* js::AllocateObject<NoGC>(JSContext* cx,
79+
gc::AllocKind kind,
80+
size_t nDynamicSlots,
81+
gc::InitialHeap heap,
82+
const Class* clasp);
83+
template JSObject* js::AllocateObject<CanGC>(JSContext* cx,
84+
gc::AllocKind kind,
85+
size_t nDynamicSlots,
86+
gc::InitialHeap heap,
87+
const Class* clasp);
9088

9189

9290

@@ -177,7 +175,7 @@ JSString* GCRuntime::tryNewNurseryString(JSContext* cx, size_t thingSize,
177175
}
178176

179177
template <typename StringAllocT, AllowGC allowGC >
180-
StringAllocT* js::AllocateString(JSContext* cx, InitialHeap heap) {
178+
StringAllocT* js::AllocateStringImpl(JSContext* cx, InitialHeap heap) {
181179
static_assert(mozilla::IsConvertible<StringAllocT*, JSString*>::value,
182180
"must be JSString derived");
183181

@@ -224,10 +222,10 @@ StringAllocT* js::AllocateString(JSContext* cx, InitialHeap heap) {
224222

225223
#define DECL_ALLOCATOR_INSTANCES(allocKind, traceKind, type, sizedType, \
226224
bgfinal, nursery, compact) \
227-
template type* js::AllocateString<type, NoGC>(JSContext * cx, \
228-
InitialHeap heap); \
229-
template type* js::AllocateString<type, CanGC>(JSContext * cx, \
230-
InitialHeap heap);
225+
template type* js::AllocateStringImpl<type, NoGC>(JSContext * cx, \
226+
InitialHeap heap); \
227+
template type* js::AllocateStringImpl<type, CanGC>(JSContext * cx, \
228+
InitialHeap heap);
231229
FOR_EACH_NURSERY_STRING_ALLOCKIND(DECL_ALLOCATOR_INSTANCES)
232230
#undef DECL_ALLOCATOR_INSTANCES
233231

js/src/gc/Allocator.h

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,42 +22,47 @@ struct Class;
2222

2323

2424

25+
2526
template <typename T, AllowGC allowGC = CanGC>
2627
T* Allocate(JSContext* cx);
2728

2829

2930

3031

31-
template <typename, AllowGC allowGC = CanGC>
32-
JSObject* Allocate(JSContext* cx, gc::AllocKind kind, size_t nDynamicSlots,
33-
gc::InitialHeap heap, const Class* clasp);
32+
33+
34+
template <AllowGC allowGC = CanGC>
35+
JSObject* AllocateObject(JSContext* cx, gc::AllocKind kind, size_t nDynamicSlots,
36+
gc::InitialHeap heap, const Class* clasp);
3437

3538

3639
template <typename StringAllocT, AllowGC allowGC = CanGC>
37-
StringAllocT* AllocateString(JSContext* cx, gc::InitialHeap heap);
40+
StringAllocT* AllocateStringImpl(JSContext* cx, gc::InitialHeap heap);
41+
42+
3843

3944

4045

4146
template <typename StringT, AllowGC allowGC = CanGC>
42-
StringT* Allocate(JSContext* cx, gc::InitialHeap heap) {
43-
return static_cast<StringT*>(js::AllocateString<JSString, allowGC>(cx, heap));
47+
StringT* AllocateString(JSContext* cx, gc::InitialHeap heap) {
48+
return static_cast<StringT*>(AllocateStringImpl<JSString, allowGC>(cx, heap));
4449
}
4550

4651

4752

4853

4954
template <>
50-
inline JSFatInlineString* Allocate<JSFatInlineString, CanGC>(
55+
inline JSFatInlineString* AllocateString<JSFatInlineString, CanGC>(
5156
JSContext* cx, gc::InitialHeap heap) {
5257
return static_cast<JSFatInlineString*>(
53-
js::AllocateString<JSFatInlineString, CanGC>(cx, heap));
58+
js::AllocateStringImpl<JSFatInlineString, CanGC>(cx, heap));
5459
}
5560

5661
template <>
57-
inline JSFatInlineString* Allocate<JSFatInlineString, NoGC>(
62+
inline JSFatInlineString* AllocateString<JSFatInlineString, NoGC>(
5863
JSContext* cx, gc::InitialHeap heap) {
5964
return static_cast<JSFatInlineString*>(
60-
js::AllocateString<JSFatInlineString, NoGC>(cx, heap));
65+
js::AllocateStringImpl<JSFatInlineString, NoGC>(cx, heap));
6166
}
6267

6368
}

js/src/jit/CodeGenerator.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2402,12 +2402,12 @@ void CreateDependentString::generate(MacroAssembler& masm,
24022402

24032403
static void* AllocateString(JSContext* cx) {
24042404
AutoUnsafeCallWithABI unsafe;
2405-
return js::Allocate<JSString, NoGC>(cx, js::gc::TenuredHeap);
2405+
return js::AllocateString<JSString, NoGC>(cx, js::gc::TenuredHeap);
24062406
}
24072407

24082408
static void* AllocateFatInlineString(JSContext* cx) {
24092409
AutoUnsafeCallWithABI unsafe;
2410-
return js::Allocate<JSFatInlineString, NoGC>(cx, js::gc::TenuredHeap);
2410+
return js::AllocateString<JSFatInlineString, NoGC>(cx, js::gc::TenuredHeap);
24112411
}
24122412

24132413
void CreateDependentString::generateFallback(MacroAssembler& masm) {
@@ -2443,8 +2443,8 @@ void CreateDependentString::generateFallback(MacroAssembler& masm) {
24432443
static void* CreateMatchResultFallbackFunc(JSContext* cx, gc::AllocKind kind,
24442444
size_t nDynamicSlots) {
24452445
AutoUnsafeCallWithABI unsafe;
2446-
return js::Allocate<JSObject, NoGC>(cx, kind, nDynamicSlots, gc::DefaultHeap,
2447-
&ArrayObject::class_);
2446+
return js::AllocateObject<NoGC>(cx, kind, nDynamicSlots, gc::DefaultHeap,
2447+
&ArrayObject::class_);
24482448
}
24492449

24502450
static void CreateMatchResultFallback(MacroAssembler& masm, Register object,

js/src/vm/ArrayObject-inl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ inline void ArrayObject::setLength(JSContext* cx, uint32_t length) {
5050
MOZ_ASSERT(shape->numFixedSlots() == 0);
5151

5252
size_t nDynamicSlots = dynamicSlotsCount(0, shape->slotSpan(), clasp);
53-
JSObject* obj = js::Allocate<JSObject>(cx, kind, nDynamicSlots, heap, clasp);
53+
JSObject* obj = js::AllocateObject(cx, kind, nDynamicSlots, heap, clasp);
5454
if (!obj) {
5555
return nullptr;
5656
}

js/src/vm/Caches-inl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ inline NativeObject* NewObjectCache::newObjectFromHit(JSContext* cx,
7373
}
7474

7575
NativeObject* obj = static_cast<NativeObject*>(
76-
Allocate<JSObject, NoGC>(cx, entry->kind,
77-
0, heap, group->clasp()));
76+
AllocateObject<NoGC>(cx, entry->kind, 0,
77+
heap, group->clasp()));
7878
if (!obj) {
7979
return nullptr;
8080
}

js/src/vm/JSFunction-inl.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,7 @@ inline JSFunction* CloneFunctionObjectIfNotSingleton(
113113
MOZ_ASSERT(dynamicSlotsCount(shape->numFixedSlots(), shape->slotSpan(),
114114
clasp) == NumDynamicSlots);
115115

116-
JSObject* obj =
117-
js::Allocate<JSObject>(cx, kind, NumDynamicSlots, heap, clasp);
116+
JSObject* obj = js::AllocateObject(cx, kind, NumDynamicSlots, heap, clasp);
118117
if (!obj) {
119118
return cx->alreadyReportedOOM();
120119
}

js/src/vm/NativeObject-inl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ inline bool NativeObject::isInWholeCellBuffer() const {
488488
size_t nDynamicSlots =
489489
dynamicSlotsCount(shape->numFixedSlots(), shape->slotSpan(), clasp);
490490

491-
JSObject* obj = js::Allocate<JSObject>(cx, kind, nDynamicSlots, heap, clasp);
491+
JSObject* obj = js::AllocateObject(cx, kind, nDynamicSlots, heap, clasp);
492492
if (!obj) {
493493
return cx->alreadyReportedOOM();
494494
}

js/src/vm/ProxyObject.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,8 @@ void ProxyObject::nuke() {
187187
gc::InitialHeap heap = GetInitialHeap(newKind, group);
188188
debugCheckNewObject(group, shape, allocKind, heap);
189189

190-
JSObject* obj = js::Allocate<JSObject>(cx, allocKind, 0,
191-
heap, clasp);
190+
JSObject* obj = js::AllocateObject(cx, allocKind, 0,
191+
heap, clasp);
192192
if (!obj) {
193193
return cx->alreadyReportedOOM();
194194
}

js/src/vm/StringType-inl.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ MOZ_ALWAYS_INLINE JSRope* JSRope::new_(
159159
if (!validateLength(cx, length)) {
160160
return nullptr;
161161
}
162-
JSRope* str = js::Allocate<JSRope, allowGC>(cx, heap);
162+
JSRope* str = js::AllocateString<JSRope, allowGC>(cx, heap);
163163
if (!str) {
164164
return nullptr;
165165
}
@@ -220,15 +220,15 @@ MOZ_ALWAYS_INLINE JSLinearString* JSDependentString::new_(
220220
}
221221

222222
JSDependentString* str =
223-
js::Allocate<JSDependentString, js::NoGC>(cx, js::gc::DefaultHeap);
223+
js::AllocateString<JSDependentString, js::NoGC>(cx, js::gc::DefaultHeap);
224224
if (str) {
225225
str->init(cx, baseArg, start, length);
226226
return str;
227227
}
228228

229229
js::RootedLinearString base(cx, baseArg);
230230

231-
str = js::Allocate<JSDependentString>(cx, js::gc::DefaultHeap);
231+
str = js::AllocateString<JSDependentString>(cx, js::gc::DefaultHeap);
232232
if (!str) {
233233
return nullptr;
234234
}
@@ -262,7 +262,7 @@ MOZ_ALWAYS_INLINE JSFlatString* JSFlatString::new_(JSContext* cx,
262262
if (cx->zone()->isAtomsZone()) {
263263
str = js::Allocate<js::NormalAtom, allowGC>(cx);
264264
} else {
265-
str = js::Allocate<JSFlatString, allowGC>(cx, js::gc::DefaultHeap);
265+
str = js::AllocateString<JSFlatString, allowGC>(cx, js::gc::DefaultHeap);
266266
}
267267
if (!str) {
268268
return nullptr;
@@ -308,7 +308,7 @@ MOZ_ALWAYS_INLINE JSThinInlineString* JSThinInlineString::new_(JSContext* cx) {
308308
return (JSThinInlineString*)(js::Allocate<js::NormalAtom, allowGC>(cx));
309309
}
310310

311-
return js::Allocate<JSThinInlineString, allowGC>(cx, js::gc::DefaultHeap);
311+
return js::AllocateString<JSThinInlineString, allowGC>(cx, js::gc::DefaultHeap);
312312
}
313313

314314
template <js::AllowGC allowGC>
@@ -317,7 +317,7 @@ MOZ_ALWAYS_INLINE JSFatInlineString* JSFatInlineString::new_(JSContext* cx) {
317317
return (JSFatInlineString*)(js::Allocate<js::FatInlineAtom, allowGC>(cx));
318318
}
319319

320-
return js::Allocate<JSFatInlineString, allowGC>(cx, js::gc::DefaultHeap);
320+
return js::AllocateString<JSFatInlineString, allowGC>(cx, js::gc::DefaultHeap);
321321
}
322322

323323
template <>

0 commit comments

Comments
 (0)