commit 3412fc553500750f8b02794298922a4227f2aa6e
parent 4952555f14c530954273bb9f038b347ec56e5266
Author: Tooru Fujisawa <arai_a@mac.com>
Date: Wed, 8 Oct 2025 04:04:43 +0000
Bug 1991380 - Remove MarkedForCache state from the caching plan. r=nbp
Differential Revision: https://phabricator.services.mozilla.com/D266621
Diffstat:
4 files changed, 13 insertions(+), 89 deletions(-)
diff --git a/dom/script/ScriptLoader.cpp b/dom/script/ScriptLoader.cpp
@@ -3321,18 +3321,9 @@ nsCString& ScriptLoader::BytecodeMimeTypeFor(
return nsContentUtils::JSScriptBytecodeMimeType();
}
-void ScriptLoader::MaybePrepareForCacheBeforeExecute(
- ScriptLoadRequest* aRequest) {
- if (!aRequest->PassedConditionForEitherCache()) {
- return;
- }
-
- aRequest->MarkForCache();
-}
-
nsresult ScriptLoader::MaybePrepareForCacheAfterExecute(
ScriptLoadRequest* aRequest, nsresult aRv) {
- if (aRequest->IsMarkedForEitherCache()) {
+ if (aRequest->PassedConditionForEitherCache()) {
TRACE_FOR_TEST(aRequest, "scriptloader_encode");
// Bytecode-encoding branch is used for 2 purposes right now:
// * If the request is stencil, reflect delazifications to cached stencil
@@ -3359,30 +3350,6 @@ nsresult ScriptLoader::MaybePrepareForCacheAfterExecute(
return aRv;
}
-void ScriptLoader::MaybePrepareModuleForCacheBeforeExecute(
- JSContext* aCx, ModuleLoadRequest* aRequest) {
- if (aRequest->IsMarkedForEitherCache()) {
- // This module is imported multiple times, and already marked.
- return;
- }
-
- if (aRequest->PassedConditionForEitherCache()) {
- aRequest->MarkForCache();
- }
-
- for (auto* r = mCacheableDependencyModules.getFirst(); r; r = r->getNext()) {
- auto* dep = r->AsModuleRequest();
- MOZ_ASSERT(dep->PassedConditionForEitherCache());
-
- if (dep->GetRootModule() != aRequest) {
- continue;
- }
- MOZ_ASSERT(!dep->IsMarkedForEitherCache());
-
- dep->MarkForCache();
- }
-}
-
nsresult ScriptLoader::MaybePrepareModuleForCacheAfterExecute(
ModuleLoadRequest* aRequest, nsresult aRv) {
MOZ_ASSERT(aRequest->IsTopLevel());
@@ -3498,17 +3465,13 @@ nsresult ScriptLoader::EvaluateScript(nsIGlobalObject* aGlobalObject,
classicScriptValue, introductionScript, erv);
if (!erv.Failed()) {
- MaybePrepareForCacheBeforeExecute(aRequest);
+ LOG(("ScriptLoadRequest (%p): Evaluate Script", aRequest));
+ AUTO_PROFILER_MARKER_TEXT("ScriptExecution", JS,
+ MarkerInnerWindowIdFromJSContext(cx),
+ profilerLabelString);
- {
- LOG(("ScriptLoadRequest (%p): Evaluate Script", aRequest));
- AUTO_PROFILER_MARKER_TEXT("ScriptExecution", JS,
- MarkerInnerWindowIdFromJSContext(cx),
- profilerLabelString);
-
- MOZ_ASSERT(options.noScriptRval);
- ExecuteCompiledScript(cx, classicScript, script, erv);
- }
+ MOZ_ASSERT(options.noScriptRval);
+ ExecuteCompiledScript(cx, classicScript, script, erv);
}
rv = EvaluationExceptionToNSResult(erv);
@@ -3540,8 +3503,8 @@ LoadedScript* ScriptLoader::GetActiveScript(JSContext* aCx) {
}
void ScriptLoader::RegisterForCache(ScriptLoadRequest* aRequest) {
- MOZ_ASSERT(aRequest->IsMarkedForEitherCache());
- MOZ_ASSERT_IF(aRequest->IsMarkedForDiskCache(),
+ MOZ_ASSERT(aRequest->PassedConditionForEitherCache());
+ MOZ_ASSERT_IF(aRequest->PassedConditionForDiskCache(),
aRequest->getLoadedScript()->HasDiskCacheReference());
MOZ_DIAGNOSTIC_ASSERT(!aRequest->isInList());
mCachingQueue.AppendElement(aRequest);
@@ -3641,7 +3604,7 @@ void ScriptLoader::UpdateCache() {
// bytecode stored in the necko cache.
//
// TODO: Move this to SharedScriptCache.
- if (request->IsMarkedForDiskCache() &&
+ if (request->PassedConditionForDiskCache() &&
request->getLoadedScript()->HasDiskCacheReference()) {
EncodeBytecodeAndSave(aes.cx(), request->getLoadedScript());
}
diff --git a/dom/script/ScriptLoader.h b/dom/script/ScriptLoader.h
@@ -710,11 +710,6 @@ class ScriptLoader final : public JS::loader::ScriptLoaderInterface {
static nsCString& BytecodeMimeTypeFor(
JS::loader::LoadedScript* aLoadedScript);
- // Decide whether to encode bytecode for given script load request.
- //
- // This method must be called before executing the script.
- void MaybePrepareForCacheBeforeExecute(ScriptLoadRequest* aRequest);
-
// Queue the script load request for caching if we decided to cache it, or
// cleanup the script load request fields otherwise.
//
@@ -722,9 +717,6 @@ class ScriptLoader final : public JS::loader::ScriptLoaderInterface {
nsresult MaybePrepareForCacheAfterExecute(ScriptLoadRequest* aRequest,
nsresult aRv);
- void MaybePrepareModuleForCacheBeforeExecute(
- JSContext* aCx, ModuleLoadRequest* aRequest) override;
-
// Queue the top-level module load request for caching if we decided to cache
// it, or cleanup the module load request fields otherwise.
//
diff --git a/js/loader/ModuleLoaderBase.cpp b/js/loader/ModuleLoaderBase.cpp
@@ -1622,9 +1622,6 @@ nsresult ModuleLoaderBase::EvaluateModuleInContext(
Rooted<Value> rval(aCx);
- // TODO: Bug 1973321: Prepare Bytecode encoding for dynamic import
- mLoader->MaybePrepareModuleForCacheBeforeExecute(aCx, aRequest);
-
bool ok = ModuleEvaluate(aCx, module, &rval);
// ModuleEvaluate will usually set a pending exception if it returns false,
@@ -1652,6 +1649,7 @@ nsresult ModuleLoaderBase::EvaluateModuleInContext(
LOG(("ScriptLoadRequest (%p): evaluation failed on throw", aRequest));
}
+ // TODO: Bug 1973321: Prepare Bytecode encoding for dynamic import
rv = mLoader->MaybePrepareModuleForCacheAfterExecute(aRequest, NS_OK);
mLoader->MaybeUpdateCache();
diff --git a/js/loader/ScriptLoadRequest.h b/js/loader/ScriptLoadRequest.h
@@ -187,13 +187,11 @@ class ScriptLoadRequest : public nsISupports,
void SetPendingFetchingError();
bool PassedConditionForDiskCache() const {
- return mDiskCachingPlan == CachingPlan::PassedCondition ||
- mDiskCachingPlan == CachingPlan::MarkedForCache;
+ return mDiskCachingPlan == CachingPlan::PassedCondition;
}
bool PassedConditionForMemoryCache() const {
- return mMemoryCachingPlan == CachingPlan::PassedCondition ||
- mMemoryCachingPlan == CachingPlan::MarkedForCache;
+ return mMemoryCachingPlan == CachingPlan::PassedCondition;
}
bool PassedConditionForEitherCache() const {
@@ -227,30 +225,6 @@ class ScriptLoadRequest : public nsISupports,
mMemoryCachingPlan = CachingPlan::PassedCondition;
}
- bool IsMarkedForDiskCache() const {
- return mDiskCachingPlan == CachingPlan::MarkedForCache;
- }
-
- bool IsMarkedForMemoryCache() const {
- return mMemoryCachingPlan == CachingPlan::MarkedForCache;
- }
-
- bool IsMarkedForEitherCache() const {
- return IsMarkedForDiskCache() || IsMarkedForMemoryCache();
- }
-
- void MarkForCache() {
- MOZ_ASSERT(mDiskCachingPlan == CachingPlan::PassedCondition ||
- mMemoryCachingPlan == CachingPlan::PassedCondition);
-
- if (mDiskCachingPlan == CachingPlan::PassedCondition) {
- mDiskCachingPlan = CachingPlan::MarkedForCache;
- }
- if (mMemoryCachingPlan == CachingPlan::PassedCondition) {
- mMemoryCachingPlan = CachingPlan::MarkedForCache;
- }
- }
-
public:
mozilla::CORSMode CORSMode() const { return mFetchOptions->mCORSMode; }
@@ -298,9 +272,6 @@ class ScriptLoadRequest : public nsISupports,
// This fits the condition for the caching (e.g. file size, fetch count).
PassedCondition,
-
- // This is marked for encoding.
- MarkedForCache,
};
CachingPlan mDiskCachingPlan = CachingPlan::Uninitialized;
CachingPlan mMemoryCachingPlan = CachingPlan::Uninitialized;