mrowe@apple.com | f88a463 | 2008-09-07 05:44:58 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 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 | #ifndef CTI_h |
| 27 | #define CTI_h |
| 28 | |
| 29 | #if ENABLE(CTI) |
| 30 | |
barraclough@apple.com | 71500d5 | 2008-09-15 02:18:13 +0000 | [diff] [blame] | 31 | #define WTF_USE_CTI_REPATCH_PIC 1 |
| 32 | |
alp@webkit.org | 7e2b6cd | 2008-10-10 00:50:25 +0000 | [diff] [blame] | 33 | #include "Machine.h" |
mrowe@apple.com | f88a463 | 2008-09-07 05:44:58 +0000 | [diff] [blame] | 34 | #include "Opcode.h" |
mrowe@apple.com | f88a463 | 2008-09-07 05:44:58 +0000 | [diff] [blame] | 35 | #include "RegisterFile.h" |
cwzwarich@webkit.org | 8a33457 | 2008-09-10 03:22:04 +0000 | [diff] [blame] | 36 | #include <masm/X86Assembler.h> |
mrowe@apple.com | f88a463 | 2008-09-07 05:44:58 +0000 | [diff] [blame] | 37 | #include <profiler/Profiler.h> |
| 38 | #include <wtf/AlwaysInline.h> |
| 39 | #include <wtf/Vector.h> |
| 40 | |
mrowe@apple.com | f88a463 | 2008-09-07 05:44:58 +0000 | [diff] [blame] | 41 | #define CTI_ARGS_code 0x0C |
darin@apple.com | d3f4640 | 2008-10-04 21:12:54 +0000 | [diff] [blame] | 42 | #define CTI_ARGS_registerFile 0x0D |
darin@apple.com | 8c2bac0 | 2008-10-09 00:40:43 +0000 | [diff] [blame] | 43 | #define CTI_ARGS_callFrame 0x0E |
darin@apple.com | d3f4640 | 2008-10-04 21:12:54 +0000 | [diff] [blame] | 44 | #define CTI_ARGS_exception 0x0F |
| 45 | #define CTI_ARGS_profilerReference 0x10 |
| 46 | #define CTI_ARGS_globalData 0x11 |
mjs@apple.com | 36f4f42 | 2008-10-15 02:39:52 +0000 | [diff] [blame] | 47 | #define ARG_callFrame ((CallFrame*)(ARGS)[CTI_ARGS_callFrame]) |
mjs@apple.com | 0d68a33 | 2008-10-17 09:06:42 +0000 | [diff] [blame^] | 48 | #define ARG_registerFile ((RegisterFile*)(ARGS)[CTI_ARGS_registerFile]) |
mjs@apple.com | 36f4f42 | 2008-10-15 02:39:52 +0000 | [diff] [blame] | 49 | #define ARG_exception ((JSValue**)(ARGS)[CTI_ARGS_exception]) |
| 50 | #define ARG_profilerReference ((Profiler**)(ARGS)[CTI_ARGS_profilerReference]) |
| 51 | #define ARG_globalData ((JSGlobalData*)(ARGS)[CTI_ARGS_globalData]) |
mrowe@apple.com | f88a463 | 2008-09-07 05:44:58 +0000 | [diff] [blame] | 52 | |
mjs@apple.com | 36f4f42 | 2008-10-15 02:39:52 +0000 | [diff] [blame] | 53 | #define ARG_setCallFrame(newCallFrame) (*(CallFrame**)&(ARGS)[CTI_ARGS_callFrame] = (newCallFrame)) |
mrowe@apple.com | f88a463 | 2008-09-07 05:44:58 +0000 | [diff] [blame] | 54 | |
mjs@apple.com | 36f4f42 | 2008-10-15 02:39:52 +0000 | [diff] [blame] | 55 | #define ARG_src1 ((JSValue*)((ARGS)[1])) |
| 56 | #define ARG_src2 ((JSValue*)((ARGS)[2])) |
| 57 | #define ARG_src3 ((JSValue*)((ARGS)[3])) |
| 58 | #define ARG_src4 ((JSValue*)((ARGS)[4])) |
| 59 | #define ARG_src5 ((JSValue*)((ARGS)[5])) |
| 60 | #define ARG_id1 ((Identifier*)((ARGS)[1])) |
| 61 | #define ARG_id2 ((Identifier*)((ARGS)[2])) |
| 62 | #define ARG_id3 ((Identifier*)((ARGS)[3])) |
| 63 | #define ARG_id4 ((Identifier*)((ARGS)[4])) |
| 64 | #define ARG_int1 ((int)((ARGS)[1])) |
| 65 | #define ARG_int2 ((int)((ARGS)[2])) |
| 66 | #define ARG_int3 ((int)((ARGS)[3])) |
| 67 | #define ARG_int4 ((int)((ARGS)[4])) |
| 68 | #define ARG_int5 ((int)((ARGS)[5])) |
| 69 | #define ARG_func1 ((FuncDeclNode*)((ARGS)[1])) |
| 70 | #define ARG_funcexp1 ((FuncExprNode*)((ARGS)[1])) |
| 71 | #define ARG_registers1 ((Register*)((ARGS)[1])) |
| 72 | #define ARG_regexp1 ((RegExp*)((ARGS)[1])) |
| 73 | #define ARG_pni1 ((JSPropertyNameIterator*)((ARGS)[1])) |
| 74 | #define ARG_instr1 ((Instruction*)((ARGS)[1])) |
| 75 | #define ARG_instr2 ((Instruction*)((ARGS)[2])) |
| 76 | #define ARG_instr3 ((Instruction*)((ARGS)[3])) |
| 77 | #define ARG_instr4 ((Instruction*)((ARGS)[4])) |
| 78 | #define ARG_instr5 ((Instruction*)((ARGS)[5])) |
| 79 | #define ARG_instr6 ((Instruction*)((ARGS)[6])) |
mrowe@apple.com | f88a463 | 2008-09-07 05:44:58 +0000 | [diff] [blame] | 80 | |
mjs@apple.com | 36f4f42 | 2008-10-15 02:39:52 +0000 | [diff] [blame] | 81 | #define CTI_RETURN_ADDRESS ((ARGS)[-1]) |
mrowe@apple.com | f88a463 | 2008-09-07 05:44:58 +0000 | [diff] [blame] | 82 | |
cwzwarich@webkit.org | 3f782f6 | 2008-09-08 01:28:33 +0000 | [diff] [blame] | 83 | namespace JSC { |
mrowe@apple.com | f88a463 | 2008-09-07 05:44:58 +0000 | [diff] [blame] | 84 | |
| 85 | class CodeBlock; |
mrowe@apple.com | f88a463 | 2008-09-07 05:44:58 +0000 | [diff] [blame] | 86 | class JSPropertyNameIterator; |
| 87 | class JSValue; |
| 88 | class Machine; |
| 89 | class Register; |
| 90 | class RegisterFile; |
| 91 | class ScopeChainNode; |
| 92 | class SimpleJumpTable; |
| 93 | class StringJumpTable; |
| 94 | class StructureIDChain; |
| 95 | struct Instruction; |
barraclough@apple.com | b8b15e2 | 2008-09-27 01:44:15 +0000 | [diff] [blame] | 96 | struct OperandTypes; |
mrowe@apple.com | f88a463 | 2008-09-07 05:44:58 +0000 | [diff] [blame] | 97 | |
mjs@apple.com | 36f4f42 | 2008-10-15 02:39:52 +0000 | [diff] [blame] | 98 | typedef JSValue* (SFX_CALL *CTIHelper_j)(CTI_ARGS); |
| 99 | typedef JSPropertyNameIterator* (SFX_CALL *CTIHelper_p)(CTI_ARGS); |
| 100 | typedef void (SFX_CALL *CTIHelper_v)(CTI_ARGS); |
| 101 | typedef void* (SFX_CALL *CTIHelper_s)(CTI_ARGS); |
| 102 | typedef int (SFX_CALL *CTIHelper_b)(CTI_ARGS); |
| 103 | typedef VoidPtrPair (SFX_CALL *CTIHelper_2)(CTI_ARGS); |
mrowe@apple.com | f88a463 | 2008-09-07 05:44:58 +0000 | [diff] [blame] | 104 | |
mrowe@apple.com | f88a463 | 2008-09-07 05:44:58 +0000 | [diff] [blame] | 105 | struct CallRecord { |
cwzwarich@webkit.org | 8a33457 | 2008-09-10 03:22:04 +0000 | [diff] [blame] | 106 | X86Assembler::JmpSrc from; |
mrowe@apple.com | f88a463 | 2008-09-07 05:44:58 +0000 | [diff] [blame] | 107 | void* to; |
| 108 | unsigned opcodeIndex; |
| 109 | |
| 110 | CallRecord() |
| 111 | { |
| 112 | } |
| 113 | |
cwzwarich@webkit.org | 8a33457 | 2008-09-10 03:22:04 +0000 | [diff] [blame] | 114 | CallRecord(X86Assembler::JmpSrc f, CTIHelper_j t, unsigned i) |
mrowe@apple.com | f88a463 | 2008-09-07 05:44:58 +0000 | [diff] [blame] | 115 | : from(f) |
| 116 | , to((void*)t) |
| 117 | , opcodeIndex(i) |
| 118 | { |
| 119 | } |
| 120 | |
cwzwarich@webkit.org | 8a33457 | 2008-09-10 03:22:04 +0000 | [diff] [blame] | 121 | CallRecord(X86Assembler::JmpSrc f, CTIHelper_p t, unsigned i) |
mrowe@apple.com | f88a463 | 2008-09-07 05:44:58 +0000 | [diff] [blame] | 122 | : from(f) |
| 123 | , to((void*)t) |
| 124 | , opcodeIndex(i) |
| 125 | { |
| 126 | } |
| 127 | |
cwzwarich@webkit.org | 8a33457 | 2008-09-10 03:22:04 +0000 | [diff] [blame] | 128 | CallRecord(X86Assembler::JmpSrc f, CTIHelper_v t, unsigned i) |
mrowe@apple.com | f88a463 | 2008-09-07 05:44:58 +0000 | [diff] [blame] | 129 | : from(f) |
| 130 | , to((void*)t) |
| 131 | , opcodeIndex(i) |
| 132 | { |
| 133 | } |
| 134 | |
cwzwarich@webkit.org | 8a33457 | 2008-09-10 03:22:04 +0000 | [diff] [blame] | 135 | CallRecord(X86Assembler::JmpSrc f, CTIHelper_s t, unsigned i) |
mrowe@apple.com | f88a463 | 2008-09-07 05:44:58 +0000 | [diff] [blame] | 136 | : from(f) |
| 137 | , to((void*)t) |
| 138 | , opcodeIndex(i) |
| 139 | { |
| 140 | } |
| 141 | |
cwzwarich@webkit.org | 8a33457 | 2008-09-10 03:22:04 +0000 | [diff] [blame] | 142 | CallRecord(X86Assembler::JmpSrc f, CTIHelper_b t, unsigned i) |
mrowe@apple.com | f88a463 | 2008-09-07 05:44:58 +0000 | [diff] [blame] | 143 | : from(f) |
| 144 | , to((void*)t) |
| 145 | , opcodeIndex(i) |
| 146 | { |
| 147 | } |
ggaren@apple.com | 107bd0e | 2008-09-24 00:27:18 +0000 | [diff] [blame] | 148 | |
barraclough@apple.com | 79c9ae1 | 2008-10-07 20:27:50 +0000 | [diff] [blame] | 149 | CallRecord(X86Assembler::JmpSrc f, CTIHelper_2 t, unsigned i) |
| 150 | : from(f) |
| 151 | , to((void*)t) |
| 152 | , opcodeIndex(i) |
| 153 | { |
| 154 | } |
| 155 | |
ggaren@apple.com | 107bd0e | 2008-09-24 00:27:18 +0000 | [diff] [blame] | 156 | CallRecord(X86Assembler::JmpSrc f, unsigned i) |
| 157 | : from(f) |
| 158 | , to(0) |
| 159 | , opcodeIndex(i) |
| 160 | { |
| 161 | } |
mrowe@apple.com | f88a463 | 2008-09-07 05:44:58 +0000 | [diff] [blame] | 162 | }; |
| 163 | |
| 164 | struct JmpTable { |
cwzwarich@webkit.org | 8a33457 | 2008-09-10 03:22:04 +0000 | [diff] [blame] | 165 | X86Assembler::JmpSrc from; |
mrowe@apple.com | f88a463 | 2008-09-07 05:44:58 +0000 | [diff] [blame] | 166 | unsigned to; |
| 167 | |
cwzwarich@webkit.org | 8a33457 | 2008-09-10 03:22:04 +0000 | [diff] [blame] | 168 | JmpTable(X86Assembler::JmpSrc f, unsigned t) |
mrowe@apple.com | f88a463 | 2008-09-07 05:44:58 +0000 | [diff] [blame] | 169 | : from(f) |
| 170 | , to(t) |
| 171 | { |
| 172 | } |
| 173 | }; |
| 174 | |
| 175 | struct SlowCaseEntry { |
cwzwarich@webkit.org | 8a33457 | 2008-09-10 03:22:04 +0000 | [diff] [blame] | 176 | X86Assembler::JmpSrc from; |
mrowe@apple.com | f88a463 | 2008-09-07 05:44:58 +0000 | [diff] [blame] | 177 | unsigned to; |
| 178 | unsigned hint; |
| 179 | |
cwzwarich@webkit.org | 8a33457 | 2008-09-10 03:22:04 +0000 | [diff] [blame] | 180 | SlowCaseEntry(X86Assembler::JmpSrc f, unsigned t, unsigned h = 0) |
mrowe@apple.com | f88a463 | 2008-09-07 05:44:58 +0000 | [diff] [blame] | 181 | : from(f) |
| 182 | , to(t) |
| 183 | , hint(h) |
| 184 | { |
| 185 | } |
| 186 | }; |
| 187 | |
| 188 | struct SwitchRecord { |
| 189 | enum Type { |
| 190 | Immediate, |
| 191 | Character, |
| 192 | String |
| 193 | }; |
| 194 | |
| 195 | Type m_type; |
| 196 | |
| 197 | union { |
| 198 | SimpleJumpTable* m_simpleJumpTable; |
| 199 | StringJumpTable* m_stringJumpTable; |
| 200 | } m_jumpTable; |
| 201 | |
| 202 | unsigned m_opcodeIndex; |
| 203 | unsigned m_defaultOffset; |
| 204 | |
| 205 | SwitchRecord(SimpleJumpTable* jumpTable, unsigned opcodeIndex, unsigned defaultOffset, Type type) |
| 206 | : m_type(type) |
| 207 | , m_opcodeIndex(opcodeIndex) |
| 208 | , m_defaultOffset(defaultOffset) |
| 209 | { |
| 210 | m_jumpTable.m_simpleJumpTable = jumpTable; |
| 211 | } |
| 212 | |
| 213 | SwitchRecord(StringJumpTable* jumpTable, unsigned opcodeIndex, unsigned defaultOffset) |
| 214 | : m_type(String) |
| 215 | , m_opcodeIndex(opcodeIndex) |
| 216 | , m_defaultOffset(defaultOffset) |
| 217 | { |
| 218 | m_jumpTable.m_stringJumpTable = jumpTable; |
| 219 | } |
| 220 | }; |
| 221 | |
barraclough@apple.com | 71500d5 | 2008-09-15 02:18:13 +0000 | [diff] [blame] | 222 | struct StructureStubCompilationInfo { |
| 223 | X86Assembler::JmpSrc callReturnLocation; |
| 224 | X86Assembler::JmpDst hotPathBegin; |
| 225 | }; |
| 226 | |
mrowe@apple.com | f88a463 | 2008-09-07 05:44:58 +0000 | [diff] [blame] | 227 | extern "C" { |
darin@apple.com | 8c2bac0 | 2008-10-09 00:40:43 +0000 | [diff] [blame] | 228 | JSValue* ctiTrampoline(void* code, RegisterFile*, CallFrame*, JSValue** exception, Profiler**, JSGlobalData*); |
mrowe@apple.com | f88a463 | 2008-09-07 05:44:58 +0000 | [diff] [blame] | 229 | void ctiVMThrowTrampoline(); |
| 230 | }; |
| 231 | |
| 232 | void ctiSetReturnAddress(void** where, void* what); |
| 233 | void ctiRepatchCallByReturnAddress(void* where, void* what); |
| 234 | |
| 235 | class CTI { |
barraclough@apple.com | 71500d5 | 2008-09-15 02:18:13 +0000 | [diff] [blame] | 236 | static const int repatchGetByIdDefaultStructureID = -1; |
| 237 | // Magic number - initial offset cannot be representable as a signed 8bit value, or the X86Assembler |
| 238 | // will compress the displacement, and we may not be able to fit a repatched offset. |
| 239 | static const int repatchGetByIdDefaultOffset = 256; |
| 240 | |
mjs@apple.com | 36f4f42 | 2008-10-15 02:39:52 +0000 | [diff] [blame] | 241 | #if USE(FAST_CALL_CTI_ARGUMENT) |
oliver@apple.com | 6dc83fb | 2008-10-08 04:56:38 +0000 | [diff] [blame] | 242 | static const int ctiArgumentInitSize = 2; |
mjs@apple.com | 36f4f42 | 2008-10-15 02:39:52 +0000 | [diff] [blame] | 243 | #elif USE(CTI_ARGUMENT) |
| 244 | static const int ctiArgumentInitSize = 4; |
| 245 | #else |
| 246 | static const int ctiArgumentInitSize = 0; |
| 247 | #endif |
barraclough@apple.com | 71500d5 | 2008-09-15 02:18:13 +0000 | [diff] [blame] | 248 | // These architecture specific value are used to enable repatching - see comment on op_put_by_id. |
| 249 | static const int repatchOffsetPutByIdStructureID = 19; |
| 250 | static const int repatchOffsetPutByIdPropertyMapOffset = 34; |
| 251 | // These architecture specific value are used to enable repatching - see comment on op_get_by_id. |
| 252 | static const int repatchOffsetGetByIdStructureID = 19; |
| 253 | static const int repatchOffsetGetByIdBranchToSlowCase = 25; |
| 254 | static const int repatchOffsetGetByIdPropertyMapOffset = 34; |
barraclough@apple.com | 6bd3e165 | 2008-10-05 17:38:32 +0000 | [diff] [blame] | 255 | #if ENABLE(SAMPLING_TOOL) |
mjs@apple.com | 0d68a33 | 2008-10-17 09:06:42 +0000 | [diff] [blame^] | 256 | static const int repatchOffsetGetByIdSlowCaseCall = 27 + 4 + ctiArgumentInitSize; |
barraclough@apple.com | 6bd3e165 | 2008-10-05 17:38:32 +0000 | [diff] [blame] | 257 | #else |
mjs@apple.com | 0d68a33 | 2008-10-17 09:06:42 +0000 | [diff] [blame^] | 258 | static const int repatchOffsetGetByIdSlowCaseCall = 17 + 4 + ctiArgumentInitSize; |
barraclough@apple.com | 6bd3e165 | 2008-10-05 17:38:32 +0000 | [diff] [blame] | 259 | #endif |
barraclough@apple.com | 71500d5 | 2008-09-15 02:18:13 +0000 | [diff] [blame] | 260 | |
mrowe@apple.com | f88a463 | 2008-09-07 05:44:58 +0000 | [diff] [blame] | 261 | public: |
darin@apple.com | 8c2bac0 | 2008-10-09 00:40:43 +0000 | [diff] [blame] | 262 | static void compile(Machine* machine, CallFrame* callFrame, CodeBlock* codeBlock) |
mrowe@apple.com | f88a463 | 2008-09-07 05:44:58 +0000 | [diff] [blame] | 263 | { |
darin@apple.com | 8c2bac0 | 2008-10-09 00:40:43 +0000 | [diff] [blame] | 264 | CTI cti(machine, callFrame, codeBlock); |
mrowe@apple.com | f88a463 | 2008-09-07 05:44:58 +0000 | [diff] [blame] | 265 | cti.privateCompile(); |
| 266 | } |
| 267 | |
cwzwarich@webkit.org | 56a4aeb1 | 2008-09-09 01:05:06 +0000 | [diff] [blame] | 268 | #if ENABLE(WREC) |
darin@apple.com | 8c2bac0 | 2008-10-09 00:40:43 +0000 | [diff] [blame] | 269 | static void* compileRegExp(Machine*, const UString& pattern, unsigned* numSubpatterns_ptr, const char** error_ptr, bool ignoreCase = false, bool multiline = false); |
cwzwarich@webkit.org | 56a4aeb1 | 2008-09-09 01:05:06 +0000 | [diff] [blame] | 270 | #endif |
mrowe@apple.com | f88a463 | 2008-09-07 05:44:58 +0000 | [diff] [blame] | 271 | |
darin@apple.com | 8c2bac0 | 2008-10-09 00:40:43 +0000 | [diff] [blame] | 272 | static void compileGetByIdSelf(Machine* machine, CallFrame* callFrame, CodeBlock* codeBlock, StructureID* structureID, size_t cachedOffset, void* returnAddress) |
mrowe@apple.com | f88a463 | 2008-09-07 05:44:58 +0000 | [diff] [blame] | 273 | { |
darin@apple.com | 8c2bac0 | 2008-10-09 00:40:43 +0000 | [diff] [blame] | 274 | CTI cti(machine, callFrame, codeBlock); |
barraclough@apple.com | 71500d5 | 2008-09-15 02:18:13 +0000 | [diff] [blame] | 275 | cti.privateCompileGetByIdSelf(structureID, cachedOffset, returnAddress); |
mrowe@apple.com | f88a463 | 2008-09-07 05:44:58 +0000 | [diff] [blame] | 276 | } |
| 277 | |
darin@apple.com | 8c2bac0 | 2008-10-09 00:40:43 +0000 | [diff] [blame] | 278 | static void compileGetByIdProto(Machine* machine, CallFrame* callFrame, CodeBlock* codeBlock, StructureID* structureID, StructureID* prototypeStructureID, size_t cachedOffset, void* returnAddress) |
mrowe@apple.com | f88a463 | 2008-09-07 05:44:58 +0000 | [diff] [blame] | 279 | { |
darin@apple.com | 8c2bac0 | 2008-10-09 00:40:43 +0000 | [diff] [blame] | 280 | CTI cti(machine, callFrame, codeBlock); |
barraclough@apple.com | 71500d5 | 2008-09-15 02:18:13 +0000 | [diff] [blame] | 281 | cti.privateCompileGetByIdProto(structureID, prototypeStructureID, cachedOffset, returnAddress); |
mrowe@apple.com | f88a463 | 2008-09-07 05:44:58 +0000 | [diff] [blame] | 282 | } |
| 283 | |
darin@apple.com | 8c2bac0 | 2008-10-09 00:40:43 +0000 | [diff] [blame] | 284 | static void compileGetByIdChain(Machine* machine, CallFrame* callFrame, CodeBlock* codeBlock, StructureID* structureID, StructureIDChain* chain, size_t count, size_t cachedOffset, void* returnAddress) |
mrowe@apple.com | f88a463 | 2008-09-07 05:44:58 +0000 | [diff] [blame] | 285 | { |
darin@apple.com | 8c2bac0 | 2008-10-09 00:40:43 +0000 | [diff] [blame] | 286 | CTI cti(machine, callFrame, codeBlock); |
barraclough@apple.com | 71500d5 | 2008-09-15 02:18:13 +0000 | [diff] [blame] | 287 | cti.privateCompileGetByIdChain(structureID, chain, count, cachedOffset, returnAddress); |
mrowe@apple.com | f88a463 | 2008-09-07 05:44:58 +0000 | [diff] [blame] | 288 | } |
| 289 | |
darin@apple.com | 8c2bac0 | 2008-10-09 00:40:43 +0000 | [diff] [blame] | 290 | static void compilePutByIdReplace(Machine* machine, CallFrame* callFrame, CodeBlock* codeBlock, StructureID* structureID, size_t cachedOffset, void* returnAddress) |
mrowe@apple.com | f88a463 | 2008-09-07 05:44:58 +0000 | [diff] [blame] | 291 | { |
darin@apple.com | 8c2bac0 | 2008-10-09 00:40:43 +0000 | [diff] [blame] | 292 | CTI cti(machine, callFrame, codeBlock); |
barraclough@apple.com | 71500d5 | 2008-09-15 02:18:13 +0000 | [diff] [blame] | 293 | cti.privateCompilePutByIdReplace(structureID, cachedOffset, returnAddress); |
mrowe@apple.com | f88a463 | 2008-09-07 05:44:58 +0000 | [diff] [blame] | 294 | } |
oliver@apple.com | e3c5d0e | 2008-09-14 08:18:49 +0000 | [diff] [blame] | 295 | |
darin@apple.com | 8c2bac0 | 2008-10-09 00:40:43 +0000 | [diff] [blame] | 296 | static void compilePutByIdTransition(Machine* machine, CallFrame* callFrame, CodeBlock* codeBlock, StructureID* oldStructureID, StructureID* newStructureID, size_t cachedOffset, StructureIDChain* sIDC, void* returnAddress) |
oliver@apple.com | e3c5d0e | 2008-09-14 08:18:49 +0000 | [diff] [blame] | 297 | { |
darin@apple.com | 8c2bac0 | 2008-10-09 00:40:43 +0000 | [diff] [blame] | 298 | CTI cti(machine, callFrame, codeBlock); |
barraclough@apple.com | 71500d5 | 2008-09-15 02:18:13 +0000 | [diff] [blame] | 299 | cti.privateCompilePutByIdTransition(oldStructureID, newStructureID, cachedOffset, sIDC, returnAddress); |
oliver@apple.com | e3c5d0e | 2008-09-14 08:18:49 +0000 | [diff] [blame] | 300 | } |
mrowe@apple.com | f88a463 | 2008-09-07 05:44:58 +0000 | [diff] [blame] | 301 | |
darin@apple.com | 8c2bac0 | 2008-10-09 00:40:43 +0000 | [diff] [blame] | 302 | static void* compileArrayLengthTrampoline(Machine* machine, CallFrame* callFrame, CodeBlock* codeBlock) |
mrowe@apple.com | f88a463 | 2008-09-07 05:44:58 +0000 | [diff] [blame] | 303 | { |
darin@apple.com | 8c2bac0 | 2008-10-09 00:40:43 +0000 | [diff] [blame] | 304 | CTI cti(machine, callFrame, codeBlock); |
barraclough@apple.com | 71500d5 | 2008-09-15 02:18:13 +0000 | [diff] [blame] | 305 | return cti.privateCompileArrayLengthTrampoline(); |
mrowe@apple.com | f88a463 | 2008-09-07 05:44:58 +0000 | [diff] [blame] | 306 | } |
| 307 | |
darin@apple.com | 8c2bac0 | 2008-10-09 00:40:43 +0000 | [diff] [blame] | 308 | static void* compileStringLengthTrampoline(Machine* machine, CallFrame* callFrame, CodeBlock* codeBlock) |
mrowe@apple.com | f88a463 | 2008-09-07 05:44:58 +0000 | [diff] [blame] | 309 | { |
darin@apple.com | 8c2bac0 | 2008-10-09 00:40:43 +0000 | [diff] [blame] | 310 | CTI cti(machine, callFrame, codeBlock); |
barraclough@apple.com | 71500d5 | 2008-09-15 02:18:13 +0000 | [diff] [blame] | 311 | return cti.privateCompileStringLengthTrampoline(); |
| 312 | } |
| 313 | |
| 314 | static void patchGetByIdSelf(CodeBlock* codeBlock, StructureID* structureID, size_t cachedOffset, void* returnAddress); |
| 315 | static void patchPutByIdReplace(CodeBlock* codeBlock, StructureID* structureID, size_t cachedOffset, void* returnAddress); |
| 316 | |
darin@apple.com | 8c2bac0 | 2008-10-09 00:40:43 +0000 | [diff] [blame] | 317 | static void compilePatchGetArrayLength(Machine* machine, CallFrame* callFrame, CodeBlock* codeBlock, void* returnAddress) |
barraclough@apple.com | 71500d5 | 2008-09-15 02:18:13 +0000 | [diff] [blame] | 318 | { |
darin@apple.com | 8c2bac0 | 2008-10-09 00:40:43 +0000 | [diff] [blame] | 319 | CTI cti(machine, callFrame, codeBlock); |
barraclough@apple.com | 71500d5 | 2008-09-15 02:18:13 +0000 | [diff] [blame] | 320 | return cti.privateCompilePatchGetArrayLength(returnAddress); |
mrowe@apple.com | f88a463 | 2008-09-07 05:44:58 +0000 | [diff] [blame] | 321 | } |
| 322 | |
darin@apple.com | 8c2bac0 | 2008-10-09 00:40:43 +0000 | [diff] [blame] | 323 | inline static JSValue* execute(void* code, RegisterFile* registerFile, CallFrame* callFrame, JSGlobalData* globalData, JSValue** exception) |
mrowe@apple.com | f88a463 | 2008-09-07 05:44:58 +0000 | [diff] [blame] | 324 | { |
darin@apple.com | 8c2bac0 | 2008-10-09 00:40:43 +0000 | [diff] [blame] | 325 | return ctiTrampoline(code, registerFile, callFrame, exception, Profiler::enabledProfilerReference(), globalData); |
mrowe@apple.com | f88a463 | 2008-09-07 05:44:58 +0000 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | private: |
darin@apple.com | 8c2bac0 | 2008-10-09 00:40:43 +0000 | [diff] [blame] | 329 | CTI(Machine*, CallFrame*, CodeBlock*); |
ggaren@apple.com | 107bd0e | 2008-09-24 00:27:18 +0000 | [diff] [blame] | 330 | |
| 331 | bool isConstant(int src); |
darin@apple.com | 8c2bac0 | 2008-10-09 00:40:43 +0000 | [diff] [blame] | 332 | JSValue* getConstant(CallFrame*, int src); |
ggaren@apple.com | 107bd0e | 2008-09-24 00:27:18 +0000 | [diff] [blame] | 333 | |
mrowe@apple.com | f88a463 | 2008-09-07 05:44:58 +0000 | [diff] [blame] | 334 | void privateCompileMainPass(); |
| 335 | void privateCompileLinkPass(); |
| 336 | void privateCompileSlowCases(); |
| 337 | void privateCompile(); |
barraclough@apple.com | 71500d5 | 2008-09-15 02:18:13 +0000 | [diff] [blame] | 338 | void privateCompileGetByIdSelf(StructureID*, size_t cachedOffset, void* returnAddress); |
| 339 | void privateCompileGetByIdProto(StructureID*, StructureID* prototypeStructureID, size_t cachedOffset, void* returnAddress); |
| 340 | void privateCompileGetByIdChain(StructureID*, StructureIDChain*, size_t count, size_t cachedOffset, void* returnAddress); |
| 341 | void privateCompilePutByIdReplace(StructureID*, size_t cachedOffset, void* returnAddress); |
| 342 | void privateCompilePutByIdTransition(StructureID*, StructureID*, size_t cachedOffset, StructureIDChain*, void* returnAddress); |
| 343 | |
| 344 | void* privateCompileArrayLengthTrampoline(); |
| 345 | void* privateCompileStringLengthTrampoline(); |
| 346 | void privateCompilePatchGetArrayLength(void* returnAddress); |
mrowe@apple.com | f88a463 | 2008-09-07 05:44:58 +0000 | [diff] [blame] | 347 | |
| 348 | enum CompileOpCallType { OpCallNormal, OpCallEval, OpConstruct }; |
| 349 | void compileOpCall(Instruction* instruction, unsigned i, CompileOpCallType type = OpCallNormal); |
barraclough@apple.com | 79c9ae1 | 2008-10-07 20:27:50 +0000 | [diff] [blame] | 350 | void compileOpCallInitializeCallFrame(unsigned callee, unsigned argCount); |
mjs@apple.com | db29af2 | 2008-09-23 13:20:23 +0000 | [diff] [blame] | 351 | enum CompileOpStrictEqType { OpStrictEq, OpNStrictEq }; |
| 352 | void compileOpStrictEq(Instruction* instruction, unsigned i, CompileOpStrictEqType type); |
barraclough@apple.com | b8b15e2 | 2008-09-27 01:44:15 +0000 | [diff] [blame] | 353 | void putDoubleResultToJSNumberCellOrJSImmediate(X86::XMMRegisterID xmmSource, X86::RegisterID jsNumberCell, unsigned dst, X86Assembler::JmpSrc* wroteJSNumberCell, X86::XMMRegisterID tempXmm, X86::RegisterID tempReg1, X86::RegisterID tempReg2); |
| 354 | void compileBinaryArithOp(OpcodeID, unsigned dst, unsigned src1, unsigned src2, OperandTypes opi, unsigned i); |
| 355 | void compileBinaryArithOpSlowCase(OpcodeID, Vector<SlowCaseEntry>::iterator& iter, unsigned dst, unsigned src1, unsigned src2, OperandTypes opi, unsigned i); |
mrowe@apple.com | f88a463 | 2008-09-07 05:44:58 +0000 | [diff] [blame] | 356 | |
ggaren@apple.com | 0c67773 | 2008-09-30 00:46:25 +0000 | [diff] [blame] | 357 | void emitGetArg(int src, X86Assembler::RegisterID dst); |
cwzwarich@webkit.org | 8a33457 | 2008-09-10 03:22:04 +0000 | [diff] [blame] | 358 | void emitGetPutArg(unsigned src, unsigned offset, X86Assembler::RegisterID scratch); |
| 359 | void emitPutArg(X86Assembler::RegisterID src, unsigned offset); |
mrowe@apple.com | f88a463 | 2008-09-07 05:44:58 +0000 | [diff] [blame] | 360 | void emitPutArgConstant(unsigned value, unsigned offset); |
cwzwarich@webkit.org | 8a33457 | 2008-09-10 03:22:04 +0000 | [diff] [blame] | 361 | void emitPutResult(unsigned dst, X86Assembler::RegisterID from = X86::eax); |
mrowe@apple.com | f88a463 | 2008-09-07 05:44:58 +0000 | [diff] [blame] | 362 | |
ggaren@apple.com | 107bd0e | 2008-09-24 00:27:18 +0000 | [diff] [blame] | 363 | void emitInitRegister(unsigned dst); |
oliver@apple.com | ecfd224 | 2008-09-20 03:00:43 +0000 | [diff] [blame] | 364 | |
barraclough@apple.com | ce5a0b3 | 2008-09-16 17:40:01 +0000 | [diff] [blame] | 365 | void emitPutCTIParam(void* value, unsigned name); |
cwzwarich@webkit.org | 8a33457 | 2008-09-10 03:22:04 +0000 | [diff] [blame] | 366 | void emitPutCTIParam(X86Assembler::RegisterID from, unsigned name); |
| 367 | void emitGetCTIParam(unsigned name, X86Assembler::RegisterID to); |
mrowe@apple.com | f88a463 | 2008-09-07 05:44:58 +0000 | [diff] [blame] | 368 | |
cwzwarich@webkit.org | 8a33457 | 2008-09-10 03:22:04 +0000 | [diff] [blame] | 369 | void emitPutToCallFrameHeader(X86Assembler::RegisterID from, RegisterFile::CallFrameHeaderEntry entry); |
| 370 | void emitGetFromCallFrameHeader(RegisterFile::CallFrameHeaderEntry entry, X86Assembler::RegisterID to); |
mrowe@apple.com | f88a463 | 2008-09-07 05:44:58 +0000 | [diff] [blame] | 371 | |
| 372 | JSValue* getConstantImmediateNumericArg(unsigned src); |
| 373 | unsigned getDeTaggedConstantImmediate(JSValue* imm); |
| 374 | |
mrowe@apple.com | f73971a | 2008-09-16 01:34:20 +0000 | [diff] [blame] | 375 | void emitJumpSlowCaseIfIsJSCell(X86Assembler::RegisterID reg, unsigned opcodeIndex); |
| 376 | void emitJumpSlowCaseIfNotJSCell(X86Assembler::RegisterID reg, unsigned opcodeIndex); |
weinig@apple.com | 262302f | 2008-09-16 03:46:58 +0000 | [diff] [blame] | 377 | |
darin@apple.com | 7161091 | 2008-09-21 23:08:15 +0000 | [diff] [blame] | 378 | void emitJumpSlowCaseIfNotImmNum(X86Assembler::RegisterID, unsigned opcodeIndex); |
| 379 | void emitJumpSlowCaseIfNotImmNums(X86Assembler::RegisterID, X86Assembler::RegisterID, unsigned opcodeIndex); |
mrowe@apple.com | f88a463 | 2008-09-07 05:44:58 +0000 | [diff] [blame] | 380 | |
cwzwarich@webkit.org | 8a33457 | 2008-09-10 03:22:04 +0000 | [diff] [blame] | 381 | void emitFastArithDeTagImmediate(X86Assembler::RegisterID); |
barraclough@apple.com | c8c2bb2 | 2008-10-09 23:59:26 +0000 | [diff] [blame] | 382 | X86Assembler::JmpSrc emitFastArithDeTagImmediateJumpIfZero(X86Assembler::RegisterID); |
cwzwarich@webkit.org | 8a33457 | 2008-09-10 03:22:04 +0000 | [diff] [blame] | 383 | void emitFastArithReTagImmediate(X86Assembler::RegisterID); |
| 384 | void emitFastArithPotentiallyReTagImmediate(X86Assembler::RegisterID); |
| 385 | void emitFastArithImmToInt(X86Assembler::RegisterID); |
| 386 | void emitFastArithIntToImmOrSlowCase(X86Assembler::RegisterID, unsigned opcodeIndex); |
| 387 | void emitFastArithIntToImmNoCheck(X86Assembler::RegisterID); |
mrowe@apple.com | f88a463 | 2008-09-07 05:44:58 +0000 | [diff] [blame] | 388 | |
mjs@apple.com | 4032873 | 2008-09-21 10:39:29 +0000 | [diff] [blame] | 389 | void emitTagAsBoolImmediate(X86Assembler::RegisterID reg); |
| 390 | |
ggaren@apple.com | 107bd0e | 2008-09-24 00:27:18 +0000 | [diff] [blame] | 391 | X86Assembler::JmpSrc emitCall(unsigned opcodeIndex, X86::RegisterID); |
mjs@apple.com | 0d68a33 | 2008-10-17 09:06:42 +0000 | [diff] [blame^] | 392 | X86Assembler::JmpSrc emitCTICall(unsigned opcodeIndex, CTIHelper_j); |
| 393 | X86Assembler::JmpSrc emitCTICall(unsigned opcodeIndex, CTIHelper_p); |
| 394 | X86Assembler::JmpSrc emitCTICall(unsigned opcodeIndex, CTIHelper_v); |
| 395 | X86Assembler::JmpSrc emitCTICall(unsigned opcodeIndex, CTIHelper_s); |
| 396 | X86Assembler::JmpSrc emitCTICall(unsigned opcodeIndex, CTIHelper_b); |
| 397 | X86Assembler::JmpSrc emitCTICall(unsigned opcodeIndex, CTIHelper_2); |
barraclough@apple.com | 79c9ae1 | 2008-10-07 20:27:50 +0000 | [diff] [blame] | 398 | |
oliver@apple.com | 957eefc | 2008-09-10 09:23:35 +0000 | [diff] [blame] | 399 | void emitGetVariableObjectRegister(X86Assembler::RegisterID variableObject, int index, X86Assembler::RegisterID dst); |
| 400 | void emitPutVariableObjectRegister(X86Assembler::RegisterID src, X86Assembler::RegisterID variableObject, int index); |
| 401 | |
oliver@apple.com | ffa7692 | 2008-09-09 04:43:25 +0000 | [diff] [blame] | 402 | void emitSlowScriptCheck(unsigned opcodeIndex); |
mrowe@apple.com | f88a463 | 2008-09-07 05:44:58 +0000 | [diff] [blame] | 403 | #ifndef NDEBUG |
| 404 | void printOpcodeOperandTypes(unsigned src1, unsigned src2); |
| 405 | #endif |
| 406 | |
cwzwarich@webkit.org | 8a33457 | 2008-09-10 03:22:04 +0000 | [diff] [blame] | 407 | X86Assembler m_jit; |
mrowe@apple.com | f88a463 | 2008-09-07 05:44:58 +0000 | [diff] [blame] | 408 | Machine* m_machine; |
darin@apple.com | 8c2bac0 | 2008-10-09 00:40:43 +0000 | [diff] [blame] | 409 | CallFrame* m_callFrame; |
mrowe@apple.com | f88a463 | 2008-09-07 05:44:58 +0000 | [diff] [blame] | 410 | CodeBlock* m_codeBlock; |
| 411 | |
| 412 | Vector<CallRecord> m_calls; |
cwzwarich@webkit.org | 8a33457 | 2008-09-10 03:22:04 +0000 | [diff] [blame] | 413 | Vector<X86Assembler::JmpDst> m_labels; |
barraclough@apple.com | 71500d5 | 2008-09-15 02:18:13 +0000 | [diff] [blame] | 414 | Vector<StructureStubCompilationInfo> m_structureStubCompilationInfo; |
mrowe@apple.com | f88a463 | 2008-09-07 05:44:58 +0000 | [diff] [blame] | 415 | Vector<JmpTable> m_jmpTable; |
| 416 | |
| 417 | struct JSRInfo { |
cwzwarich@webkit.org | 8a33457 | 2008-09-10 03:22:04 +0000 | [diff] [blame] | 418 | X86Assembler::JmpDst addrPosition; |
| 419 | X86Assembler::JmpDst target; |
mrowe@apple.com | f88a463 | 2008-09-07 05:44:58 +0000 | [diff] [blame] | 420 | |
cwzwarich@webkit.org | 8a33457 | 2008-09-10 03:22:04 +0000 | [diff] [blame] | 421 | JSRInfo(const X86Assembler::JmpDst& storeLocation, const X86Assembler::JmpDst& targetLocation) |
mrowe@apple.com | f88a463 | 2008-09-07 05:44:58 +0000 | [diff] [blame] | 422 | : addrPosition(storeLocation) |
| 423 | , target(targetLocation) |
| 424 | { |
| 425 | } |
| 426 | }; |
| 427 | |
| 428 | Vector<JSRInfo> m_jsrSites; |
| 429 | Vector<SlowCaseEntry> m_slowCases; |
| 430 | Vector<SwitchRecord> m_switches; |
| 431 | |
| 432 | // This limit comes from the limit set in PCRE |
| 433 | static const int MaxPatternSize = (1 << 16); |
| 434 | |
| 435 | }; |
| 436 | } |
| 437 | |
| 438 | #endif // ENABLE(CTI) |
| 439 | |
| 440 | #endif // CTI_h |