2 * Copyright (C) 2011 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
27 #include "LLIntData.h"
28 #include "BytecodeConventions.h"
30 #include "Instruction.h"
32 #include "LLIntCLoop.h"
33 #include "MaxFrameExtentForSlowPathCall.h"
35 #include "PropertyOffset.h"
37 namespace JSC
{ namespace LLInt
{
39 Instruction
* Data::s_exceptionInstructions
= 0;
40 Opcode
Data::s_opcodeMap
[numOpcodeIDs
] = { };
43 extern "C" void llint_entry(void*);
48 Data::s_exceptionInstructions
= new Instruction
[maxOpcodeLength
+ 1];
54 llint_entry(&Data::s_opcodeMap
);
56 for (int i
= 0; i
< maxOpcodeLength
+ 1; ++i
)
57 Data::s_exceptionInstructions
[i
].u
.pointer
=
58 LLInt::getCodePtr(llint_throw_from_slow_path_trampoline
);
63 #pragma clang diagnostic push
64 #pragma clang diagnostic ignored "-Wmissing-noreturn"
66 void Data::performAssertions(VM
& vm
)
70 // Assertions to match LowLevelInterpreter.asm. If you change any of this code, be
71 // prepared to change LowLevelInterpreter.asm as well!!
75 const ptrdiff_t PtrSize
= 8;
76 const ptrdiff_t CallFrameHeaderSlots
= 5;
77 #else // USE(JSVALUE64) // i.e. 32-bit version
78 const ptrdiff_t PtrSize
= 4;
79 const ptrdiff_t CallFrameHeaderSlots
= 4;
81 const ptrdiff_t SlotSize
= 8;
84 ASSERT(sizeof(void*) == PtrSize
);
85 ASSERT(sizeof(Register
) == SlotSize
);
86 ASSERT(JSStack::CallFrameHeaderSize
== CallFrameHeaderSlots
);
88 ASSERT(!CallFrame::callerFrameOffset());
89 ASSERT(JSStack::CallerFrameAndPCSize
== (PtrSize
* 2) / SlotSize
);
90 ASSERT(CallFrame::returnPCOffset() == CallFrame::callerFrameOffset() + PtrSize
);
91 ASSERT(JSStack::CodeBlock
* sizeof(Register
) == CallFrame::returnPCOffset() + PtrSize
);
92 ASSERT(JSStack::Callee
* sizeof(Register
) == JSStack::CodeBlock
* sizeof(Register
) + SlotSize
);
93 ASSERT(JSStack::ArgumentCount
* sizeof(Register
) == JSStack::Callee
* sizeof(Register
) + SlotSize
);
94 ASSERT(JSStack::ThisArgument
* sizeof(Register
) == JSStack::ArgumentCount
* sizeof(Register
) + SlotSize
);
95 ASSERT(JSStack::CallFrameHeaderSize
== JSStack::ThisArgument
);
97 ASSERT(CallFrame::argumentOffsetIncludingThis(0) == JSStack::ThisArgument
);
100 ASSERT(OBJECT_OFFSETOF(EncodedValueDescriptor
, asBits
.tag
) == 0);
101 ASSERT(OBJECT_OFFSETOF(EncodedValueDescriptor
, asBits
.payload
) == 4);
103 ASSERT(OBJECT_OFFSETOF(EncodedValueDescriptor
, asBits
.tag
) == 4);
104 ASSERT(OBJECT_OFFSETOF(EncodedValueDescriptor
, asBits
.payload
) == 0);
106 #if USE(JSVALUE32_64)
107 ASSERT(JSValue::Int32Tag
== static_cast<unsigned>(-1));
108 ASSERT(JSValue::BooleanTag
== static_cast<unsigned>(-2));
109 ASSERT(JSValue::NullTag
== static_cast<unsigned>(-3));
110 ASSERT(JSValue::UndefinedTag
== static_cast<unsigned>(-4));
111 ASSERT(JSValue::CellTag
== static_cast<unsigned>(-5));
112 ASSERT(JSValue::EmptyValueTag
== static_cast<unsigned>(-6));
113 ASSERT(JSValue::DeletedValueTag
== static_cast<unsigned>(-7));
114 ASSERT(JSValue::LowestTag
== static_cast<unsigned>(-7));
116 ASSERT(TagBitTypeOther
== 0x2);
117 ASSERT(TagBitBool
== 0x4);
118 ASSERT(TagBitUndefined
== 0x8);
119 ASSERT(ValueEmpty
== 0x0);
120 ASSERT(ValueFalse
== (TagBitTypeOther
| TagBitBool
));
121 ASSERT(ValueTrue
== (TagBitTypeOther
| TagBitBool
| 1));
122 ASSERT(ValueUndefined
== (TagBitTypeOther
| TagBitUndefined
));
123 ASSERT(ValueNull
== TagBitTypeOther
);
125 #if (CPU(X86_64) && !OS(WINDOWS)) || CPU(ARM64) || !ENABLE(JIT)
126 ASSERT(!maxFrameExtentForSlowPathCall
);
127 #elif CPU(ARM) || CPU(SH4)
128 ASSERT(maxFrameExtentForSlowPathCall
== 24);
129 #elif CPU(X86) || CPU(MIPS)
130 ASSERT(maxFrameExtentForSlowPathCall
== 40);
131 #elif CPU(X86_64) && OS(WINDOWS)
132 ASSERT(maxFrameExtentForSlowPathCall
== 64);
134 ASSERT(StringType
== 6);
135 ASSERT(ObjectType
== 18);
136 ASSERT(FinalObjectType
== 19);
137 ASSERT(MasqueradesAsUndefined
== 1);
138 ASSERT(ImplementsHasInstance
== 2);
139 ASSERT(ImplementsDefaultHasInstance
== 8);
140 ASSERT(FirstConstantRegisterIndex
== 0x40000000);
141 ASSERT(GlobalCode
== 0);
142 ASSERT(EvalCode
== 1);
143 ASSERT(FunctionCode
== 2);
145 static_assert(GlobalProperty
== 0, "LLInt assumes GlobalProperty ResultType is == 0");
146 static_assert(GlobalVar
== 1, "LLInt assumes GlobalVar ResultType is == 1");
147 static_assert(ClosureVar
== 2, "LLInt assumes ClosureVar ResultType is == 2");
148 static_assert(LocalClosureVar
== 3, "LLInt assumes LocalClosureVar ResultType is == 3");
149 static_assert(GlobalPropertyWithVarInjectionChecks
== 4, "LLInt assumes GlobalPropertyWithVarInjectionChecks ResultType is == 4");
150 static_assert(GlobalVarWithVarInjectionChecks
== 5, "LLInt assumes GlobalVarWithVarInjectionChecks ResultType is == 5");
151 static_assert(ClosureVarWithVarInjectionChecks
== 6, "LLInt assumes ClosureVarWithVarInjectionChecks ResultType is == 6");
152 static_assert(Dynamic
== 7, "LLInt assumes Dynamic ResultType is == 7");
154 ASSERT(ResolveModeAndType::mask
== 0xffff);
156 ASSERT(MarkedBlock::blockMask
== ~static_cast<decltype(MarkedBlock::blockMask
)>(0x3fff));
158 // FIXME: make these assertions less horrible.
160 Vector
<int> testVector
;
161 testVector
.resize(42);
162 ASSERT(bitwise_cast
<uint32_t*>(&testVector
)[sizeof(void*)/sizeof(uint32_t) + 1] == 42);
163 ASSERT(bitwise_cast
<int**>(&testVector
)[0] == testVector
.begin());
166 ASSERT(StringImpl::s_hashFlag8BitBuffer
== 8);
169 #pragma clang diagnostic pop
172 } } // namespace JSC::LLInt