Bug 1742381 - Finish pending parse tasks in xpcom-shutdown. r=tcampbell

Differential Revision: https://phabricator.services.mozilla.com/D132655
This commit is contained in:
Tooru Fujisawa 2021-12-02 05:07:54 +00:00
parent bdceca20fa
commit a01a1ec7ce

View File

@ -46,6 +46,7 @@
#define DOC_ELEM_INSERTED_TOPIC "document-element-inserted"
#define CONTENT_DOCUMENT_LOADED_TOPIC "content-document-loaded"
#define CACHE_WRITE_TOPIC "browser-idle-startup-tasks-finished"
#define XPCOM_SHUTDOWN_TOPIC "xpcom-shutdown"
#define CACHE_INVALIDATE_TOPIC "startupcache-invalidate"
// The maximum time we'll wait for a child process to finish starting up before
@ -235,22 +236,14 @@ ScriptPreloader::ScriptPreloader(AutoMemMap* cacheData)
obs->AddObserver(this, CACHE_WRITE_TOPIC, false);
}
obs->AddObserver(this, XPCOM_SHUTDOWN_TOPIC, false);
obs->AddObserver(this, CACHE_INVALIDATE_TOPIC, false);
}
ScriptPreloader::~ScriptPreloader() { Cleanup(); }
void ScriptPreloader::Cleanup() {
// Wait for any pending parses to finish before clearing the mScripts
// hashtable, since the parse tasks depend on memory allocated by those
// scripts.
{
MonitorAutoLock mal(mMonitor);
FinishPendingParses(mal);
mScripts.Clear();
}
mScripts.Clear();
UnregisterWeakMemoryReporter(this);
}
@ -340,6 +333,11 @@ nsresult ScriptPreloader::Observe(nsISupports* subject, const char* topic,
FinishContentStartup();
} else if (!strcmp(topic, "timer-callback")) {
FinishContentStartup();
} else if (!strcmp(topic, XPCOM_SHUTDOWN_TOPIC)) {
// Wait for any pending parses to finish at this point, to avoid creating
// new stencils during destroying the JS runtime.
MonitorAutoLock mal(mMonitor);
FinishPendingParses(mal);
} else if (!strcmp(topic, CACHE_INVALIDATE_TOPIC)) {
InvalidateCache();
}