diff --git a/Source/JavaScriptCore/bytecode/CodeOrigin.h b/Source/JavaScriptCore/bytecode/CodeOrigin.h index 804d3516469..200bbcdf43f 100644 --- a/Source/JavaScriptCore/bytecode/CodeOrigin.h +++ b/Source/JavaScriptCore/bytecode/CodeOrigin.h @@ -20,7 +20,7 @@ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #pragma once @@ -31,6 +31,8 @@ #include #include +#define USE_COMPRESSED_CODE_ORIGIN CPU(ARM64) || CPU(X86_64) + namespace JSC { class CodeBlock; @@ -40,7 +42,7 @@ struct InlineCallFrame; class CodeOrigin { public: CodeOrigin() -#if CPU(ADDRESS64) +#if USE(COMPRESSED_CODE_ORIGIN) : m_compositeValue(buildCompositeValue(nullptr, s_invalidBytecodeIndex)) #else : m_bytecodeIndex(s_invalidBytecodeIndex) @@ -48,9 +50,9 @@ public: #endif { } - + CodeOrigin(WTF::HashTableDeletedValueType) -#if CPU(ADDRESS64) +#if USE(COMPRESSED_CODE_ORIGIN) : m_compositeValue(buildCompositeValue(deletedMarker(), s_invalidBytecodeIndex)) #else : m_bytecodeIndex(s_invalidBytecodeIndex) @@ -58,9 +60,9 @@ public: #endif { } - + explicit CodeOrigin(unsigned bytecodeIndex, InlineCallFrame* inlineCallFrame = nullptr) -#if CPU(ADDRESS64) +#if USE(COMPRESSED_CODE_ORIGIN) : m_compositeValue(buildCompositeValue(inlineCallFrame, bytecodeIndex)) #else : m_bytecodeIndex(bytecodeIndex) @@ -68,18 +70,18 @@ public: #endif { ASSERT(bytecodeIndex < s_invalidBytecodeIndex); -#if CPU(ADDRESS64) +#if USE(COMPRESSED_CODE_ORIGIN) ASSERT(!(bitwise_cast(inlineCallFrame) & ~s_maskCompositeValueForPointer)); #endif } - -#if CPU(ADDRESS64) + +#if USE(COMPRESSED_CODE_ORIGIN) CodeOrigin& operator=(const CodeOrigin& other) { if (this != &other) { if (UNLIKELY(isOutOfLine())) delete outOfLineCodeOrigin(); - + if (UNLIKELY(other.isOutOfLine())) m_compositeValue = buildCompositeValue(other.inlineCallFrame(), other.bytecodeIndex()); else @@ -118,58 +120,58 @@ public: delete outOfLineCodeOrigin(); } #endif - + bool isSet() const { -#if CPU(ADDRESS64) +#if USE(COMPRESSED_CODE_ORIGIN) return !(m_compositeValue & s_maskIsBytecodeIndexInvalid); #else return m_bytecodeIndex != s_invalidBytecodeIndex; #endif } explicit operator bool() const { return isSet(); } - + bool isHashTableDeletedValue() const { -#if CPU(ADDRESS64) +#if USE(COMPRESSED_CODE_ORIGIN) return !isSet() && (m_compositeValue & s_maskCompositeValueForPointer); #else return m_bytecodeIndex == s_invalidBytecodeIndex && !!m_inlineCallFrame; #endif } - + // The inline depth is the depth of the inline stack, so 1 = not inlined, // 2 = inlined one deep, etc. unsigned inlineDepth() const; - + // If the code origin corresponds to inlined code, gives you the heap object that // would have owned the code if it had not been inlined. Otherwise returns 0. CodeBlock* codeOriginOwner() const; - + int stackOffset() const; - + unsigned hash() const; bool operator==(const CodeOrigin& other) const; bool operator!=(const CodeOrigin& other) const { return !(*this == other); } - + // This checks if the two code origins correspond to the same stack trace snippets, // but ignore whether the InlineCallFrame's are identical. bool isApproximatelyEqualTo(const CodeOrigin& other, InlineCallFrame* terminal = nullptr) const; - + unsigned approximateHash(InlineCallFrame* terminal = nullptr) const; template void walkUpInlineStack(const Function&); - + // Get the inline stack. This is slow, and is intended for debugging only. Vector inlineStack() const; - + JS_EXPORT_PRIVATE void dump(PrintStream&) const; void dumpInContext(PrintStream&, DumpContext*) const; unsigned bytecodeIndex() const { -#if CPU(ADDRESS64) +#if USE(COMPRESSED_CODE_ORIGIN) if (!isSet()) return s_invalidBytecodeIndex; if (UNLIKELY(isOutOfLine())) @@ -182,7 +184,7 @@ public: InlineCallFrame* inlineCallFrame() const { -#if CPU(ADDRESS64) +#if USE(COMPRESSED_CODE_ORIGIN) if (UNLIKELY(isOutOfLine())) return outOfLineCodeOrigin()->inlineCallFrame; return bitwise_cast(m_compositeValue & s_maskCompositeValueForPointer); @@ -194,7 +196,7 @@ public: private: static constexpr unsigned s_invalidBytecodeIndex = UINT_MAX; -#if CPU(ADDRESS64) +#if USE(COMPRESSED_CODE_ORIGIN) static constexpr uintptr_t s_maskIsOutOfLine = 1; static constexpr uintptr_t s_maskIsBytecodeIndexInvalid = 2; @@ -203,14 +205,14 @@ private: public: InlineCallFrame* inlineCallFrame; unsigned bytecodeIndex; - + OutOfLineCodeOrigin(InlineCallFrame* inlineCallFrame, unsigned bytecodeIndex) : inlineCallFrame(inlineCallFrame) , bytecodeIndex(bytecodeIndex) { } }; - + bool isOutOfLine() const { return m_compositeValue & s_maskIsOutOfLine; @@ -225,21 +227,22 @@ private: static InlineCallFrame* deletedMarker() { auto value = static_cast(1 << 3); -#if CPU(ADDRESS64) +#if USE(COMPRESSED_CODE_ORIGIN) ASSERT(value & s_maskCompositeValueForPointer); ASSERT(!(value & ~s_maskCompositeValueForPointer)); #endif return bitwise_cast(value); } -#if CPU(X86_64) && CPU(ADDRESS64) +#if USE(COMPRESSED_CODE_ORIGIN) +#if CPU(X86_64) static constexpr unsigned s_freeBitsAtTop = 16; static constexpr uintptr_t s_maskCompositeValueForPointer = 0x0000fffffffffff8; -#elif CPU(ARM64) && CPU(ADDRESS64) +#elif CPU(ARM64) static constexpr unsigned s_freeBitsAtTop = 28; static constexpr uintptr_t s_maskCompositeValueForPointer = 0x0000000ffffffff8; -#endif -#if CPU(ADDRESS64) +#endif // CPU(X86_64) + static uintptr_t buildCompositeValue(InlineCallFrame* inlineCallFrame, unsigned bytecodeIndex) { if (bytecodeIndex == s_invalidBytecodeIndex) @@ -276,7 +279,7 @@ inline unsigned CodeOrigin::hash() const inline bool CodeOrigin::operator==(const CodeOrigin& other) const { -#if CPU(ADDRESS64) +#if USE(COMPRESSED_CODE_ORIGIN) if (m_compositeValue == other.m_compositeValue) return true; #endif