Bug 996983 - Part 3: Push JitActivations for each PJS thread during ForkJoin. (r=nmatsakis)
authorShu-yu Guo <shu@rfrn.org>
Wed, 30 Apr 2014 21:12:17 -0700
changeset 181536 ed3ea6cb5afeb1ec05fa2dd9ba41aa1acd4e9fdc
parent 181535 3de709d633552254112ce6b923dfb48b7b40ff99
child 181537 8c3758dd1ba8cabb8df03180f646187b07c60d11
push id272
push userpvanderbeken@mozilla.com
push dateMon, 05 May 2014 16:31:18 +0000
reviewersnmatsakis
bugs996983
milestone32.0a1
Bug 996983 - Part 3: Push JitActivations for each PJS thread during ForkJoin. (r=nmatsakis)
js/src/vm/ForkJoin.cpp
js/src/vm/Stack.cpp
js/src/vm/Stack.h
--- a/js/src/vm/ForkJoin.cpp
+++ b/js/src/vm/ForkJoin.cpp
@@ -1326,20 +1326,21 @@ class ParallelIonInvoke
         // Find JIT code pointer.
         IonScript *ion = callee->nonLazyScript()->parallelIonScript();
         JitCode *code = ion->method();
         jitcode_ = code->raw();
         enter_ = rt->jitRuntime()->enterIon();
         calleeToken_ = CalleeToToken(callee);
     }
 
-    bool invoke(PerThreadData *perThread) {
-        RootedValue result(perThread);
+    bool invoke(ForkJoinContext *cx) {
+        JitActivation activation(cx);
+        Value result;
         CALL_GENERATED_CODE(enter_, jitcode_, argc_ + 1, argv_ + 1, nullptr, calleeToken_,
-                            nullptr, 0, result.address());
+                            nullptr, 0, &result);
         return !result.isMagic();
     }
 };
 
 /////////////////////////////////////////////////////////////////////////////
 // ForkJoinShared
 //
 
@@ -1530,23 +1531,23 @@ ForkJoinShared::executePortion(PerThread
         // Sometimes, particularly with GCZeal, the parallel ion
         // script can be collected between starting the parallel
         // op and reaching this point.  In that case, we just fail
         // and fallback.
         Spew(SpewOps, "Down (Script no longer present)");
         cx.bailoutRecord->setCause(ParallelBailoutMainScriptNotPresent);
         setAbortFlagAndRequestInterrupt(false);
     } else {
-        ParallelIonInvoke<3> fii(cx_->runtime(), fun_, 3);
+        ParallelIonInvoke<3> fii(runtime(), fun_, 3);
 
         fii.args[0] = Int32Value(worker->id());
         fii.args[1] = Int32Value(sliceStart_);
         fii.args[2] = Int32Value(sliceEnd_);
 
-        bool ok = fii.invoke(perThread);
+        bool ok = fii.invoke(&cx);
         JS_ASSERT(ok == !cx.bailoutRecord->topScript);
         if (!ok)
             setAbortFlagAndRequestInterrupt(false);
     }
 
     Spew(SpewOps, "Down");
 }
 
--- a/js/src/vm/Stack.cpp
+++ b/js/src/vm/Stack.cpp
@@ -1533,16 +1533,29 @@ jit::JitActivation::JitActivation(JSCont
         prevJitJSContext_ = cx->mainThread().jitJSContext;
         cx->mainThread().jitJSContext = cx;
     } else {
         prevIonTop_ = nullptr;
         prevJitJSContext_ = nullptr;
     }
 }
 
+jit::JitActivation::JitActivation(ForkJoinContext *cx)
+  : Activation(cx, Jit),
+    firstFrameIsConstructing_(false),
+    active_(true)
+#ifdef JS_ION
+  , rematerializedFrames_(nullptr)
+#endif
+{
+    prevIonTop_ = cx->perThreadData->ionTop;
+    prevJitJSContext_ = cx->perThreadData->jitJSContext;
+    cx->perThreadData->jitJSContext = nullptr;
+}
+
 jit::JitActivation::~JitActivation()
 {
     if (active_) {
         cx_->perThreadData->ionTop = prevIonTop_;
         cx_->perThreadData->jitJSContext = prevJitJSContext_;
     }
 
 #ifdef JS_ION
@@ -1709,20 +1722,20 @@ AsmJSActivation::AsmJSActivation(JSConte
 }
 
 AsmJSActivation::~AsmJSActivation()
 {
     if (profiler_)
         profiler_->exitNative();
 
     JSContext *cx = cx_->asJSContext();
-    JS_ASSERT(cx->runtime()->mainThread.asmJSActivationStack_ == this);
+    JS_ASSERT(cx->mainThread().asmJSActivationStack_ == this);
 
     JSRuntime::AutoLockForInterrupt lock(cx->runtime());
-    cx->runtime()->mainThread.asmJSActivationStack_ = prevAsmJS_;
+    cx->mainThread().asmJSActivationStack_ = prevAsmJS_;
 }
 
 InterpreterFrameIterator &
 InterpreterFrameIterator::operator++()
 {
     JS_ASSERT(!done());
     if (fp_ != activation_->entryFrame_) {
         pc_ = fp_->prevpc();
--- a/js/src/vm/Stack.h
+++ b/js/src/vm/Stack.h
@@ -1351,16 +1351,17 @@ class JitActivation : public Activation
     // Used to verify that live registers don't change between a VM call and
     // the OsiPoint that follows it. Protected to silence Clang warning.
     uint32_t checkRegs_;
     RegisterDump regs_;
 #endif
 
   public:
     JitActivation(JSContext *cx, bool firstFrameIsConstructing, bool active = true);
+    JitActivation(ForkJoinContext *cx);
     ~JitActivation();
 
     bool isActive() const {
         return active_;
     }
     void setActive(JSContext *cx, bool active = true);
 
     uint8_t *prevIonTop() const {