Bug 714050 - Make Ion compile threads optional (r=luke)
authorBill McCloskey <wmccloskey@mozilla.com>
Tue, 16 Oct 2012 11:57:09 -0700
changeset 110731 15791e9e6e5de027033d41af4013493adb9a8660
parent 110730 08302471419d5635e79c4d8b0adba82af11d7998
child 110732 35b7bc10cc4289773f3add34907863861c9ef9b5
push id93
push usernmatsakis@mozilla.com
push dateWed, 31 Oct 2012 21:26:57 +0000
reviewersluke
bugs714050
milestone19.0a1
Bug 714050 - Make Ion compile threads optional (r=luke)
js/src/ion/Ion.cpp
js/src/jsworkers.cpp
js/src/jsworkers.h
--- a/js/src/ion/Ion.cpp
+++ b/js/src/ion/Ion.cpp
@@ -1013,17 +1013,17 @@ IonCompile(JSContext *cx, JSScript *scri
     IonSpewNewFunction(graph, builder->script().unsafeGet());
 
     if (!builder->build()) {
         IonSpew(IonSpew_Abort, "Builder failed to build.");
         return false;
     }
     builder->clearForBackEnd();
 
-    if (js_IonOptions.parallelCompilation) {
+    if (js_IonOptions.parallelCompilation && OffThreadCompilationAvailable(cx)) {
         builder->script()->ion = ION_COMPILING_SCRIPT;
 
         if (!StartOffThreadIonCompile(cx, builder)) {
             IonSpew(IonSpew_Abort, "Unable to start off-thread ion compilation.");
             return false;
         }
 
         // The allocator and associated data will be destroyed after being
--- a/js/src/jsworkers.cpp
+++ b/js/src/jsworkers.cpp
@@ -10,16 +10,23 @@
 # include "ion/IonBuilder.h"
 #endif
 
 using namespace js;
 
 #ifdef JS_PARALLEL_COMPILATION
 
 bool
+js::OffThreadCompilationAvailable(JSContext *cx)
+{
+    WorkerThreadState &state = *cx->runtime->workerThreadState;
+    return state.numThreads > 0;
+}
+
+bool
 js::StartOffThreadIonCompile(JSContext *cx, ion::IonBuilder *builder)
 {
     JSRuntime *rt = cx->runtime;
     if (!rt->workerThreadState) {
         rt->workerThreadState = rt->new_<WorkerThreadState>();
         if (!rt->workerThreadState)
             return false;
         if (!rt->workerThreadState->init(rt)) {
@@ -106,16 +113,21 @@ js::CancelOffThreadIonCompile(JSCompartm
             compilations.popBack();
         }
     }
 }
 
 bool
 WorkerThreadState::init(JSRuntime *rt)
 {
+    if (!rt->useHelperThreads()) {
+        numThreads = 0;
+        return true;
+    }
+
     workerLock = PR_NewLock();
     if (!workerLock)
         return false;
 
     mainWakeup = PR_NewCondVar(workerLock);
     if (!mainWakeup)
         return false;
 
@@ -314,9 +326,15 @@ js::StartOffThreadIonCompile(JSContext *
     return false;
 }
 
 void
 js::CancelOffThreadIonCompile(JSCompartment *compartment, JSScript *script)
 {
 }
 
+bool
+js::OffThreadCompilationAvailable(JSContext *cx)
+{
+    return false;
+}
+
 #endif /* JS_PARALLEL_COMPILATION */
--- a/js/src/jsworkers.h
+++ b/js/src/jsworkers.h
@@ -99,23 +99,29 @@ struct WorkerThread
 #endif /* JS_THREADSAFE && JS_ION */
 
 /* Methods for interacting with worker threads. */
 
 /*
  * Schedule an Ion compilation for a script, given a builder which has been
  * generated and read everything needed from the VM state.
  */
-bool StartOffThreadIonCompile(JSContext *cx, ion::IonBuilder *builder);
+bool
+StartOffThreadIonCompile(JSContext *cx, ion::IonBuilder *builder);
 
 /*
  * Cancel a scheduled or in progress Ion compilation for script. If script is
  * NULL, all compilations for the compartment are cancelled.
  */
-void CancelOffThreadIonCompile(JSCompartment *compartment, JSScript *script);
+void
+CancelOffThreadIonCompile(JSCompartment *compartment, JSScript *script);
+
+/* Return true iff off-thread compilation is possible. */
+bool
+OffThreadCompilationAvailable(JSContext *cx);
 
 class AutoLockWorkerThreadState
 {
     JSRuntime *rt;
     JS_DECL_USE_GUARD_OBJECT_NOTIFIER
 
   public: