mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-05 00:25:27 +00:00
Bug 1141234 - Part 3: Share the code to allocate a tenured thing; r=sfink
--HG-- extra : rebase_source : 9b9b320a6e94abc9a543b54d6e968217c20a0696
This commit is contained in:
parent
37560d20b5
commit
355d820daa
@ -41,6 +41,10 @@ ShouldNurseryAllocateObject(const Nursery &nursery, InitialHeap heap)
|
||||
return nursery.isEnabled() && heap != TenuredHeap;
|
||||
}
|
||||
|
||||
template <typename T, AllowGC allowGC>
|
||||
T *
|
||||
TryNewTenuredThing(ExclusiveContext *cx, AllocKind kind, size_t thingSize);
|
||||
|
||||
/*
|
||||
* Attempt to allocate a new GC thing out of the nursery. If there is not enough
|
||||
* room in the nursery or there is an OOM, this method will return nullptr.
|
||||
@ -197,15 +201,11 @@ js::Allocate(ExclusiveContext *cx, AllocKind kind, size_t nDynamicSlots, Initial
|
||||
if (nDynamicSlots && !slots)
|
||||
return nullptr;
|
||||
|
||||
JSObject *obj = reinterpret_cast<JSObject *>(cx->arenas()->allocateFromFreeList(kind, thingSize));
|
||||
if (!obj)
|
||||
obj = reinterpret_cast<JSObject *>(GCRuntime::refillFreeListFromAnyThread<allowGC>(cx, kind));
|
||||
JSObject *obj = TryNewTenuredThing<JSObject, allowGC>(cx, kind, thingSize);
|
||||
|
||||
if (obj)
|
||||
obj->setInitialSlotsMaybeNonNative(slots.release());
|
||||
|
||||
CheckIncrementalZoneState(cx, obj);
|
||||
TraceTenuredAlloc(obj, kind);
|
||||
return obj;
|
||||
}
|
||||
template JSObject *js::Allocate<JSObject, NoGC>(ExclusiveContext *cx, gc::AllocKind kind,
|
||||
@ -230,13 +230,7 @@ js::Allocate(ExclusiveContext *cx)
|
||||
if (!CheckAllocatorState<allowGC>(cx, kind))
|
||||
return nullptr;
|
||||
|
||||
T *t = static_cast<T *>(cx->arenas()->allocateFromFreeList(kind, thingSize));
|
||||
if (!t)
|
||||
t = static_cast<T *>(GCRuntime::refillFreeListFromAnyThread<allowGC>(cx, kind));
|
||||
|
||||
CheckIncrementalZoneState(cx, t);
|
||||
gc::TraceTenuredAlloc(t, kind);
|
||||
return t;
|
||||
return TryNewTenuredThing<T, allowGC>(cx, kind, thingSize);
|
||||
}
|
||||
|
||||
#define FOR_ALL_NON_OBJECT_GC_LAYOUTS(macro) \
|
||||
@ -257,3 +251,16 @@ js::Allocate(ExclusiveContext *cx)
|
||||
template type *js::Allocate<type, CanGC>(ExclusiveContext *cx);
|
||||
FOR_ALL_NON_OBJECT_GC_LAYOUTS(DECL_ALLOCATOR_INSTANCES)
|
||||
#undef DECL_ALLOCATOR_INSTANCES
|
||||
|
||||
template <typename T, AllowGC allowGC>
|
||||
T *
|
||||
TryNewTenuredThing(ExclusiveContext *cx, AllocKind kind, size_t thingSize)
|
||||
{
|
||||
T *t = reinterpret_cast<T *>(cx->arenas()->allocateFromFreeList(kind, thingSize));
|
||||
if (!t)
|
||||
t = reinterpret_cast<T *>(GCRuntime::refillFreeListFromAnyThread<allowGC>(cx, kind));
|
||||
|
||||
CheckIncrementalZoneState(cx, t);
|
||||
TraceTenuredAlloc(t, kind);
|
||||
return t;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user