Bug 1678774 - Track more top level load requests while they are being parsed off-thread r=dpalmeiro

The original patch had caused some assertions so I rewrote it. This now puts
all untracked top-level requests on the new list while they are being compiled
so handles preload requests too.

Differential Revision: https://phabricator.services.mozilla.com/D119386
This commit is contained in:
Jon Coppeard
2021-07-12 16:31:00 +00:00
parent 4c9bc4cf55
commit c61f167a5e
4 changed files with 34 additions and 1 deletions

View File

@@ -211,7 +211,8 @@ NS_INTERFACE_MAP_END
NS_IMPL_CYCLE_COLLECTION(ScriptLoader, mNonAsyncExternalScriptInsertedRequests,
mLoadingAsyncRequests, mLoadedAsyncRequests,
mDeferRequests, mXSLTRequests, mDynamicImportRequests,
mOffThreadCompilingRequests, mDeferRequests,
mXSLTRequests, mDynamicImportRequests,
mParserBlockingRequest, mBytecodeEncodingQueue,
mPreloads, mPendingChildLoaders, mFetchedModules,
mFetchingModules)
@@ -2349,6 +2350,8 @@ void ScriptLoader::CancelScriptLoadRequests() {
for (size_t i = 0; i < mPreloads.Length(); i++) {
mPreloads[i].mRequest->Cancel();
}
mOffThreadCompilingRequests.CancelRequestsAndClear();
}
nsresult ScriptLoader::ProcessOffThreadRequest(ScriptLoadRequest* aRequest) {
@@ -2361,6 +2364,11 @@ nsresult ScriptLoader::ProcessOffThreadRequest(ScriptLoadRequest* aRequest) {
aRequest->mWasCompiledOMT = true;
if (aRequest->mInCompilingList) {
mOffThreadCompilingRequests.Remove(aRequest);
aRequest->mInCompilingList = false;
}
if (aRequest->IsModuleRequest()) {
MOZ_ASSERT(aRequest->mOffThreadToken);
ModuleLoadRequest* request = aRequest->AsModuleRequest();
@@ -2639,6 +2647,17 @@ nsresult ScriptLoader::AttemptAsyncScriptCompile(ScriptLoadRequest* aRequest,
// to call ScriptLoader::ProcessOffThreadRequest with the same request.
aRequest->mProgress = ScriptLoadRequest::Progress::eCompiling;
// Requests that are not tracked elsewhere are added to a list while they are
// being compiled off-thread, so we can cancel the compilation later if
// necessary.
//
// Non-top-level modules not tracked because these are cancelled from their
// importing module.
if (aRequest->IsTopLevel() && !aRequest->isInList()) {
mOffThreadCompilingRequests.AppendElement(aRequest);
aRequest->mInCompilingList = true;
}
*aCouldCompileOut = true;
Unused << runnable.forget();
return NS_OK;
@@ -3605,6 +3624,7 @@ bool ScriptLoader::HasPendingRequests() {
!mNonAsyncExternalScriptInsertedRequests.isEmpty() ||
!mDeferRequests.isEmpty() || !mDynamicImportRequests.isEmpty() ||
!mPendingChildLoaders.IsEmpty();
// mOffThreadCompilingRequests are already being processed.
}
void ScriptLoader::ProcessPendingRequestsAsync() {
@@ -4406,6 +4426,11 @@ void ScriptLoader::AddDeferRequest(ScriptLoadRequest* aRequest) {
MOZ_ASSERT(aRequest->IsDeferredScript());
MOZ_ASSERT(!aRequest->mInDeferList && !aRequest->mInAsyncList);
if (aRequest->mInCompilingList) {
mOffThreadCompilingRequests.Remove(aRequest);
aRequest->mInCompilingList = false;
}
aRequest->mInDeferList = true;
mDeferRequests.AppendElement(aRequest);
if (mDeferEnabled && aRequest == mDeferRequests.getFirst() && mDocument &&
@@ -4420,6 +4445,11 @@ void ScriptLoader::AddAsyncRequest(ScriptLoadRequest* aRequest) {
MOZ_ASSERT(aRequest->IsAsyncScript());
MOZ_ASSERT(!aRequest->mInDeferList && !aRequest->mInAsyncList);
if (aRequest->mInCompilingList) {
mOffThreadCompilingRequests.Remove(aRequest);
aRequest->mInCompilingList = false;
}
aRequest->mInAsyncList = true;
if (aRequest->IsReadyToRun()) {
mLoadedAsyncRequests.AppendElement(aRequest);