]> git.saurik.com Git - apple/javascriptcore.git/blame - llint/LLIntData.cpp
JavaScriptCore-7601.1.46.3.tar.gz
[apple/javascriptcore.git] / llint / LLIntData.cpp
CommitLineData
6fe7ccc8
A
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"
6fe7ccc8
A
28#include "BytecodeConventions.h"
29#include "CodeType.h"
30#include "Instruction.h"
81345200 31#include "JSScope.h"
93a37866 32#include "LLIntCLoop.h"
81345200 33#include "MaxFrameExtentForSlowPathCall.h"
6fe7ccc8 34#include "Opcode.h"
81345200 35#include "PropertyOffset.h"
6fe7ccc8
A
36
37namespace JSC { namespace LLInt {
38
93a37866 39Instruction* Data::s_exceptionInstructions = 0;
81345200
A
40Opcode Data::s_opcodeMap[numOpcodeIDs] = { };
41
42#if ENABLE(JIT)
43extern "C" void llint_entry(void*);
44#endif
93a37866
A
45
46void initialize()
6fe7ccc8 47{
93a37866 48 Data::s_exceptionInstructions = new Instruction[maxOpcodeLength + 1];
93a37866 49
81345200 50#if !ENABLE(JIT)
93a37866
A
51 CLoop::initialize();
52
81345200
A
53#else // ENABLE(JIT)
54 llint_entry(&Data::s_opcodeMap);
55
6fe7ccc8 56 for (int i = 0; i < maxOpcodeLength + 1; ++i)
93a37866
A
57 Data::s_exceptionInstructions[i].u.pointer =
58 LLInt::getCodePtr(llint_throw_from_slow_path_trampoline);
81345200 59#endif // ENABLE(JIT)
6fe7ccc8
A
60}
61
62#if COMPILER(CLANG)
63#pragma clang diagnostic push
64#pragma clang diagnostic ignored "-Wmissing-noreturn"
65#endif
93a37866 66void Data::performAssertions(VM& vm)
6fe7ccc8 67{
93a37866 68 UNUSED_PARAM(vm);
6fe7ccc8
A
69
70 // Assertions to match LowLevelInterpreter.asm. If you change any of this code, be
71 // prepared to change LowLevelInterpreter.asm as well!!
81345200
A
72
73#ifndef NDEBUG
74#if USE(JSVALUE64)
75 const ptrdiff_t PtrSize = 8;
ed1e77d3 76 const ptrdiff_t CallFrameHeaderSlots = 5;
81345200
A
77#else // USE(JSVALUE64) // i.e. 32-bit version
78 const ptrdiff_t PtrSize = 4;
ed1e77d3 79 const ptrdiff_t CallFrameHeaderSlots = 4;
81345200
A
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);
ed1e77d3 92 ASSERT(JSStack::Callee * sizeof(Register) == JSStack::CodeBlock * sizeof(Register) + SlotSize);
81345200
A
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);
96
97 ASSERT(CallFrame::argumentOffsetIncludingThis(0) == JSStack::ThisArgument);
98
6fe7ccc8
A
99#if CPU(BIG_ENDIAN)
100 ASSERT(OBJECT_OFFSETOF(EncodedValueDescriptor, asBits.tag) == 0);
101 ASSERT(OBJECT_OFFSETOF(EncodedValueDescriptor, asBits.payload) == 4);
102#else
103 ASSERT(OBJECT_OFFSETOF(EncodedValueDescriptor, asBits.tag) == 4);
104 ASSERT(OBJECT_OFFSETOF(EncodedValueDescriptor, asBits.payload) == 0);
105#endif
106#if USE(JSVALUE32_64)
93a37866
A
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));
6fe7ccc8
A
115#else
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);
81345200
A
124#endif
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);
6fe7ccc8 133#endif
ed1e77d3 134 ASSERT(StringType == 6);
81345200
A
135 ASSERT(ObjectType == 18);
136 ASSERT(FinalObjectType == 19);
6fe7ccc8
A
137 ASSERT(MasqueradesAsUndefined == 1);
138 ASSERT(ImplementsHasInstance == 2);
139 ASSERT(ImplementsDefaultHasInstance == 8);
6fe7ccc8
A
140 ASSERT(FirstConstantRegisterIndex == 0x40000000);
141 ASSERT(GlobalCode == 0);
142 ASSERT(EvalCode == 1);
143 ASSERT(FunctionCode == 2);
81345200 144
ed1e77d3
A
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");
6fe7ccc8 153
81345200
A
154 ASSERT(ResolveModeAndType::mask == 0xffff);
155
ed1e77d3 156 ASSERT(MarkedBlock::blockMask == ~static_cast<decltype(MarkedBlock::blockMask)>(0x3fff));
81345200 157
6fe7ccc8
A
158 // FIXME: make these assertions less horrible.
159#if !ASSERT_DISABLED
160 Vector<int> testVector;
161 testVector.resize(42);
93a37866
A
162 ASSERT(bitwise_cast<uint32_t*>(&testVector)[sizeof(void*)/sizeof(uint32_t) + 1] == 42);
163 ASSERT(bitwise_cast<int**>(&testVector)[0] == testVector.begin());
6fe7ccc8
A
164#endif
165
ed1e77d3 166 ASSERT(StringImpl::s_hashFlag8BitBuffer == 8);
6fe7ccc8
A
167}
168#if COMPILER(CLANG)
169#pragma clang diagnostic pop
170#endif
171
6fe7ccc8 172} } // namespace JSC::LLInt