diff --git a/js/src/gc/Allocator.cpp b/js/src/gc/Allocator.cpp index bdc17bdc8..761341029 100644 --- a/js/src/gc/Allocator.cpp +++ b/js/src/gc/Allocator.cpp @@ -189,7 +189,7 @@ GCRuntime::tryNewTenuredObject(ExclusiveContext* cx, AllocKind kind, size_t thin JSObject* obj = tryNewTenuredThing(cx, kind, thingSize); - if (obj) + if (MOZ_LIKELY(obj)) obj->setInitialSlotsMaybeNonNative(slots); else js_free(slots); @@ -262,7 +262,7 @@ GCRuntime::tryNewTenuredThing(ExclusiveContext* cx, AllocKind kind, size_t thing rt->gc.waitBackgroundSweepOrAllocEnd(); t = tryNewTenuredThing(cx, kind, thingSize); - if (!t) + if (MOZ_UNLIKELY(!t)) ReportOutOfMemory(cx); } } diff --git a/js/src/gc/Nursery.cpp b/js/src/gc/Nursery.cpp index 7e002f916..5e8f30a41 100644 --- a/js/src/gc/Nursery.cpp +++ b/js/src/gc/Nursery.cpp @@ -215,7 +215,7 @@ js::Nursery::allocateObject(JSContext* cx, size_t size, size_t numDynamic, const /* Make the object allocation. */ JSObject* obj = static_cast(allocate(size)); - if (!obj) + if (MOZ_UNLIKELY(!obj)) return nullptr; /* If we want external slots, add them. */ @@ -223,7 +223,7 @@ js::Nursery::allocateObject(JSContext* cx, size_t size, size_t numDynamic, const if (numDynamic) { MOZ_ASSERT(clasp->isNative()); slots = static_cast(allocateBuffer(cx->zone(), numDynamic * sizeof(HeapSlot))); - if (!slots) { + if (MOZ_UNLIKELY(!slots)) { /* * It is safe to leave the allocated object uninitialized, since we * do not visit unallocated things in the nursery. diff --git a/js/src/jsgc.cpp b/js/src/jsgc.cpp index cf3612d41..d9f41d4eb 100644 --- a/js/src/jsgc.cpp +++ b/js/src/jsgc.cpp @@ -2095,7 +2095,7 @@ AllocRelocatedCell(Zone* zone, AllocKind thingKind, size_t thingSize) void* dstAlloc = zone->arenas.allocateFromFreeList(thingKind, thingSize); if (!dstAlloc) dstAlloc = GCRuntime::refillFreeListInGC(zone, thingKind); - if (!dstAlloc) { + if (MOZ_UNLIKELY(!dstAlloc)) { // This can only happen in zeal mode or debug builds as we don't // otherwise relocate more cells than we have existing free space // for. @@ -4313,7 +4313,7 @@ js::gc::MarkingValidator::nonIncrementalMark() for (auto chunk = gc->allNonEmptyChunks(); !chunk.done(); chunk.next()) { ChunkBitmap* bitmap = &chunk->bitmap; ChunkBitmap* entry = js_new(); - if (!entry) + if (MOZ_UNLIKELY(!entry)) return; memcpy((void*)entry->bitmap, (void*)bitmap->bitmap, sizeof(bitmap->bitmap)); diff --git a/js/src/jsobj.cpp b/js/src/jsobj.cpp index fc8085715..4afb15acd 100644 --- a/js/src/jsobj.cpp +++ b/js/src/jsobj.cpp @@ -233,7 +233,7 @@ js::Throw(JSContext* cx, jsid id, unsigned errorNumber) if (!idstr) return false; JSAutoByteString bytes(cx, idstr); - if (!bytes) + if (MOZ_UNLIKELY(!bytes)) return false; JS_ReportErrorNumber(cx, GetErrorMessage, nullptr, errorNumber, bytes.ptr()); return false; @@ -661,12 +661,12 @@ NewObject(ExclusiveContext* cx, HandleObjectGroup group, gc::AllocKind kind, RootedShape shape(cx, EmptyShape::getInitialShape(cx, clasp, group->proto(), nfixed, initialShapeFlags)); - if (!shape) + if (MOZ_UNLIKELY(!shape)) return nullptr; gc::InitialHeap heap = GetInitialHeap(newKind, clasp); JSObject* obj = JSObject::create(cx, kind, heap, shape, group); - if (!obj) + if (MOZ_UNLIKELY(!obj)) return nullptr; if (newKind == SingletonObject) { @@ -723,11 +723,11 @@ js::NewObjectWithGivenTaggedProto(ExclusiveContext* cxArg, const Class* clasp, } RootedObjectGroup group(cxArg, ObjectGroup::defaultNewGroup(cxArg, clasp, proto, nullptr)); - if (!group) + if (MOZ_UNLIKELY(!group)) return nullptr; RootedObject obj(cxArg, NewObject(cxArg, group, allocKind, newKind, initialShapeFlags)); - if (!obj) + if (MOZ_UNLIKELY(!obj)) return nullptr; if (isCachable && !obj->as().hasDynamicSlots()) { @@ -790,11 +790,11 @@ js::NewObjectWithClassProtoCommon(ExclusiveContext* cxArg, const Class* clasp, Rooted taggedProto(cxArg, TaggedProto(proto)); RootedObjectGroup group(cxArg, ObjectGroup::defaultNewGroup(cxArg, clasp, taggedProto)); - if (!group) + if (MOZ_UNLIKELY(!group)) return nullptr; JSObject* obj = NewObject(cxArg, group, allocKind, newKind); - if (!obj) + if (MOZ_UNLIKELY(!obj)) return nullptr; if (isCachable && !obj->as().hasDynamicSlots()) { @@ -844,7 +844,7 @@ js::NewObjectWithGroupCommon(ExclusiveContext* cx, HandleObjectGroup group, } JSObject* obj = NewObject(cx, group, allocKind, newKind); - if (!obj) + if (MOZ_UNLIKELY(!obj)) return nullptr; if (isCachable && !obj->as().hasDynamicSlots()) { @@ -957,7 +957,7 @@ js::CreateThisForFunctionWithProto(JSContext* cx, HandleObject callee, HandleObj if (proto) { RootedObjectGroup group(cx, ObjectGroup::defaultNewGroup(cx, nullptr, TaggedProto(proto), newTarget)); - if (!group) + if (MOZ_UNLIKELY(!group)) return nullptr; if (group->newScript() && !group->newScript()->analyzed()) { @@ -980,7 +980,7 @@ js::CreateThisForFunctionWithProto(JSContext* cx, HandleObject callee, HandleObj if (res) { JSScript* script = callee->as().getOrCreateScript(cx); - if (!script) + if (MOZ_UNLIKELY(!script)) return nullptr; TypeScript::SetThis(cx, script, TypeSet::ObjectType(res)); } @@ -1145,7 +1145,7 @@ js::CloneObject(JSContext* cx, HandleObject obj, Handle proto) RootedObject clone(cx); if (obj->isNative()) { clone = NewObjectWithGivenTaggedProto(cx, obj->getClass(), proto); - if (!clone) + if (MOZ_UNLIKELY(!clone)) return nullptr; if (clone->is() && (obj->compartment() != clone->compartment())) { @@ -1161,7 +1161,7 @@ js::CloneObject(JSContext* cx, HandleObject obj, Handle proto) options.setClass(obj->getClass()); clone = ProxyObject::New(cx, GetProxyHandler(obj), JS::NullHandleValue, proto, options); - if (!clone) + if (MOZ_UNLIKELY(!clone)) return nullptr; if (!CopyProxyObject(cx, obj.as(), clone.as())) @@ -1345,13 +1345,13 @@ InitializePropertiesFromCompatibleNativeObject(JSContext* cx, // dst's object flags are 0. shape = EmptyShape::getInitialShape(cx, dst->getClass(), dst->getTaggedProto(), dst->numFixedSlots(), 0); - if (!shape) + if (MOZ_UNLIKELY(!shape)) return false; // Get an in-order list of the shapes in the src object. Rooted shapes(cx, ShapeVector(cx)); for (Shape::Range r(src->lastProperty()); !r.empty(); r.popFront()) { - if (!shapes.append(&r.front())) + if (MOZ_UNLIKELY(!shapes.append(&r.front()))) return false; } Reverse(shapes.begin(), shapes.end()); @@ -1442,7 +1442,7 @@ js::XDRObjectLiteral(XDRState* xdr, MutableHandleObject obj) : ObjectGroup::NewArrayKind::Normal; obj.set(ObjectGroup::newArrayObject(cx, values.begin(), values.length(), TenuredObject, arrayKind)); - if (!obj) + if (MOZ_UNLIKELY(!obj)) return false; } @@ -1560,9 +1560,9 @@ JSObject::swap(JSContext* cx, HandleObject a, HandleObject b) AutoCompartment ac(cx, a); - if (!a->getGroup(cx)) + if (MOZ_UNLIKELY(!a->getGroup(cx))) oomUnsafe.crash("JSObject::swap"); - if (!b->getGroup(cx)) + if (MOZ_UNLIKELY(!b->getGroup(cx))) oomUnsafe.crash("JSObject::swap"); /* @@ -1644,9 +1644,9 @@ JSObject::swap(JSContext* cx, HandleObject a, HandleObject b) a->fixDictionaryShapeAfterSwap(); b->fixDictionaryShapeAfterSwap(); - if (na && !b->as().fillInAfterSwap(cx, avals, apriv)) + if (MOZ_UNLIKELY(na && !b->as().fillInAfterSwap(cx, avals, apriv))) oomUnsafe.crash("fillInAfterSwap"); - if (nb && !a->as().fillInAfterSwap(cx, bvals, bpriv)) + if (MOZ_UNLIKELY(nb && !a->as().fillInAfterSwap(cx, bvals, bpriv))) oomUnsafe.crash("fillInAfterSwap"); } @@ -1758,7 +1758,7 @@ DefineConstructorAndPrototype(JSContext* cx, HandleObject obj, JSProtoKey key, H * used because it won't let us use protoProto as the proto. */ RootedNativeObject proto(cx, NewNativeObjectWithClassProto(cx, clasp, protoProto, SingletonObject)); - if (!proto) + if (MOZ_UNLIKELY(!proto)) return nullptr; /* After this point, control must exit via label bad or out. */ @@ -1786,7 +1786,7 @@ DefineConstructorAndPrototype(JSContext* cx, HandleObject obj, JSProtoKey key, H ctor = proto; } else { RootedFunction fun(cx, NewNativeConstructor(cx, constructor, nargs, atom, ctorKind)); - if (!fun) + if (MOZ_UNLIKELY(!fun)) goto bad; /* @@ -1960,7 +1960,7 @@ js::SetClassAndProto(JSContext* cx, HandleObject obj, } ObjectGroup* group = ObjectGroup::defaultNewGroup(cx, clasp, proto); - if (!group) + if (MOZ_UNLIKELY(!group)) return false; /* @@ -1987,7 +1987,7 @@ JSObject::changeToSingleton(JSContext* cx, HandleObject obj) ObjectGroup* group = ObjectGroup::lazySingletonGroup(cx, obj->getClass(), obj->getTaggedProto()); - if (!group) + if (MOZ_UNLIKELY(!group)) return false; obj->group_ = group; @@ -3656,12 +3656,12 @@ JSObject::addSizeOfExcludingThis(mozilla::MallocSizeOf mallocSizeOf, JS::ClassIn } // Other things may be measured in the future if DMD indicates it is worthwhile. - if (is() || + if (MOZ_LIKELY((is() || is() || is() || is() || is() || - is()) + is()))) { // Do nothing. But this function is hot, and we win by getting the // common cases out of the way early. Some stats on the most common diff --git a/js/src/vm/RegExpObject.cpp b/js/src/vm/RegExpObject.cpp index f6973edeb..2f3ea5f6e 100644 --- a/js/src/vm/RegExpObject.cpp +++ b/js/src/vm/RegExpObject.cpp @@ -54,7 +54,7 @@ js::RegExpAlloc(ExclusiveContext* cx, HandleObject proto /* = nullptr */) regexp->initPrivate(nullptr); - if (!EmptyShape::ensureInitialCustomShape(cx, regexp)) + if (MOZ_UNLIKELY(!EmptyShape::ensureInitialCustomShape(cx, regexp))) return nullptr; MOZ_ASSERT(regexp->lookupPure(cx->names().lastIndex)->slot() == @@ -70,7 +70,7 @@ MatchPairs::initArrayFrom(MatchPairs& copyFrom) { MOZ_ASSERT(copyFrom.pairCount() > 0); - if (!allocOrExpandArray(copyFrom.pairCount())) + if (MOZ_UNLIKELY(!allocOrExpandArray(copyFrom.pairCount()))) return false; PodCopy(pairs_, copyFrom.pairs_, pairCount_); @@ -90,7 +90,7 @@ ScopedMatchPairs::allocOrExpandArray(size_t pairCount) MOZ_ASSERT(!pairs_); pairs_ = (MatchPair*)lifoScope_.alloc().alloc(sizeof(MatchPair) * pairCount); - if (!pairs_) + if (MOZ_UNLIKELY(!pairs_)) return false; pairCount_ = pairCount; @@ -224,7 +224,7 @@ RegExpObject::createNoStatics(ExclusiveContext* cx, HandleAtom source, RegExpFla return nullptr; Rooted regexp(cx, RegExpAlloc(cx)); - if (!regexp) + if (MOZ_UNLIKELY(!regexp)) return nullptr; regexp->initAndZeroLastIndex(source, flags, cx); @@ -341,7 +341,7 @@ SetupBuffer(StringBuffer& sb, const CharT* oldChars, size_t oldLen, const CharT* if (mozilla::IsSame::value && !sb.ensureTwoByteChars()) return false; - if (!sb.reserve(oldLen + 1)) + if (MOZ_UNLIKELY(!sb.reserve(oldLen + 1))) return false; sb.infallibleAppend(oldChars, size_t(it - oldChars)); @@ -837,10 +837,10 @@ RegExpCompartment::get(JSContext* cx, JSAtom* source, RegExpFlag flags, RegExpGu } ScopedJSDeletePtr shared(cx->new_(source, flags)); - if (!shared) + if (MOZ_UNLIKELY(!shared)) return false; - if (!set_.add(p, shared)) { + if (MOZ_UNLIKELY(!set_.add(p, shared))) { ReportOutOfMemory(cx); return false; } @@ -885,18 +885,18 @@ js::CloneRegExpObject(JSContext* cx, JSObject* obj_) // in the tenured heap to simplify embedding them in JIT code. RootedObjectGroup group(cx, regex->group()); Rooted clone(cx, NewObjectWithGroup(cx, group, TenuredObject)); - if (!clone) + if (MOZ_UNLIKELY(!clone)) return nullptr; clone->initPrivate(nullptr); - if (!EmptyShape::ensureInitialCustomShape(cx, clone)) + if (MOZ_UNLIKELY(!EmptyShape::ensureInitialCustomShape(cx, clone))) return nullptr; Rooted source(cx, regex->getSource()); // Check that the RegExpShared for |regex| is okay to reuse in the clone. RegExpStatics* currentStatics = regex->getProto()->global().getRegExpStatics(cx); - if (!currentStatics) + if (MOZ_UNLIKELY(!currentStatics)) return nullptr; RegExpFlag origFlags = regex->getFlags(); @@ -969,7 +969,7 @@ bool js::ParseRegExpFlags(JSContext* cx, JSString* flagStr, RegExpFlag* flagsOut) { JSLinearString* linear = flagStr->ensureLinear(cx); - if (!linear) + if (MOZ_UNLIKELY(!linear)) return false; size_t len = linear->length();