commit 1ef85f97ca493b55ba1ed4dd73906dcde05c0ee9
parent cf0ac52917eb90c4e1f3b725b5df54a05167edb5
Author: Tooru Fujisawa <arai_a@mac.com>
Date: Wed, 29 Oct 2025 14:30:55 +0000
Bug 1995994 - Do not check already-collecting-delazifications condition and let the disk cache logic to filter out properly. r=nbp
Given that the in-memory cache doesn't need any followup task, and also
the disk cache should reflect the latest fetch's condition for the fetch count
etc, we don't have to check the already-collecting-delazifications condition
on instantiation.
For example, if the previous fetch doesn't meet the minimum fetch count but
the current meet, the disk cache should be performed with the current fetch's
input.
Differential Revision: https://phabricator.services.mozilla.com/D270108
Diffstat:
1 file changed, 17 insertions(+), 33 deletions(-)
diff --git a/dom/script/ScriptLoader.cpp b/dom/script/ScriptLoader.cpp
@@ -3053,8 +3053,8 @@ static void InstantiateStencil(
JS::Handle<JS::Value> aDebuggerPrivateValue,
JS::Handle<JSScript*> aDebuggerIntroductionScript, ErrorResult& aRv,
JS::InstantiationStorage* aStorage = nullptr,
- CollectDelazifications aCollectDelazifications = CollectDelazifications::No,
- IsAlreadyCollecting* aIsAlreadyCollecting = nullptr) {
+ CollectDelazifications aCollectDelazifications =
+ CollectDelazifications::No) {
JS::InstantiateOptions instantiateOptions(aCompileOptions);
JS::Rooted<JSScript*> script(
aCx, JS::InstantiateGlobalStencil(aCx, instantiateOptions, aStencil,
@@ -3065,20 +3065,11 @@ static void InstantiateStencil(
}
if (aCollectDelazifications == CollectDelazifications::Yes) {
- bool alreadyStarted;
- if (!JS::StartCollectingDelazifications(aCx, script, aStencil,
- alreadyStarted)) {
+ bool ignored;
+ if (!JS::StartCollectingDelazifications(aCx, script, aStencil, ignored)) {
aRv.NoteJSContextException(aCx);
return;
}
- if (aIsAlreadyCollecting) {
- *aIsAlreadyCollecting =
- alreadyStarted ? IsAlreadyCollecting::Yes : IsAlreadyCollecting::No;
- } else {
- // The consumer can omit the aIsAlreadyCollecting parameter only when
- // the stencil is exclusively owned.
- MOZ_ASSERT(!alreadyStarted);
- }
}
aScript.set(script);
@@ -3220,26 +3211,18 @@ void ScriptLoader::InstantiateClassicScriptFromCachedStencil(
MOZ_ASSERT(aRequest->PassedConditionForMemoryCache());
- IsAlreadyCollecting isAlreadyCollecting = IsAlreadyCollecting::No;
+ // For cached stencils, there can be already ongoing work for the in-memory
+ // cache and the disk cache.
+ //
+ // For collecting delazifications, it's detected by
+ // JS::StartCollectingDelazifications API and it's not a problem.
+ //
+ // For disk cache, ScriptLoader::UpdateDiskCache checks the
+ // HasDiskCacheReference condition, and that filters out any loaded scripts
+ // queued multiple times.
InstantiateStencil(aCx, aCompileOptions, aStencil, aScript,
aDebuggerPrivateValue, aDebuggerIntroductionScript, aRv,
- /* aStorage = */ nullptr, CollectDelazifications::Yes,
- &isAlreadyCollecting);
- if (isAlreadyCollecting == IsAlreadyCollecting::Yes) {
- LOG(("ScriptLoadRequest (%p): Bytecode-cache: Skip: IsAlreadyCollecting",
- aRequest));
-
- // NOTE: non-top-level modules are added to mDiskCacheableDependencyModules
- // at the same time as MarkPassedConditionForDiskCache.
- // Undo it here.
- if (aRequest->IsModuleRequest() &&
- !aRequest->AsModuleRequest()->IsTopLevel()) {
- MOZ_ASSERT(aRequest->isInList());
- mDiskCacheableDependencyModules.Remove(aRequest);
- }
-
- aRequest->MarkSkippedMemoryCaching();
- }
+ /* aStorage = */ nullptr, CollectDelazifications::Yes);
}
void ScriptLoader::InstantiateClassicScriptFromAny(
@@ -3405,7 +3388,7 @@ nsresult ScriptLoader::MaybePrepareModuleForDiskCacheAfterExecute(
// NOTE: If a module is passed to this multiple times, it can be
// enqueued multiple times.
- // This is okay because ScriptLoader::UpdateCache filters out
+ // This is okay because ScriptLoader::UpdateDiskCache filters out
// any script without the disk cache reference.
aRv = MaybePrepareForDiskCacheAfterExecute(aRequest, aRv);
@@ -3617,7 +3600,8 @@ void ScriptLoader::UpdateDiskCache() {
// bytecode stored in the necko cache.
//
// For in-memory cached case, the save might already be performed
- // by other request.
+ // by other requests.
+ // See also ScriptLoader::MaybePrepareModuleForDiskCacheAfterExecute.
//
// TODO: Move this to SharedScriptCache.
if (!loadedScript->HasDiskCacheReference()) {