Bug 1320118 part 1 - Remove emitted_ bool from GetPropIRGenerator. r=evilpie
authorJan de Mooij <jdemooij@mozilla.com>
Mon, 28 Nov 2016 09:51:48 +0100
changeset 324421 12185bff2467607b0d68a4bb456c717213f3b126
parent 324420 b4a687eff8e5886dad0e27eadd575091e3905180
child 324422 88423aaff4daff129ef8712c90952630174cfd0b
push id24
push usermaklebus@msu.edu
push dateTue, 20 Dec 2016 03:11:33 +0000
reviewersevilpie
bugs1320118
milestone53.0a1
Bug 1320118 part 1 - Remove emitted_ bool from GetPropIRGenerator. r=evilpie
js/src/jit/CacheIR.cpp
js/src/jit/CacheIR.h
js/src/jit/SharedIC.cpp
--- a/js/src/jit/CacheIR.cpp
+++ b/js/src/jit/CacheIR.cpp
@@ -25,17 +25,16 @@ GetPropIRGenerator::GetPropIRGenerator(J
   : writer(cx),
     cx_(cx),
     pc_(pc),
     val_(val),
     name_(name),
     res_(res),
     engine_(engine),
     isTemporarilyUnoptimizable_(isTemporarilyUnoptimizable),
-    emitted_(false),
     preliminaryObjectAction_(PreliminaryObjectAction::None)
 {}
 
 static void
 EmitLoadSlotResult(CacheIRWriter& writer, ObjOperandId holderOp, NativeObject* holder,
                    Shape* shape)
 {
     if (holder->isFixedSlot(shape->slot())) {
@@ -46,47 +45,45 @@ EmitLoadSlotResult(CacheIRWriter& writer
     }
 }
 
 bool
 GetPropIRGenerator::tryAttachStub()
 {
     AutoAssertNoPendingException aanpe(cx_);
 
-    MOZ_ASSERT(!emitted_);
-
     ValOperandId valId(writer.setInputOperandId(0));
 
     if (val_.isObject()) {
         RootedObject obj(cx_, &val_.toObject());
         ObjOperandId objId = writer.guardIsObject(valId);
 
-        if (!emitted_ && !tryAttachObjectLength(obj, objId))
-            return false;
-        if (!emitted_ && !tryAttachNative(obj, objId))
-            return false;
-        if (!emitted_ && !tryAttachUnboxed(obj, objId))
-            return false;
-        if (!emitted_ && !tryAttachUnboxedExpando(obj, objId))
-            return false;
-        if (!emitted_ && !tryAttachTypedObject(obj, objId))
-            return false;
-        if (!emitted_ && !tryAttachModuleNamespace(obj, objId))
-            return false;
-        if (!emitted_ && !tryAttachWindowProxy(obj, objId))
-            return false;
-        if (!emitted_ && !tryAttachProxy(obj, objId))
-            return false;
-        return true;
+        if (tryAttachObjectLength(obj, objId))
+            return true;
+        if (tryAttachNative(obj, objId))
+            return true;
+        if (tryAttachUnboxed(obj, objId))
+            return true;
+        if (tryAttachUnboxedExpando(obj, objId))
+            return true;
+        if (tryAttachTypedObject(obj, objId))
+            return true;
+        if (tryAttachModuleNamespace(obj, objId))
+            return true;
+        if (tryAttachWindowProxy(obj, objId))
+            return true;
+        if (tryAttachProxy(obj, objId))
+            return true;
+        return false;
     }
 
-    if (!emitted_ && !tryAttachPrimitive(valId))
-        return false;
+    if (tryAttachPrimitive(valId))
+        return true;
 
-    return true;
+    return false;
 }
 
 static bool
 IsCacheableNoProperty(JSContext* cx, JSObject* obj, JSObject* holder, Shape* shape, jsid id,
                       jsbytecode* pc)
 {
     if (shape)
         return false;
@@ -297,28 +294,24 @@ EmitCallGetterResult(CacheIRWriter& writ
     }
 
     EmitCallGetterResultNoGuards(writer, obj, holder, shape, objId);
 }
 
 bool
 GetPropIRGenerator::tryAttachNative(HandleObject obj, ObjOperandId objId)
 {
-    MOZ_ASSERT(!emitted_);
-
     RootedShape shape(cx_);
     RootedNativeObject holder(cx_);
 
     RootedId id(cx_, NameToId(name_));
     NativeGetPropCacheability type = CanAttachNativeGetProp(cx_, obj, id, &holder, &shape, pc_,
                                                             engine_, isTemporarilyUnoptimizable_);
     if (type == CanAttachNone)
-        return true;
-
-    emitted_ = true;
+        return false;
 
     switch (type) {
       case CanAttachReadSlot:
         if (holder) {
             EnsureTrackPropertyTypes(cx_, holder, NameToId(name_));
             if (obj == holder) {
                 // See the comment in StripPreliminaryObjectStubs.
                 if (IsPreliminaryObject(obj))
@@ -341,20 +334,18 @@ GetPropIRGenerator::tryAttachNative(Hand
 }
 
 bool
 GetPropIRGenerator::tryAttachWindowProxy(HandleObject obj, ObjOperandId objId)
 {
     // Attach a stub when the receiver is a WindowProxy and we are calling some
     // kinds of JSNative getters on the Window object (the global object).
 
-    MOZ_ASSERT(!emitted_);
-
     if (!IsWindowProxy(obj))
-        return true;
+        return false;
 
     // This must be a WindowProxy for the current Window/global. Else it would
     // be a cross-compartment wrapper and IsWindowProxy returns false for
     // those.
     MOZ_ASSERT(obj->getClass() == cx_->maybeWindowProxyClass());
     MOZ_ASSERT(ToWindowIfWindowProxy(obj) == cx_->global());
 
     // Now try to do the lookup on the Window (the current global) and see if
@@ -363,63 +354,55 @@ GetPropIRGenerator::tryAttachWindowProxy
     RootedShape shape(cx_);
     RootedNativeObject holder(cx_);
     RootedId id(cx_, NameToId(name_));
     NativeGetPropCacheability type = CanAttachNativeGetProp(cx_, windowObj, id, &holder, &shape, pc_,
                                                             engine_, isTemporarilyUnoptimizable_);
     if (type != CanAttachCallGetter ||
         !IsCacheableGetPropCallNative(windowObj, holder, shape))
     {
-        return true;
+        return false;
     }
 
     // Make sure the native getter is okay with the IC passing the Window
     // instead of the WindowProxy as |this| value.
     JSFunction* callee = &shape->getterObject()->as<JSFunction>();
     MOZ_ASSERT(callee->isNative());
     if (!callee->jitInfo() || callee->jitInfo()->needsOuterizedThisObject())
-        return true;
-
-    emitted_ = true;
+        return false;
 
     // Guard the incoming object is a WindowProxy and inline a getter call based
     // on the Window object.
     writer.guardClass(objId, GuardClassKind::WindowProxy);
     ObjOperandId windowObjId = writer.loadObject(windowObj);
     EmitCallGetterResult(writer, windowObj, holder, shape, windowObjId);
     return true;
 }
 
 bool
 GetPropIRGenerator::tryAttachGenericProxy(HandleObject obj, ObjOperandId objId)
 {
-    MOZ_ASSERT(!emitted_);
     MOZ_ASSERT(obj->is<ProxyObject>());
 
-    emitted_ = true;
-
     writer.guardIsProxy(objId);
 
     // Ensure that the incoming object is not a DOM proxy, so that we can get to
     // the specialized stubs
     writer.guardNotDOMProxy(objId);
 
     writer.callProxyGetResult(objId, NameToId(name_));
     writer.typeMonitorResult();
     return true;
 }
 
 bool
 GetPropIRGenerator::tryAttachDOMProxyShadowed(HandleObject obj, ObjOperandId objId)
 {
-    MOZ_ASSERT(!emitted_);
     MOZ_ASSERT(IsCacheableDOMProxy(obj));
 
-    emitted_ = true;
-
     writer.guardShape(objId, obj->maybeShape());
 
     // No need for more guards: we know this is a DOM proxy, since the shape
     // guard enforces a given JSClass, so just go ahead and emit the call to
     // ProxyGet.
     writer.callProxyGetResult(objId, NameToId(name_));
     writer.typeMonitorResult();
     return true;
@@ -457,31 +440,28 @@ CheckDOMProxyExpandoDoesNotShadow(CacheI
     } else {
         MOZ_CRASH("Invalid expando value");
     }
 }
 
 bool
 GetPropIRGenerator::tryAttachDOMProxyUnshadowed(HandleObject obj, ObjOperandId objId)
 {
-    MOZ_ASSERT(!emitted_);
     MOZ_ASSERT(IsCacheableDOMProxy(obj));
 
     RootedObject checkObj(cx_, obj->staticPrototype());
     RootedNativeObject holder(cx_);
     RootedShape shape(cx_);
 
     RootedId id(cx_, NameToId(name_));
     NativeGetPropCacheability canCache = CanAttachNativeGetProp(cx_, checkObj, id, &holder, &shape,
                                                                 pc_, engine_,
                                                                 isTemporarilyUnoptimizable_);
     if (canCache == CanAttachNone)
-        return true;
-
-    emitted_ = true;
+        return false;
 
     writer.guardShape(objId, obj->maybeShape());
 
     // Guard that our expando object hasn't started shadowing this property.
     CheckDOMProxyExpandoDoesNotShadow(writer, obj, id, objId);
 
     if (holder) {
         // Found the property on the prototype chain. Treat it like a native
@@ -511,20 +491,18 @@ GetPropIRGenerator::tryAttachDOMProxyUns
     }
 
     return true;
 }
 
 bool
 GetPropIRGenerator::tryAttachProxy(HandleObject obj, ObjOperandId objId)
 {
-    MOZ_ASSERT(!emitted_);
-
     if (!obj->is<ProxyObject>())
-        return true;
+        return false;
 
     // Skim off DOM proxies.
     if (IsCacheableDOMProxy(obj)) {
         RootedId id(cx_, NameToId(name_));
         DOMProxyShadowsResult shadows = GetDOMProxyShadowsCheck()(cx_, obj, id);
         if (shadows == ShadowCheckFailed) {
             cx_->clearPendingException();
             return false;
@@ -537,88 +515,79 @@ GetPropIRGenerator::tryAttachProxy(Handl
     }
 
     return tryAttachGenericProxy(obj, objId);
 }
 
 bool
 GetPropIRGenerator::tryAttachUnboxed(HandleObject obj, ObjOperandId objId)
 {
-    MOZ_ASSERT(!emitted_);
-
     if (!obj->is<UnboxedPlainObject>())
-        return true;
+        return false;
 
     const UnboxedLayout::Property* property = obj->as<UnboxedPlainObject>().layout().lookup(name_);
     if (!property)
-        return true;
+        return false;
 
     if (!cx_->runtime()->jitSupportsFloatingPoint)
-        return true;
+        return false;
 
     writer.guardGroup(objId, obj->group());
     writer.loadUnboxedPropertyResult(objId, property->type,
                                      UnboxedPlainObject::offsetOfData() + property->offset);
     if (property->type == JSVAL_TYPE_OBJECT)
         writer.typeMonitorResult();
     else
         writer.returnFromIC();
 
-    emitted_ = true;
     preliminaryObjectAction_ = PreliminaryObjectAction::Unlink;
     return true;
 }
 
 bool
 GetPropIRGenerator::tryAttachUnboxedExpando(HandleObject obj, ObjOperandId objId)
 {
-    MOZ_ASSERT(!emitted_);
-
     if (!obj->is<UnboxedPlainObject>())
-        return true;
+        return false;
 
     UnboxedExpandoObject* expando = obj->as<UnboxedPlainObject>().maybeExpando();
     if (!expando)
-        return true;
+        return false;
 
     Shape* shape = expando->lookup(cx_, NameToId(name_));
     if (!shape || !shape->hasDefaultGetter() || !shape->hasSlot())
-        return true;
-
-    emitted_ = true;
+        return false;
 
     EmitReadSlotResult(writer, obj, obj, shape, objId);
     EmitReadSlotReturn(writer, obj, obj, shape);
     return true;
 }
 
 bool
 GetPropIRGenerator::tryAttachTypedObject(HandleObject obj, ObjOperandId objId)
 {
-    MOZ_ASSERT(!emitted_);
-
     if (!obj->is<TypedObject>() ||
         !cx_->runtime()->jitSupportsFloatingPoint ||
         cx_->compartment()->detachedTypedObjects)
     {
-        return true;
+        return false;
     }
 
     TypedObject* typedObj = &obj->as<TypedObject>();
     if (!typedObj->typeDescr().is<StructTypeDescr>())
-        return true;
+        return false;
 
     StructTypeDescr* structDescr = &typedObj->typeDescr().as<StructTypeDescr>();
     size_t fieldIndex;
     if (!structDescr->fieldIndex(NameToId(name_), &fieldIndex))
-        return true;
+        return false;
 
     TypeDescr* fieldDescr = &structDescr->fieldDescr(fieldIndex);
     if (!fieldDescr->is<SimpleTypeDescr>())
-        return true;
+        return false;
 
     Shape* shape = typedObj->maybeShape();
     TypedThingLayout layout = GetTypedThingLayout(shape->getObjectClass());
 
     uint32_t fieldOffset = structDescr->fieldOffset(fieldIndex);
     uint32_t typeDescr = SimpleTypeDescrKey(&fieldDescr->as<SimpleTypeDescr>());
 
     writer.guardNoDetachedTypedObjects();
@@ -635,139 +604,125 @@ GetPropIRGenerator::tryAttachTypedObject
         monitorLoad = type != ReferenceTypeDescr::TYPE_STRING;
     }
 
     if (monitorLoad)
         writer.typeMonitorResult();
     else
         writer.returnFromIC();
 
-    emitted_ = true;
     return true;
 }
 
 bool
 GetPropIRGenerator::tryAttachObjectLength(HandleObject obj, ObjOperandId objId)
 {
-    MOZ_ASSERT(!emitted_);
-
     if (name_ != cx_->names().length)
-        return true;
+        return false;
 
     if (obj->is<ArrayObject>()) {
         // Make sure int32 is added to the TypeSet before we attach a stub, so
         // the stub can return int32 values without monitoring the result.
         if (obj->as<ArrayObject>().length() > INT32_MAX)
-            return true;
+            return false;
 
         writer.guardClass(objId, GuardClassKind::Array);
         writer.loadInt32ArrayLengthResult(objId);
         writer.returnFromIC();
-        emitted_ = true;
         return true;
     }
 
     if (obj->is<UnboxedArrayObject>()) {
         writer.guardClass(objId, GuardClassKind::UnboxedArray);
         writer.loadUnboxedArrayLengthResult(objId);
         writer.returnFromIC();
-        emitted_ = true;
         return true;
     }
 
     if (obj->is<ArgumentsObject>() && !obj->as<ArgumentsObject>().hasOverriddenLength()) {
         if (obj->is<MappedArgumentsObject>()) {
             writer.guardClass(objId, GuardClassKind::MappedArguments);
         } else {
             MOZ_ASSERT(obj->is<UnmappedArgumentsObject>());
             writer.guardClass(objId, GuardClassKind::UnmappedArguments);
         }
         writer.loadArgumentsObjectLengthResult(objId);
         writer.returnFromIC();
-        emitted_ = true;
         return true;
     }
 
-    return true;
+    return false;
 }
 
 bool
 GetPropIRGenerator::tryAttachModuleNamespace(HandleObject obj, ObjOperandId objId)
 {
-    MOZ_ASSERT(!emitted_);
-
     if (!obj->is<ModuleNamespaceObject>())
-        return true;
+        return false;
 
     Rooted<ModuleNamespaceObject*> ns(cx_, &obj->as<ModuleNamespaceObject>());
     RootedModuleEnvironmentObject env(cx_);
     RootedShape shape(cx_);
     if (!ns->bindings().lookup(NameToId(name_), env.address(), shape.address()))
-        return true;
+        return false;
 
     // Don't emit a stub until the target binding has been initialized.
     if (env->getSlot(shape->slot()).isMagic(JS_UNINITIALIZED_LEXICAL))
-        return true;
+        return false;
 
     if (IsIonEnabled(cx_))
         EnsureTrackPropertyTypes(cx_, env, shape->propid());
 
-    emitted_ = true;
-
     // Check for the specific namespace object.
     writer.guardSpecificObject(objId, ns);
 
     ObjOperandId envId = writer.loadObject(env);
     EmitLoadSlotResult(writer, envId, env, shape);
     writer.typeMonitorResult();
     return true;
 }
 
 bool
 GetPropIRGenerator::tryAttachPrimitive(ValOperandId valId)
 {
-    MOZ_ASSERT(!emitted_);
-
     JSValueType primitiveType;
     RootedNativeObject proto(cx_);
     if (val_.isString()) {
         if (name_ == cx_->names().length) {
             // String length is special-cased, see js::GetProperty.
-            return true;
+            return false;
         }
         primitiveType = JSVAL_TYPE_STRING;
         proto = MaybeNativeObject(GetBuiltinPrototypePure(cx_->global(), JSProto_String));
     } else if (val_.isNumber()) {
         primitiveType = JSVAL_TYPE_DOUBLE;
         proto = MaybeNativeObject(GetBuiltinPrototypePure(cx_->global(), JSProto_Number));
     } else if (val_.isBoolean()) {
         primitiveType = JSVAL_TYPE_BOOLEAN;
         proto = MaybeNativeObject(GetBuiltinPrototypePure(cx_->global(), JSProto_Boolean));
     } else if (val_.isSymbol()) {
         primitiveType = JSVAL_TYPE_SYMBOL;
         proto = MaybeNativeObject(GetBuiltinPrototypePure(cx_->global(), JSProto_Symbol));
     } else {
         MOZ_ASSERT(val_.isNullOrUndefined() || val_.isMagic());
-        return true;
+        return false;
     }
     if (!proto)
-        return true;
+        return false;
 
     // Instantiate this property, for use during Ion compilation.
     RootedId id(cx_, NameToId(name_));
     if (IsIonEnabled(cx_))
         EnsureTrackPropertyTypes(cx_, proto, id);
 
     // For now, only look for properties directly set on the prototype.
     Shape* shape = proto->lookup(cx_, id);
     if (!shape || !shape->hasSlot() || !shape->hasDefaultGetter())
-        return true;
+        return false;
 
     writer.guardType(valId, primitiveType);
 
     ObjOperandId protoId = writer.loadObject(proto);
     writer.guardShape(protoId, proto->lastProperty());
     EmitLoadSlotResult(writer, protoId, proto, shape);
     writer.typeMonitorResult();
-
-    emitted_ = true;
     return true;
 }
--- a/js/src/jit/CacheIR.h
+++ b/js/src/jit/CacheIR.h
@@ -514,47 +514,44 @@ class MOZ_RAII GetPropIRGenerator
     CacheIRWriter writer;
     JSContext* cx_;
     jsbytecode* pc_;
     HandleValue val_;
     HandlePropertyName name_;
     MutableHandleValue res_;
     ICStubEngine engine_;
     bool* isTemporarilyUnoptimizable_;
-    bool emitted_;
 
     enum class PreliminaryObjectAction { None, Unlink, NotePreliminary };
     PreliminaryObjectAction preliminaryObjectAction_;
 
-    MOZ_MUST_USE bool tryAttachNative(HandleObject obj, ObjOperandId objId);
-    MOZ_MUST_USE bool tryAttachUnboxed(HandleObject obj, ObjOperandId objId);
-    MOZ_MUST_USE bool tryAttachUnboxedExpando(HandleObject obj, ObjOperandId objId);
-    MOZ_MUST_USE bool tryAttachTypedObject(HandleObject obj, ObjOperandId objId);
-    MOZ_MUST_USE bool tryAttachObjectLength(HandleObject obj, ObjOperandId objId);
-    MOZ_MUST_USE bool tryAttachModuleNamespace(HandleObject obj, ObjOperandId objId);
-    MOZ_MUST_USE bool tryAttachWindowProxy(HandleObject obj, ObjOperandId objId);
+    bool tryAttachNative(HandleObject obj, ObjOperandId objId);
+    bool tryAttachUnboxed(HandleObject obj, ObjOperandId objId);
+    bool tryAttachUnboxedExpando(HandleObject obj, ObjOperandId objId);
+    bool tryAttachTypedObject(HandleObject obj, ObjOperandId objId);
+    bool tryAttachObjectLength(HandleObject obj, ObjOperandId objId);
+    bool tryAttachModuleNamespace(HandleObject obj, ObjOperandId objId);
+    bool tryAttachWindowProxy(HandleObject obj, ObjOperandId objId);
 
-    MOZ_MUST_USE bool tryAttachGenericProxy(HandleObject obj, ObjOperandId objId);
-    MOZ_MUST_USE bool tryAttachDOMProxyShadowed(HandleObject obj, ObjOperandId objId);
-    MOZ_MUST_USE bool tryAttachDOMProxyUnshadowed(HandleObject obj, ObjOperandId objId);
-    MOZ_MUST_USE bool tryAttachProxy(HandleObject obj, ObjOperandId objId);
+    bool tryAttachGenericProxy(HandleObject obj, ObjOperandId objId);
+    bool tryAttachDOMProxyShadowed(HandleObject obj, ObjOperandId objId);
+    bool tryAttachDOMProxyUnshadowed(HandleObject obj, ObjOperandId objId);
+    bool tryAttachProxy(HandleObject obj, ObjOperandId objId);
 
-    MOZ_MUST_USE bool tryAttachPrimitive(ValOperandId valId);
+    bool tryAttachPrimitive(ValOperandId valId);
 
     GetPropIRGenerator(const GetPropIRGenerator&) = delete;
     GetPropIRGenerator& operator=(const GetPropIRGenerator&) = delete;
 
   public:
     GetPropIRGenerator(JSContext* cx, jsbytecode* pc, ICStubEngine engine,
                        bool* isTemporarilyUnoptimizable,
                        HandleValue val, HandlePropertyName name, MutableHandleValue res);
 
-    bool emitted() const { return emitted_; }
-
-    MOZ_MUST_USE bool tryAttachStub();
+    bool tryAttachStub();
 
     bool shouldUnlinkPreliminaryObjectStubs() const {
         return preliminaryObjectAction_ == PreliminaryObjectAction::Unlink;
     }
     bool shouldNotePreliminaryObjectStub() const {
         return preliminaryObjectAction_ == PreliminaryObjectAction::NotePreliminary;
     }
     const CacheIRWriter& writerRef() const {
--- a/js/src/jit/SharedIC.cpp
+++ b/js/src/jit/SharedIC.cpp
@@ -2467,19 +2467,17 @@ DoGetPropFallback(JSContext* cx, void* p
         if (!newStub)
             return false;
         stub->addNewStub(newStub);
         attached = true;
     }
 
     if (!attached && !JitOptions.disableCacheIR) {
         GetPropIRGenerator gen(cx, pc, engine, &isTemporarilyUnoptimizable, val, name, res);
-        if (!gen.tryAttachStub())
-            return false;
-        if (gen.emitted()) {
+        if (gen.tryAttachStub()) {
             ICStub* newStub = AttachBaselineCacheIRStub(cx, gen.writerRef(), CacheKind::GetProp,
                                                         engine, info.outerScript(cx), stub);
             if (newStub) {
                 JitSpew(JitSpew_BaselineIC, "  Attached CacheIR stub");
                 attached = true;
                 if (gen.shouldNotePreliminaryObjectStub())
                     newStub->toCacheIR_Monitored()->notePreliminaryObject();
                 else if (gen.shouldUnlinkPreliminaryObjectStubs())