Back out changeset d9a4c7d198f0 (bug 1084009) for b2g emulator chrome and debug mochitest bustage
authorPhil Ringnalda <philringnalda@gmail.com>
Thu, 10 Sep 2015 15:17:23 -0700
changeset 296186 68ca35b8034bb4cb2d2aab24790fb961800c28e1
parent 296185 9bbb4ad6efc50ae35765a73c355bd7b34a3b6f61
child 296187 0a18e5db95a4505d26260e6690a3e6241f0e16de
push id962
push userjlund@mozilla.com
push dateFri, 04 Dec 2015 23:28:54 +0000
treeherdermozilla-release@23a2d286e80f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1084009
milestone43.0a1
backs outd9a4c7d198f08432ddc5b41d64879c15f2cb2391
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Back out changeset d9a4c7d198f0 (bug 1084009) for b2g emulator chrome and debug mochitest bustage CLOSED TREE
dom/base/nsScriptLoader.cpp
dom/base/nsScriptLoader.h
js/src/jsapi.cpp
--- a/dom/base/nsScriptLoader.cpp
+++ b/dom/base/nsScriptLoader.cpp
@@ -660,17 +660,17 @@ nsScriptLoader::ProcessScriptElement(nsI
     if (aElement->GetScriptAsync()) {
       request->mIsAsync = true;
       if (request->IsDoneLoading()) {
         mLoadedAsyncRequests.AppendElement(request);
         // The script is available already. Run it ASAP when the event
         // loop gets a chance to spin.
 
         // KVKV TODO: Instead of processing immediately, try off-thread-parsing
-        // it and only schedule a pending ProcessRequest if that fails.
+        // it and only schedule a ProcessRequest if that fails.
         ProcessPendingRequestsAsync();
       } else {
         mLoadingAsyncRequests.AppendElement(request);
       }
       return false;
     }
     if (!aElement->GetParserCreated()) {
       // Violate the HTML5 spec in order to make LABjs and the "order" plug-in
@@ -709,64 +709,36 @@ nsScriptLoader::ProcessScriptElement(nsI
       mXSLTRequests.AppendElement(request);
       if (request->IsDoneLoading()) {
         // The script is available already. Run it ASAP when the event
         // loop gets a chance to spin.
         ProcessPendingRequestsAsync();
       }
       return true;
     }
-
-    if (request->IsDoneLoading()) {
+    if (request->IsDoneLoading() && ReadyToExecuteScripts()) {
+      // The request has already been loaded and there are no pending style
+      // sheets. If the script comes from the network stream, cheat for
+      // performance reasons and avoid a trip through the event loop.
       if (aElement->GetParserCreated() == FROM_PARSER_NETWORK) {
-        // The request has already been loaded.  Attempt to immediately
-        // start an off-thread compile for it.
-        nsresult rv = AttemptAsyncScriptCompile(request);
-        if (rv == NS_OK) {
-          // Off-thread compile started.  Set the script as blocking the parser
-          // and continue.  Script will be executed when ready.
-          NS_ASSERTION(!mParserBlockingRequest,
-              "There can be only one parser-blocking script at a time");
-          NS_ASSERTION(mXSLTRequests.isEmpty(),
-              "Parser-blocking scripts and XSLT scripts in the same doc!");
-          mParserBlockingRequest = request;
-          return true;
-        }
-
-        // If off-thread compile errored, return immediately, without blocking parser.
-        // Script is discarded.
-        if (rv != NS_ERROR_FAILURE) {
-          return false;
-        }
-      }
-
-      // If we get here, it means the request is fully loaded, and is either
-      // from a document.write, or a network-loaded script tag that for which
-      // off-thread compile was rejected.
-
-      // If the script comes from the network stream, and document is ready
-      // to execute scripts, cheat for performance reasons and avoid a trip
-      // through the event loop.
-      if (aElement->GetParserCreated() == FROM_PARSER_NETWORK &&
-          ReadyToExecuteScripts()) {
         return ProcessRequest(request) == NS_ERROR_HTMLPARSER_BLOCK;
       }
-
-      // Document is not ready to execute scripts (style sheet blocking
-      // execution), or script was introduced by a document.write.
+      // Otherwise, we've got a document.written script, make a trip through
+      // the event loop to hide the preload effects from the scripts on the
+      // Web page.
       NS_ASSERTION(!mParserBlockingRequest,
           "There can be only one parser-blocking script at a time");
       NS_ASSERTION(mXSLTRequests.isEmpty(),
           "Parser-blocking scripts and XSLT scripts in the same doc!");
       mParserBlockingRequest = request;
       ProcessPendingRequestsAsync();
       return true;
     }
-
-    // The script hasn't loaded yet, it will be run when it loads.
+    // The script hasn't loaded yet or there's a style sheet blocking it.
+    // The script will be run when it loads or the style sheet loads.
     NS_ASSERTION(!mParserBlockingRequest,
         "There can be only one parser-blocking script at a time");
     NS_ASSERTION(mXSLTRequests.isEmpty(),
         "Parser-blocking scripts and XSLT scripts in the same doc!");
     mParserBlockingRequest = request;
     return true;
   }
 
@@ -853,33 +825,16 @@ public:
 
 } /* anonymous namespace */
 
 nsresult
 nsScriptLoader::ProcessOffThreadRequest(nsScriptLoadRequest* aRequest)
 {
   MOZ_ASSERT(aRequest->mProgress == nsScriptLoadRequest::Progress_Compiling);
   aRequest->mProgress = nsScriptLoadRequest::Progress_DoneCompiling;
-  if (aRequest == mParserBlockingRequest) {
-    if (!ReadyToExecuteScripts()) {
-      // If not ready to execute scripts, schedule an async call to
-      // ProcessPendingRequests to handle it.
-      ProcessPendingRequestsAsync();
-      return NS_OK;
-    }
-
-    // Same logic as in top of ProcessPendingRequests.
-    mParserBlockingRequest = nullptr;
-    UnblockParser(aRequest);
-    ProcessRequest(aRequest);
-    mDocument->UnblockOnload(false);
-    ContinueParserAsync(aRequest);
-    return NS_OK;
-  }
-
   nsresult rv = ProcessRequest(aRequest);
   mDocument->UnblockOnload(false);
   return rv;
 }
 
 NotifyOffThreadScriptLoadCompletedRunnable::~NotifyOffThreadScriptLoadCompletedRunnable()
 {
   if (MOZ_UNLIKELY(mRequest || mLoader) && !NS_IsMainThread()) {
@@ -918,20 +873,19 @@ OffThreadScriptLoaderCallback(void *aTok
 {
   nsRefPtr<NotifyOffThreadScriptLoadCompletedRunnable> aRunnable =
     dont_AddRef(static_cast<NotifyOffThreadScriptLoadCompletedRunnable*>(aCallbackData));
   aRunnable->SetToken(aToken);
   NS_DispatchToMainThread(aRunnable);
 }
 
 nsresult
-nsScriptLoader::AttemptAsyncScriptCompile(nsScriptLoadRequest* aRequest)
+nsScriptLoader::AttemptAsyncScriptParse(nsScriptLoadRequest* aRequest)
 {
-  // Don't off-thread compile inline scripts.
-  if (aRequest->mIsInline) {
+  if (!aRequest->mElement->GetScriptAsync() || aRequest->mIsInline) {
     return NS_ERROR_FAILURE;
   }
 
   nsCOMPtr<nsIScriptGlobalObject> globalObject = GetScriptGlobalObject();
   if (!globalObject) {
     return NS_ERROR_FAILURE;
   }
 
@@ -962,31 +916,27 @@ nsScriptLoader::AttemptAsyncScriptCompil
   mDocument->BlockOnload();
   aRequest->mProgress = nsScriptLoadRequest::Progress_Compiling;
 
   unused << runnable.forget();
   return NS_OK;
 }
 
 nsresult
-nsScriptLoader::CompileOffThreadOrProcessRequest(nsScriptLoadRequest* aRequest,
-                                                 bool* oCompiledOffThread)
+nsScriptLoader::CompileOffThreadOrProcessRequest(nsScriptLoadRequest* aRequest)
 {
   NS_ASSERTION(nsContentUtils::IsSafeToRunScript(),
                "Processing requests when running scripts is unsafe.");
   NS_ASSERTION(!aRequest->mOffThreadToken,
                "Candidate for off-thread compile is already parsed off-thread");
   NS_ASSERTION(!aRequest->InCompilingStage(),
                "Candidate for off-thread compile is already in compiling stage.");
 
-  nsresult rv = AttemptAsyncScriptCompile(aRequest);
+  nsresult rv = AttemptAsyncScriptParse(aRequest);
   if (rv != NS_ERROR_FAILURE) {
-    if (oCompiledOffThread && rv == NS_OK) {
-      *oCompiledOffThread = true;
-    }
     return rv;
   }
 
   return ProcessRequest(aRequest);
 }
 
 nsresult
 nsScriptLoader::ProcessRequest(nsScriptLoadRequest* aRequest)
@@ -1267,22 +1217,18 @@ void
 nsScriptLoader::ProcessPendingRequests()
 {
   nsRefPtr<nsScriptLoadRequest> request;
 
   if (mParserBlockingRequest &&
       mParserBlockingRequest->IsReadyToRun() &&
       ReadyToExecuteScripts()) {
     request.swap(mParserBlockingRequest);
-    bool offThreadCompiled = request->mProgress == nsScriptLoadRequest::Progress_DoneCompiling;
     UnblockParser(request);
     ProcessRequest(request);
-    if (offThreadCompiled) {
-      mDocument->UnblockOnload(false);
-    }
     ContinueParserAsync(request);
   }
 
   while (ReadyToExecuteScripts() && 
          !mXSLTRequests.isEmpty() &&
          mXSLTRequests.getFirst()->IsReadyToRun()) {
     request = mXSLTRequests.StealFirst();
     ProcessRequest(request);
@@ -1676,33 +1622,16 @@ nsScriptLoader::PrepareLoadedRequest(nsS
                mXSLTRequests.Contains(aRequest)  ||
                mPreloads.Contains(aRequest, PreloadRequestComparator()) ||
                mParserBlockingRequest,
                "aRequest should be pending!");
 
   // Mark this as loaded
   aRequest->mProgress = nsScriptLoadRequest::Progress_DoneLoading;
 
-  // If this is currently blocking the parser, attempt to compile it off-main-thread.
-  if (aRequest == mParserBlockingRequest) {
-    nsresult rv = AttemptAsyncScriptCompile(aRequest);
-    if (rv == NS_OK) {
-      NS_ASSERTION(aRequest->mProgress == nsScriptLoadRequest::Progress_Compiling,
-          "Request should be off-thread compiling now.");
-      return NS_OK;
-    }
-
-    // If off-thread compile errored, return the error.
-    if (rv != NS_ERROR_FAILURE) {
-      return rv;
-    }
-
-    // If off-thread compile was rejected, continue with regular processing.
-  }
-
   // And if it's async, move it to the loaded list.  aRequest->mIsAsync really
   // _should_ be in a list, but the consequences if it's not are bad enough we
   // want to avoid trying to move it if it's not.
   if (aRequest->mIsAsync) {
     MOZ_ASSERT(aRequest->isInList());
     if (aRequest->isInList()) {
       nsRefPtr<nsScriptLoadRequest> req = mLoadingAsyncRequests.Steal(aRequest);
       mLoadedAsyncRequests.AppendElement(req);
--- a/dom/base/nsScriptLoader.h
+++ b/dom/base/nsScriptLoader.h
@@ -463,20 +463,19 @@ private:
   /**
    * Return whether just this loader is ready to execute scripts.
    */
   bool SelfReadyToExecuteScripts()
   {
     return mEnabled && !mBlockerCount;
   }
 
-  nsresult AttemptAsyncScriptCompile(nsScriptLoadRequest* aRequest);
+  nsresult AttemptAsyncScriptParse(nsScriptLoadRequest* aRequest);
   nsresult ProcessRequest(nsScriptLoadRequest* aRequest);
-  nsresult CompileOffThreadOrProcessRequest(nsScriptLoadRequest* aRequest,
-                                            bool* oCompiledOffThread=nullptr);
+  nsresult CompileOffThreadOrProcessRequest(nsScriptLoadRequest* aRequest);
   void FireScriptAvailable(nsresult aResult,
                            nsScriptLoadRequest* aRequest);
   void FireScriptEvaluated(nsresult aResult,
                            nsScriptLoadRequest* aRequest);
   nsresult EvaluateScript(nsScriptLoadRequest* aRequest,
                           JS::SourceBufferHolder& aSrcBuf);
 
   already_AddRefed<nsIScriptGlobalObject> GetScriptGlobalObject();
--- a/js/src/jsapi.cpp
+++ b/js/src/jsapi.cpp
@@ -4070,17 +4070,17 @@ JS::CompileForNonSyntacticScope(JSContex
                                 const char* filename, JS::MutableHandleScript script)
 {
     return ::Compile(cx, options, HasNonSyntacticScope, filename, script);
 }
 
 JS_PUBLIC_API(bool)
 JS::CanCompileOffThread(JSContext* cx, const ReadOnlyCompileOptions& options, size_t length)
 {
-    static const size_t TINY_LENGTH = 5 * 1000;
+    static const size_t TINY_LENGTH = 1000;
     static const size_t HUGE_LENGTH = 100 * 1000;
 
     // These are heuristics which the caller may choose to ignore (e.g., for
     // testing purposes).
     if (!options.forceAsync) {
         // Compiling off the main thread inolves creating a new Zone and other
         // significant overheads.  Don't bother if the script is tiny.
         if (length < TINY_LENGTH)