barraclough@apple.com | e367b00 | 2008-12-04 05:43:14 +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 | #include "config.h" |
| 27 | #include "JIT.h" |
| 28 | |
| 29 | #if ENABLE(JIT) |
| 30 | |
| 31 | #include "CodeBlock.h" |
| 32 | #include "JITInlineMethods.h" |
ggaren@apple.com | 0e5741a | 2009-05-12 01:26:52 +0000 | [diff] [blame] | 33 | #include "JITStubCall.h" |
barraclough@apple.com | e367b00 | 2008-12-04 05:43:14 +0000 | [diff] [blame] | 34 | #include "JSArray.h" |
| 35 | #include "JSFunction.h" |
| 36 | #include "Interpreter.h" |
| 37 | #include "ResultType.h" |
| 38 | #include "SamplingTool.h" |
| 39 | |
| 40 | #ifndef NDEBUG |
| 41 | #include <stdio.h> |
| 42 | #endif |
| 43 | |
| 44 | using namespace std; |
| 45 | |
| 46 | namespace JSC { |
| 47 | |
barraclough@apple.com | e367b00 | 2008-12-04 05:43:14 +0000 | [diff] [blame] | 48 | void JIT::compileOpCallInitializeCallFrame() |
| 49 | { |
barraclough@apple.com | ea6b609 | 2009-02-13 04:22:02 +0000 | [diff] [blame] | 50 | store32(regT1, Address(callFrameRegister, RegisterFile::ArgumentCount * static_cast<int>(sizeof(Register)))); |
barraclough@apple.com | e367b00 | 2008-12-04 05:43:14 +0000 | [diff] [blame] | 51 | |
barraclough@apple.com | 9c15d5a | 2009-06-20 01:29:36 +0000 | [diff] [blame] | 52 | loadPtr(Address(regT2, OBJECT_OFFSETOF(JSFunction, m_data) + OBJECT_OFFSETOF(ScopeChain, m_node)), regT1); // newScopeChain |
barraclough@apple.com | e367b00 | 2008-12-04 05:43:14 +0000 | [diff] [blame] | 53 | |
ggaren@apple.com | acea358 | 2009-05-03 01:58:45 +0000 | [diff] [blame] | 54 | storePtr(ImmPtr(JSValue::encode(JSValue())), Address(callFrameRegister, RegisterFile::OptionalCalleeArguments * static_cast<int>(sizeof(Register)))); |
barraclough@apple.com | ea6b609 | 2009-02-13 04:22:02 +0000 | [diff] [blame] | 55 | storePtr(regT2, Address(callFrameRegister, RegisterFile::Callee * static_cast<int>(sizeof(Register)))); |
| 56 | storePtr(regT1, Address(callFrameRegister, RegisterFile::ScopeChain * static_cast<int>(sizeof(Register)))); |
barraclough@apple.com | e367b00 | 2008-12-04 05:43:14 +0000 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | void JIT::compileOpCallSetupArgs(Instruction* instruction) |
| 60 | { |
| 61 | int argCount = instruction[3].u.operand; |
| 62 | int registerOffset = instruction[4].u.operand; |
| 63 | |
| 64 | // ecx holds func |
barraclough@apple.com | ea6b609 | 2009-02-13 04:22:02 +0000 | [diff] [blame] | 65 | emitPutJITStubArg(regT2, 1); |
barraclough@apple.com | 732c7bf | 2008-12-13 05:25:22 +0000 | [diff] [blame] | 66 | emitPutJITStubArgConstant(argCount, 3); |
oliver@apple.com | 65e286e | 2009-04-08 23:08:28 +0000 | [diff] [blame] | 67 | emitPutJITStubArgConstant(registerOffset, 2); |
| 68 | } |
| 69 | |
| 70 | void JIT::compileOpCallVarargsSetupArgs(Instruction* instruction) |
| 71 | { |
| 72 | int registerOffset = instruction[4].u.operand; |
| 73 | |
| 74 | // ecx holds func |
| 75 | emitPutJITStubArg(regT2, 1); |
| 76 | emitPutJITStubArg(regT1, 3); |
| 77 | addPtr(Imm32(registerOffset), regT1, regT0); |
| 78 | emitPutJITStubArg(regT0, 2); |
barraclough@apple.com | e367b00 | 2008-12-04 05:43:14 +0000 | [diff] [blame] | 79 | } |
| 80 | |
barraclough@apple.com | e367b00 | 2008-12-04 05:43:14 +0000 | [diff] [blame] | 81 | void JIT::compileOpConstructSetupArgs(Instruction* instruction) |
| 82 | { |
| 83 | int argCount = instruction[3].u.operand; |
| 84 | int registerOffset = instruction[4].u.operand; |
| 85 | int proto = instruction[5].u.operand; |
| 86 | int thisRegister = instruction[6].u.operand; |
| 87 | |
| 88 | // ecx holds func |
barraclough@apple.com | ea6b609 | 2009-02-13 04:22:02 +0000 | [diff] [blame] | 89 | emitPutJITStubArg(regT2, 1); |
barraclough@apple.com | 732c7bf | 2008-12-13 05:25:22 +0000 | [diff] [blame] | 90 | emitPutJITStubArgConstant(registerOffset, 2); |
| 91 | emitPutJITStubArgConstant(argCount, 3); |
barraclough@apple.com | ea6b609 | 2009-02-13 04:22:02 +0000 | [diff] [blame] | 92 | emitPutJITStubArgFromVirtualRegister(proto, 4, regT0); |
barraclough@apple.com | 732c7bf | 2008-12-13 05:25:22 +0000 | [diff] [blame] | 93 | emitPutJITStubArgConstant(thisRegister, 5); |
barraclough@apple.com | e367b00 | 2008-12-04 05:43:14 +0000 | [diff] [blame] | 94 | } |
| 95 | |
ggaren@apple.com | 2949660 | 2009-05-12 04:20:29 +0000 | [diff] [blame] | 96 | void JIT::compileOpCallVarargs(Instruction* instruction) |
| 97 | { |
| 98 | int dst = instruction[1].u.operand; |
| 99 | int callee = instruction[2].u.operand; |
| 100 | int argCountRegister = instruction[3].u.operand; |
| 101 | |
| 102 | emitGetVirtualRegister(argCountRegister, regT1); |
| 103 | emitGetVirtualRegister(callee, regT2); |
| 104 | compileOpCallVarargsSetupArgs(instruction); |
| 105 | |
| 106 | // Check for JSFunctions. |
| 107 | emitJumpSlowCaseIfNotJSCell(regT2); |
| 108 | addSlowCase(branchPtr(NotEqual, Address(regT2), ImmPtr(m_globalData->jsFunctionVPtr))); |
| 109 | |
| 110 | // Speculatively roll the callframe, assuming argCount will match the arity. |
| 111 | mul32(Imm32(sizeof(Register)), regT0, regT0); |
| 112 | intptr_t offset = (intptr_t)sizeof(Register) * (intptr_t)RegisterFile::CallerFrame; |
| 113 | addPtr(Imm32((int32_t)offset), regT0, regT3); |
| 114 | addPtr(callFrameRegister, regT3); |
| 115 | storePtr(callFrameRegister, regT3); |
| 116 | addPtr(regT0, callFrameRegister); |
| 117 | emitNakedCall(m_globalData->jitStubs.ctiVirtualCall()); |
| 118 | |
| 119 | // Put the return value in dst. In the interpreter, op_ret does this. |
| 120 | emitPutVirtualRegister(dst); |
| 121 | |
| 122 | sampleCodeBlock(m_codeBlock); |
| 123 | } |
| 124 | |
| 125 | void JIT::compileOpCallVarargsSlowCase(Instruction* instruction, Vector<SlowCaseEntry>::iterator& iter) |
| 126 | { |
| 127 | int dst = instruction[1].u.operand; |
| 128 | |
| 129 | linkSlowCase(iter); |
| 130 | linkSlowCase(iter); |
| 131 | JITStubCall stubCall(this, JITStubs::cti_op_call_NotJSFunction); |
| 132 | stubCall.call(dst); // In the interpreter, the callee puts the return value in dst. |
| 133 | |
| 134 | sampleCodeBlock(m_codeBlock); |
| 135 | } |
| 136 | |
barraclough@apple.com | e367b00 | 2008-12-04 05:43:14 +0000 | [diff] [blame] | 137 | #if !ENABLE(JIT_OPTIMIZE_CALL) |
| 138 | |
ggaren@apple.com | 2949660 | 2009-05-12 04:20:29 +0000 | [diff] [blame] | 139 | /* ------------------------------ BEGIN: !ENABLE(JIT_OPTIMIZE_CALL) ------------------------------ */ |
| 140 | |
barraclough@apple.com | 249befb | 2008-12-13 03:18:10 +0000 | [diff] [blame] | 141 | void JIT::compileOpCall(OpcodeID opcodeID, Instruction* instruction, unsigned) |
barraclough@apple.com | e367b00 | 2008-12-04 05:43:14 +0000 | [diff] [blame] | 142 | { |
| 143 | int dst = instruction[1].u.operand; |
| 144 | int callee = instruction[2].u.operand; |
| 145 | int argCount = instruction[3].u.operand; |
| 146 | int registerOffset = instruction[4].u.operand; |
| 147 | |
| 148 | // Handle eval |
barraclough@apple.com | 4f46a50 | 2008-12-13 01:39:38 +0000 | [diff] [blame] | 149 | Jump wasEval; |
barraclough@apple.com | e367b00 | 2008-12-04 05:43:14 +0000 | [diff] [blame] | 150 | if (opcodeID == op_call_eval) { |
ggaren@apple.com | d8fccca | 2009-05-08 20:51:53 +0000 | [diff] [blame] | 151 | CallEvalJITStub(this, instruction).call(); |
ggaren@apple.com | acea358 | 2009-05-03 01:58:45 +0000 | [diff] [blame] | 152 | wasEval = branchPtr(NotEqual, regT0, ImmPtr(JSValue::encode(JSValue()))); |
barraclough@apple.com | e367b00 | 2008-12-04 05:43:14 +0000 | [diff] [blame] | 153 | } |
| 154 | |
barraclough@apple.com | ea6b609 | 2009-02-13 04:22:02 +0000 | [diff] [blame] | 155 | emitGetVirtualRegister(callee, regT2); |
barraclough@apple.com | e367b00 | 2008-12-04 05:43:14 +0000 | [diff] [blame] | 156 | // The arguments have been set up on the hot path for op_call_eval |
| 157 | if (opcodeID == op_call) |
| 158 | compileOpCallSetupArgs(instruction); |
| 159 | else if (opcodeID == op_construct) |
| 160 | compileOpConstructSetupArgs(instruction); |
| 161 | |
| 162 | // Check for JSFunctions. |
barraclough@apple.com | ea6b609 | 2009-02-13 04:22:02 +0000 | [diff] [blame] | 163 | emitJumpSlowCaseIfNotJSCell(regT2); |
ggaren@apple.com | c3343bd | 2009-02-24 03:58:09 +0000 | [diff] [blame] | 164 | addSlowCase(branchPtr(NotEqual, Address(regT2), ImmPtr(m_globalData->jsFunctionVPtr))); |
barraclough@apple.com | e367b00 | 2008-12-04 05:43:14 +0000 | [diff] [blame] | 165 | |
| 166 | // First, in the case of a construct, allocate the new object. |
| 167 | if (opcodeID == op_construct) { |
barraclough@apple.com | 4027bab | 2009-05-15 03:44:10 +0000 | [diff] [blame] | 168 | JITStubCall(this, JITStubs::cti_op_construct_JSConstruct).call(registerOffset - RegisterFile::CallFrameHeaderSize - argCount); |
barraclough@apple.com | ea6b609 | 2009-02-13 04:22:02 +0000 | [diff] [blame] | 169 | emitGetVirtualRegister(callee, regT2); |
barraclough@apple.com | e367b00 | 2008-12-04 05:43:14 +0000 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | // Speculatively roll the callframe, assuming argCount will match the arity. |
barraclough@apple.com | e0aa4b6 | 2008-12-18 03:38:10 +0000 | [diff] [blame] | 173 | storePtr(callFrameRegister, Address(callFrameRegister, (RegisterFile::CallerFrame + registerOffset) * static_cast<int>(sizeof(Register)))); |
| 174 | addPtr(Imm32(registerOffset * static_cast<int>(sizeof(Register))), callFrameRegister); |
barraclough@apple.com | ea6b609 | 2009-02-13 04:22:02 +0000 | [diff] [blame] | 175 | move(Imm32(argCount), regT1); |
barraclough@apple.com | e367b00 | 2008-12-04 05:43:14 +0000 | [diff] [blame] | 176 | |
ggaren@apple.com | c3343bd | 2009-02-24 03:58:09 +0000 | [diff] [blame] | 177 | emitNakedCall(m_globalData->jitStubs.ctiVirtualCall()); |
barraclough@apple.com | e367b00 | 2008-12-04 05:43:14 +0000 | [diff] [blame] | 178 | |
| 179 | if (opcodeID == op_call_eval) |
barraclough@apple.com | 4f46a50 | 2008-12-13 01:39:38 +0000 | [diff] [blame] | 180 | wasEval.link(this); |
barraclough@apple.com | e367b00 | 2008-12-04 05:43:14 +0000 | [diff] [blame] | 181 | |
| 182 | // Put the return value in dst. In the interpreter, op_ret does this. |
| 183 | emitPutVirtualRegister(dst); |
| 184 | |
barraclough@apple.com | 24a7abb | 2009-01-16 23:34:46 +0000 | [diff] [blame] | 185 | sampleCodeBlock(m_codeBlock); |
barraclough@apple.com | e367b00 | 2008-12-04 05:43:14 +0000 | [diff] [blame] | 186 | } |
| 187 | |
barraclough@apple.com | 249befb | 2008-12-13 03:18:10 +0000 | [diff] [blame] | 188 | void JIT::compileOpCallSlowCase(Instruction* instruction, Vector<SlowCaseEntry>::iterator& iter, unsigned, OpcodeID opcodeID) |
barraclough@apple.com | e367b00 | 2008-12-04 05:43:14 +0000 | [diff] [blame] | 189 | { |
| 190 | int dst = instruction[1].u.operand; |
| 191 | |
barraclough@apple.com | 4f46a50 | 2008-12-13 01:39:38 +0000 | [diff] [blame] | 192 | linkSlowCase(iter); |
| 193 | linkSlowCase(iter); |
barraclough@apple.com | 4027bab | 2009-05-15 03:44:10 +0000 | [diff] [blame] | 194 | JITStubCall stubCall(this, opcodeID == op_construct ? JITStubs::cti_op_construct_NotJSConstruct : JITStubs::cti_op_call_NotJSFunction); |
ggaren@apple.com | d8fccca | 2009-05-08 20:51:53 +0000 | [diff] [blame] | 195 | stubCall.call(dst); // In the interpreter, the callee puts the return value in dst. |
barraclough@apple.com | e367b00 | 2008-12-04 05:43:14 +0000 | [diff] [blame] | 196 | |
barraclough@apple.com | 24a7abb | 2009-01-16 23:34:46 +0000 | [diff] [blame] | 197 | sampleCodeBlock(m_codeBlock); |
barraclough@apple.com | e367b00 | 2008-12-04 05:43:14 +0000 | [diff] [blame] | 198 | } |
| 199 | |
ggaren@apple.com | 2949660 | 2009-05-12 04:20:29 +0000 | [diff] [blame] | 200 | #else // !ENABLE(JIT_OPTIMIZE_CALL) |
| 201 | |
| 202 | /* ------------------------------ BEGIN: ENABLE(JIT_OPTIMIZE_CALL) ------------------------------ */ |
barraclough@apple.com | e367b00 | 2008-12-04 05:43:14 +0000 | [diff] [blame] | 203 | |
barraclough@apple.com | 249befb | 2008-12-13 03:18:10 +0000 | [diff] [blame] | 204 | void JIT::compileOpCall(OpcodeID opcodeID, Instruction* instruction, unsigned callLinkInfoIndex) |
barraclough@apple.com | e367b00 | 2008-12-04 05:43:14 +0000 | [diff] [blame] | 205 | { |
| 206 | int dst = instruction[1].u.operand; |
| 207 | int callee = instruction[2].u.operand; |
| 208 | int argCount = instruction[3].u.operand; |
| 209 | int registerOffset = instruction[4].u.operand; |
| 210 | |
| 211 | // Handle eval |
barraclough@apple.com | 289318a | 2008-12-22 01:00:07 +0000 | [diff] [blame] | 212 | Jump wasEval; |
barraclough@apple.com | e367b00 | 2008-12-04 05:43:14 +0000 | [diff] [blame] | 213 | if (opcodeID == op_call_eval) { |
ggaren@apple.com | d8fccca | 2009-05-08 20:51:53 +0000 | [diff] [blame] | 214 | CallEvalJITStub(this, instruction).call(); |
ggaren@apple.com | acea358 | 2009-05-03 01:58:45 +0000 | [diff] [blame] | 215 | wasEval = branchPtr(NotEqual, regT0, ImmPtr(JSValue::encode(JSValue()))); |
barraclough@apple.com | e367b00 | 2008-12-04 05:43:14 +0000 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | // This plants a check for a cached JSFunction value, so we can plant a fast link to the callee. |
| 219 | // This deliberately leaves the callee in ecx, used when setting up the stack frame below |
barraclough@apple.com | ea6b609 | 2009-02-13 04:22:02 +0000 | [diff] [blame] | 220 | emitGetVirtualRegister(callee, regT2); |
barraclough@apple.com | 289318a | 2008-12-22 01:00:07 +0000 | [diff] [blame] | 221 | DataLabelPtr addressOfLinkedFunctionCheck; |
ggaren@apple.com | acea358 | 2009-05-03 01:58:45 +0000 | [diff] [blame] | 222 | Jump jumpToSlow = branchPtrWithPatch(NotEqual, regT2, addressOfLinkedFunctionCheck, ImmPtr(JSValue::encode(JSValue()))); |
barraclough@apple.com | 289318a | 2008-12-22 01:00:07 +0000 | [diff] [blame] | 223 | addSlowCase(jumpToSlow); |
weinig@apple.com | 76b0f8a | 2008-12-22 21:21:18 +0000 | [diff] [blame] | 224 | ASSERT(differenceBetween(addressOfLinkedFunctionCheck, jumpToSlow) == patchOffsetOpCallCompareToJump); |
barraclough@apple.com | e367b00 | 2008-12-04 05:43:14 +0000 | [diff] [blame] | 225 | m_callStructureStubCompilationInfo[callLinkInfoIndex].hotPathBegin = addressOfLinkedFunctionCheck; |
| 226 | |
| 227 | // The following is the fast case, only used whan a callee can be linked. |
| 228 | |
| 229 | // In the case of OpConstruct, call out to a cti_ function to create the new object. |
| 230 | if (opcodeID == op_construct) { |
| 231 | int proto = instruction[5].u.operand; |
| 232 | int thisRegister = instruction[6].u.operand; |
| 233 | |
barraclough@apple.com | ea6b609 | 2009-02-13 04:22:02 +0000 | [diff] [blame] | 234 | emitPutJITStubArg(regT2, 1); |
| 235 | emitPutJITStubArgFromVirtualRegister(proto, 4, regT0); |
ggaren@apple.com | d8fccca | 2009-05-08 20:51:53 +0000 | [diff] [blame] | 236 | JITStubCall stubCall(this, JITStubs::cti_op_construct_JSConstruct); |
| 237 | stubCall.call(thisRegister); |
barraclough@apple.com | ea6b609 | 2009-02-13 04:22:02 +0000 | [diff] [blame] | 238 | emitGetVirtualRegister(callee, regT2); |
barraclough@apple.com | e367b00 | 2008-12-04 05:43:14 +0000 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | // Fast version of stack frame initialization, directly relative to edi. |
| 242 | // Note that this omits to set up RegisterFile::CodeBlock, which is set in the callee |
ggaren@apple.com | acea358 | 2009-05-03 01:58:45 +0000 | [diff] [blame] | 243 | storePtr(ImmPtr(JSValue::encode(JSValue())), Address(callFrameRegister, (registerOffset + RegisterFile::OptionalCalleeArguments) * static_cast<int>(sizeof(Register)))); |
barraclough@apple.com | ea6b609 | 2009-02-13 04:22:02 +0000 | [diff] [blame] | 244 | storePtr(regT2, Address(callFrameRegister, (registerOffset + RegisterFile::Callee) * static_cast<int>(sizeof(Register)))); |
barraclough@apple.com | 9c15d5a | 2009-06-20 01:29:36 +0000 | [diff] [blame] | 245 | loadPtr(Address(regT2, OBJECT_OFFSETOF(JSFunction, m_data) + OBJECT_OFFSETOF(ScopeChain, m_node)), regT1); // newScopeChain |
barraclough@apple.com | 289318a | 2008-12-22 01:00:07 +0000 | [diff] [blame] | 246 | store32(Imm32(argCount), Address(callFrameRegister, (registerOffset + RegisterFile::ArgumentCount) * static_cast<int>(sizeof(Register)))); |
| 247 | storePtr(callFrameRegister, Address(callFrameRegister, (registerOffset + RegisterFile::CallerFrame) * static_cast<int>(sizeof(Register)))); |
barraclough@apple.com | ea6b609 | 2009-02-13 04:22:02 +0000 | [diff] [blame] | 248 | storePtr(regT1, Address(callFrameRegister, (registerOffset + RegisterFile::ScopeChain) * static_cast<int>(sizeof(Register)))); |
barraclough@apple.com | 289318a | 2008-12-22 01:00:07 +0000 | [diff] [blame] | 249 | addPtr(Imm32(registerOffset * sizeof(Register)), callFrameRegister); |
barraclough@apple.com | e367b00 | 2008-12-04 05:43:14 +0000 | [diff] [blame] | 250 | |
| 251 | // Call to the callee |
barraclough@apple.com | 97bacef | 2009-06-05 07:55:38 +0000 | [diff] [blame] | 252 | m_callStructureStubCompilationInfo[callLinkInfoIndex].hotPathOther = emitNakedCall(); |
barraclough@apple.com | e367b00 | 2008-12-04 05:43:14 +0000 | [diff] [blame] | 253 | |
| 254 | if (opcodeID == op_call_eval) |
barraclough@apple.com | 289318a | 2008-12-22 01:00:07 +0000 | [diff] [blame] | 255 | wasEval.link(this); |
barraclough@apple.com | e367b00 | 2008-12-04 05:43:14 +0000 | [diff] [blame] | 256 | |
| 257 | // Put the return value in dst. In the interpreter, op_ret does this. |
| 258 | emitPutVirtualRegister(dst); |
| 259 | |
barraclough@apple.com | 24a7abb | 2009-01-16 23:34:46 +0000 | [diff] [blame] | 260 | sampleCodeBlock(m_codeBlock); |
barraclough@apple.com | e367b00 | 2008-12-04 05:43:14 +0000 | [diff] [blame] | 261 | } |
| 262 | |
barraclough@apple.com | 249befb | 2008-12-13 03:18:10 +0000 | [diff] [blame] | 263 | void JIT::compileOpCallSlowCase(Instruction* instruction, Vector<SlowCaseEntry>::iterator& iter, unsigned callLinkInfoIndex, OpcodeID opcodeID) |
barraclough@apple.com | e367b00 | 2008-12-04 05:43:14 +0000 | [diff] [blame] | 264 | { |
| 265 | int dst = instruction[1].u.operand; |
| 266 | int callee = instruction[2].u.operand; |
| 267 | int argCount = instruction[3].u.operand; |
| 268 | int registerOffset = instruction[4].u.operand; |
| 269 | |
barraclough@apple.com | 4f46a50 | 2008-12-13 01:39:38 +0000 | [diff] [blame] | 270 | linkSlowCase(iter); |
barraclough@apple.com | e367b00 | 2008-12-04 05:43:14 +0000 | [diff] [blame] | 271 | |
| 272 | // The arguments have been set up on the hot path for op_call_eval |
| 273 | if (opcodeID == op_call) |
| 274 | compileOpCallSetupArgs(instruction); |
| 275 | else if (opcodeID == op_construct) |
| 276 | compileOpConstructSetupArgs(instruction); |
| 277 | |
| 278 | // Fast check for JS function. |
barraclough@apple.com | ea6b609 | 2009-02-13 04:22:02 +0000 | [diff] [blame] | 279 | Jump callLinkFailNotObject = emitJumpIfNotJSCell(regT2); |
ggaren@apple.com | c3343bd | 2009-02-24 03:58:09 +0000 | [diff] [blame] | 280 | Jump callLinkFailNotJSFunction = branchPtr(NotEqual, Address(regT2), ImmPtr(m_globalData->jsFunctionVPtr)); |
barraclough@apple.com | e367b00 | 2008-12-04 05:43:14 +0000 | [diff] [blame] | 281 | |
| 282 | // First, in the case of a construct, allocate the new object. |
| 283 | if (opcodeID == op_construct) { |
ggaren@apple.com | d8fccca | 2009-05-08 20:51:53 +0000 | [diff] [blame] | 284 | JITStubCall(this, JITStubs::cti_op_construct_JSConstruct).call(registerOffset - RegisterFile::CallFrameHeaderSize - argCount); |
barraclough@apple.com | ea6b609 | 2009-02-13 04:22:02 +0000 | [diff] [blame] | 285 | emitGetVirtualRegister(callee, regT2); |
barraclough@apple.com | e367b00 | 2008-12-04 05:43:14 +0000 | [diff] [blame] | 286 | } |
| 287 | |
barraclough@apple.com | e367b00 | 2008-12-04 05:43:14 +0000 | [diff] [blame] | 288 | // Speculatively roll the callframe, assuming argCount will match the arity. |
barraclough@apple.com | 289318a | 2008-12-22 01:00:07 +0000 | [diff] [blame] | 289 | storePtr(callFrameRegister, Address(callFrameRegister, (RegisterFile::CallerFrame + registerOffset) * static_cast<int>(sizeof(Register)))); |
| 290 | addPtr(Imm32(registerOffset * static_cast<int>(sizeof(Register))), callFrameRegister); |
barraclough@apple.com | baf4f32 | 2009-06-15 20:17:50 +0000 | [diff] [blame] | 291 | move(Imm32(argCount), regT1); |
barraclough@apple.com | e367b00 | 2008-12-04 05:43:14 +0000 | [diff] [blame] | 292 | |
barraclough@apple.com | baf4f32 | 2009-06-15 20:17:50 +0000 | [diff] [blame] | 293 | m_callStructureStubCompilationInfo[callLinkInfoIndex].callReturnLocation = emitNakedCall(m_globalData->jitStubs.ctiVirtualCallPreLink()); |
barraclough@apple.com | e367b00 | 2008-12-04 05:43:14 +0000 | [diff] [blame] | 294 | |
barraclough@apple.com | baf4f32 | 2009-06-15 20:17:50 +0000 | [diff] [blame] | 295 | // Put the return value in dst. |
| 296 | emitPutVirtualRegister(dst); |
| 297 | sampleCodeBlock(m_codeBlock); |
barraclough@apple.com | e367b00 | 2008-12-04 05:43:14 +0000 | [diff] [blame] | 298 | |
barraclough@apple.com | baf4f32 | 2009-06-15 20:17:50 +0000 | [diff] [blame] | 299 | // If not, we need an extra case in the if below! |
| 300 | ASSERT(OPCODE_LENGTH(op_call) == OPCODE_LENGTH(op_call_eval)); |
barraclough@apple.com | e367b00 | 2008-12-04 05:43:14 +0000 | [diff] [blame] | 301 | |
barraclough@apple.com | baf4f32 | 2009-06-15 20:17:50 +0000 | [diff] [blame] | 302 | // Done! - return back to the hot path. |
| 303 | if (opcodeID == op_construct) |
| 304 | emitJumpSlowToHot(jump(), OPCODE_LENGTH(op_construct)); |
| 305 | else |
| 306 | emitJumpSlowToHot(jump(), OPCODE_LENGTH(op_call)); |
barraclough@apple.com | e367b00 | 2008-12-04 05:43:14 +0000 | [diff] [blame] | 307 | |
| 308 | // This handles host functions |
barraclough@apple.com | 289318a | 2008-12-22 01:00:07 +0000 | [diff] [blame] | 309 | callLinkFailNotObject.link(this); |
| 310 | callLinkFailNotJSFunction.link(this); |
barraclough@apple.com | baf4f32 | 2009-06-15 20:17:50 +0000 | [diff] [blame] | 311 | JITStubCall(this, opcodeID == op_construct ? JITStubs::cti_op_construct_NotJSConstruct : JITStubs::cti_op_call_NotJSFunction).call(); |
barraclough@apple.com | e367b00 | 2008-12-04 05:43:14 +0000 | [diff] [blame] | 312 | |
barraclough@apple.com | e367b00 | 2008-12-04 05:43:14 +0000 | [diff] [blame] | 313 | emitPutVirtualRegister(dst); |
barraclough@apple.com | 24a7abb | 2009-01-16 23:34:46 +0000 | [diff] [blame] | 314 | sampleCodeBlock(m_codeBlock); |
barraclough@apple.com | e367b00 | 2008-12-04 05:43:14 +0000 | [diff] [blame] | 315 | } |
| 316 | |
ggaren@apple.com | 2949660 | 2009-05-12 04:20:29 +0000 | [diff] [blame] | 317 | /* ------------------------------ END: !ENABLE / ENABLE(JIT_OPTIMIZE_CALL) ------------------------------ */ |
barraclough@apple.com | e367b00 | 2008-12-04 05:43:14 +0000 | [diff] [blame] | 318 | |
ggaren@apple.com | 2949660 | 2009-05-12 04:20:29 +0000 | [diff] [blame] | 319 | #endif // !ENABLE(JIT_OPTIMIZE_CALL) |
oliver@apple.com | 65e286e | 2009-04-08 23:08:28 +0000 | [diff] [blame] | 320 | |
barraclough@apple.com | e367b00 | 2008-12-04 05:43:14 +0000 | [diff] [blame] | 321 | } // namespace JSC |
| 322 | |
| 323 | #endif // ENABLE(JIT) |