commit c858cd0fdd613c8f96e27e275ff0186d80d97dd4
parent d76d0ab5ce6036611afde8d69571aee3b76420ac
Author: Matthew Gaudet <mgaudet@mozilla.com>
Date: Thu, 6 Nov 2025 21:21:53 +0000
Bug 1997702 - Remove use of PersistentRooted on JSContext for MicroTaskQueues r=jonco
Differential Revision: https://phabricator.services.mozilla.com/D271502
Diffstat:
2 files changed, 12 insertions(+), 6 deletions(-)
diff --git a/js/src/vm/JSContext.cpp b/js/src/vm/JSContext.cpp
@@ -1140,7 +1140,7 @@ JS_PUBLIC_API bool JS::HasDebuggerMicroTasks(JSContext* cx) {
struct SavedMicroTaskQueueImpl : public JS::SavedMicroTaskQueue {
explicit SavedMicroTaskQueueImpl(JSContext* cx) : savedQueues(cx) {
savedQueues = js::MakeUnique<js::MicroTaskQueueSet>(cx);
- std::swap(cx->microTaskQueues.get(), savedQueues.get());
+ std::swap(cx->microTaskQueues, savedQueues.get());
}
~SavedMicroTaskQueueImpl() override = default;
JS::PersistentRooted<js::UniquePtr<js::MicroTaskQueueSet>> savedQueues;
@@ -1163,7 +1163,7 @@ JS_PUBLIC_API void JS::RestoreMicroTaskQueue(
// There's only one impl, so we know this is safe.
SavedMicroTaskQueueImpl* savedQueueImpl =
static_cast<SavedMicroTaskQueueImpl*>(savedQueue.get());
- std::swap(savedQueueImpl->savedQueues.get(), cx->microTaskQueues.get());
+ std::swap(savedQueueImpl->savedQueues.get(), cx->microTaskQueues);
}
JS_PUBLIC_API size_t JS::GetRegularMicroTaskCount(JSContext* cx) {
@@ -1268,8 +1268,7 @@ JSContext::JSContext(JSRuntime* runtime, const JS::ContextOptions& options)
canSkipEnqueuingJobs(this, false),
promiseRejectionTrackerCallback(this, nullptr),
promiseRejectionTrackerCallbackData(this, nullptr),
- insideExclusiveDebuggerOnEval(this, nullptr),
- microTaskQueues(this) {
+ insideExclusiveDebuggerOnEval(this, nullptr) {
MOZ_ASSERT(static_cast<JS::RootingContext*>(this) ==
JS::RootingContext::get(this));
}
@@ -1525,6 +1524,12 @@ void JSContext::trace(JSTracer* trc) {
#ifdef ENABLE_WASM_JSPI
wasm().promiseIntegration.trace(trc);
#endif
+
+ // Skip tracing the microtask queues on minor GC as we will be updating
+ // nursery pointers through the store buffer instead.
+ if (!trc->isTenuringTracer() && microTaskQueues) {
+ microTaskQueues->trace(trc);
+ }
}
JS::NativeStackLimit JSContext::stackLimitForJitCode(JS::StackKind kind) {
diff --git a/js/src/vm/JSContext.h b/js/src/vm/JSContext.h
@@ -158,7 +158,8 @@ enum class ShouldCaptureStack { Maybe, Always };
// MG:XXX: It would be nice to explore the typical depth of the queue
// to see if we can get it all inline in the common case.
// MG:XXX: This appears to be broken for non-zero values of inline!
-using MicroTaskQueue = js::TraceableFifo<JS::Value, 0, TempAllocPolicy>;
+using MicroTaskQueue =
+ js::TraceableFifo<js::HeapPtr<JS::Value>, 0, TempAllocPolicy>;
// A pair of microtask queues; one debug and one 'regular' (non-debug).
struct MicroTaskQueueSet {
@@ -1053,7 +1054,7 @@ struct JS_PUBLIC_API JSContext : public JS::RootingContext,
bool hasExecutionTracer() { return false; }
#endif
- JS::PersistentRooted<js::UniquePtr<js::MicroTaskQueueSet>> microTaskQueues;
+ js::UniquePtr<js::MicroTaskQueueSet> microTaskQueues;
}; /* struct JSContext */
inline JSContext* JSRuntime::mainContextFromOwnThread() {