diff --git a/js/src/builtin/TypedObject.h b/js/src/builtin/TypedObject.h index 07e6ee2f2fb6..bbae61747932 100644 --- a/js/src/builtin/TypedObject.h +++ b/js/src/builtin/TypedObject.h @@ -333,7 +333,8 @@ class SimdTypeDescr : public ComplexTypeDescr enum Type { TYPE_INT32 = JS_SIMDTYPEREPR_INT32, TYPE_FLOAT32 = JS_SIMDTYPEREPR_FLOAT32, - TYPE_FLOAT64 = JS_SIMDTYPEREPR_FLOAT64 + TYPE_FLOAT64 = JS_SIMDTYPEREPR_FLOAT64, + LAST_TYPE = TYPE_FLOAT64 }; static const type::Kind Kind = type::Simd; diff --git a/js/src/jit/BaselineIC.cpp b/js/src/jit/BaselineIC.cpp index d5f9c52b778b..cb85866cb8c5 100644 --- a/js/src/jit/BaselineIC.cpp +++ b/js/src/jit/BaselineIC.cpp @@ -9167,17 +9167,13 @@ GetTemplateObjectForNative(JSContext *cx, HandleScript script, jsbytecode *pc, if (native == js_String) { RootedString emptyString(cx, cx->runtime()->emptyString); res.set(StringObject::create(cx, emptyString, TenuredObject)); - if (!res) - return false; - return true; + return !!res; } if (native == obj_create && args.length() == 1 && args[0].isObjectOrNull()) { RootedObject proto(cx, args[0].toObjectOrNull()); res.set(ObjectCreateImpl(cx, proto, TenuredObject)); - if (!res) - return false; - return true; + return !!res; } if (JitSupportsSimd()) { @@ -9186,11 +9182,9 @@ GetTemplateObjectForNative(JSContext *cx, HandleScript script, jsbytecode *pc, ARITH_COMMONX4_SIMD_OP(ADD_INT32X4_SIMD_OP_NAME_) BITWISE_COMMONX4_SIMD_OP(ADD_INT32X4_SIMD_OP_NAME_)) { - Rooted descr(cx, &Int32x4::GetTypeDescr(*cx->global())); - res.set(TypedObject::createZeroed(cx, descr, 0, gc::TenuredHeap)); - if (!res) - return false; - return true; + Rooted descr(cx, &cx->global()->int32x4TypeDescr().as()); + res.set(cx->compartment()->jitCompartment()->getSimdTemplateObjectFor(cx, descr)); + return !!res; } #undef ADD_INT32X4_SIMD_OP_NAME_ } @@ -9204,20 +9198,14 @@ GetTemplateObjectForClassHook(JSContext *cx, JSNative hook, CallArgs &args, { if (hook == TypedObject::construct) { Rooted descr(cx, &args.callee().as()); - JSObject *obj = TypedObject::createZeroed(cx, descr, 1, gc::TenuredHeap); - if (!obj) - return false; - templateObject.set(obj); - return true; + templateObject.set(TypedObject::createZeroed(cx, descr, 1, gc::TenuredHeap)); + return !!templateObject; } if (hook == SimdTypeDescr::call && JitSupportsSimd()) { Rooted descr(cx, &args.callee().as()); - JSObject *obj = TypedObject::createZeroed(cx, descr, 0, gc::TenuredHeap); - if (!obj) - return false; - templateObject.set(obj); - return true; + templateObject.set(cx->compartment()->jitCompartment()->getSimdTemplateObjectFor(cx, descr)); + return !!templateObject; } return true; diff --git a/js/src/jit/Ion.cpp b/js/src/jit/Ion.cpp index 6e88cc4a915d..76f39e751566 100644 --- a/js/src/jit/Ion.cpp +++ b/js/src/jit/Ion.cpp @@ -533,6 +533,12 @@ JitCompartment::sweep(FreeOp *fop, JSCompartment *compartment) if (regExpTestStub_ && !IsJitCodeMarked(®ExpTestStub_)) regExpTestStub_ = nullptr; + + for (size_t i = 0; i <= SimdTypeDescr::LAST_TYPE; i++) { + ReadBarrieredObject &obj = simdTemplateObjects_[i]; + if (obj && IsObjectAboutToBeFinalized(obj.unsafeGet())) + obj.set(nullptr); + } } void diff --git a/js/src/jit/JitCompartment.h b/js/src/jit/JitCompartment.h index 49805d45039a..9521a39a6ae3 100644 --- a/js/src/jit/JitCompartment.h +++ b/js/src/jit/JitCompartment.h @@ -7,10 +7,12 @@ #ifndef jit_JitCompartment_h #define jit_JitCompartment_h +#include "mozilla/Array.h" #include "mozilla/MemoryReporting.h" #include "jsweakcache.h" +#include "builtin/TypedObject.h" #include "jit/CompileInfo.h" #include "jit/IonCode.h" #include "jit/JitFrames.h" @@ -433,11 +435,19 @@ class JitCompartment JitCode *regExpExecStub_; JitCode *regExpTestStub_; + mozilla::Array simdTemplateObjects_; + JitCode *generateStringConcatStub(JSContext *cx); JitCode *generateRegExpExecStub(JSContext *cx); JitCode *generateRegExpTestStub(JSContext *cx); public: + JSObject *getSimdTemplateObjectFor(JSContext *cx, Handle descr) { + ReadBarrieredObject &tpl = simdTemplateObjects_[descr->type()]; + if (!tpl) + tpl.set(TypedObject::createZeroed(cx, descr, 0, gc::TenuredHeap)); + return tpl.get(); + } JitCode *getStubCode(uint32_t key) { ICStubCodeMap::AddPtr p = stubCodes_->lookupForAdd(key); if (p) diff --git a/js/src/jit/MIR.h b/js/src/jit/MIR.h index a36c40a1b0e5..0623cabec8d6 100644 --- a/js/src/jit/MIR.h +++ b/js/src/jit/MIR.h @@ -3012,8 +3012,6 @@ class MSimdBox bool congruentTo(const MDefinition *ins) const MOZ_OVERRIDE { if (congruentIfOperandsEqual(ins)) { MOZ_ASSERT(ins->toSimdBox()->initialHeap() == initialHeap()); - // The template object is likely to be different, but represents the - // same kind of objects as the MIRTypes are identical. return true; }