|
| 1 | +/* |
| 2 | + * Copyright (C) 2024 Apple Inc. All rights reserved. |
| 3 | + * |
| 4 | + * Redistribution and use in source and binary forms, with or without |
| 5 | + * modification, are permitted provided that the following conditions |
| 6 | + * are met: |
| 7 | + * 1. Redistributions of source code must retain the above copyright |
| 8 | + * notice, this list of conditions and the following disclaimer. |
| 9 | + * 2. Redistributions in binary form must reproduce the above copyright |
| 10 | + * notice, this list of conditions and the following disclaimer in the |
| 11 | + * documentation and/or other materials provided with the distribution. |
| 12 | + * |
| 13 | + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
| 14 | + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 15 | + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 | + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
| 17 | + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 18 | + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 19 | + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 20 | + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 21 | + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 | + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 23 | + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 | + */ |
| 25 | + |
| 26 | +#include "config.h" |
| 27 | +#include "AssertInvariants.h" |
| 28 | + |
| 29 | +#include "ArithProfile.h" |
| 30 | +#include "BaselineJITCode.h" |
| 31 | +#include "CodeBlock.h" |
| 32 | +#include "DFGJITCode.h" |
| 33 | + |
| 34 | +namespace JSC { |
| 35 | + |
| 36 | +void assertInvariants() |
| 37 | +{ |
| 38 | + // Assertions to match LowLevelInterpreter.asm. If you change any of this code, be |
| 39 | + // prepared to change LowLevelInterpreter.asm as well!! |
| 40 | + { |
| 41 | +#if USE(JSVALUE64) |
| 42 | + const ptrdiff_t CallFrameHeaderSlots = 5; |
| 43 | +#else // USE(JSVALUE64) // i.e. 32-bit version |
| 44 | + const ptrdiff_t CallFrameHeaderSlots = 4; |
| 45 | +#endif |
| 46 | + const ptrdiff_t MachineRegisterSize = sizeof(CPURegister); |
| 47 | + const ptrdiff_t SlotSize = 8; |
| 48 | + |
| 49 | + static_assert(sizeof(Register) == SlotSize); |
| 50 | + static_assert(CallFrame::headerSizeInRegisters == CallFrameHeaderSlots); |
| 51 | + |
| 52 | + static_assert(!CallFrame::callerFrameOffset()); |
| 53 | + static_assert(CallerFrameAndPC::sizeInRegisters == (MachineRegisterSize * 2) / SlotSize); |
| 54 | + static_assert(CallFrame::returnPCOffset() == CallFrame::callerFrameOffset() + MachineRegisterSize); |
| 55 | + static_assert(static_cast<std::underlying_type_t<CallFrameSlot>>(CallFrameSlot::codeBlock) * sizeof(Register) == CallFrame::returnPCOffset() + MachineRegisterSize); |
| 56 | + static_assert(CallFrameSlot::callee * sizeof(Register) == CallFrameSlot::codeBlock * sizeof(Register) + SlotSize); |
| 57 | + static_assert(CallFrameSlot::argumentCountIncludingThis * sizeof(Register) == CallFrameSlot::callee * sizeof(Register) + SlotSize); |
| 58 | + static_assert(CallFrameSlot::thisArgument * sizeof(Register) == CallFrameSlot::argumentCountIncludingThis * sizeof(Register) + SlotSize); |
| 59 | + static_assert(CallFrame::headerSizeInRegisters == CallFrameSlot::thisArgument); |
| 60 | + |
| 61 | + static_assert(CallFrame::argumentOffsetIncludingThis(0) == CallFrameSlot::thisArgument); |
| 62 | + |
| 63 | +#if CPU(BIG_ENDIAN) |
| 64 | + static_assert(TagOffset == 0); |
| 65 | + static_assert(PayloadOffset == 4); |
| 66 | +#else |
| 67 | + static_assert(TagOffset == 4); |
| 68 | + static_assert(PayloadOffset == 0); |
| 69 | +#endif |
| 70 | + |
| 71 | +#if ENABLE(C_LOOP) |
| 72 | + ASSERT(CodeBlock::llintBaselineCalleeSaveSpaceAsVirtualRegisters() == 1); |
| 73 | +#elif USE(JSVALUE32_64) |
| 74 | + ASSERT(CodeBlock::llintBaselineCalleeSaveSpaceAsVirtualRegisters() == 1); |
| 75 | +#elif (CPU(X86_64) && !OS(WINDOWS)) || CPU(ARM64) |
| 76 | + ASSERT(CodeBlock::llintBaselineCalleeSaveSpaceAsVirtualRegisters() == 4); |
| 77 | +#elif (CPU(X86_64) && OS(WINDOWS)) |
| 78 | + ASSERT(CodeBlock::llintBaselineCalleeSaveSpaceAsVirtualRegisters() == 4); |
| 79 | +#endif |
| 80 | + |
| 81 | + ASSERT(!(reinterpret_cast<ptrdiff_t>((reinterpret_cast<WriteBarrier<JSCell>*>(0x4000)->slot())) - 0x4000)); |
| 82 | + } |
| 83 | + |
| 84 | + // FIXME: make these assertions less horrible. |
| 85 | +#if ASSERT_ENABLED |
| 86 | + Vector<int> testVector; |
| 87 | + testVector.resize(42); |
| 88 | + ASSERT(bitwise_cast<uint32_t*>(&testVector)[sizeof(void*) / sizeof(uint32_t) + 1] == 42); |
| 89 | + ASSERT(bitwise_cast<int**>(&testVector)[0] == testVector.begin()); |
| 90 | +#endif |
| 91 | + |
| 92 | + { |
| 93 | + UnaryArithProfile arithProfile; |
| 94 | + arithProfile.argSawInt32(); |
| 95 | + ASSERT(arithProfile.bits() == UnaryArithProfile::observedIntBits()); |
| 96 | + ASSERT(arithProfile.argObservedType().isOnlyInt32()); |
| 97 | + } |
| 98 | + { |
| 99 | + UnaryArithProfile arithProfile; |
| 100 | + arithProfile.argSawNumber(); |
| 101 | + ASSERT(arithProfile.bits() == UnaryArithProfile::observedNumberBits()); |
| 102 | + ASSERT(arithProfile.argObservedType().isOnlyNumber()); |
| 103 | + } |
| 104 | + |
| 105 | + { |
| 106 | + BinaryArithProfile arithProfile; |
| 107 | + arithProfile.lhsSawInt32(); |
| 108 | + arithProfile.rhsSawInt32(); |
| 109 | + ASSERT(arithProfile.bits() == BinaryArithProfile::observedIntIntBits()); |
| 110 | + ASSERT(arithProfile.lhsObservedType().isOnlyInt32()); |
| 111 | + ASSERT(arithProfile.rhsObservedType().isOnlyInt32()); |
| 112 | + } |
| 113 | + { |
| 114 | + BinaryArithProfile arithProfile; |
| 115 | + arithProfile.lhsSawNumber(); |
| 116 | + arithProfile.rhsSawInt32(); |
| 117 | + ASSERT(arithProfile.bits() == BinaryArithProfile::observedNumberIntBits()); |
| 118 | + ASSERT(arithProfile.lhsObservedType().isOnlyNumber()); |
| 119 | + ASSERT(arithProfile.rhsObservedType().isOnlyInt32()); |
| 120 | + } |
| 121 | + { |
| 122 | + BinaryArithProfile arithProfile; |
| 123 | + arithProfile.lhsSawNumber(); |
| 124 | + arithProfile.rhsSawNumber(); |
| 125 | + ASSERT(arithProfile.bits() == BinaryArithProfile::observedNumberNumberBits()); |
| 126 | + ASSERT(arithProfile.lhsObservedType().isOnlyNumber()); |
| 127 | + ASSERT(arithProfile.rhsObservedType().isOnlyNumber()); |
| 128 | + } |
| 129 | + { |
| 130 | + BinaryArithProfile arithProfile; |
| 131 | + arithProfile.lhsSawInt32(); |
| 132 | + arithProfile.rhsSawNumber(); |
| 133 | + ASSERT(arithProfile.bits() == BinaryArithProfile::observedIntNumberBits()); |
| 134 | + ASSERT(arithProfile.lhsObservedType().isOnlyInt32()); |
| 135 | + ASSERT(arithProfile.rhsObservedType().isOnlyNumber()); |
| 136 | + } |
| 137 | + |
| 138 | +#if ENABLE(DFG_JIT) |
| 139 | + // We share the same layout for particular fields in all JITData to make our data IC assume this. |
| 140 | + static_assert(BaselineJITData::offsetOfGlobalObject() == DFG::JITData::offsetOfGlobalObject()); |
| 141 | + static_assert(BaselineJITData::offsetOfStackOffset() == DFG::JITData::offsetOfStackOffset()); |
| 142 | +#endif |
| 143 | +} |
| 144 | + |
| 145 | +} // namespace JSC |
0 commit comments