Skip to content

Commit

Permalink
Bug 1787579 - Move AllocateObject into js::gc::CellAllocator alongsid…
Browse files Browse the repository at this point in the history
…e AllocateString and AllocateBigInt r=arai

Differential Revision: https://phabricator.services.mozilla.com/D155766
  • Loading branch information
hotsphink committed Mar 19, 2023
1 parent 6cbb38a commit b4a4d32
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
13 changes: 7 additions & 6 deletions js/src/gc/Allocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ using namespace js;
using namespace gc;

template <AllowGC allowGC /* = CanGC */>
JSObject* gc::detail::AllocateObject(JSContext* cx, AllocKind kind,
size_t nDynamicSlots, gc::InitialHeap heap,
const JSClass* clasp,
AllocSite* site /* = nullptr */) {
JSObject* gc::CellAllocator::AllocateObject(JSContext* cx, AllocKind kind,
size_t nDynamicSlots,
gc::InitialHeap heap,
const JSClass* clasp,
AllocSite* site /* = nullptr */) {
MOZ_ASSERT(!cx->isHelperThreadContext());
MOZ_ASSERT(IsObjectAllocKind(kind));
size_t thingSize = Arena::thingSize(kind);
Expand Down Expand Up @@ -81,10 +82,10 @@ JSObject* gc::detail::AllocateObject(JSContext* cx, AllocKind kind,
return GCRuntime::tryNewTenuredObject<allowGC>(cx, kind, thingSize,
nDynamicSlots);
}
template JSObject* gc::detail::AllocateObject<NoGC>(
template JSObject* gc::CellAllocator::AllocateObject<NoGC>(
JSContext* cx, gc::AllocKind kind, size_t nDynamicSlots,
gc::InitialHeap heap, const JSClass* clasp, gc::AllocSite* site);
template JSObject* gc::detail::AllocateObject<CanGC>(
template JSObject* gc::CellAllocator::AllocateObject<CanGC>(
JSContext* cx, gc::AllocKind kind, size_t nDynamicSlots,
gc::InitialHeap heap, const JSClass* clasp, gc::AllocSite* site);

Expand Down
22 changes: 12 additions & 10 deletions js/src/gc/Allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,17 @@ class CellAllocator {
template <AllowGC allowGC = CanGC>
static JS::BigInt* AllocateBigInt(JSContext* cx, gc::InitialHeap heap);

// Allocate a JSObject. Use cx->newCell<ObjectT>(kind, ...).
//
// Parameters support various optimizations. If dynamic slots are requested
// they will be allocated and the pointer stored directly in
// |NativeObject::slots_|.
template <AllowGC allowGC = CanGC>
static JSObject* AllocateObject(JSContext* cx, gc::AllocKind kind,
size_t nDynamicSlots, gc::InitialHeap heap,
const JSClass* clasp,
gc::AllocSite* site = nullptr);

public:
template <typename T, js::AllowGC allowGC = CanGC, typename... Args>
static T* NewCell(JSContext* cx, Args&&... args);
Expand All @@ -93,15 +104,6 @@ template <AllowGC allowGC = CanGC>
gc::TenuredCell* AllocateTenuredImpl(JSContext* cx, gc::AllocKind kind,
size_t size);

// Allocate a JSObject. Use cx->newCell<ObjectT>(kind, ...).
//
// Parameters support 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 JSClass* clasp, gc::AllocSite* site = nullptr);

} // namespace detail
} // namespace gc

Expand All @@ -118,7 +120,7 @@ T* gc::CellAllocator::NewCell(JSContext* cx, Args&&... args) {
return AllocateBigInt<allowGC>(cx, std::forward<Args>(args)...);
} else if constexpr (std::is_base_of_v<JSObject, T>) {
return static_cast<T*>(
gc::detail::AllocateObject<allowGC>(cx, std::forward<Args>(args)...));
AllocateObject<allowGC>(cx, std::forward<Args>(args)...));
} else {
// Allocate a new tenured GC thing that's not nursery-allocatable. Use
// cx->newCell<T>(...), where the parameters are prefixed with a cx
Expand Down

0 comments on commit b4a4d32

Please sign in to comment.