Merge with shu's refactorings
authorNicholas D. Matsakis <nmatsakis@mozilla.com>
Sat, 27 Oct 2012 10:21:25 -0700
changeset 110075 c8ac829d2bb4ec1d08e39095ba39fc7e5d322aa2
parent 110074 1fc6386d421f2baec494392d62bc457e063ab497 (current diff)
parent 110073 3f7002684de2afe87a1d01d695a53736b5284462 (diff)
child 110076 ae4c0c7b18167ce176818039c60eba4f28d60560
push id89
push usernmatsakis@mozilla.com
push dateSat, 27 Oct 2012 17:21:29 +0000
milestone19.0a1
Merge with shu's refactorings
--- a/js/src/builtin/ParallelArray.cpp
+++ b/js/src/builtin/ParallelArray.cpp
@@ -985,64 +985,59 @@ ParallelArrayObject::BaseSequentialMode:
 
         SetLeafValueWithType(cx, buffer, type, i, args.rval());
     }
 
     return ExecutionSucceeded;
 }
 
 template<typename Source, typename Result>
-/* static */ ParallelArrayObject::ExecutionStatus
-ParallelArrayObject::reduceUpToGeneric(
-    JSContext *cx,
-    Source &source,
-    Result &result,
-    HandleObject elementalFun,
-    MutableHandleValue vp,
-    uint32_t limit)
+static bool ReduceUpToGeneric(JSContext *cx, Source &source, Result &result,
+                              HandleObject elementalFun, MutableHandleValue vp,
+                              uint32_t limit)
 {
     // The accumulator: the objet petit a.
     //
     // "A VM's accumulator register is Objet petit a: the unattainable object
     // of desire that sets in motion the symbolic movement of interpretation."
     //     -- PLT Žižek
     RootedValue acc(cx);
 
     if (!source.getElement(cx, 0, &acc))
-        return ExecutionFatal;
+        return false;
 
     result.update(cx, 0, acc);
 
     FastInvokeGuard fig(cx, ObjectValue(*elementalFun), COMPILE_MODE_SEQ);
     InvokeArgsGuard &args = fig.args();
     if (!cx->stack.pushInvokeArgs(cx, 2, &args))
-        return ExecutionFatal;
+        return false;
 
     RootedValue elem(cx);
     for (uint32_t i = 1; i < limit; i++) {
         args.setCallee(ObjectValue(*elementalFun));
         args.setThis(UndefinedValue());
 
         if (!source.getElement(cx, i, &elem))
-            return ExecutionFatal;
+            return false;
 
         // Set the two arguments to the elemental function.
         args[0] = acc;
         args[1] = elem;
 
         if (!fig.invoke(cx))
-            return ExecutionFatal;
+            return false;
 
         // Update the accumulator.
         acc = args.rval();
         result.update(cx, i, args.rval());
     }
 
     vp.set(acc);
-    return ExecutionSucceeded;
+    return true;
 }
 
 class ParallelArrayObjectSource
 {
 private:
     HandleParallelArrayObject source;
     IndexInfo iv;
 
@@ -1102,17 +1097,19 @@ ParallelArrayObject::BaseSequentialMode:
     JS_ASSERT_IF(result, result->buffer()->getDenseArrayInitializedLength() >= 1);
 
     ParallelArrayObjectSource pasource(cx, source);
     if (!pasource.init(cx))
         return ExecutionFatal;
 
     ParallelArrayObjectResult paresult(cx, result);
 
-    return reduceUpToGeneric(cx, pasource, paresult, elementalFun, vp, limit);
+    if (!ReduceUpToGeneric(cx, pasource, paresult, elementalFun, vp, limit))
+        return ExecutionFatal;
+    return ExecutionSucceeded;
 }
 
 ParallelArrayObject::ExecutionStatus
 ParallelArrayObject::BaseSequentialMode::scatterUpTo(JSContext *cx,
                                                      HandleParallelArrayObject source,
                                                      HandleParallelArrayObject result,
                                                      HandleObject targets,
                                                      HandleValue defaultValue,
@@ -1622,17 +1619,19 @@ public:
 };
 
 ParallelArrayObject::ExecutionStatus
 ParallelArrayObject::ReduceOpDefn::post(MutableHandleValue vp)
 {
     // Reduce the results from each thread into a single result:
     AutoValueVectorSource avsource(results);
     DummyResult result;
-    return reduceUpToGeneric(cx, avsource, result, elementalFun, vp, results.length());
+    if (!ReduceUpToGeneric(cx, avsource, result, elementalFun, vp, results.length()))
+        return ExecutionFatal;
+    return ExecutionSucceeded;
 }
 
 ParallelArrayObject::ReduceOp::ReduceOp(ReduceOpDefn &opDefn, size_t threadId,
                                         size_t numThreads)
     : opDefn_(opDefn)
 {}
 
 bool
--- a/js/src/builtin/ParallelArray.h
+++ b/js/src/builtin/ParallelArray.h
@@ -552,43 +552,34 @@ class ParallelArrayObject : public JSObj
                                 MutableHandleValue rval, JSBool strict);
     static JSBool deleteProperty(JSContext *cx, HandleObject obj, HandlePropertyName name,
                                  MutableHandleValue rval, JSBool strict);
     static JSBool deleteElement(JSContext *cx, HandleObject obj, uint32_t index,
                                 MutableHandleValue rval, JSBool strict);
     static JSBool deleteSpecial(JSContext *cx, HandleObject obj, HandleSpecialId sid,
                                 MutableHandleValue rval, JSBool strict);
 
-    /****************************************************************************
-     * In some cases, the parallel execution and the sequential execution share
-     * a bit of common code.  These are the helpers for those cases. */
-
-    template<typename Source, typename Result>
-    static ExecutionStatus reduceUpToGeneric(
-        JSContext *cx, Source &source,Result &result,
-        HandleObject elementalFun, MutableHandleValue vp, uint32_t limit);
-
-    /****************************************************************************
-     * Parallel execution
-     *
-     * The ParallelArrayTaskSet embodies the main logic for running
-     * any parallel operation.  It is parameterized by two types,
-     * OpDefn and Op.  OpDefn corresponds to the state for a
-     * particular operation that is shared between all threads.  The
-     * OpDefn instance is created by the method (e.g.,
-     * ParallelMode::map()) for the operation.  The Op class
-     * corresponds the per-thread state.  It will be instantiated and
-     * initialized once per worker.  The final template parameter,
-     * MaxArgc, indicates how large of an argc vector we should
-     * statically allocate.  The operation does not have to use the
-     * entire thing; the OpDefn returns a value (argc) for the actual
-     * number of arguments (sometimes it varies depending on the
-     * number of dimensions and so forth).  The ParallelArrayTaskSet
-     * will check that argc is less than MaxArgc and abort otherwise.
-     */
+    //////////////////////////////////////////////////////////////////////////
+    // Parallel execution
+    //////////////////////////////////////////////////////////////////////////
+    //
+    // The ParallelArrayTaskSet embodies the main logic for running
+    // any parallel operation.  It is parameterized by two types,
+    // OpDefn and Op.  OpDefn corresponds to the state for a
+    // particular operation that is shared between all threads.  The
+    // OpDefn instance is created by the method (e.g.,
+    // ParallelMode::map()) for the operation.  The Op class
+    // corresponds the per-thread state.  It will be instantiated and
+    // initialized once per worker.  The final template parameter,
+    // MaxArgc, indicates how large of an argc vector we should
+    // statically allocate.  The operation does not have to use the
+    // entire thing; the OpDefn returns a value (argc) for the actual
+    // number of arguments (sometimes it varies depending on the
+    // number of dimensions and so forth).  The ParallelArrayTaskSet
+    // will check that argc is less than MaxArgc and abort otherwise.
 
     template<typename OpDefn, typename Op, uint32_t MaxArgc>
     class ParallelArrayTaskSet : public TaskSet {
     private:
         JSContext *cx_;
         OpDefn &opDefn_;
         HandleObject elementalFun_;
         HandleParallelArrayObject result_;
@@ -612,24 +603,24 @@ class ParallelArrayObject : public JSObj
 
         virtual bool pre(size_t numThreads);
         virtual bool parallel(ThreadContext &taskSetCx);
         virtual bool post(size_t numThreads);
     };
 
     struct ExecuteArgs;
 
-    /* A base class for |OpDefns| that will apply to each member of
-       the result vector.  The associated |Op| type should be
-       |ApplyToEach<OpDefn, PerElemOp>|.  Here |OpDefn| is a subtype
-       of |ApplyToEachOpDefn| and |PerElemOp| defines the code to
-       apply per-element. An example would be |MapOpDefn| and |MapOp|.
-
-       The type supplied |PerElemOp| must |init()| (which is called
-       once) and |initializeArgv()| (which is called per element). */
+    // A base class for |OpDefns| that will apply to each member of the result
+    // vector.  The associated |Op| type should be |ApplyToEach<OpDefn,
+    // PerElemOp>|.  Here |OpDefn| is a subtype of |ApplyToEachOpDefn| and
+    // |PerElemOp| defines the code to apply per-element. An example would be
+    // |MapOpDefn| and |MapOp|.
+    //
+    // The type supplied |PerElemOp| must |init()| (which is called once) and
+    // |initializeArgv()| (which is called per element).
     class ApplyToEachOpDefn {
     public:
         JSContext *cx;
         HandleParallelArrayObject result;
 
         // the type set of the buffer
         types::TypeSet *typeSet;