diff --git a/js/src/jit/BaselineCacheIRCompiler.cpp b/js/src/jit/BaselineCacheIRCompiler.cpp index 2f35bb614ddb..4aa694734eaa 100644 --- a/js/src/jit/BaselineCacheIRCompiler.cpp +++ b/js/src/jit/BaselineCacheIRCompiler.cpp @@ -164,6 +164,20 @@ BaselineCacheIRCompiler::tailCallVM(MacroAssembler& masm, const VMFunction& fun) return true; } +static size_t +GetEnteredOffset(BaselineCacheIRStubKind kind) +{ + switch (kind) { + case BaselineCacheIRStubKind::Regular: + return ICCacheIR_Regular::offsetOfEnteredCount(); + case BaselineCacheIRStubKind::Updated: + return ICCacheIR_Updated::offsetOfEnteredCount(); + case BaselineCacheIRStubKind::Monitored: + return ICCacheIR_Monitored::offsetOfEnteredCount(); + } + MOZ_CRASH("unhandled BaselineCacheIRStubKind"); +} + JitCode* BaselineCacheIRCompiler::compile() { @@ -177,10 +191,8 @@ BaselineCacheIRCompiler::compile() #endif // Count stub entries: We count entries rather than successes as it much easier to // ensure ICStubReg is valid at entry than at exit. - if (kind_ == BaselineCacheIRStubKind::Regular) { - Address enteredCount(ICStubReg, ICCacheIR_Regular::offsetOfEnteredCount()); - masm.add32(Imm32(1), enteredCount); - } + Address enteredCount(ICStubReg, GetEnteredOffset(kind_)); + masm.add32(Imm32(1), enteredCount); do { switch (reader.readOp()) { diff --git a/js/src/jit/BaselineIC.h b/js/src/jit/BaselineIC.h index 5953fe5ae28a..1f9bf2d4b8ad 100644 --- a/js/src/jit/BaselineIC.h +++ b/js/src/jit/BaselineIC.h @@ -750,9 +750,11 @@ class ICFallbackStub : public ICStub inline void incrementEnteredCount() { enteredCount_++; } }; -// Base class for Trait::Regular CacheIR stubs -class ICCacheIR_Regular : public ICStub +// Shared trait for all CacheIR stubs. +template +class ICCacheIR_Trait { + protected: const CacheIRStubInfo* stubInfo_; // Counts the number of times the stub was entered @@ -761,11 +763,29 @@ class ICCacheIR_Regular : public ICStub // becomes a concern. uint32_t enteredCount_; + public: + explicit ICCacheIR_Trait(const CacheIRStubInfo* stubInfo) + : stubInfo_(stubInfo), + enteredCount_(0) + {} + + const CacheIRStubInfo* stubInfo() const { + return stubInfo_; + } + + // Return the number of times this stub has successfully provided a value to the + // caller. + uint32_t enteredCount() const { return enteredCount_; } + static size_t offsetOfEnteredCount() { return offsetof(T, enteredCount_); } +}; + +// Base class for Trait::Regular CacheIR stubs +class ICCacheIR_Regular : public ICStub, public ICCacheIR_Trait +{ public: ICCacheIR_Regular(JitCode* stubCode, const CacheIRStubInfo* stubInfo) : ICStub(ICStub::CacheIR_Regular, stubCode), - stubInfo_(stubInfo), - enteredCount_(0) + ICCacheIR_Trait(stubInfo) {} static ICCacheIR_Regular* Clone(JSContext* cx, ICStubSpace* space, ICStub* firstMonitorStub, @@ -778,16 +798,7 @@ class ICCacheIR_Regular : public ICStub return extra_; } - const CacheIRStubInfo* stubInfo() const { - return stubInfo_; - } - uint8_t* stubDataStart(); - - // Return the number of times this stub has successfully provided a value to the - // caller. - uint32_t enteredCount() const { return enteredCount_; } - static size_t offsetOfEnteredCount() { return offsetof(ICCacheIR_Regular, enteredCount_); } }; // Monitored stubs are IC stubs that feed a single resulting value out to a @@ -820,15 +831,14 @@ class ICMonitoredStub : public ICStub } }; -class ICCacheIR_Monitored : public ICMonitoredStub +class ICCacheIR_Monitored : public ICMonitoredStub, public ICCacheIR_Trait { - const CacheIRStubInfo* stubInfo_; public: ICCacheIR_Monitored(JitCode* stubCode, ICStub* firstMonitorStub, const CacheIRStubInfo* stubInfo) : ICMonitoredStub(ICStub::CacheIR_Monitored, stubCode, firstMonitorStub), - stubInfo_(stubInfo) + ICCacheIR_Trait(stubInfo) {} static ICCacheIR_Monitored* Clone(JSContext* cx, ICStubSpace* space, ICStub* firstMonitorStub, @@ -841,10 +851,6 @@ class ICCacheIR_Monitored : public ICMonitoredStub return extra_; } - const CacheIRStubInfo* stubInfo() const { - return stubInfo_; - } - uint8_t* stubDataStart(); }; @@ -917,16 +923,15 @@ class ICUpdatedStub : public ICStub } }; -class ICCacheIR_Updated : public ICUpdatedStub +class ICCacheIR_Updated : public ICUpdatedStub, public ICCacheIR_Trait { - const CacheIRStubInfo* stubInfo_; GCPtrObjectGroup updateStubGroup_; GCPtrId updateStubId_; public: ICCacheIR_Updated(JitCode* stubCode, const CacheIRStubInfo* stubInfo) : ICUpdatedStub(ICStub::CacheIR_Updated, stubCode), - stubInfo_(stubInfo), + ICCacheIR_Trait(stubInfo), updateStubGroup_(nullptr), updateStubId_(JSID_EMPTY) {} @@ -948,10 +953,6 @@ class ICCacheIR_Updated : public ICUpdatedStub return extra_; } - const CacheIRStubInfo* stubInfo() const { - return stubInfo_; - } - uint8_t* stubDataStart(); }; diff --git a/js/src/jit/BaselineJIT.cpp b/js/src/jit/BaselineJIT.cpp index 1ce9aaff5a19..7917095e89b8 100644 --- a/js/src/jit/BaselineJIT.cpp +++ b/js/src/jit/BaselineJIT.cpp @@ -1171,11 +1171,19 @@ BaselineScript::purgeOptimizedStubs(Zone* zone) static bool GetStubEnteredCount(ICStub* stub, uint32_t* count) { - if (stub->isCacheIR_Regular()) { + switch (stub->kind()) { + case ICStub::CacheIR_Regular: *count = stub->toCacheIR_Regular()->enteredCount(); return true; + case ICStub::CacheIR_Updated: + *count = stub->toCacheIR_Updated()->enteredCount(); + return true; + case ICStub::CacheIR_Monitored: + *count = stub->toCacheIR_Monitored()->enteredCount(); + return true; + default: + return false; } - return false; } void