From b8915fed414c1701fe79951b687c1bed5c43c6e2 Mon Sep 17 00:00:00 2001 From: Tooru Fujisawa Date: Tue, 19 Sep 2023 11:12:53 +0000 Subject: [PATCH] Bug 1853480 - Part 2: Use TaskController thread stack size as JS stack quota in nsXULPrototypeScript off-thread compilation. r=nbp Depends on D188556 Differential Revision: https://phabricator.services.mozilla.com/D188557 --- dom/xul/nsXULElement.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/dom/xul/nsXULElement.cpp b/dom/xul/nsXULElement.cpp index 1a832cea8a902..9347c7f99093a 100644 --- a/dom/xul/nsXULElement.cpp +++ b/dom/xul/nsXULElement.cpp @@ -1856,10 +1856,17 @@ class ScriptCompileTask final : public Task { } private: + static size_t ThreadStackQuotaForSize(size_t size) { + // Set the stack quota to 10% less that the actual size. + // NOTE: This follows what JS helper thread does. + return size_t(double(size) * 0.9); + } + void Compile() { // NOTE: The stack limit must be set from the same thread that compiles. - const size_t kDefaultStackQuota = 128 * sizeof(size_t) * 1024; - JS::SetNativeStackQuota(mFrontendContext, kDefaultStackQuota); + size_t stackSize = TaskController::GetThreadStackSize(); + JS::SetNativeStackQuota(mFrontendContext, + ThreadStackQuotaForSize(stackSize)); JS::SourceText srcBuf; if (NS_WARN_IF(!srcBuf.init(mFrontendContext, mText.get(), mTextLength,