Bug 897956 - Tidy use of fromMarkedLocation() in interpreter r=luke
authorJon Coppeard <jcoppeard@mozilla.com>
Fri, 26 Jul 2013 10:00:39 +0100
changeset 152424 7a73c9157311ef9ca8023d8db59692825c66f368
parent 152423 ae8d72538dee1b99fa67fcebca8ecd8deadda517
child 152425 e978bb426e87a0cdca79f827904c954ffdc47439
push id2859
push userakeybl@mozilla.com
push dateMon, 16 Sep 2013 19:14:59 +0000
treeherdermozilla-beta@87d3c51cd2bf [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersluke
bugs897956
milestone25.0a1
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
Bug 897956 - Tidy use of fromMarkedLocation() in interpreter r=luke
js/src/vm/Interpreter.cpp
js/src/vm/Stack.h
--- a/js/src/vm/Interpreter.cpp
+++ b/js/src/vm/Interpreter.cpp
@@ -961,17 +961,17 @@ TryNoteIter::settle()
 #define PUSH_OBJECT(obj)         do { regs.sp++->setObject(obj); assertSameCompartmentDebugOnly(cx, regs.sp[-1]); } while (0)
 #define PUSH_OBJECT_OR_NULL(obj) do { regs.sp++->setObjectOrNull(obj); assertSameCompartmentDebugOnly(cx, regs.sp[-1]); } while (0)
 #define PUSH_HOLE()              regs.sp++->setMagic(JS_ELEMENTS_HOLE)
 #define POP_COPY_TO(v)           v = *--regs.sp
 #define POP_RETURN_VALUE()       regs.fp()->setReturnValue(*--regs.sp)
 
 #define FETCH_OBJECT(cx, n, obj)                                              \
     JS_BEGIN_MACRO                                                            \
-        HandleValue val = HandleValue::fromMarkedLocation(&regs.sp[n]);       \
+        HandleValue val = regs.stackHandleAt(n);                              \
         obj = ToObjectFromStack(cx, (val));                                   \
         if (!obj)                                                             \
             goto error;                                                       \
     JS_END_MACRO
 
 template<typename T>
 class GenericInterruptEnabler : public InterpreterFrames::InterruptEnablerBase {
   public:
@@ -1792,17 +1792,17 @@ BEGIN_CASE(JSOP_AND)
         len = GET_JUMP_OFFSET(regs.pc);
         goto advanceAndDoOp;
     }
 }
 END_CASE(JSOP_AND)
 
 #define FETCH_ELEMENT_ID(n, id)                                               \
     JS_BEGIN_MACRO                                                            \
-        if (!ValueToId<CanGC>(cx, HandleValue::fromMarkedLocation(&regs.sp[n]), &id))\
+        if (!ValueToId<CanGC>(cx, regs.stackHandleAt(n), &id))                \
             goto error;                                                       \
     JS_END_MACRO
 
 #define TRY_BRANCH_AFTER_COND(cond,spdec)                                     \
     JS_BEGIN_MACRO                                                            \
         JS_ASSERT(js_CodeSpec[op].length == 1);                               \
         unsigned diff_ = (unsigned) GET_UINT8(regs.pc) - (unsigned) JSOP_IFEQ;         \
         if (diff_ <= 1) {                                                     \
@@ -1814,17 +1814,17 @@ END_CASE(JSOP_AND)
             }                                                                 \
             len = 1 + JSOP_IFEQ_LENGTH;                                       \
             goto advanceAndDoOp;                                              \
         }                                                                     \
     JS_END_MACRO
 
 BEGIN_CASE(JSOP_IN)
 {
-    HandleValue rref = HandleValue::fromMarkedLocation(&regs.sp[-1]);
+    HandleValue rref = regs.stackHandleAt(-1);
     if (!rref.isObject()) {
         js_ReportValueError(cx, JSMSG_IN_NOT_OBJECT, -1, rref, NullPtr());
         goto error;
     }
     RootedObject &obj = rootObject0;
     obj = &rref.toObject();
     RootedId &id = rootId0;
     FETCH_ELEMENT_ID(-2, id);
@@ -1839,41 +1839,41 @@ BEGIN_CASE(JSOP_IN)
     regs.sp[-1].setBoolean(cond);
 }
 END_CASE(JSOP_IN)
 
 BEGIN_CASE(JSOP_ITER)
 {
     JS_ASSERT(regs.stackDepth() >= 1);
     uint8_t flags = GET_UINT8(regs.pc);
-    MutableHandleValue res = MutableHandleValue::fromMarkedLocation(&regs.sp[-1]);
+    MutableHandleValue res = regs.stackHandleAt(-1);
     if (!ValueToIterator(cx, flags, res))
         goto error;
     JS_ASSERT(!res.isPrimitive());
 }
 END_CASE(JSOP_ITER)
 
 BEGIN_CASE(JSOP_MOREITER)
 {
     JS_ASSERT(regs.stackDepth() >= 1);
     JS_ASSERT(regs.sp[-1].isObject());
     PUSH_NULL();
     bool cond;
-    MutableHandleValue res = MutableHandleValue::fromMarkedLocation(&regs.sp[-1]);
+    MutableHandleValue res = regs.stackHandleAt(-1);
     if (!IteratorMore(cx, &regs.sp[-2].toObject(), &cond, res))
         goto error;
     regs.sp[-1].setBoolean(cond);
 }
 END_CASE(JSOP_MOREITER)
 
 BEGIN_CASE(JSOP_ITERNEXT)
 {
     JS_ASSERT(regs.sp[-1].isObject());
     PUSH_NULL();
-    MutableHandleValue res = MutableHandleValue::fromMarkedLocation(&regs.sp[-1]);
+    MutableHandleValue res = regs.stackHandleAt(-1);
     RootedObject &obj = rootObject0;
     obj = &regs.sp[-2].toObject();
     if (!IteratorNext(cx, obj, res))
         goto error;
 }
 END_CASE(JSOP_ITERNEXT)
 
 BEGIN_CASE(JSOP_ENDITER)
@@ -2061,57 +2061,57 @@ BEGIN_CASE(JSOP_CASE)
 }
 END_CASE(JSOP_CASE)
 
 #undef STRICT_EQUALITY_OP
 
 BEGIN_CASE(JSOP_LT)
 {
     bool cond;
-    MutableHandleValue lval = MutableHandleValue::fromMarkedLocation(&regs.sp[-2]);
-    MutableHandleValue rval = MutableHandleValue::fromMarkedLocation(&regs.sp[-1]);
+    MutableHandleValue lval = regs.stackHandleAt(-2);
+    MutableHandleValue rval = regs.stackHandleAt(-1);
     if (!LessThanOperation(cx, lval, rval, &cond))
         goto error;
     TRY_BRANCH_AFTER_COND(cond, 2);
     regs.sp[-2].setBoolean(cond);
     regs.sp--;
 }
 END_CASE(JSOP_LT)
 
 BEGIN_CASE(JSOP_LE)
 {
     bool cond;
-    MutableHandleValue lval = MutableHandleValue::fromMarkedLocation(&regs.sp[-2]);
-    MutableHandleValue rval = MutableHandleValue::fromMarkedLocation(&regs.sp[-1]);
+    MutableHandleValue lval = regs.stackHandleAt(-2);
+    MutableHandleValue rval = regs.stackHandleAt(-1);
     if (!LessThanOrEqualOperation(cx, lval, rval, &cond))
         goto error;
     TRY_BRANCH_AFTER_COND(cond, 2);
     regs.sp[-2].setBoolean(cond);
     regs.sp--;
 }
 END_CASE(JSOP_LE)
 
 BEGIN_CASE(JSOP_GT)
 {
     bool cond;
-    MutableHandleValue lval = MutableHandleValue::fromMarkedLocation(&regs.sp[-2]);
-    MutableHandleValue rval = MutableHandleValue::fromMarkedLocation(&regs.sp[-1]);
+    MutableHandleValue lval = regs.stackHandleAt(-2);
+    MutableHandleValue rval = regs.stackHandleAt(-1);
     if (!GreaterThanOperation(cx, lval, rval, &cond))
         goto error;
     TRY_BRANCH_AFTER_COND(cond, 2);
     regs.sp[-2].setBoolean(cond);
     regs.sp--;
 }
 END_CASE(JSOP_GT)
 
 BEGIN_CASE(JSOP_GE)
 {
     bool cond;
-    MutableHandleValue lval = MutableHandleValue::fromMarkedLocation(&regs.sp[-2]);
-    MutableHandleValue rval = MutableHandleValue::fromMarkedLocation(&regs.sp[-1]);
+    MutableHandleValue lval = regs.stackHandleAt(-2);
+    MutableHandleValue rval = regs.stackHandleAt(-1);
     if (!GreaterThanOrEqualOperation(cx, lval, rval, &cond))
         goto error;
     TRY_BRANCH_AFTER_COND(cond, 2);
     regs.sp[-2].setBoolean(cond);
     regs.sp--;
 }
 END_CASE(JSOP_GE)
 
@@ -2134,28 +2134,28 @@ END_CASE(JSOP_LSH)
 BEGIN_CASE(JSOP_RSH)
     SIGNED_SHIFT_OP(>>);
 END_CASE(JSOP_RSH)
 
 #undef SIGNED_SHIFT_OP
 
 BEGIN_CASE(JSOP_URSH)
 {
-    HandleValue lval = HandleValue::fromMarkedLocation(&regs.sp[-2]);
-    HandleValue rval = HandleValue::fromMarkedLocation(&regs.sp[-1]);
+    HandleValue lval = regs.stackHandleAt(-2);
+    HandleValue rval = regs.stackHandleAt(-1);
     if (!UrshOperation(cx, script, regs.pc, lval, rval, &regs.sp[-2]))
         goto error;
     regs.sp--;
 }
 END_CASE(JSOP_URSH)
 
 BEGIN_CASE(JSOP_ADD)
 {
-    MutableHandleValue lval = MutableHandleValue::fromMarkedLocation(&regs.sp[-2]);
-    MutableHandleValue rval = MutableHandleValue::fromMarkedLocation(&regs.sp[-1]);
+    MutableHandleValue lval = regs.stackHandleAt(-2);
+    MutableHandleValue rval = regs.stackHandleAt(-1);
     if (!AddOperation(cx, script, regs.pc, lval, rval, &regs.sp[-2]))
         goto error;
     regs.sp--;
 }
 END_CASE(JSOP_ADD)
 
 BEGIN_CASE(JSOP_SUB)
 {
@@ -2207,35 +2207,35 @@ BEGIN_CASE(JSOP_NOT)
     regs.sp--;
     PUSH_BOOLEAN(!cond);
 }
 END_CASE(JSOP_NOT)
 
 BEGIN_CASE(JSOP_BITNOT)
 {
     int32_t i;
-    HandleValue value = HandleValue::fromMarkedLocation(&regs.sp[-1]);
+    HandleValue value = regs.stackHandleAt(-1);
     if (!BitNot(cx, value, &i))
         goto error;
     regs.sp[-1].setInt32(i);
 }
 END_CASE(JSOP_BITNOT)
 
 BEGIN_CASE(JSOP_NEG)
 {
     RootedValue &val = rootValue0;
     val = regs.sp[-1];
-    MutableHandleValue res = MutableHandleValue::fromMarkedLocation(&regs.sp[-1]);
+    MutableHandleValue res = regs.stackHandleAt(-1);
     if (!NegOperation(cx, script, regs.pc, val, res))
         goto error;
 }
 END_CASE(JSOP_NEG)
 
 BEGIN_CASE(JSOP_POS)
-    if (!ToNumber(cx, MutableHandleValue::fromMarkedLocation(&regs.sp[-1])))
+    if (!ToNumber(cx, regs.stackHandleAt(-1)))
         goto error;
     if (!regs.sp[-1].isInt32())
         TypeScript::MonitorOverflow(cx, script, regs.pc);
 END_CASE(JSOP_POS)
 
 BEGIN_CASE(JSOP_DELNAME)
 {
     /* Strict mode code should never contain JSOP_DELNAME opcodes. */
@@ -2243,17 +2243,17 @@ BEGIN_CASE(JSOP_DELNAME)
 
     RootedPropertyName &name = rootName0;
     name = script->getName(regs.pc);
 
     RootedObject &scopeObj = rootObject0;
     scopeObj = regs.fp()->scopeChain();
 
     PUSH_BOOLEAN(true);
-    MutableHandleValue res = MutableHandleValue::fromMarkedLocation(&regs.sp[-1]);
+    MutableHandleValue res = regs.stackHandleAt(-1);
     if (!DeleteNameOperation(cx, name, scopeObj, res))
         goto error;
 }
 END_CASE(JSOP_DELNAME)
 
 BEGIN_CASE(JSOP_DELPROP)
 {
     RootedPropertyName &name = rootName0;
@@ -2264,17 +2264,17 @@ BEGIN_CASE(JSOP_DELPROP)
 
     JSBool succeeded;
     if (!JSObject::deleteProperty(cx, obj, name, &succeeded))
         goto error;
     if (!succeeded && script->strict) {
         obj->reportNotConfigurable(cx, NameToId(name));
         goto error;
     }
-    MutableHandleValue res = MutableHandleValue::fromMarkedLocation(&regs.sp[-1]);
+    MutableHandleValue res = regs.stackHandleAt(-1);
     res.setBoolean(succeeded);
 }
 END_CASE(JSOP_DELPROP)
 
 BEGIN_CASE(JSOP_DELELEM)
 {
     /* Fetch the left part and resolve it to a non-null object. */
     RootedObject &obj = rootObject0;
@@ -2292,43 +2292,43 @@ BEGIN_CASE(JSOP_DELELEM)
         //     necessary!
         RootedId id(cx);
         if (!ValueToId<CanGC>(cx, propval, &id))
             goto error;
         obj->reportNotConfigurable(cx, id);
         goto error;
     }
 
-    MutableHandleValue res = MutableHandleValue::fromMarkedLocation(&regs.sp[-2]);
+    MutableHandleValue res = regs.stackHandleAt(-2);
     res.setBoolean(succeeded);
     regs.sp--;
 }
 END_CASE(JSOP_DELELEM)
 
 BEGIN_CASE(JSOP_TOID)
 {
     /*
      * Increment or decrement requires use to lookup the same property twice,
      * but we need to avoid the observable stringification the second time.
      * There must be an object value below the id, which will not be popped.
      */
     RootedValue &objval = rootValue0, &idval = rootValue1;
     objval = regs.sp[-2];
     idval = regs.sp[-1];
 
-    MutableHandleValue res = MutableHandleValue::fromMarkedLocation(&regs.sp[-1]);
+    MutableHandleValue res = regs.stackHandleAt(-1);
     if (!ToIdOperation(cx, script, regs.pc, objval, idval, res))
         goto error;
 }
 END_CASE(JSOP_TOID)
 
 BEGIN_CASE(JSOP_TYPEOFEXPR)
 BEGIN_CASE(JSOP_TYPEOF)
 {
-    HandleValue ref = HandleValue::fromMarkedLocation(&regs.sp[-1]);
+    HandleValue ref = regs.stackHandleAt(-1);
     regs.sp[-1].setString(TypeOfOperation(cx, ref));
 }
 END_CASE(JSOP_TYPEOF)
 
 BEGIN_CASE(JSOP_VOID)
     regs.sp[-1].setUndefined();
 END_CASE(JSOP_VOID)
 
@@ -2339,72 +2339,72 @@ BEGIN_CASE(JSOP_THIS)
 END_CASE(JSOP_THIS)
 
 BEGIN_CASE(JSOP_GETPROP)
 BEGIN_CASE(JSOP_GETXPROP)
 BEGIN_CASE(JSOP_LENGTH)
 BEGIN_CASE(JSOP_CALLPROP)
 {
 
-    MutableHandleValue lval = MutableHandleValue::fromMarkedLocation(&regs.sp[-1]);
+    MutableHandleValue lval = regs.stackHandleAt(-1);
     if (!GetPropertyOperation(cx, regs.fp(), script, regs.pc, lval, lval))
         goto error;
 
     TypeScript::Monitor(cx, script, regs.pc, lval);
     assertSameCompartmentDebugOnly(cx, lval);
 }
 END_CASE(JSOP_GETPROP)
 
 BEGIN_CASE(JSOP_SETINTRINSIC)
 {
-    HandleValue value = HandleValue::fromMarkedLocation(&regs.sp[-1]);
+    HandleValue value = regs.stackHandleAt(-1);
 
     if (!SetIntrinsicOperation(cx, script, regs.pc, value))
         goto error;
 
     regs.sp[-2] = regs.sp[-1];
     regs.sp--;
 }
 END_CASE(JSOP_SETINTRINSIC)
 
 BEGIN_CASE(JSOP_SETGNAME)
 BEGIN_CASE(JSOP_SETNAME)
 {
     RootedObject &scope = rootObject0;
     scope = &regs.sp[-2].toObject();
 
-    HandleValue value = HandleValue::fromMarkedLocation(&regs.sp[-1]);
+    HandleValue value = regs.stackHandleAt(-1);
 
     if (!SetNameOperation(cx, script, regs.pc, scope, value))
         goto error;
 
     regs.sp[-2] = regs.sp[-1];
     regs.sp--;
 }
 END_CASE(JSOP_SETNAME)
 
 BEGIN_CASE(JSOP_SETPROP)
 {
-    HandleValue lval = HandleValue::fromMarkedLocation(&regs.sp[-2]);
-    HandleValue rval = HandleValue::fromMarkedLocation(&regs.sp[-1]);
+    HandleValue lval = regs.stackHandleAt(-2);
+    HandleValue rval = regs.stackHandleAt(-1);
 
     if (!SetPropertyOperation(cx, script, regs.pc, lval, rval))
         goto error;
 
     regs.sp[-2] = regs.sp[-1];
     regs.sp--;
 }
 END_CASE(JSOP_SETPROP)
 
 BEGIN_CASE(JSOP_GETELEM)
 BEGIN_CASE(JSOP_CALLELEM)
 {
-    MutableHandleValue lval = MutableHandleValue::fromMarkedLocation(&regs.sp[-2]);
-    HandleValue rval = HandleValue::fromMarkedLocation(&regs.sp[-1]);
-    MutableHandleValue res = MutableHandleValue::fromMarkedLocation(&regs.sp[-2]);
+    MutableHandleValue lval = regs.stackHandleAt(-2);
+    HandleValue rval = regs.stackHandleAt(-1);
+    MutableHandleValue res = regs.stackHandleAt(-2);
 
     bool done = false;
     if (!GetElemOptimizedArguments(cx, regs.fp(), lval, rval, res, &done))
         goto error;
 
     if (!done) {
         if (!GetElementOperation(cx, op, lval, rval, res))
             goto error;
@@ -3034,33 +3034,33 @@ BEGIN_CASE(JSOP_INITPROP)
 
     regs.sp--;
 }
 END_CASE(JSOP_INITPROP);
 
 BEGIN_CASE(JSOP_INITELEM)
 {
     JS_ASSERT(regs.stackDepth() >= 3);
-    HandleValue val = HandleValue::fromMarkedLocation(&regs.sp[-1]);
-    HandleValue id = HandleValue::fromMarkedLocation(&regs.sp[-2]);
+    HandleValue val = regs.stackHandleAt(-1);
+    HandleValue id = regs.stackHandleAt(-2);
 
     RootedObject &obj = rootObject0;
     obj = &regs.sp[-3].toObject();
 
     if (!InitElemOperation(cx, obj, id, val))
         goto error;
 
     regs.sp -= 2;
 }
 END_CASE(JSOP_INITELEM)
 
 BEGIN_CASE(JSOP_INITELEM_ARRAY)
 {
     JS_ASSERT(regs.stackDepth() >= 2);
-    HandleValue val = HandleValue::fromMarkedLocation(&regs.sp[-1]);
+    HandleValue val = regs.stackHandleAt(-1);
 
     RootedObject &obj = rootObject0;
     obj = &regs.sp[-2].toObject();
 
     JS_ASSERT(obj->is<ArrayObject>());
 
     uint32_t index = GET_UINT24(regs.pc);
     if (!InitArrayElemOperation(cx, regs.pc, obj, index, val))
@@ -3068,17 +3068,17 @@ BEGIN_CASE(JSOP_INITELEM_ARRAY)
 
     regs.sp--;
 }
 END_CASE(JSOP_INITELEM_ARRAY)
 
 BEGIN_CASE(JSOP_INITELEM_INC)
 {
     JS_ASSERT(regs.stackDepth() >= 3);
-    HandleValue val = HandleValue::fromMarkedLocation(&regs.sp[-1]);
+    HandleValue val = regs.stackHandleAt(-1);
 
     RootedObject &obj = rootObject0;
     obj = &regs.sp[-3].toObject();
 
     uint32_t index = regs.sp[-2].toInt32();
     if (!InitArrayElemOperation(cx, regs.pc, obj, index, val))
         goto error;
 
@@ -3143,17 +3143,17 @@ BEGIN_CASE(JSOP_RETSUB)
     /* Increment the PC by this much. */
     len = rval.toInt32() - int32_t(regs.pc - script->code);
 END_VARLEN_CASE
 }
 
 BEGIN_CASE(JSOP_EXCEPTION)
 {
     PUSH_NULL();
-    MutableHandleValue res = MutableHandleValue::fromMarkedLocation(&regs.sp[-1]);
+    MutableHandleValue res = regs.stackHandleAt(-1);
     if (!GetAndClearException(cx, res))
         goto error;
 }
 END_CASE(JSOP_EXCEPTION)
 
 BEGIN_CASE(JSOP_FINALLY)
     CHECK_BRANCH();
 END_CASE(JSOP_FINALLY)
@@ -3183,17 +3183,17 @@ BEGIN_CASE(JSOP_INSTANCEOF)
     rref = regs.sp[-1];
     if (rref.isPrimitive()) {
         js_ReportValueError(cx, JSMSG_BAD_INSTANCEOF_RHS, -1, rref, NullPtr());
         goto error;
     }
     RootedObject &obj = rootObject0;
     obj = &rref.toObject();
     JSBool cond = JS_FALSE;
-    if (!HasInstance(cx, obj, HandleValue::fromMarkedLocation(&regs.sp[-2]), &cond))
+    if (!HasInstance(cx, obj, regs.stackHandleAt(-2), &cond))
         goto error;
     regs.sp--;
     regs.sp[-1].setBoolean(cond);
 }
 END_CASE(JSOP_INSTANCEOF)
 
 BEGIN_CASE(JSOP_DEBUGGER)
 {
--- a/js/src/vm/Stack.h
+++ b/js/src/vm/Stack.h
@@ -1017,16 +1017,24 @@ class FrameRegs
     }
 
     void setToEndOfScript() {
         JSScript *script = fp()->script();
         sp = fp()->base();
         pc = script->code + script->length - JSOP_STOP_LENGTH;
         JS_ASSERT(*pc == JSOP_STOP);
     }
+
+    MutableHandleValue stackHandleAt(int i) {
+        return MutableHandleValue::fromMarkedLocation(&sp[i]);
+    }
+
+    HandleValue stackHandleAt(int i) const {
+        return HandleValue::fromMarkedLocation(&sp[i]);
+    }
 };
 
 /*****************************************************************************/
 
 class InterpreterStack
 {
     friend class FrameGuard;
     friend class InterpreterActivation;