]> git.saurik.com Git - apple/javascriptcore.git/blob - llint/LLIntData.cpp
JavaScriptCore-7600.1.4.16.1.tar.gz
[apple/javascriptcore.git] / llint / LLIntData.cpp
1 /*
2 * Copyright (C) 2011 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 "LLIntData.h"
28 #include "BytecodeConventions.h"
29 #include "CodeType.h"
30 #include "Instruction.h"
31 #include "JSScope.h"
32 #include "LLIntCLoop.h"
33 #include "MaxFrameExtentForSlowPathCall.h"
34 #include "Opcode.h"
35 #include "PropertyOffset.h"
36
37 namespace JSC { namespace LLInt {
38
39 Instruction* Data::s_exceptionInstructions = 0;
40 Opcode Data::s_opcodeMap[numOpcodeIDs] = { };
41
42 #if ENABLE(JIT)
43 extern "C" void llint_entry(void*);
44 #endif
45
46 void initialize()
47 {
48 Data::s_exceptionInstructions = new Instruction[maxOpcodeLength + 1];
49
50 #if !ENABLE(JIT)
51 CLoop::initialize();
52
53 #else // ENABLE(JIT)
54 llint_entry(&Data::s_opcodeMap);
55
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);
59 #endif // ENABLE(JIT)
60 }
61
62 #if COMPILER(CLANG)
63 #pragma clang diagnostic push
64 #pragma clang diagnostic ignored "-Wmissing-noreturn"
65 #endif
66 void Data::performAssertions(VM& vm)
67 {
68 UNUSED_PARAM(vm);
69
70 // Assertions to match LowLevelInterpreter.asm. If you change any of this code, be
71 // prepared to change LowLevelInterpreter.asm as well!!
72
73 #ifndef NDEBUG
74 #if USE(JSVALUE64)
75 const ptrdiff_t PtrSize = 8;
76 const ptrdiff_t CallFrameHeaderSlots = 6;
77 #else // USE(JSVALUE64) // i.e. 32-bit version
78 const ptrdiff_t PtrSize = 4;
79 const ptrdiff_t CallFrameHeaderSlots = 5;
80 #endif
81 const ptrdiff_t SlotSize = 8;
82 #endif
83
84 ASSERT(sizeof(void*) == PtrSize);
85 ASSERT(sizeof(Register) == SlotSize);
86 ASSERT(JSStack::CallFrameHeaderSize == CallFrameHeaderSlots);
87
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::ScopeChain * sizeof(Register) == JSStack::CodeBlock * sizeof(Register) + SlotSize);
93 ASSERT(JSStack::Callee * sizeof(Register) == JSStack::ScopeChain * sizeof(Register) + SlotSize);
94 ASSERT(JSStack::ArgumentCount * sizeof(Register) == JSStack::Callee * sizeof(Register) + SlotSize);
95 ASSERT(JSStack::ThisArgument * sizeof(Register) == JSStack::ArgumentCount * sizeof(Register) + SlotSize);
96 ASSERT(JSStack::CallFrameHeaderSize == JSStack::ThisArgument);
97
98 ASSERT(CallFrame::argumentOffsetIncludingThis(0) == JSStack::ThisArgument);
99
100 #if CPU(BIG_ENDIAN)
101 ASSERT(OBJECT_OFFSETOF(EncodedValueDescriptor, asBits.tag) == 0);
102 ASSERT(OBJECT_OFFSETOF(EncodedValueDescriptor, asBits.payload) == 4);
103 #else
104 ASSERT(OBJECT_OFFSETOF(EncodedValueDescriptor, asBits.tag) == 4);
105 ASSERT(OBJECT_OFFSETOF(EncodedValueDescriptor, asBits.payload) == 0);
106 #endif
107 #if USE(JSVALUE32_64)
108 ASSERT(JSValue::Int32Tag == static_cast<unsigned>(-1));
109 ASSERT(JSValue::BooleanTag == static_cast<unsigned>(-2));
110 ASSERT(JSValue::NullTag == static_cast<unsigned>(-3));
111 ASSERT(JSValue::UndefinedTag == static_cast<unsigned>(-4));
112 ASSERT(JSValue::CellTag == static_cast<unsigned>(-5));
113 ASSERT(JSValue::EmptyValueTag == static_cast<unsigned>(-6));
114 ASSERT(JSValue::DeletedValueTag == static_cast<unsigned>(-7));
115 ASSERT(JSValue::LowestTag == static_cast<unsigned>(-7));
116 #else
117 ASSERT(TagBitTypeOther == 0x2);
118 ASSERT(TagBitBool == 0x4);
119 ASSERT(TagBitUndefined == 0x8);
120 ASSERT(ValueEmpty == 0x0);
121 ASSERT(ValueFalse == (TagBitTypeOther | TagBitBool));
122 ASSERT(ValueTrue == (TagBitTypeOther | TagBitBool | 1));
123 ASSERT(ValueUndefined == (TagBitTypeOther | TagBitUndefined));
124 ASSERT(ValueNull == TagBitTypeOther);
125 #endif
126 #if (CPU(X86_64) && !OS(WINDOWS)) || CPU(ARM64) || !ENABLE(JIT)
127 ASSERT(!maxFrameExtentForSlowPathCall);
128 #elif CPU(ARM) || CPU(SH4)
129 ASSERT(maxFrameExtentForSlowPathCall == 24);
130 #elif CPU(X86) || CPU(MIPS)
131 ASSERT(maxFrameExtentForSlowPathCall == 40);
132 #elif CPU(X86_64) && OS(WINDOWS)
133 ASSERT(maxFrameExtentForSlowPathCall == 64);
134 #endif
135 ASSERT(StringType == 5);
136 ASSERT(ObjectType == 18);
137 ASSERT(FinalObjectType == 19);
138 ASSERT(MasqueradesAsUndefined == 1);
139 ASSERT(ImplementsHasInstance == 2);
140 ASSERT(ImplementsDefaultHasInstance == 8);
141 ASSERT(FirstConstantRegisterIndex == 0x40000000);
142 ASSERT(GlobalCode == 0);
143 ASSERT(EvalCode == 1);
144 ASSERT(FunctionCode == 2);
145
146 ASSERT(GlobalProperty == 0);
147 ASSERT(GlobalVar == 1);
148 ASSERT(ClosureVar == 2);
149 ASSERT(GlobalPropertyWithVarInjectionChecks == 3);
150 ASSERT(GlobalVarWithVarInjectionChecks == 4);
151 ASSERT(ClosureVarWithVarInjectionChecks == 5);
152 ASSERT(Dynamic == 6);
153
154 ASSERT(ResolveModeAndType::mask == 0xffff);
155
156 ASSERT(MarkedBlock::blockMask == ~static_cast<decltype(MarkedBlock::blockMask)>(0xffff));
157
158 // FIXME: make these assertions less horrible.
159 #if !ASSERT_DISABLED
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());
164 #endif
165
166 ASSERT(StringImpl::s_hashFlag8BitBuffer == 32);
167 }
168 #if COMPILER(CLANG)
169 #pragma clang diagnostic pop
170 #endif
171
172 } } // namespace JSC::LLInt