diff --git a/js/src/gc/Allocator.cpp b/js/src/gc/Allocator.cpp index 6b262c0e8afc..8ab0bd5adadc 100644 --- a/js/src/gc/Allocator.cpp +++ b/js/src/gc/Allocator.cpp @@ -25,6 +25,10 @@ ShouldNurseryAllocateObject(const Nursery &nursery, InitialHeap heap) return nursery.isEnabled() && heap != TenuredHeap; } +template +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. @@ -185,17 +189,13 @@ js::Allocate(ExclusiveContext *cx, AllocKind kind, size_t nDynamicSlots, Initial Debug_SetSlotRangeToCrashOnTouch(slots, nDynamicSlots); } - JSObject *obj = reinterpret_cast(cx->arenas()->allocateFromFreeList(kind, thingSize)); - if (!obj) - obj = reinterpret_cast(GCRuntime::refillFreeListFromAnyThread(cx, kind)); + JSObject *obj = TryNewTenuredThing(cx, kind, thingSize); if (obj) obj->setInitialSlotsMaybeNonNative(slots); else js_free(slots); - CheckIncrementalZoneState(cx, obj); - TraceTenuredAlloc(obj, kind); return obj; } template JSObject *js::Allocate(ExclusiveContext *cx, gc::AllocKind kind, @@ -220,13 +220,7 @@ js::Allocate(ExclusiveContext *cx) if (!CheckAllocatorState(cx, kind)) return nullptr; - T *t = static_cast(cx->arenas()->allocateFromFreeList(kind, thingSize)); - if (!t) - t = static_cast(GCRuntime::refillFreeListFromAnyThread(cx, kind)); - - CheckIncrementalZoneState(cx, t); - gc::TraceTenuredAlloc(t, kind); - return t; + return TryNewTenuredThing(cx, kind, thingSize); } #define FOR_ALL_NON_OBJECT_GC_LAYOUTS(macro) \ @@ -247,3 +241,16 @@ js::Allocate(ExclusiveContext *cx) template type *js::Allocate(ExclusiveContext *cx); FOR_ALL_NON_OBJECT_GC_LAYOUTS(DECL_ALLOCATOR_INSTANCES) #undef DECL_ALLOCATOR_INSTANCES + +template +T * +TryNewTenuredThing(ExclusiveContext *cx, AllocKind kind, size_t thingSize) +{ + T *t = reinterpret_cast(cx->arenas()->allocateFromFreeList(kind, thingSize)); + if (!t) + t = reinterpret_cast(GCRuntime::refillFreeListFromAnyThread(cx, kind)); + + CheckIncrementalZoneState(cx, t); + TraceTenuredAlloc(t, kind); + return t; +}