diff --git a/js/public/RootingAPI.h b/js/public/RootingAPI.h index 1224ee087ece..471c72dc423c 100644 --- a/js/public/RootingAPI.h +++ b/js/public/RootingAPI.h @@ -1020,8 +1020,6 @@ class RootingContext { js::GeckoProfilerThread& geckoProfiler() { return geckoProfiler_; } - JS::Zone* zoneUnchecked() const { return zone_; } - js::Nursery& nursery() const { MOZ_ASSERT(nursery_); return *nursery_; diff --git a/js/src/gc/Allocator-inl.h b/js/src/gc/Allocator-inl.h index 6019651cd735..de54a26e4688 100644 --- a/js/src/gc/Allocator-inl.h +++ b/js/src/gc/Allocator-inl.h @@ -26,17 +26,17 @@ namespace js { namespace gc { template -T* CellAllocator::NewCell(JS::RootingContext* rcx, Args&&... args) { +T* CellAllocator::NewCell(JSContext* cx, Args&&... args) { static_assert(std::is_base_of_v); // Objects. See the valid parameter list in NewObject, above. if constexpr (std::is_base_of_v) { - return NewObject(rcx, std::forward(args)...); + return NewObject(cx, std::forward(args)...); } // BigInt else if constexpr (std::is_base_of_v) { - return NewBigInt(rcx, std::forward(args)...); + return NewBigInt(cx, std::forward(args)...); } // "Normal" strings (all of which can be nursery allocated). Atoms and @@ -46,25 +46,24 @@ T* CellAllocator::NewCell(JS::RootingContext* rcx, Args&&... args) { else if constexpr (std::is_base_of_v && !std::is_base_of_v && !std::is_base_of_v) { - return NewString(rcx, std::forward(args)...); + return NewString(cx, std::forward(args)...); } else { // Allocate a new tenured GC thing that's not nursery-allocatable. Use // cx->newCell(...), where the parameters are forwarded to the type's // constructor. - return NewTenuredCell(rcx, std::forward(args)...); + return NewTenuredCell(cx, std::forward(args)...); } } template /* static */ -T* CellAllocator::NewString(JS::RootingContext* rcx, gc::Heap heap, - Args&&... args) { +T* CellAllocator::NewString(JSContext* cx, gc::Heap heap, Args&&... args) { static_assert(std::is_base_of_v); gc::AllocKind kind = gc::MapTypeToAllocKind::kind; void* ptr = AllocNurseryOrTenuredCell( - rcx, kind, sizeof(T), heap, nullptr); + cx, kind, sizeof(T), heap, nullptr); if (MOZ_UNLIKELY(!ptr)) { return nullptr; } @@ -73,9 +72,9 @@ T* CellAllocator::NewString(JS::RootingContext* rcx, gc::Heap heap, template /* static */ -T* CellAllocator::NewBigInt(JS::RootingContext* rcx, Heap heap) { +T* CellAllocator::NewBigInt(JSContext* cx, Heap heap) { void* ptr = AllocNurseryOrTenuredCell( - rcx, gc::AllocKind::BIGINT, sizeof(T), heap, nullptr); + cx, gc::AllocKind::BIGINT, sizeof(T), heap, nullptr); if (MOZ_UNLIKELY(!ptr)) { return nullptr; } @@ -84,16 +83,15 @@ T* CellAllocator::NewBigInt(JS::RootingContext* rcx, Heap heap) { template /* static */ -T* CellAllocator::NewObject(JS::RootingContext* rcx, gc::AllocKind kind, - gc::Heap heap, const JSClass* clasp, - gc::AllocSite* site) { +T* CellAllocator::NewObject(JSContext* cx, gc::AllocKind kind, gc::Heap heap, + const JSClass* clasp, gc::AllocSite* site) { MOZ_ASSERT(IsObjectAllocKind(kind)); MOZ_ASSERT_IF(heap != gc::Heap::Tenured && clasp->hasFinalize() && !clasp->isProxyObject(), CanNurseryAllocateFinalizedClass(clasp)); size_t thingSize = JSObject::thingSize(kind); void* cell = AllocNurseryOrTenuredCell( - rcx, kind, thingSize, heap, site); + cx, kind, thingSize, heap, site); if (MOZ_UNLIKELY(!cell)) { return nullptr; } @@ -102,7 +100,7 @@ T* CellAllocator::NewObject(JS::RootingContext* rcx, gc::AllocKind kind, template /* static */ -void* CellAllocator::AllocNurseryOrTenuredCell(JS::RootingContext* rcx, +void* CellAllocator::AllocNurseryOrTenuredCell(JSContext* cx, gc::AllocKind allocKind, size_t thingSize, gc::Heap heap, AllocSite* site) { @@ -112,27 +110,27 @@ void* CellAllocator::AllocNurseryOrTenuredCell(JS::RootingContext* rcx, MOZ_ASSERT_IF(site && site->initialHeap() == Heap::Tenured, heap == Heap::Tenured); - if (!PreAllocChecks(rcx, allocKind)) { + if (!PreAllocChecks(cx, allocKind)) { return nullptr; } - JS::Zone* zone = rcx->zoneUnchecked(); + JS::Zone* zone = cx->zone(); gc::Heap minHeapToTenure = CheckedHeap(zone->minHeapToTenure(traceKind)); if (CheckedHeap(heap) < minHeapToTenure) { if (!site) { site = zone->unknownAllocSite(traceKind); } - void* ptr = rcx->nursery().tryAllocateCell(site, thingSize, traceKind); + void* ptr = cx->nursery().tryAllocateCell(site, thingSize, traceKind); if (MOZ_LIKELY(ptr)) { return ptr; } - return RetryNurseryAlloc(rcx, traceKind, allocKind, thingSize, + return RetryNurseryAlloc(cx, traceKind, allocKind, thingSize, site); } - return TryNewTenuredCell(rcx, allocKind, thingSize); + return TryNewTenuredCell(cx, allocKind, thingSize); } /* static */ @@ -148,9 +146,9 @@ MOZ_ALWAYS_INLINE gc::Heap CellAllocator::CheckedHeap(gc::Heap heap) { template /* static */ -T* CellAllocator::NewTenuredCell(JS::RootingContext* rcx, Args&&... args) { +T* CellAllocator::NewTenuredCell(JSContext* cx, Args&&... args) { gc::AllocKind kind = gc::MapTypeToAllocKind::kind; - void* cell = AllocTenuredCell(rcx, kind, sizeof(T)); + void* cell = AllocTenuredCell(cx, kind, sizeof(T)); if (MOZ_UNLIKELY(!cell)) { return nullptr; } diff --git a/js/src/gc/Allocator.cpp b/js/src/gc/Allocator.cpp index b4a92b86909b..c1b1d355cb08 100644 --- a/js/src/gc/Allocator.cpp +++ b/js/src/gc/Allocator.cpp @@ -58,7 +58,7 @@ void Zone::setNurseryAllocFlags(bool allocObjects, bool allocStrings, #define INSTANTIATE_ALLOC_NURSERY_CELL(traceKind, allowGc) \ template void* \ gc::CellAllocator::AllocNurseryOrTenuredCell( \ - JS::RootingContext*, AllocKind, size_t, gc::Heap, AllocSite*); + JSContext*, AllocKind, size_t, gc::Heap, AllocSite*); INSTANTIATE_ALLOC_NURSERY_CELL(JS::TraceKind::Object, NoGC) INSTANTIATE_ALLOC_NURSERY_CELL(JS::TraceKind::Object, CanGC) INSTANTIATE_ALLOC_NURSERY_CELL(JS::TraceKind::String, NoGC) @@ -71,12 +71,11 @@ INSTANTIATE_ALLOC_NURSERY_CELL(JS::TraceKind::BigInt, CanGC) // the nursery or there is an OOM, this method will return nullptr. template /* static */ -MOZ_NEVER_INLINE void* CellAllocator::RetryNurseryAlloc(JS::RootingContext* rcx, +MOZ_NEVER_INLINE void* CellAllocator::RetryNurseryAlloc(JSContext* cx, JS::TraceKind traceKind, AllocKind allocKind, size_t thingSize, AllocSite* site) { - auto* cx = JSContext::from(rcx); MOZ_ASSERT(cx->isNurseryAllocAllowed()); MOZ_ASSERT(cx->zone() == site->zone()); MOZ_ASSERT(!cx->zone()->isAtomsZone()); @@ -115,40 +114,38 @@ MOZ_NEVER_INLINE void* CellAllocator::RetryNurseryAlloc(JS::RootingContext* rcx, return TryNewTenuredCell(cx, allocKind, thingSize); } -template void* CellAllocator::RetryNurseryAlloc(JS::RootingContext* rcx, +template void* CellAllocator::RetryNurseryAlloc(JSContext* cx, JS::TraceKind traceKind, AllocKind allocKind, size_t thingSize, AllocSite* site); -template void* CellAllocator::RetryNurseryAlloc(JS::RootingContext* rcx, +template void* CellAllocator::RetryNurseryAlloc(JSContext* cx, JS::TraceKind traceKind, AllocKind allocKind, size_t thingSize, AllocSite* site); template -void* gc::CellAllocator::AllocTenuredCell(JS::RootingContext* rcx, - gc::AllocKind kind, size_t size) { +void* gc::CellAllocator::AllocTenuredCell(JSContext* cx, gc::AllocKind kind, + size_t size) { MOZ_ASSERT(!IsNurseryAllocable(kind)); MOZ_ASSERT(size == Arena::thingSize(kind)); - if (!PreAllocChecks(rcx, kind)) { + if (!PreAllocChecks(cx, kind)) { return nullptr; } - return TryNewTenuredCell(rcx, kind, size); + return TryNewTenuredCell(cx, kind, size); } -template void* gc::CellAllocator::AllocTenuredCell(JS::RootingContext*, - AllocKind, size_t); -template void* gc::CellAllocator::AllocTenuredCell(JS::RootingContext*, - AllocKind, size_t); +template void* gc::CellAllocator::AllocTenuredCell(JSContext*, AllocKind, + size_t); +template void* gc::CellAllocator::AllocTenuredCell(JSContext*, AllocKind, + size_t); template /* static */ -void* CellAllocator::TryNewTenuredCell(JS::RootingContext* rcx, AllocKind kind, +void* CellAllocator::TryNewTenuredCell(JSContext* cx, AllocKind kind, size_t thingSize) { - auto* cx = JSContext::from(rcx); - if constexpr (allowGC) { // Invoking the interrupt callback can fail and we can't usefully // handle that here. Just check in case we need to collect instead. @@ -193,10 +190,10 @@ void* CellAllocator::TryNewTenuredCell(JS::RootingContext* rcx, AllocKind kind, return ptr; } -template void* CellAllocator::TryNewTenuredCell(JS::RootingContext* rcx, +template void* CellAllocator::TryNewTenuredCell(JSContext* cx, AllocKind kind, size_t thingSize); -template void* CellAllocator::TryNewTenuredCell(JS::RootingContext* rcx, +template void* CellAllocator::TryNewTenuredCell(JSContext* cx, AllocKind kind, size_t thingSize); @@ -242,9 +239,7 @@ static inline void CheckAllocZone(Zone* zone, AllocKind kind) { // // This is a no-op in release builds. template -bool CellAllocator::PreAllocChecks(JS::RootingContext* rcx, AllocKind kind) { - auto* cx = JSContext::from(rcx); - +bool CellAllocator::PreAllocChecks(JSContext* cx, AllocKind kind) { MOZ_ASSERT(CurrentThreadCanAccessRuntime(cx->runtime())); CheckAllocZone(cx->zone(), kind); @@ -275,9 +270,9 @@ bool CellAllocator::PreAllocChecks(JS::RootingContext* rcx, AllocKind kind) { return true; } -template bool CellAllocator::PreAllocChecks(JS::RootingContext* cx, +template bool CellAllocator::PreAllocChecks(JSContext* cx, AllocKind kind); -template bool CellAllocator::PreAllocChecks(JS::RootingContext* cx, +template bool CellAllocator::PreAllocChecks(JSContext* cx, AllocKind kind); #endif // DEBUG || JS_GC_ZEAL || JS_OOM_BREAKPOINT diff --git a/js/src/gc/Allocator.h b/js/src/gc/Allocator.h index 96102699e165..8cb80ef7aed3 100644 --- a/js/src/gc/Allocator.h +++ b/js/src/gc/Allocator.h @@ -15,10 +15,6 @@ #include "gc/GCEnum.h" #include "js/TypeDecls.h" -namespace JS { -class RootingContext; -} // namespace JS - namespace js { namespace gc { @@ -53,23 +49,23 @@ class CellAllocator { // ensure that GC tracing never sees junk values stored in the partially // initialized thing. template - static inline T* NewCell(JS::RootingContext* rcx, Args&&... args); + static inline T* NewCell(JSContext* cx, Args&&... args); private: template - static void* RetryNurseryAlloc(JS::RootingContext* rcx, - JS::TraceKind traceKind, AllocKind allocKind, - size_t thingSize, AllocSite* site); + static void* RetryNurseryAlloc(JSContext* cx, JS::TraceKind traceKind, + AllocKind allocKind, size_t thingSize, + AllocSite* site); template - static void* TryNewTenuredCell(JS::RootingContext* rcx, AllocKind kind, + static void* TryNewTenuredCell(JSContext* cx, AllocKind kind, size_t thingSize); #if defined(DEBUG) || defined(JS_GC_ZEAL) || defined(JS_OOM_BREAKPOINT) template - static bool PreAllocChecks(JS::RootingContext* rcx, AllocKind kind); + static bool PreAllocChecks(JSContext* cx, AllocKind kind); #else template - static bool PreAllocChecks(JS::RootingContext* rcx, AllocKind kind) { + static bool PreAllocChecks(JSContext* cx, AllocKind kind) { return true; } #endif @@ -83,15 +79,13 @@ class CellAllocator { // Allocate a cell in the nursery, unless |heap| is Heap::Tenured or nursery // allocation is disabled for |traceKind| in the current zone. template - static void* AllocNurseryOrTenuredCell(JS::RootingContext* rcx, - gc::AllocKind allocKind, + static void* AllocNurseryOrTenuredCell(JSContext* cx, gc::AllocKind allocKind, size_t thingSize, gc::Heap heap, AllocSite* site); // Allocate a cell in the tenured heap. template - static void* AllocTenuredCell(JS::RootingContext* rcx, gc::AllocKind kind, - size_t size); + static void* AllocTenuredCell(JSContext* cx, gc::AllocKind kind, size_t size); // Allocate a string. Use cx->newCell([heap]). // @@ -99,19 +93,18 @@ class CellAllocator { // type. Non-nursery-allocatable strings will go through the fallback // tenured-only allocation path. template - static T* NewString(JS::RootingContext* rcx, gc::Heap heap, Args&&... args); + static T* NewString(JSContext* cx, gc::Heap heap, Args&&... args); template - static T* NewBigInt(JS::RootingContext* rcx, Heap heap); + static T* NewBigInt(JSContext* cx, Heap heap); template - static T* NewObject(JS::RootingContext* rcx, gc::AllocKind kind, - gc::Heap heap, const JSClass* clasp, - gc::AllocSite* site = nullptr); + static T* NewObject(JSContext* cx, gc::AllocKind kind, gc::Heap heap, + const JSClass* clasp, gc::AllocSite* site = nullptr); // Allocate all other kinds of GC thing. template - static T* NewTenuredCell(JS::RootingContext* rcx, Args&&... args); + static T* NewTenuredCell(JSContext* cx, Args&&... args); }; } // namespace gc diff --git a/js/src/vm/JSContext.h b/js/src/vm/JSContext.h index 38b00daa98a1..773c3e2c40f5 100644 --- a/js/src/vm/JSContext.h +++ b/js/src/vm/JSContext.h @@ -292,7 +292,7 @@ struct JS_PUBLIC_API JSContext : public JS::RootingContext, JS::Zone* zone() const { MOZ_ASSERT_IF(!realm() && zone_, inAtomsZone()); MOZ_ASSERT_IF(realm(), js::GetRealmZone(realm()) == zone_); - return zoneUnchecked(); + return zone_; } // For JIT use.