Bug 1385822 - Don't save new scripts from child process after cache flush. r=erahm, a=jcristau
authorKris Maglione <maglione.k@gmail.com>
Mon, 31 Jul 2017 14:30:51 -0700
changeset 420968 f07ddce64e8c9ed9e12d9d38162a9c774d3da127
parent 420967 ffbcc905a80aedaec00a145b8336a1164c9f404a
child 420969 5f16075f776817a88e6c853f80bd0720198b345e
push id7570
push userryanvm@gmail.com
push dateThu, 03 Aug 2017 18:52:06 +0000
treeherdermozilla-beta@c78102e7a5c2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerserahm, jcristau
bugs1385822
milestone56.0
Bug 1385822 - Don't save new scripts from child process after cache flush. r=erahm, a=jcristau MozReview-Commit-ID: GKInmHvwVMP
js/xpconnect/loader/ScriptPreloader.cpp
--- a/js/xpconnect/loader/ScriptPreloader.cpp
+++ b/js/xpconnect/loader/ScriptPreloader.cpp
@@ -752,16 +752,25 @@ ScriptPreloader::NoteScript(const nsCStr
     script->mProcessTypes += CurrentProcessType();
 }
 
 void
 ScriptPreloader::NoteScript(const nsCString& url, const nsCString& cachePath,
                             ProcessType processType, nsTArray<uint8_t>&& xdrData,
                             TimeStamp loadTime)
 {
+    // After data has been prepared, there's no point in noting further scripts,
+    // since the cache either has already been written, or is about to be
+    // written. Any time prior to the data being prepared, we can safely mutate
+    // mScripts without locking. After that point, the save thread is free to
+    // access it, and we can't alter it without locking.
+    if (mDataPrepared) {
+        return;
+    }
+
     auto script = mScripts.LookupOrAdd(cachePath, *this, url, cachePath, nullptr);
 
     if (!script->HasRange()) {
         MOZ_ASSERT(!script->HasArray());
 
         script->mSize = xdrData.Length();
         script->mXDRData.construct<nsTArray<uint8_t>>(Forward<nsTArray<uint8_t>>(xdrData));