author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 14 May 2010 16:40:13 +0300 | |
changeset 22 | 79de32ba3296 |
parent 3 | 41300fa6a67c |
child 30 | 5dc02b23752f |
permissions | -rw-r--r-- |
0 | 1 |
/* |
2 |
* Copyright (C) 2009 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 "JITInlineMethods.h" |
|
32 |
#include "JITStubCall.h" |
|
33 |
#include "JSArray.h" |
|
34 |
#include "JSCell.h" |
|
35 |
#include "JSFunction.h" |
|
36 |
#include "JSPropertyNameIterator.h" |
|
37 |
#include "LinkBuffer.h" |
|
38 |
||
39 |
namespace JSC { |
|
40 |
||
41 |
#if USE(JSVALUE32_64) |
|
42 |
||
43 |
void JIT::privateCompileCTIMachineTrampolines(RefPtr<ExecutablePool>* executablePool, JSGlobalData* globalData, CodePtr* ctiStringLengthTrampoline, CodePtr* ctiVirtualCallLink, CodePtr* ctiVirtualCall, CodePtr* ctiNativeCallThunk) |
|
44 |
{ |
|
45 |
#if ENABLE(JIT_OPTIMIZE_PROPERTY_ACCESS) |
|
46 |
// (1) This function provides fast property access for string length |
|
47 |
Label stringLengthBegin = align(); |
|
48 |
||
49 |
// regT0 holds payload, regT1 holds tag |
|
50 |
||
51 |
Jump string_failureCases1 = branch32(NotEqual, regT1, Imm32(JSValue::CellTag)); |
|
52 |
Jump string_failureCases2 = branchPtr(NotEqual, Address(regT0), ImmPtr(m_globalData->jsStringVPtr)); |
|
53 |
||
54 |
// Checks out okay! - get the length from the Ustring. |
|
55 |
loadPtr(Address(regT0, OBJECT_OFFSETOF(JSString, m_value) + OBJECT_OFFSETOF(UString, m_rep)), regT2); |
|
56 |
load32(Address(regT2, OBJECT_OFFSETOF(UString::Rep, len)), regT2); |
|
57 |
||
58 |
Jump string_failureCases3 = branch32(Above, regT2, Imm32(INT_MAX)); |
|
59 |
move(regT2, regT0); |
|
60 |
move(Imm32(JSValue::Int32Tag), regT1); |
|
61 |
||
62 |
ret(); |
|
63 |
#endif |
|
64 |
||
65 |
// (2) Trampolines for the slow cases of op_call / op_call_eval / op_construct. |
|
66 |
||
67 |
#if ENABLE(JIT_OPTIMIZE_CALL) |
|
68 |
// VirtualCallLink Trampoline |
|
69 |
// regT0 holds callee, regT1 holds argCount. regT2 will hold the FunctionExecutable. |
|
70 |
Label virtualCallLinkBegin = align(); |
|
71 |
loadPtr(Address(regT0, OBJECT_OFFSETOF(JSFunction, m_executable)), regT2); |
|
72 |
||
73 |
Jump isNativeFunc2 = branch32(Equal, Address(regT2, OBJECT_OFFSETOF(FunctionExecutable, m_numParameters)), Imm32(0)); |
|
74 |
||
75 |
Jump hasCodeBlock2 = branch32(GreaterThan, Address(regT2, OBJECT_OFFSETOF(FunctionExecutable, m_numParameters)), Imm32(0)); |
|
76 |
preserveReturnAddressAfterCall(regT3); |
|
77 |
restoreArgumentReference(); |
|
78 |
Call callJSFunction2 = call(); |
|
79 |
loadPtr(Address(regT0, OBJECT_OFFSETOF(JSFunction, m_executable)), regT2); |
|
80 |
emitGetJITStubArg(2, regT1); // argCount |
|
81 |
restoreReturnAddressBeforeReturn(regT3); |
|
82 |
hasCodeBlock2.link(this); |
|
83 |
||
84 |
// Check argCount matches callee arity. |
|
85 |
Jump arityCheckOkay2 = branch32(Equal, Address(regT2, OBJECT_OFFSETOF(FunctionExecutable, m_numParameters)), regT1); |
|
86 |
preserveReturnAddressAfterCall(regT3); |
|
87 |
emitPutJITStubArg(regT3, 1); // return address |
|
88 |
restoreArgumentReference(); |
|
89 |
Call callArityCheck2 = call(); |
|
90 |
move(regT1, callFrameRegister); |
|
91 |
emitGetJITStubArg(2, regT1); // argCount |
|
92 |
restoreReturnAddressBeforeReturn(regT3); |
|
93 |
arityCheckOkay2.link(this); |
|
94 |
||
95 |
isNativeFunc2.link(this); |
|
96 |
||
97 |
compileOpCallInitializeCallFrame(); |
|
98 |
||
99 |
preserveReturnAddressAfterCall(regT3); |
|
100 |
emitPutJITStubArg(regT3, 1); // return address |
|
101 |
restoreArgumentReference(); |
|
102 |
Call callLazyLinkCall = call(); |
|
103 |
restoreReturnAddressBeforeReturn(regT3); |
|
104 |
jump(regT0); |
|
105 |
#endif // ENABLE(JIT_OPTIMIZE_CALL) |
|
106 |
||
107 |
// VirtualCall Trampoline |
|
108 |
// regT0 holds callee, regT1 holds argCount. regT2 will hold the FunctionExecutable. |
|
109 |
Label virtualCallBegin = align(); |
|
110 |
loadPtr(Address(regT0, OBJECT_OFFSETOF(JSFunction, m_executable)), regT2); |
|
111 |
||
112 |
Jump isNativeFunc3 = branch32(Equal, Address(regT2, OBJECT_OFFSETOF(FunctionExecutable, m_numParameters)), Imm32(0)); |
|
113 |
||
114 |
Jump hasCodeBlock3 = branch32(GreaterThan, Address(regT2, OBJECT_OFFSETOF(FunctionExecutable, m_numParameters)), Imm32(0)); |
|
115 |
preserveReturnAddressAfterCall(regT3); |
|
116 |
restoreArgumentReference(); |
|
117 |
Call callJSFunction1 = call(); |
|
118 |
emitGetJITStubArg(2, regT1); // argCount |
|
119 |
restoreReturnAddressBeforeReturn(regT3); |
|
120 |
loadPtr(Address(regT0, OBJECT_OFFSETOF(JSFunction, m_executable)), regT2); |
|
121 |
hasCodeBlock3.link(this); |
|
122 |
||
123 |
// Check argCount matches callee arity. |
|
124 |
Jump arityCheckOkay3 = branch32(Equal, Address(regT2, OBJECT_OFFSETOF(FunctionExecutable, m_numParameters)), regT1); |
|
125 |
preserveReturnAddressAfterCall(regT3); |
|
126 |
emitPutJITStubArg(regT3, 1); // return address |
|
127 |
restoreArgumentReference(); |
|
128 |
Call callArityCheck1 = call(); |
|
129 |
move(regT1, callFrameRegister); |
|
130 |
emitGetJITStubArg(2, regT1); // argCount |
|
131 |
restoreReturnAddressBeforeReturn(regT3); |
|
132 |
loadPtr(Address(regT0, OBJECT_OFFSETOF(JSFunction, m_executable)), regT2); |
|
133 |
arityCheckOkay3.link(this); |
|
134 |
||
135 |
isNativeFunc3.link(this); |
|
136 |
||
137 |
compileOpCallInitializeCallFrame(); |
|
138 |
loadPtr(Address(regT2, OBJECT_OFFSETOF(FunctionExecutable, m_jitCode)), regT0); |
|
139 |
jump(regT0); |
|
140 |
||
141 |
#if PLATFORM(X86) |
|
142 |
Label nativeCallThunk = align(); |
|
143 |
preserveReturnAddressAfterCall(regT0); |
|
144 |
emitPutToCallFrameHeader(regT0, RegisterFile::ReturnPC); // Push return address |
|
145 |
||
146 |
// Load caller frame's scope chain into this callframe so that whatever we call can |
|
147 |
// get to its global data. |
|
148 |
emitGetFromCallFrameHeaderPtr(RegisterFile::CallerFrame, regT1); |
|
149 |
emitGetFromCallFrameHeaderPtr(RegisterFile::ScopeChain, regT1, regT1); |
|
150 |
emitPutToCallFrameHeader(regT1, RegisterFile::ScopeChain); |
|
151 |
||
152 |
emitGetFromCallFrameHeader32(RegisterFile::ArgumentCount, regT0); |
|
153 |
||
154 |
/* We have two structs that we use to describe the stackframe we set up for our |
|
155 |
* call to native code. NativeCallFrameStructure describes the how we set up the stack |
|
156 |
* in advance of the call. NativeFunctionCalleeSignature describes the callframe |
|
157 |
* as the native code expects it. We do this as we are using the fastcall calling |
|
158 |
* convention which results in the callee popping its arguments off the stack, but |
|
159 |
* not the rest of the callframe so we need a nice way to ensure we increment the |
|
160 |
* stack pointer by the right amount after the call. |
|
161 |
*/ |
|
162 |
||
163 |
#if COMPILER(MSVC) || PLATFORM(LINUX) |
|
164 |
#if COMPILER(MSVC) |
|
165 |
#pragma pack(push) |
|
166 |
#pragma pack(4) |
|
167 |
#endif // COMPILER(MSVC) |
|
168 |
struct NativeCallFrameStructure { |
|
169 |
// CallFrame* callFrame; // passed in EDX |
|
170 |
JSObject* callee; |
|
171 |
JSValue thisValue; |
|
172 |
ArgList* argPointer; |
|
173 |
ArgList args; |
|
174 |
JSValue result; |
|
175 |
}; |
|
176 |
struct NativeFunctionCalleeSignature { |
|
177 |
JSObject* callee; |
|
178 |
JSValue thisValue; |
|
179 |
ArgList* argPointer; |
|
180 |
}; |
|
181 |
#if COMPILER(MSVC) |
|
182 |
#pragma pack(pop) |
|
183 |
#endif // COMPILER(MSVC) |
|
184 |
#else |
|
185 |
struct NativeCallFrameStructure { |
|
186 |
// CallFrame* callFrame; // passed in ECX |
|
187 |
// JSObject* callee; // passed in EDX |
|
188 |
JSValue thisValue; |
|
189 |
ArgList* argPointer; |
|
190 |
ArgList args; |
|
191 |
}; |
|
192 |
struct NativeFunctionCalleeSignature { |
|
193 |
JSValue thisValue; |
|
194 |
ArgList* argPointer; |
|
195 |
}; |
|
196 |
#endif |
|
197 |
||
198 |
const int NativeCallFrameSize = (sizeof(NativeCallFrameStructure) + 15) & ~15; |
|
199 |
// Allocate system stack frame |
|
200 |
subPtr(Imm32(NativeCallFrameSize), stackPointerRegister); |
|
201 |
||
202 |
// Set up arguments |
|
203 |
subPtr(Imm32(1), regT0); // Don't include 'this' in argcount |
|
204 |
||
205 |
// push argcount |
|
206 |
storePtr(regT0, Address(stackPointerRegister, OBJECT_OFFSETOF(NativeCallFrameStructure, args) + OBJECT_OFFSETOF(ArgList, m_argCount))); |
|
207 |
||
208 |
// Calculate the start of the callframe header, and store in regT1 |
|
209 |
addPtr(Imm32(-RegisterFile::CallFrameHeaderSize * (int)sizeof(Register)), callFrameRegister, regT1); |
|
210 |
||
211 |
// Calculate start of arguments as callframe header - sizeof(Register) * argcount (regT0) |
|
212 |
mul32(Imm32(sizeof(Register)), regT0, regT0); |
|
213 |
subPtr(regT0, regT1); |
|
214 |
storePtr(regT1, Address(stackPointerRegister, OBJECT_OFFSETOF(NativeCallFrameStructure, args) + OBJECT_OFFSETOF(ArgList, m_args))); |
|
215 |
||
216 |
// ArgList is passed by reference so is stackPointerRegister + 4 * sizeof(Register) |
|
217 |
addPtr(Imm32(OBJECT_OFFSETOF(NativeCallFrameStructure, args)), stackPointerRegister, regT0); |
|
218 |
storePtr(regT0, Address(stackPointerRegister, OBJECT_OFFSETOF(NativeCallFrameStructure, argPointer))); |
|
219 |
||
220 |
// regT1 currently points to the first argument, regT1 - sizeof(Register) points to 'this' |
|
221 |
loadPtr(Address(regT1, -(int)sizeof(Register) + OBJECT_OFFSETOF(JSValue, u.asBits.payload)), regT2); |
|
222 |
loadPtr(Address(regT1, -(int)sizeof(Register) + OBJECT_OFFSETOF(JSValue, u.asBits.tag)), regT3); |
|
223 |
storePtr(regT2, Address(stackPointerRegister, OBJECT_OFFSETOF(NativeCallFrameStructure, thisValue) + OBJECT_OFFSETOF(JSValue, u.asBits.payload))); |
|
224 |
storePtr(regT3, Address(stackPointerRegister, OBJECT_OFFSETOF(NativeCallFrameStructure, thisValue) + OBJECT_OFFSETOF(JSValue, u.asBits.tag))); |
|
225 |
||
226 |
#if COMPILER(MSVC) || PLATFORM(LINUX) |
|
227 |
// ArgList is passed by reference so is stackPointerRegister + 4 * sizeof(Register) |
|
228 |
addPtr(Imm32(OBJECT_OFFSETOF(NativeCallFrameStructure, result)), stackPointerRegister, X86Registers::ecx); |
|
229 |
||
230 |
// Plant callee |
|
231 |
emitGetFromCallFrameHeaderPtr(RegisterFile::Callee, X86Registers::eax); |
|
232 |
storePtr(X86Registers::eax, Address(stackPointerRegister, OBJECT_OFFSETOF(NativeCallFrameStructure, callee))); |
|
233 |
||
234 |
// Plant callframe |
|
235 |
move(callFrameRegister, X86Registers::edx); |
|
236 |
||
237 |
call(Address(X86Registers::eax, OBJECT_OFFSETOF(JSFunction, m_data))); |
|
238 |
||
239 |
// JSValue is a non-POD type, so eax points to it |
|
240 |
emitLoad(0, regT1, regT0, X86Registers::eax); |
|
241 |
#else |
|
242 |
emitGetFromCallFrameHeaderPtr(RegisterFile::Callee, X86Registers::edx); // callee |
|
243 |
move(callFrameRegister, X86Registers::ecx); // callFrame |
|
244 |
call(Address(X86Registers::edx, OBJECT_OFFSETOF(JSFunction, m_data))); |
|
245 |
#endif |
|
246 |
||
247 |
// We've put a few temporaries on the stack in addition to the actual arguments |
|
248 |
// so pull them off now |
|
249 |
addPtr(Imm32(NativeCallFrameSize - sizeof(NativeFunctionCalleeSignature)), stackPointerRegister); |
|
250 |
||
251 |
// Check for an exception |
|
252 |
move(ImmPtr(&globalData->exception), regT2); |
|
253 |
Jump sawException = branch32(NotEqual, tagFor(0, regT2), Imm32(JSValue::EmptyValueTag)); |
|
254 |
||
255 |
// Grab the return address. |
|
256 |
emitGetFromCallFrameHeaderPtr(RegisterFile::ReturnPC, regT3); |
|
257 |
||
258 |
// Restore our caller's "r". |
|
259 |
emitGetFromCallFrameHeaderPtr(RegisterFile::CallerFrame, callFrameRegister); |
|
260 |
||
261 |
// Return. |
|
262 |
restoreReturnAddressBeforeReturn(regT3); |
|
263 |
ret(); |
|
264 |
||
265 |
// Handle an exception |
|
266 |
sawException.link(this); |
|
267 |
// Grab the return address. |
|
268 |
emitGetFromCallFrameHeaderPtr(RegisterFile::ReturnPC, regT1); |
|
269 |
move(ImmPtr(&globalData->exceptionLocation), regT2); |
|
270 |
storePtr(regT1, regT2); |
|
271 |
move(ImmPtr(FunctionPtr(ctiVMThrowTrampoline).value()), regT2); |
|
272 |
emitGetFromCallFrameHeaderPtr(RegisterFile::CallerFrame, callFrameRegister); |
|
273 |
poke(callFrameRegister, OBJECT_OFFSETOF(struct JITStackFrame, callFrame) / sizeof (void*)); |
|
274 |
restoreReturnAddressBeforeReturn(regT2); |
|
275 |
ret(); |
|
276 |
||
277 |
#elif ENABLE(JIT_OPTIMIZE_NATIVE_CALL) |
|
278 |
#error "JIT_OPTIMIZE_NATIVE_CALL not yet supported on this platform." |
|
279 |
#else |
|
280 |
breakpoint(); |
|
281 |
#endif |
|
282 |
||
283 |
#if ENABLE(JIT_OPTIMIZE_PROPERTY_ACCESS) |
|
284 |
Call string_failureCases1Call = makeTailRecursiveCall(string_failureCases1); |
|
285 |
Call string_failureCases2Call = makeTailRecursiveCall(string_failureCases2); |
|
286 |
Call string_failureCases3Call = makeTailRecursiveCall(string_failureCases3); |
|
287 |
#endif |
|
288 |
||
289 |
// All trampolines constructed! copy the code, link up calls, and set the pointers on the Machine object. |
|
290 |
LinkBuffer patchBuffer(this, m_globalData->executableAllocator.poolForSize(m_assembler.size())); |
|
291 |
||
292 |
#if ENABLE(JIT_OPTIMIZE_PROPERTY_ACCESS) |
|
293 |
patchBuffer.link(string_failureCases1Call, FunctionPtr(cti_op_get_by_id_string_fail)); |
|
294 |
patchBuffer.link(string_failureCases2Call, FunctionPtr(cti_op_get_by_id_string_fail)); |
|
295 |
patchBuffer.link(string_failureCases3Call, FunctionPtr(cti_op_get_by_id_string_fail)); |
|
296 |
#endif |
|
297 |
patchBuffer.link(callArityCheck1, FunctionPtr(cti_op_call_arityCheck)); |
|
298 |
patchBuffer.link(callJSFunction1, FunctionPtr(cti_op_call_JSFunction)); |
|
299 |
#if ENABLE(JIT_OPTIMIZE_CALL) |
|
300 |
patchBuffer.link(callArityCheck2, FunctionPtr(cti_op_call_arityCheck)); |
|
301 |
patchBuffer.link(callJSFunction2, FunctionPtr(cti_op_call_JSFunction)); |
|
302 |
patchBuffer.link(callLazyLinkCall, FunctionPtr(cti_vm_lazyLinkCall)); |
|
303 |
#endif |
|
304 |
||
305 |
CodeRef finalCode = patchBuffer.finalizeCode(); |
|
306 |
*executablePool = finalCode.m_executablePool; |
|
307 |
||
308 |
*ctiVirtualCall = trampolineAt(finalCode, virtualCallBegin); |
|
309 |
*ctiNativeCallThunk = trampolineAt(finalCode, nativeCallThunk); |
|
310 |
#if ENABLE(JIT_OPTIMIZE_PROPERTY_ACCESS) |
|
311 |
*ctiStringLengthTrampoline = trampolineAt(finalCode, stringLengthBegin); |
|
312 |
#else |
|
313 |
UNUSED_PARAM(ctiStringLengthTrampoline); |
|
314 |
#endif |
|
315 |
#if ENABLE(JIT_OPTIMIZE_CALL) |
|
316 |
*ctiVirtualCallLink = trampolineAt(finalCode, virtualCallLinkBegin); |
|
317 |
#else |
|
318 |
UNUSED_PARAM(ctiVirtualCallLink); |
|
319 |
#endif |
|
320 |
} |
|
321 |
||
322 |
void JIT::emit_op_mov(Instruction* currentInstruction) |
|
323 |
{ |
|
324 |
unsigned dst = currentInstruction[1].u.operand; |
|
325 |
unsigned src = currentInstruction[2].u.operand; |
|
326 |
||
327 |
if (m_codeBlock->isConstantRegisterIndex(src)) |
|
328 |
emitStore(dst, getConstantOperand(src)); |
|
329 |
else { |
|
330 |
emitLoad(src, regT1, regT0); |
|
331 |
emitStore(dst, regT1, regT0); |
|
332 |
map(m_bytecodeIndex + OPCODE_LENGTH(op_mov), dst, regT1, regT0); |
|
333 |
} |
|
334 |
} |
|
335 |
||
336 |
void JIT::emit_op_end(Instruction* currentInstruction) |
|
337 |
{ |
|
338 |
if (m_codeBlock->needsFullScopeChain()) |
|
339 |
JITStubCall(this, cti_op_end).call(); |
|
340 |
ASSERT(returnValueRegister != callFrameRegister); |
|
341 |
emitLoad(currentInstruction[1].u.operand, regT1, regT0); |
|
342 |
restoreReturnAddressBeforeReturn(Address(callFrameRegister, RegisterFile::ReturnPC * static_cast<int>(sizeof(Register)))); |
|
343 |
ret(); |
|
344 |
} |
|
345 |
||
346 |
void JIT::emit_op_jmp(Instruction* currentInstruction) |
|
347 |
{ |
|
348 |
unsigned target = currentInstruction[1].u.operand; |
|
349 |
addJump(jump(), target); |
|
350 |
} |
|
351 |
||
352 |
void JIT::emit_op_loop(Instruction* currentInstruction) |
|
353 |
{ |
|
354 |
unsigned target = currentInstruction[1].u.operand; |
|
355 |
emitTimeoutCheck(); |
|
356 |
addJump(jump(), target); |
|
357 |
} |
|
358 |
||
359 |
void JIT::emit_op_loop_if_less(Instruction* currentInstruction) |
|
360 |
{ |
|
361 |
unsigned op1 = currentInstruction[1].u.operand; |
|
362 |
unsigned op2 = currentInstruction[2].u.operand; |
|
363 |
unsigned target = currentInstruction[3].u.operand; |
|
364 |
||
365 |
emitTimeoutCheck(); |
|
366 |
||
367 |
if (isOperandConstantImmediateInt(op1)) { |
|
368 |
emitLoad(op2, regT1, regT0); |
|
369 |
addSlowCase(branch32(NotEqual, regT1, Imm32(JSValue::Int32Tag))); |
|
370 |
addJump(branch32(GreaterThan, regT0, Imm32(getConstantOperand(op1).asInt32())), target); |
|
371 |
return; |
|
372 |
} |
|
373 |
||
374 |
if (isOperandConstantImmediateInt(op2)) { |
|
375 |
emitLoad(op1, regT1, regT0); |
|
376 |
addSlowCase(branch32(NotEqual, regT1, Imm32(JSValue::Int32Tag))); |
|
377 |
addJump(branch32(LessThan, regT0, Imm32(getConstantOperand(op2).asInt32())), target); |
|
378 |
return; |
|
379 |
} |
|
380 |
||
381 |
emitLoad2(op1, regT1, regT0, op2, regT3, regT2); |
|
382 |
addSlowCase(branch32(NotEqual, regT1, Imm32(JSValue::Int32Tag))); |
|
383 |
addSlowCase(branch32(NotEqual, regT3, Imm32(JSValue::Int32Tag))); |
|
384 |
addJump(branch32(LessThan, regT0, regT2), target); |
|
385 |
} |
|
386 |
||
387 |
void JIT::emitSlow_op_loop_if_less(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter) |
|
388 |
{ |
|
389 |
unsigned op1 = currentInstruction[1].u.operand; |
|
390 |
unsigned op2 = currentInstruction[2].u.operand; |
|
391 |
unsigned target = currentInstruction[3].u.operand; |
|
392 |
||
393 |
if (!isOperandConstantImmediateInt(op1) && !isOperandConstantImmediateInt(op2)) |
|
394 |
linkSlowCase(iter); // int32 check |
|
395 |
linkSlowCase(iter); // int32 check |
|
396 |
||
397 |
JITStubCall stubCall(this, cti_op_loop_if_less); |
|
398 |
stubCall.addArgument(op1); |
|
399 |
stubCall.addArgument(op2); |
|
400 |
stubCall.call(); |
|
401 |
emitJumpSlowToHot(branchTest32(NonZero, regT0), target); |
|
402 |
} |
|
403 |
||
404 |
void JIT::emit_op_loop_if_lesseq(Instruction* currentInstruction) |
|
405 |
{ |
|
406 |
unsigned op1 = currentInstruction[1].u.operand; |
|
407 |
unsigned op2 = currentInstruction[2].u.operand; |
|
408 |
unsigned target = currentInstruction[3].u.operand; |
|
409 |
||
410 |
emitTimeoutCheck(); |
|
411 |
||
412 |
if (isOperandConstantImmediateInt(op1)) { |
|
413 |
emitLoad(op2, regT1, regT0); |
|
414 |
addSlowCase(branch32(NotEqual, regT1, Imm32(JSValue::Int32Tag))); |
|
415 |
addJump(branch32(GreaterThanOrEqual, regT0, Imm32(getConstantOperand(op1).asInt32())), target); |
|
416 |
return; |
|
417 |
} |
|
418 |
||
419 |
if (isOperandConstantImmediateInt(op2)) { |
|
420 |
emitLoad(op1, regT1, regT0); |
|
421 |
addSlowCase(branch32(NotEqual, regT1, Imm32(JSValue::Int32Tag))); |
|
422 |
addJump(branch32(LessThanOrEqual, regT0, Imm32(getConstantOperand(op2).asInt32())), target); |
|
423 |
return; |
|
424 |
} |
|
425 |
||
426 |
emitLoad2(op1, regT1, regT0, op2, regT3, regT2); |
|
427 |
addSlowCase(branch32(NotEqual, regT1, Imm32(JSValue::Int32Tag))); |
|
428 |
addSlowCase(branch32(NotEqual, regT3, Imm32(JSValue::Int32Tag))); |
|
429 |
addJump(branch32(LessThanOrEqual, regT0, regT2), target); |
|
430 |
} |
|
431 |
||
432 |
void JIT::emitSlow_op_loop_if_lesseq(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter) |
|
433 |
{ |
|
434 |
unsigned op1 = currentInstruction[1].u.operand; |
|
435 |
unsigned op2 = currentInstruction[2].u.operand; |
|
436 |
unsigned target = currentInstruction[3].u.operand; |
|
437 |
||
438 |
if (!isOperandConstantImmediateInt(op1) && !isOperandConstantImmediateInt(op2)) |
|
439 |
linkSlowCase(iter); // int32 check |
|
440 |
linkSlowCase(iter); // int32 check |
|
441 |
||
442 |
JITStubCall stubCall(this, cti_op_loop_if_lesseq); |
|
443 |
stubCall.addArgument(op1); |
|
444 |
stubCall.addArgument(op2); |
|
445 |
stubCall.call(); |
|
446 |
emitJumpSlowToHot(branchTest32(NonZero, regT0), target); |
|
447 |
} |
|
448 |
||
449 |
void JIT::emit_op_new_object(Instruction* currentInstruction) |
|
450 |
{ |
|
451 |
JITStubCall(this, cti_op_new_object).call(currentInstruction[1].u.operand); |
|
452 |
} |
|
453 |
||
454 |
void JIT::emit_op_instanceof(Instruction* currentInstruction) |
|
455 |
{ |
|
456 |
unsigned dst = currentInstruction[1].u.operand; |
|
457 |
unsigned value = currentInstruction[2].u.operand; |
|
458 |
unsigned baseVal = currentInstruction[3].u.operand; |
|
459 |
unsigned proto = currentInstruction[4].u.operand; |
|
460 |
||
461 |
// Load the operands into registers. |
|
462 |
// We use regT0 for baseVal since we will be done with this first, and we can then use it for the result. |
|
463 |
emitLoadPayload(value, regT2); |
|
464 |
emitLoadPayload(baseVal, regT0); |
|
465 |
emitLoadPayload(proto, regT1); |
|
466 |
||
467 |
// Check that value, baseVal, and proto are cells. |
|
468 |
emitJumpSlowCaseIfNotJSCell(value); |
|
469 |
emitJumpSlowCaseIfNotJSCell(baseVal); |
|
470 |
emitJumpSlowCaseIfNotJSCell(proto); |
|
471 |
||
472 |
// Check that baseVal 'ImplementsDefaultHasInstance'. |
|
473 |
loadPtr(Address(regT0, OBJECT_OFFSETOF(JSCell, m_structure)), regT0); |
|
474 |
addSlowCase(branchTest32(Zero, Address(regT0, OBJECT_OFFSETOF(Structure, m_typeInfo.m_flags)), Imm32(ImplementsDefaultHasInstance))); |
|
475 |
||
476 |
// Optimistically load the result true, and start looping. |
|
477 |
// Initially, regT1 still contains proto and regT2 still contains value. |
|
478 |
// As we loop regT2 will be updated with its prototype, recursively walking the prototype chain. |
|
479 |
move(Imm32(JSValue::TrueTag), regT0); |
|
480 |
Label loop(this); |
|
481 |
||
482 |
// Load the prototype of the cell in regT2. If this is equal to regT1 - WIN! |
|
483 |
// Otherwise, check if we've hit null - if we have then drop out of the loop, if not go again. |
|
484 |
loadPtr(Address(regT2, OBJECT_OFFSETOF(JSCell, m_structure)), regT2); |
|
485 |
load32(Address(regT2, OBJECT_OFFSETOF(Structure, m_prototype) + OBJECT_OFFSETOF(JSValue, u.asBits.payload)), regT2); |
|
486 |
Jump isInstance = branchPtr(Equal, regT2, regT1); |
|
487 |
branchTest32(NonZero, regT2).linkTo(loop, this); |
|
488 |
||
489 |
// We get here either by dropping out of the loop, or if value was not an Object. Result is false. |
|
490 |
move(Imm32(JSValue::FalseTag), regT0); |
|
491 |
||
492 |
// isInstance jumps right down to here, to skip setting the result to false (it has already set true). |
|
493 |
isInstance.link(this); |
|
494 |
emitStoreBool(dst, regT0); |
|
495 |
} |
|
496 |
||
497 |
void JIT::emitSlow_op_instanceof(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter) |
|
498 |
{ |
|
499 |
unsigned dst = currentInstruction[1].u.operand; |
|
500 |
unsigned value = currentInstruction[2].u.operand; |
|
501 |
unsigned baseVal = currentInstruction[3].u.operand; |
|
502 |
unsigned proto = currentInstruction[4].u.operand; |
|
503 |
||
504 |
linkSlowCaseIfNotJSCell(iter, value); |
|
505 |
linkSlowCaseIfNotJSCell(iter, baseVal); |
|
506 |
linkSlowCaseIfNotJSCell(iter, proto); |
|
507 |
linkSlowCase(iter); |
|
508 |
||
509 |
JITStubCall stubCall(this, cti_op_instanceof); |
|
510 |
stubCall.addArgument(value); |
|
511 |
stubCall.addArgument(baseVal); |
|
512 |
stubCall.addArgument(proto); |
|
513 |
stubCall.call(dst); |
|
514 |
} |
|
515 |
||
516 |
void JIT::emit_op_new_func(Instruction* currentInstruction) |
|
517 |
{ |
|
518 |
JITStubCall stubCall(this, cti_op_new_func); |
|
519 |
stubCall.addArgument(ImmPtr(m_codeBlock->functionDecl(currentInstruction[2].u.operand))); |
|
520 |
stubCall.call(currentInstruction[1].u.operand); |
|
521 |
} |
|
522 |
||
523 |
void JIT::emit_op_get_global_var(Instruction* currentInstruction) |
|
524 |
{ |
|
525 |
int dst = currentInstruction[1].u.operand; |
|
526 |
JSGlobalObject* globalObject = static_cast<JSGlobalObject*>(currentInstruction[2].u.jsCell); |
|
527 |
ASSERT(globalObject->isGlobalObject()); |
|
528 |
int index = currentInstruction[3].u.operand; |
|
529 |
||
530 |
loadPtr(&globalObject->d()->registers, regT2); |
|
531 |
||
532 |
emitLoad(index, regT1, regT0, regT2); |
|
533 |
emitStore(dst, regT1, regT0); |
|
534 |
map(m_bytecodeIndex + OPCODE_LENGTH(op_get_global_var), dst, regT1, regT0); |
|
535 |
} |
|
536 |
||
537 |
void JIT::emit_op_put_global_var(Instruction* currentInstruction) |
|
538 |
{ |
|
539 |
JSGlobalObject* globalObject = static_cast<JSGlobalObject*>(currentInstruction[1].u.jsCell); |
|
540 |
ASSERT(globalObject->isGlobalObject()); |
|
541 |
int index = currentInstruction[2].u.operand; |
|
542 |
int value = currentInstruction[3].u.operand; |
|
543 |
||
544 |
emitLoad(value, regT1, regT0); |
|
545 |
||
546 |
loadPtr(&globalObject->d()->registers, regT2); |
|
547 |
emitStore(index, regT1, regT0, regT2); |
|
548 |
map(m_bytecodeIndex + OPCODE_LENGTH(op_put_global_var), value, regT1, regT0); |
|
549 |
} |
|
550 |
||
551 |
void JIT::emit_op_get_scoped_var(Instruction* currentInstruction) |
|
552 |
{ |
|
553 |
int dst = currentInstruction[1].u.operand; |
|
554 |
int index = currentInstruction[2].u.operand; |
|
555 |
int skip = currentInstruction[3].u.operand + m_codeBlock->needsFullScopeChain(); |
|
556 |
||
557 |
emitGetFromCallFrameHeaderPtr(RegisterFile::ScopeChain, regT2); |
|
558 |
while (skip--) |
|
559 |
loadPtr(Address(regT2, OBJECT_OFFSETOF(ScopeChainNode, next)), regT2); |
|
560 |
||
561 |
loadPtr(Address(regT2, OBJECT_OFFSETOF(ScopeChainNode, object)), regT2); |
|
562 |
loadPtr(Address(regT2, OBJECT_OFFSETOF(JSVariableObject, d)), regT2); |
|
563 |
loadPtr(Address(regT2, OBJECT_OFFSETOF(JSVariableObject::JSVariableObjectData, registers)), regT2); |
|
564 |
||
565 |
emitLoad(index, regT1, regT0, regT2); |
|
566 |
emitStore(dst, regT1, regT0); |
|
567 |
map(m_bytecodeIndex + OPCODE_LENGTH(op_get_scoped_var), dst, regT1, regT0); |
|
568 |
} |
|
569 |
||
570 |
void JIT::emit_op_put_scoped_var(Instruction* currentInstruction) |
|
571 |
{ |
|
572 |
int index = currentInstruction[1].u.operand; |
|
573 |
int skip = currentInstruction[2].u.operand + m_codeBlock->needsFullScopeChain(); |
|
574 |
int value = currentInstruction[3].u.operand; |
|
575 |
||
576 |
emitLoad(value, regT1, regT0); |
|
577 |
||
578 |
emitGetFromCallFrameHeaderPtr(RegisterFile::ScopeChain, regT2); |
|
579 |
while (skip--) |
|
580 |
loadPtr(Address(regT2, OBJECT_OFFSETOF(ScopeChainNode, next)), regT2); |
|
581 |
||
582 |
loadPtr(Address(regT2, OBJECT_OFFSETOF(ScopeChainNode, object)), regT2); |
|
583 |
loadPtr(Address(regT2, OBJECT_OFFSETOF(JSVariableObject, d)), regT2); |
|
584 |
loadPtr(Address(regT2, OBJECT_OFFSETOF(JSVariableObject::JSVariableObjectData, registers)), regT2); |
|
585 |
||
586 |
emitStore(index, regT1, regT0, regT2); |
|
587 |
map(m_bytecodeIndex + OPCODE_LENGTH(op_put_scoped_var), value, regT1, regT0); |
|
588 |
} |
|
589 |
||
590 |
void JIT::emit_op_tear_off_activation(Instruction* currentInstruction) |
|
591 |
{ |
|
592 |
JITStubCall stubCall(this, cti_op_tear_off_activation); |
|
593 |
stubCall.addArgument(currentInstruction[1].u.operand); |
|
594 |
stubCall.call(); |
|
595 |
} |
|
596 |
||
597 |
void JIT::emit_op_tear_off_arguments(Instruction*) |
|
598 |
{ |
|
599 |
JITStubCall(this, cti_op_tear_off_arguments).call(); |
|
600 |
} |
|
601 |
||
602 |
void JIT::emit_op_new_array(Instruction* currentInstruction) |
|
603 |
{ |
|
604 |
JITStubCall stubCall(this, cti_op_new_array); |
|
605 |
stubCall.addArgument(Imm32(currentInstruction[2].u.operand)); |
|
606 |
stubCall.addArgument(Imm32(currentInstruction[3].u.operand)); |
|
607 |
stubCall.call(currentInstruction[1].u.operand); |
|
608 |
} |
|
609 |
||
610 |
void JIT::emit_op_resolve(Instruction* currentInstruction) |
|
611 |
{ |
|
612 |
JITStubCall stubCall(this, cti_op_resolve); |
|
613 |
stubCall.addArgument(ImmPtr(&m_codeBlock->identifier(currentInstruction[2].u.operand))); |
|
614 |
stubCall.call(currentInstruction[1].u.operand); |
|
615 |
} |
|
616 |
||
617 |
void JIT::emit_op_to_primitive(Instruction* currentInstruction) |
|
618 |
{ |
|
619 |
int dst = currentInstruction[1].u.operand; |
|
620 |
int src = currentInstruction[2].u.operand; |
|
621 |
||
622 |
emitLoad(src, regT1, regT0); |
|
623 |
||
624 |
Jump isImm = branch32(NotEqual, regT1, Imm32(JSValue::CellTag)); |
|
625 |
addSlowCase(branchPtr(NotEqual, Address(regT0), ImmPtr(m_globalData->jsStringVPtr))); |
|
626 |
isImm.link(this); |
|
627 |
||
628 |
if (dst != src) |
|
629 |
emitStore(dst, regT1, regT0); |
|
630 |
map(m_bytecodeIndex + OPCODE_LENGTH(op_to_primitive), dst, regT1, regT0); |
|
631 |
} |
|
632 |
||
633 |
void JIT::emitSlow_op_to_primitive(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter) |
|
634 |
{ |
|
635 |
int dst = currentInstruction[1].u.operand; |
|
636 |
||
637 |
linkSlowCase(iter); |
|
638 |
||
639 |
JITStubCall stubCall(this, cti_op_to_primitive); |
|
640 |
stubCall.addArgument(regT1, regT0); |
|
641 |
stubCall.call(dst); |
|
642 |
} |
|
643 |
||
644 |
void JIT::emit_op_strcat(Instruction* currentInstruction) |
|
645 |
{ |
|
646 |
JITStubCall stubCall(this, cti_op_strcat); |
|
647 |
stubCall.addArgument(Imm32(currentInstruction[2].u.operand)); |
|
648 |
stubCall.addArgument(Imm32(currentInstruction[3].u.operand)); |
|
649 |
stubCall.call(currentInstruction[1].u.operand); |
|
650 |
} |
|
651 |
||
652 |
void JIT::emit_op_loop_if_true(Instruction* currentInstruction) |
|
653 |
{ |
|
654 |
unsigned cond = currentInstruction[1].u.operand; |
|
655 |
unsigned target = currentInstruction[2].u.operand; |
|
656 |
||
657 |
emitTimeoutCheck(); |
|
658 |
||
659 |
emitLoad(cond, regT1, regT0); |
|
660 |
||
661 |
Jump isNotInteger = branch32(NotEqual, regT1, Imm32(JSValue::Int32Tag)); |
|
662 |
addJump(branch32(NotEqual, regT0, Imm32(0)), target); |
|
663 |
Jump isNotZero = jump(); |
|
664 |
||
665 |
isNotInteger.link(this); |
|
666 |
||
667 |
addJump(branch32(Equal, regT1, Imm32(JSValue::TrueTag)), target); |
|
668 |
addSlowCase(branch32(NotEqual, regT1, Imm32(JSValue::FalseTag))); |
|
669 |
||
670 |
isNotZero.link(this); |
|
671 |
} |
|
672 |
||
673 |
void JIT::emitSlow_op_loop_if_true(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter) |
|
674 |
{ |
|
675 |
unsigned cond = currentInstruction[1].u.operand; |
|
676 |
unsigned target = currentInstruction[2].u.operand; |
|
677 |
||
678 |
linkSlowCase(iter); |
|
679 |
||
680 |
JITStubCall stubCall(this, cti_op_jtrue); |
|
681 |
stubCall.addArgument(cond); |
|
682 |
stubCall.call(); |
|
683 |
emitJumpSlowToHot(branchTest32(NonZero, regT0), target); |
|
684 |
} |
|
685 |
||
686 |
void JIT::emit_op_resolve_base(Instruction* currentInstruction) |
|
687 |
{ |
|
688 |
JITStubCall stubCall(this, cti_op_resolve_base); |
|
689 |
stubCall.addArgument(ImmPtr(&m_codeBlock->identifier(currentInstruction[2].u.operand))); |
|
690 |
stubCall.call(currentInstruction[1].u.operand); |
|
691 |
} |
|
692 |
||
693 |
void JIT::emit_op_resolve_skip(Instruction* currentInstruction) |
|
694 |
{ |
|
695 |
JITStubCall stubCall(this, cti_op_resolve_skip); |
|
696 |
stubCall.addArgument(ImmPtr(&m_codeBlock->identifier(currentInstruction[2].u.operand))); |
|
697 |
stubCall.addArgument(Imm32(currentInstruction[3].u.operand + m_codeBlock->needsFullScopeChain())); |
|
698 |
stubCall.call(currentInstruction[1].u.operand); |
|
699 |
} |
|
700 |
||
701 |
void JIT::emit_op_resolve_global(Instruction* currentInstruction) |
|
702 |
{ |
|
703 |
// FIXME: Optimize to use patching instead of so many memory accesses. |
|
704 |
||
705 |
unsigned dst = currentInstruction[1].u.operand; |
|
706 |
void* globalObject = currentInstruction[2].u.jsCell; |
|
707 |
||
708 |
unsigned currentIndex = m_globalResolveInfoIndex++; |
|
709 |
void* structureAddress = &(m_codeBlock->globalResolveInfo(currentIndex).structure); |
|
710 |
void* offsetAddr = &(m_codeBlock->globalResolveInfo(currentIndex).offset); |
|
711 |
||
712 |
// Verify structure. |
|
713 |
move(ImmPtr(globalObject), regT0); |
|
714 |
loadPtr(structureAddress, regT1); |
|
715 |
addSlowCase(branchPtr(NotEqual, regT1, Address(regT0, OBJECT_OFFSETOF(JSCell, m_structure)))); |
|
716 |
||
717 |
// Load property. |
|
718 |
loadPtr(Address(regT0, OBJECT_OFFSETOF(JSGlobalObject, m_externalStorage)), regT2); |
|
719 |
load32(offsetAddr, regT3); |
|
720 |
load32(BaseIndex(regT2, regT3, TimesEight), regT0); // payload |
|
721 |
load32(BaseIndex(regT2, regT3, TimesEight, 4), regT1); // tag |
|
722 |
emitStore(dst, regT1, regT0); |
|
723 |
map(m_bytecodeIndex + OPCODE_LENGTH(op_resolve_global), dst, regT1, regT0); |
|
724 |
} |
|
725 |
||
726 |
void JIT::emitSlow_op_resolve_global(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter) |
|
727 |
{ |
|
728 |
unsigned dst = currentInstruction[1].u.operand; |
|
729 |
void* globalObject = currentInstruction[2].u.jsCell; |
|
730 |
Identifier* ident = &m_codeBlock->identifier(currentInstruction[3].u.operand); |
|
731 |
||
732 |
unsigned currentIndex = m_globalResolveInfoIndex++; |
|
733 |
||
734 |
linkSlowCase(iter); |
|
735 |
JITStubCall stubCall(this, cti_op_resolve_global); |
|
736 |
stubCall.addArgument(ImmPtr(globalObject)); |
|
737 |
stubCall.addArgument(ImmPtr(ident)); |
|
738 |
stubCall.addArgument(Imm32(currentIndex)); |
|
739 |
stubCall.call(dst); |
|
740 |
} |
|
741 |
||
742 |
void JIT::emit_op_not(Instruction* currentInstruction) |
|
743 |
{ |
|
744 |
unsigned dst = currentInstruction[1].u.operand; |
|
745 |
unsigned src = currentInstruction[2].u.operand; |
|
746 |
||
747 |
emitLoadTag(src, regT0); |
|
748 |
||
749 |
xor32(Imm32(JSValue::FalseTag), regT0); |
|
750 |
addSlowCase(branchTest32(NonZero, regT0, Imm32(~1))); |
|
751 |
xor32(Imm32(JSValue::TrueTag), regT0); |
|
752 |
||
753 |
emitStoreBool(dst, regT0, (dst == src)); |
|
754 |
} |
|
755 |
||
756 |
void JIT::emitSlow_op_not(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter) |
|
757 |
{ |
|
758 |
unsigned dst = currentInstruction[1].u.operand; |
|
759 |
unsigned src = currentInstruction[2].u.operand; |
|
760 |
||
761 |
linkSlowCase(iter); |
|
762 |
||
763 |
JITStubCall stubCall(this, cti_op_not); |
|
764 |
stubCall.addArgument(src); |
|
765 |
stubCall.call(dst); |
|
766 |
} |
|
767 |
||
768 |
void JIT::emit_op_jfalse(Instruction* currentInstruction) |
|
769 |
{ |
|
770 |
unsigned cond = currentInstruction[1].u.operand; |
|
771 |
unsigned target = currentInstruction[2].u.operand; |
|
772 |
||
773 |
emitLoad(cond, regT1, regT0); |
|
774 |
||
775 |
Jump isTrue = branch32(Equal, regT1, Imm32(JSValue::TrueTag)); |
|
776 |
addJump(branch32(Equal, regT1, Imm32(JSValue::FalseTag)), target); |
|
777 |
||
778 |
Jump isNotInteger = branch32(NotEqual, regT1, Imm32(JSValue::Int32Tag)); |
|
779 |
Jump isTrue2 = branch32(NotEqual, regT0, Imm32(0)); |
|
780 |
addJump(jump(), target); |
|
781 |
||
782 |
if (supportsFloatingPoint()) { |
|
783 |
isNotInteger.link(this); |
|
784 |
||
785 |
addSlowCase(branch32(Above, regT1, Imm32(JSValue::LowestTag))); |
|
786 |
||
787 |
zeroDouble(fpRegT0); |
|
788 |
emitLoadDouble(cond, fpRegT1); |
|
789 |
addJump(branchDouble(DoubleEqual, fpRegT0, fpRegT1), target); |
|
790 |
} else |
|
791 |
addSlowCase(isNotInteger); |
|
792 |
||
793 |
isTrue.link(this); |
|
794 |
isTrue2.link(this); |
|
795 |
} |
|
796 |
||
797 |
void JIT::emitSlow_op_jfalse(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter) |
|
798 |
{ |
|
799 |
unsigned cond = currentInstruction[1].u.operand; |
|
800 |
unsigned target = currentInstruction[2].u.operand; |
|
801 |
||
802 |
linkSlowCase(iter); |
|
803 |
JITStubCall stubCall(this, cti_op_jtrue); |
|
804 |
stubCall.addArgument(cond); |
|
805 |
stubCall.call(); |
|
806 |
emitJumpSlowToHot(branchTest32(Zero, regT0), target); // Inverted. |
|
807 |
} |
|
808 |
||
809 |
void JIT::emit_op_jtrue(Instruction* currentInstruction) |
|
810 |
{ |
|
811 |
unsigned cond = currentInstruction[1].u.operand; |
|
812 |
unsigned target = currentInstruction[2].u.operand; |
|
813 |
||
814 |
emitLoad(cond, regT1, regT0); |
|
815 |
||
816 |
Jump isFalse = branch32(Equal, regT1, Imm32(JSValue::FalseTag)); |
|
817 |
addJump(branch32(Equal, regT1, Imm32(JSValue::TrueTag)), target); |
|
818 |
||
819 |
Jump isNotInteger = branch32(NotEqual, regT1, Imm32(JSValue::Int32Tag)); |
|
820 |
Jump isFalse2 = branch32(Equal, regT0, Imm32(0)); |
|
821 |
addJump(jump(), target); |
|
822 |
||
823 |
if (supportsFloatingPoint()) { |
|
824 |
isNotInteger.link(this); |
|
825 |
||
826 |
addSlowCase(branch32(Above, regT1, Imm32(JSValue::LowestTag))); |
|
827 |
||
828 |
zeroDouble(fpRegT0); |
|
829 |
emitLoadDouble(cond, fpRegT1); |
|
830 |
addJump(branchDouble(DoubleNotEqual, fpRegT0, fpRegT1), target); |
|
831 |
} else |
|
832 |
addSlowCase(isNotInteger); |
|
833 |
||
834 |
isFalse.link(this); |
|
835 |
isFalse2.link(this); |
|
836 |
} |
|
837 |
||
838 |
void JIT::emitSlow_op_jtrue(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter) |
|
839 |
{ |
|
840 |
unsigned cond = currentInstruction[1].u.operand; |
|
841 |
unsigned target = currentInstruction[2].u.operand; |
|
842 |
||
843 |
linkSlowCase(iter); |
|
844 |
JITStubCall stubCall(this, cti_op_jtrue); |
|
845 |
stubCall.addArgument(cond); |
|
846 |
stubCall.call(); |
|
847 |
emitJumpSlowToHot(branchTest32(NonZero, regT0), target); |
|
848 |
} |
|
849 |
||
850 |
void JIT::emit_op_jeq_null(Instruction* currentInstruction) |
|
851 |
{ |
|
852 |
unsigned src = currentInstruction[1].u.operand; |
|
853 |
unsigned target = currentInstruction[2].u.operand; |
|
854 |
||
855 |
emitLoad(src, regT1, regT0); |
|
856 |
||
857 |
Jump isImmediate = branch32(NotEqual, regT1, Imm32(JSValue::CellTag)); |
|
858 |
||
859 |
// First, handle JSCell cases - check MasqueradesAsUndefined bit on the structure. |
|
860 |
loadPtr(Address(regT0, OBJECT_OFFSETOF(JSCell, m_structure)), regT2); |
|
861 |
addJump(branchTest32(NonZero, Address(regT2, OBJECT_OFFSETOF(Structure, m_typeInfo.m_flags)), Imm32(MasqueradesAsUndefined)), target); |
|
862 |
||
863 |
Jump wasNotImmediate = jump(); |
|
864 |
||
865 |
// Now handle the immediate cases - undefined & null |
|
866 |
isImmediate.link(this); |
|
867 |
||
868 |
set32(Equal, regT1, Imm32(JSValue::NullTag), regT2); |
|
869 |
set32(Equal, regT1, Imm32(JSValue::UndefinedTag), regT1); |
|
870 |
or32(regT2, regT1); |
|
871 |
||
872 |
addJump(branchTest32(NonZero, regT1), target); |
|
873 |
||
874 |
wasNotImmediate.link(this); |
|
875 |
} |
|
876 |
||
877 |
void JIT::emit_op_jneq_null(Instruction* currentInstruction) |
|
878 |
{ |
|
879 |
unsigned src = currentInstruction[1].u.operand; |
|
880 |
unsigned target = currentInstruction[2].u.operand; |
|
881 |
||
882 |
emitLoad(src, regT1, regT0); |
|
883 |
||
884 |
Jump isImmediate = branch32(NotEqual, regT1, Imm32(JSValue::CellTag)); |
|
885 |
||
886 |
// First, handle JSCell cases - check MasqueradesAsUndefined bit on the structure. |
|
887 |
loadPtr(Address(regT0, OBJECT_OFFSETOF(JSCell, m_structure)), regT2); |
|
888 |
addJump(branchTest32(Zero, Address(regT2, OBJECT_OFFSETOF(Structure, m_typeInfo.m_flags)), Imm32(MasqueradesAsUndefined)), target); |
|
889 |
||
890 |
Jump wasNotImmediate = jump(); |
|
891 |
||
892 |
// Now handle the immediate cases - undefined & null |
|
893 |
isImmediate.link(this); |
|
894 |
||
895 |
set32(Equal, regT1, Imm32(JSValue::NullTag), regT2); |
|
896 |
set32(Equal, regT1, Imm32(JSValue::UndefinedTag), regT1); |
|
897 |
or32(regT2, regT1); |
|
898 |
||
899 |
addJump(branchTest32(Zero, regT1), target); |
|
900 |
||
901 |
wasNotImmediate.link(this); |
|
902 |
} |
|
903 |
||
904 |
void JIT::emit_op_jneq_ptr(Instruction* currentInstruction) |
|
905 |
{ |
|
906 |
unsigned src = currentInstruction[1].u.operand; |
|
907 |
JSCell* ptr = currentInstruction[2].u.jsCell; |
|
908 |
unsigned target = currentInstruction[3].u.operand; |
|
909 |
||
910 |
emitLoad(src, regT1, regT0); |
|
911 |
addJump(branch32(NotEqual, regT1, Imm32(JSValue::CellTag)), target); |
|
912 |
addJump(branchPtr(NotEqual, regT0, ImmPtr(ptr)), target); |
|
913 |
} |
|
914 |
||
915 |
void JIT::emit_op_jsr(Instruction* currentInstruction) |
|
916 |
{ |
|
917 |
int retAddrDst = currentInstruction[1].u.operand; |
|
918 |
int target = currentInstruction[2].u.operand; |
|
919 |
DataLabelPtr storeLocation = storePtrWithPatch(ImmPtr(0), Address(callFrameRegister, sizeof(Register) * retAddrDst)); |
|
920 |
addJump(jump(), target); |
|
921 |
m_jsrSites.append(JSRInfo(storeLocation, label())); |
|
922 |
} |
|
923 |
||
924 |
void JIT::emit_op_sret(Instruction* currentInstruction) |
|
925 |
{ |
|
926 |
jump(Address(callFrameRegister, sizeof(Register) * currentInstruction[1].u.operand)); |
|
927 |
} |
|
928 |
||
929 |
void JIT::emit_op_eq(Instruction* currentInstruction) |
|
930 |
{ |
|
931 |
unsigned dst = currentInstruction[1].u.operand; |
|
932 |
unsigned src1 = currentInstruction[2].u.operand; |
|
933 |
unsigned src2 = currentInstruction[3].u.operand; |
|
934 |
||
935 |
emitLoad2(src1, regT1, regT0, src2, regT3, regT2); |
|
936 |
addSlowCase(branch32(NotEqual, regT1, regT3)); |
|
937 |
addSlowCase(branch32(Equal, regT1, Imm32(JSValue::CellTag))); |
|
938 |
addSlowCase(branch32(Below, regT1, Imm32(JSValue::LowestTag))); |
|
939 |
||
940 |
set8(Equal, regT0, regT2, regT0); |
|
941 |
or32(Imm32(JSValue::FalseTag), regT0); |
|
942 |
||
943 |
emitStoreBool(dst, regT0); |
|
944 |
} |
|
945 |
||
946 |
void JIT::emitSlow_op_eq(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter) |
|
947 |
{ |
|
948 |
unsigned dst = currentInstruction[1].u.operand; |
|
949 |
unsigned op1 = currentInstruction[2].u.operand; |
|
950 |
unsigned op2 = currentInstruction[3].u.operand; |
|
951 |
||
952 |
JumpList storeResult; |
|
953 |
JumpList genericCase; |
|
954 |
||
955 |
genericCase.append(getSlowCase(iter)); // tags not equal |
|
956 |
||
957 |
linkSlowCase(iter); // tags equal and JSCell |
|
958 |
genericCase.append(branchPtr(NotEqual, Address(regT0), ImmPtr(m_globalData->jsStringVPtr))); |
|
959 |
genericCase.append(branchPtr(NotEqual, Address(regT2), ImmPtr(m_globalData->jsStringVPtr))); |
|
960 |
||
961 |
// String case. |
|
962 |
JITStubCall stubCallEqStrings(this, cti_op_eq_strings); |
|
963 |
stubCallEqStrings.addArgument(regT0); |
|
964 |
stubCallEqStrings.addArgument(regT2); |
|
965 |
stubCallEqStrings.call(); |
|
966 |
storeResult.append(jump()); |
|
967 |
||
968 |
// Generic case. |
|
969 |
genericCase.append(getSlowCase(iter)); // doubles |
|
970 |
genericCase.link(this); |
|
971 |
JITStubCall stubCallEq(this, cti_op_eq); |
|
972 |
stubCallEq.addArgument(op1); |
|
973 |
stubCallEq.addArgument(op2); |
|
974 |
stubCallEq.call(regT0); |
|
975 |
||
976 |
storeResult.link(this); |
|
977 |
or32(Imm32(JSValue::FalseTag), regT0); |
|
978 |
emitStoreBool(dst, regT0); |
|
979 |
} |
|
980 |
||
981 |
void JIT::emit_op_neq(Instruction* currentInstruction) |
|
982 |
{ |
|
983 |
unsigned dst = currentInstruction[1].u.operand; |
|
984 |
unsigned src1 = currentInstruction[2].u.operand; |
|
985 |
unsigned src2 = currentInstruction[3].u.operand; |
|
986 |
||
987 |
emitLoad2(src1, regT1, regT0, src2, regT3, regT2); |
|
988 |
addSlowCase(branch32(NotEqual, regT1, regT3)); |
|
989 |
addSlowCase(branch32(Equal, regT1, Imm32(JSValue::CellTag))); |
|
990 |
addSlowCase(branch32(Below, regT1, Imm32(JSValue::LowestTag))); |
|
991 |
||
992 |
set8(NotEqual, regT0, regT2, regT0); |
|
993 |
or32(Imm32(JSValue::FalseTag), regT0); |
|
994 |
||
995 |
emitStoreBool(dst, regT0); |
|
996 |
} |
|
997 |
||
998 |
void JIT::emitSlow_op_neq(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter) |
|
999 |
{ |
|
1000 |
unsigned dst = currentInstruction[1].u.operand; |
|
1001 |
||
1002 |
JumpList storeResult; |
|
1003 |
JumpList genericCase; |
|
1004 |
||
1005 |
genericCase.append(getSlowCase(iter)); // tags not equal |
|
1006 |
||
1007 |
linkSlowCase(iter); // tags equal and JSCell |
|
1008 |
genericCase.append(branchPtr(NotEqual, Address(regT0), ImmPtr(m_globalData->jsStringVPtr))); |
|
1009 |
genericCase.append(branchPtr(NotEqual, Address(regT2), ImmPtr(m_globalData->jsStringVPtr))); |
|
1010 |
||
1011 |
// String case. |
|
1012 |
JITStubCall stubCallEqStrings(this, cti_op_eq_strings); |
|
1013 |
stubCallEqStrings.addArgument(regT0); |
|
1014 |
stubCallEqStrings.addArgument(regT2); |
|
1015 |
stubCallEqStrings.call(regT0); |
|
1016 |
storeResult.append(jump()); |
|
1017 |
||
1018 |
// Generic case. |
|
1019 |
genericCase.append(getSlowCase(iter)); // doubles |
|
1020 |
genericCase.link(this); |
|
1021 |
JITStubCall stubCallEq(this, cti_op_eq); |
|
1022 |
stubCallEq.addArgument(regT1, regT0); |
|
1023 |
stubCallEq.addArgument(regT3, regT2); |
|
1024 |
stubCallEq.call(regT0); |
|
1025 |
||
1026 |
storeResult.link(this); |
|
1027 |
xor32(Imm32(0x1), regT0); |
|
1028 |
or32(Imm32(JSValue::FalseTag), regT0); |
|
1029 |
emitStoreBool(dst, regT0); |
|
1030 |
} |
|
1031 |
||
1032 |
void JIT::compileOpStrictEq(Instruction* currentInstruction, CompileOpStrictEqType type) |
|
1033 |
{ |
|
1034 |
unsigned dst = currentInstruction[1].u.operand; |
|
1035 |
unsigned src1 = currentInstruction[2].u.operand; |
|
1036 |
unsigned src2 = currentInstruction[3].u.operand; |
|
1037 |
||
1038 |
emitLoadTag(src1, regT0); |
|
1039 |
emitLoadTag(src2, regT1); |
|
1040 |
||
1041 |
// Jump to a slow case if either operand is double, or if both operands are |
|
1042 |
// cells and/or Int32s. |
|
1043 |
move(regT0, regT2); |
|
1044 |
and32(regT1, regT2); |
|
1045 |
addSlowCase(branch32(Below, regT2, Imm32(JSValue::LowestTag))); |
|
1046 |
addSlowCase(branch32(AboveOrEqual, regT2, Imm32(JSValue::CellTag))); |
|
1047 |
||
1048 |
if (type == OpStrictEq) |
|
1049 |
set8(Equal, regT0, regT1, regT0); |
|
1050 |
else |
|
1051 |
set8(NotEqual, regT0, regT1, regT0); |
|
1052 |
||
1053 |
or32(Imm32(JSValue::FalseTag), regT0); |
|
1054 |
||
1055 |
emitStoreBool(dst, regT0); |
|
1056 |
} |
|
1057 |
||
1058 |
void JIT::emit_op_stricteq(Instruction* currentInstruction) |
|
1059 |
{ |
|
1060 |
compileOpStrictEq(currentInstruction, OpStrictEq); |
|
1061 |
} |
|
1062 |
||
1063 |
void JIT::emitSlow_op_stricteq(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter) |
|
1064 |
{ |
|
1065 |
unsigned dst = currentInstruction[1].u.operand; |
|
1066 |
unsigned src1 = currentInstruction[2].u.operand; |
|
1067 |
unsigned src2 = currentInstruction[3].u.operand; |
|
1068 |
||
1069 |
linkSlowCase(iter); |
|
1070 |
linkSlowCase(iter); |
|
1071 |
||
1072 |
JITStubCall stubCall(this, cti_op_stricteq); |
|
1073 |
stubCall.addArgument(src1); |
|
1074 |
stubCall.addArgument(src2); |
|
1075 |
stubCall.call(dst); |
|
1076 |
} |
|
1077 |
||
1078 |
void JIT::emit_op_nstricteq(Instruction* currentInstruction) |
|
1079 |
{ |
|
1080 |
compileOpStrictEq(currentInstruction, OpNStrictEq); |
|
1081 |
} |
|
1082 |
||
1083 |
void JIT::emitSlow_op_nstricteq(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter) |
|
1084 |
{ |
|
1085 |
unsigned dst = currentInstruction[1].u.operand; |
|
1086 |
unsigned src1 = currentInstruction[2].u.operand; |
|
1087 |
unsigned src2 = currentInstruction[3].u.operand; |
|
1088 |
||
1089 |
linkSlowCase(iter); |
|
1090 |
linkSlowCase(iter); |
|
1091 |
||
1092 |
JITStubCall stubCall(this, cti_op_nstricteq); |
|
1093 |
stubCall.addArgument(src1); |
|
1094 |
stubCall.addArgument(src2); |
|
1095 |
stubCall.call(dst); |
|
1096 |
} |
|
1097 |
||
1098 |
void JIT::emit_op_eq_null(Instruction* currentInstruction) |
|
1099 |
{ |
|
1100 |
unsigned dst = currentInstruction[1].u.operand; |
|
1101 |
unsigned src = currentInstruction[2].u.operand; |
|
1102 |
||
1103 |
emitLoad(src, regT1, regT0); |
|
1104 |
Jump isImmediate = branch32(NotEqual, regT1, Imm32(JSValue::CellTag)); |
|
1105 |
||
1106 |
loadPtr(Address(regT0, OBJECT_OFFSETOF(JSCell, m_structure)), regT1); |
|
1107 |
setTest8(NonZero, Address(regT1, OBJECT_OFFSETOF(Structure, m_typeInfo.m_flags)), Imm32(MasqueradesAsUndefined), regT1); |
|
1108 |
||
1109 |
Jump wasNotImmediate = jump(); |
|
1110 |
||
1111 |
isImmediate.link(this); |
|
1112 |
||
1113 |
set8(Equal, regT1, Imm32(JSValue::NullTag), regT2); |
|
1114 |
set8(Equal, regT1, Imm32(JSValue::UndefinedTag), regT1); |
|
1115 |
or32(regT2, regT1); |
|
1116 |
||
1117 |
wasNotImmediate.link(this); |
|
1118 |
||
1119 |
or32(Imm32(JSValue::FalseTag), regT1); |
|
1120 |
||
1121 |
emitStoreBool(dst, regT1); |
|
1122 |
} |
|
1123 |
||
1124 |
void JIT::emit_op_neq_null(Instruction* currentInstruction) |
|
1125 |
{ |
|
1126 |
unsigned dst = currentInstruction[1].u.operand; |
|
1127 |
unsigned src = currentInstruction[2].u.operand; |
|
1128 |
||
1129 |
emitLoad(src, regT1, regT0); |
|
1130 |
Jump isImmediate = branch32(NotEqual, regT1, Imm32(JSValue::CellTag)); |
|
1131 |
||
1132 |
loadPtr(Address(regT0, OBJECT_OFFSETOF(JSCell, m_structure)), regT1); |
|
1133 |
setTest8(Zero, Address(regT1, OBJECT_OFFSETOF(Structure, m_typeInfo.m_flags)), Imm32(MasqueradesAsUndefined), regT1); |
|
1134 |
||
1135 |
Jump wasNotImmediate = jump(); |
|
1136 |
||
1137 |
isImmediate.link(this); |
|
1138 |
||
1139 |
set8(NotEqual, regT1, Imm32(JSValue::NullTag), regT2); |
|
1140 |
set8(NotEqual, regT1, Imm32(JSValue::UndefinedTag), regT1); |
|
1141 |
and32(regT2, regT1); |
|
1142 |
||
1143 |
wasNotImmediate.link(this); |
|
1144 |
||
1145 |
or32(Imm32(JSValue::FalseTag), regT1); |
|
1146 |
||
1147 |
emitStoreBool(dst, regT1); |
|
1148 |
} |
|
1149 |
||
1150 |
void JIT::emit_op_resolve_with_base(Instruction* currentInstruction) |
|
1151 |
{ |
|
1152 |
JITStubCall stubCall(this, cti_op_resolve_with_base); |
|
1153 |
stubCall.addArgument(ImmPtr(&m_codeBlock->identifier(currentInstruction[3].u.operand))); |
|
1154 |
stubCall.addArgument(Imm32(currentInstruction[1].u.operand)); |
|
1155 |
stubCall.call(currentInstruction[2].u.operand); |
|
1156 |
} |
|
1157 |
||
1158 |
void JIT::emit_op_new_func_exp(Instruction* currentInstruction) |
|
1159 |
{ |
|
1160 |
JITStubCall stubCall(this, cti_op_new_func_exp); |
|
1161 |
stubCall.addArgument(ImmPtr(m_codeBlock->functionExpr(currentInstruction[2].u.operand))); |
|
1162 |
stubCall.call(currentInstruction[1].u.operand); |
|
1163 |
} |
|
1164 |
||
1165 |
void JIT::emit_op_new_regexp(Instruction* currentInstruction) |
|
1166 |
{ |
|
1167 |
JITStubCall stubCall(this, cti_op_new_regexp); |
|
1168 |
stubCall.addArgument(ImmPtr(m_codeBlock->regexp(currentInstruction[2].u.operand))); |
|
1169 |
stubCall.call(currentInstruction[1].u.operand); |
|
1170 |
} |
|
1171 |
||
1172 |
void JIT::emit_op_throw(Instruction* currentInstruction) |
|
1173 |
{ |
|
1174 |
unsigned exception = currentInstruction[1].u.operand; |
|
1175 |
JITStubCall stubCall(this, cti_op_throw); |
|
1176 |
stubCall.addArgument(exception); |
|
1177 |
stubCall.call(); |
|
1178 |
||
1179 |
#ifndef NDEBUG |
|
1180 |
// cti_op_throw always changes it's return address, |
|
1181 |
// this point in the code should never be reached. |
|
1182 |
breakpoint(); |
|
1183 |
#endif |
|
1184 |
} |
|
1185 |
||
1186 |
void JIT::emit_op_get_pnames(Instruction* currentInstruction) |
|
1187 |
{ |
|
1188 |
int dst = currentInstruction[1].u.operand; |
|
1189 |
int base = currentInstruction[2].u.operand; |
|
1190 |
int i = currentInstruction[3].u.operand; |
|
1191 |
int size = currentInstruction[4].u.operand; |
|
1192 |
int breakTarget = currentInstruction[5].u.operand; |
|
1193 |
||
1194 |
JumpList isNotObject; |
|
1195 |
||
1196 |
emitLoad(base, regT1, regT0); |
|
1197 |
if (!m_codeBlock->isKnownNotImmediate(base)) |
|
1198 |
isNotObject.append(branch32(NotEqual, regT1, Imm32(JSValue::CellTag))); |
|
1199 |
if (base != m_codeBlock->thisRegister()) { |
|
1200 |
loadPtr(Address(regT0, OBJECT_OFFSETOF(JSCell, m_structure)), regT2); |
|
1201 |
isNotObject.append(branch32(NotEqual, Address(regT2, OBJECT_OFFSETOF(Structure, m_typeInfo.m_type)), Imm32(ObjectType))); |
|
1202 |
} |
|
1203 |
||
1204 |
// We could inline the case where you have a valid cache, but |
|
1205 |
// this call doesn't seem to be hot. |
|
1206 |
Label isObject(this); |
|
1207 |
JITStubCall getPnamesStubCall(this, cti_op_get_pnames); |
|
1208 |
getPnamesStubCall.addArgument(regT0); |
|
1209 |
getPnamesStubCall.call(dst); |
|
1210 |
load32(Address(regT0, OBJECT_OFFSETOF(JSPropertyNameIterator, m_jsStringsSize)), regT3); |
|
1211 |
store32(Imm32(0), addressFor(i)); |
|
1212 |
store32(regT3, addressFor(size)); |
|
1213 |
Jump end = jump(); |
|
1214 |
||
1215 |
isNotObject.link(this); |
|
1216 |
addJump(branch32(Equal, regT1, Imm32(JSValue::NullTag)), breakTarget); |
|
1217 |
addJump(branch32(Equal, regT1, Imm32(JSValue::UndefinedTag)), breakTarget); |
|
1218 |
JITStubCall toObjectStubCall(this, cti_to_object); |
|
1219 |
toObjectStubCall.addArgument(regT1, regT0); |
|
1220 |
toObjectStubCall.call(base); |
|
1221 |
jump().linkTo(isObject, this); |
|
1222 |
||
1223 |
end.link(this); |
|
1224 |
} |
|
1225 |
||
1226 |
void JIT::emit_op_next_pname(Instruction* currentInstruction) |
|
1227 |
{ |
|
1228 |
int dst = currentInstruction[1].u.operand; |
|
1229 |
int base = currentInstruction[2].u.operand; |
|
1230 |
int i = currentInstruction[3].u.operand; |
|
1231 |
int size = currentInstruction[4].u.operand; |
|
1232 |
int it = currentInstruction[5].u.operand; |
|
1233 |
int target = currentInstruction[6].u.operand; |
|
1234 |
||
1235 |
JumpList callHasProperty; |
|
1236 |
||
1237 |
Label begin(this); |
|
1238 |
load32(addressFor(i), regT0); |
|
1239 |
Jump end = branch32(Equal, regT0, addressFor(size)); |
|
1240 |
||
1241 |
// Grab key @ i |
|
1242 |
loadPtr(addressFor(it), regT1); |
|
1243 |
loadPtr(Address(regT1, OBJECT_OFFSETOF(JSPropertyNameIterator, m_jsStrings)), regT2); |
|
1244 |
load32(BaseIndex(regT2, regT0, TimesEight), regT2); |
|
1245 |
store32(Imm32(JSValue::CellTag), tagFor(dst)); |
|
1246 |
store32(regT2, payloadFor(dst)); |
|
1247 |
||
1248 |
// Increment i |
|
1249 |
add32(Imm32(1), regT0); |
|
1250 |
store32(regT0, addressFor(i)); |
|
1251 |
||
1252 |
// Verify that i is valid: |
|
1253 |
loadPtr(addressFor(base), regT0); |
|
1254 |
||
1255 |
// Test base's structure |
|
1256 |
loadPtr(Address(regT0, OBJECT_OFFSETOF(JSCell, m_structure)), regT2); |
|
1257 |
callHasProperty.append(branchPtr(NotEqual, regT2, Address(Address(regT1, OBJECT_OFFSETOF(JSPropertyNameIterator, m_cachedStructure))))); |
|
1258 |
||
1259 |
// Test base's prototype chain |
|
1260 |
loadPtr(Address(Address(regT1, OBJECT_OFFSETOF(JSPropertyNameIterator, m_cachedPrototypeChain))), regT3); |
|
1261 |
loadPtr(Address(regT3, OBJECT_OFFSETOF(StructureChain, m_vector)), regT3); |
|
1262 |
addJump(branchTestPtr(Zero, Address(regT3)), target); |
|
1263 |
||
1264 |
Label checkPrototype(this); |
|
1265 |
callHasProperty.append(branch32(Equal, Address(regT2, OBJECT_OFFSETOF(Structure, m_prototype) + OBJECT_OFFSETOF(JSValue, u.asBits.tag)), Imm32(JSValue::NullTag))); |
|
1266 |
loadPtr(Address(regT2, OBJECT_OFFSETOF(Structure, m_prototype) + OBJECT_OFFSETOF(JSValue, u.asBits.payload)), regT2); |
|
1267 |
loadPtr(Address(regT2, OBJECT_OFFSETOF(JSCell, m_structure)), regT2); |
|
1268 |
callHasProperty.append(branchPtr(NotEqual, regT2, Address(regT3))); |
|
1269 |
addPtr(Imm32(sizeof(Structure*)), regT3); |
|
1270 |
branchTestPtr(NonZero, Address(regT3)).linkTo(checkPrototype, this); |
|
1271 |
||
1272 |
// Continue loop. |
|
1273 |
addJump(jump(), target); |
|
1274 |
||
1275 |
// Slow case: Ask the object if i is valid. |
|
1276 |
callHasProperty.link(this); |
|
1277 |
loadPtr(addressFor(dst), regT1); |
|
1278 |
JITStubCall stubCall(this, cti_has_property); |
|
1279 |
stubCall.addArgument(regT0); |
|
1280 |
stubCall.addArgument(regT1); |
|
1281 |
stubCall.call(); |
|
1282 |
||
1283 |
// Test for valid key. |
|
1284 |
addJump(branchTest32(NonZero, regT0), target); |
|
1285 |
jump().linkTo(begin, this); |
|
1286 |
||
1287 |
// End of loop. |
|
1288 |
end.link(this); |
|
1289 |
} |
|
1290 |
||
1291 |
void JIT::emit_op_push_scope(Instruction* currentInstruction) |
|
1292 |
{ |
|
1293 |
JITStubCall stubCall(this, cti_op_push_scope); |
|
1294 |
stubCall.addArgument(currentInstruction[1].u.operand); |
|
1295 |
stubCall.call(currentInstruction[1].u.operand); |
|
1296 |
} |
|
1297 |
||
1298 |
void JIT::emit_op_pop_scope(Instruction*) |
|
1299 |
{ |
|
1300 |
JITStubCall(this, cti_op_pop_scope).call(); |
|
1301 |
} |
|
1302 |
||
1303 |
void JIT::emit_op_to_jsnumber(Instruction* currentInstruction) |
|
1304 |
{ |
|
1305 |
int dst = currentInstruction[1].u.operand; |
|
1306 |
int src = currentInstruction[2].u.operand; |
|
1307 |
||
1308 |
emitLoad(src, regT1, regT0); |
|
1309 |
||
1310 |
Jump isInt32 = branch32(Equal, regT1, Imm32(JSValue::Int32Tag)); |
|
1311 |
addSlowCase(branch32(AboveOrEqual, regT1, Imm32(JSValue::EmptyValueTag))); |
|
1312 |
isInt32.link(this); |
|
1313 |
||
1314 |
if (src != dst) |
|
1315 |
emitStore(dst, regT1, regT0); |
|
1316 |
map(m_bytecodeIndex + OPCODE_LENGTH(op_to_jsnumber), dst, regT1, regT0); |
|
1317 |
} |
|
1318 |
||
1319 |
void JIT::emitSlow_op_to_jsnumber(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter) |
|
1320 |
{ |
|
1321 |
int dst = currentInstruction[1].u.operand; |
|
1322 |
||
1323 |
linkSlowCase(iter); |
|
1324 |
||
1325 |
JITStubCall stubCall(this, cti_op_to_jsnumber); |
|
1326 |
stubCall.addArgument(regT1, regT0); |
|
1327 |
stubCall.call(dst); |
|
1328 |
} |
|
1329 |
||
1330 |
void JIT::emit_op_push_new_scope(Instruction* currentInstruction) |
|
1331 |
{ |
|
1332 |
JITStubCall stubCall(this, cti_op_push_new_scope); |
|
1333 |
stubCall.addArgument(ImmPtr(&m_codeBlock->identifier(currentInstruction[2].u.operand))); |
|
1334 |
stubCall.addArgument(currentInstruction[3].u.operand); |
|
1335 |
stubCall.call(currentInstruction[1].u.operand); |
|
1336 |
} |
|
1337 |
||
1338 |
void JIT::emit_op_catch(Instruction* currentInstruction) |
|
1339 |
{ |
|
1340 |
unsigned exception = currentInstruction[1].u.operand; |
|
1341 |
||
1342 |
// This opcode only executes after a return from cti_op_throw. |
|
1343 |
||
1344 |
// cti_op_throw may have taken us to a call frame further up the stack; reload |
|
1345 |
// the call frame pointer to adjust. |
|
1346 |
peek(callFrameRegister, OBJECT_OFFSETOF(struct JITStackFrame, callFrame) / sizeof (void*)); |
|
1347 |
||
1348 |
// Now store the exception returned by cti_op_throw. |
|
1349 |
emitStore(exception, regT1, regT0); |
|
1350 |
map(m_bytecodeIndex + OPCODE_LENGTH(op_catch), exception, regT1, regT0); |
|
1351 |
} |
|
1352 |
||
1353 |
void JIT::emit_op_jmp_scopes(Instruction* currentInstruction) |
|
1354 |
{ |
|
1355 |
JITStubCall stubCall(this, cti_op_jmp_scopes); |
|
1356 |
stubCall.addArgument(Imm32(currentInstruction[1].u.operand)); |
|
1357 |
stubCall.call(); |
|
1358 |
addJump(jump(), currentInstruction[2].u.operand); |
|
1359 |
} |
|
1360 |
||
1361 |
void JIT::emit_op_switch_imm(Instruction* currentInstruction) |
|
1362 |
{ |
|
1363 |
unsigned tableIndex = currentInstruction[1].u.operand; |
|
1364 |
unsigned defaultOffset = currentInstruction[2].u.operand; |
|
1365 |
unsigned scrutinee = currentInstruction[3].u.operand; |
|
1366 |
||
1367 |
// create jump table for switch destinations, track this switch statement. |
|
1368 |
SimpleJumpTable* jumpTable = &m_codeBlock->immediateSwitchJumpTable(tableIndex); |
|
1369 |
m_switches.append(SwitchRecord(jumpTable, m_bytecodeIndex, defaultOffset, SwitchRecord::Immediate)); |
|
1370 |
jumpTable->ctiOffsets.grow(jumpTable->branchOffsets.size()); |
|
1371 |
||
1372 |
JITStubCall stubCall(this, cti_op_switch_imm); |
|
1373 |
stubCall.addArgument(scrutinee); |
|
1374 |
stubCall.addArgument(Imm32(tableIndex)); |
|
1375 |
stubCall.call(); |
|
1376 |
jump(regT0); |
|
1377 |
} |
|
1378 |
||
1379 |
void JIT::emit_op_switch_char(Instruction* currentInstruction) |
|
1380 |
{ |
|
1381 |
unsigned tableIndex = currentInstruction[1].u.operand; |
|
1382 |
unsigned defaultOffset = currentInstruction[2].u.operand; |
|
1383 |
unsigned scrutinee = currentInstruction[3].u.operand; |
|
1384 |
||
1385 |
// create jump table for switch destinations, track this switch statement. |
|
1386 |
SimpleJumpTable* jumpTable = &m_codeBlock->characterSwitchJumpTable(tableIndex); |
|
1387 |
m_switches.append(SwitchRecord(jumpTable, m_bytecodeIndex, defaultOffset, SwitchRecord::Character)); |
|
1388 |
jumpTable->ctiOffsets.grow(jumpTable->branchOffsets.size()); |
|
1389 |
||
1390 |
JITStubCall stubCall(this, cti_op_switch_char); |
|
1391 |
stubCall.addArgument(scrutinee); |
|
1392 |
stubCall.addArgument(Imm32(tableIndex)); |
|
1393 |
stubCall.call(); |
|
1394 |
jump(regT0); |
|
1395 |
} |
|
1396 |
||
1397 |
void JIT::emit_op_switch_string(Instruction* currentInstruction) |
|
1398 |
{ |
|
1399 |
unsigned tableIndex = currentInstruction[1].u.operand; |
|
1400 |
unsigned defaultOffset = currentInstruction[2].u.operand; |
|
1401 |
unsigned scrutinee = currentInstruction[3].u.operand; |
|
1402 |
||
1403 |
// create jump table for switch destinations, track this switch statement. |
|
1404 |
StringJumpTable* jumpTable = &m_codeBlock->stringSwitchJumpTable(tableIndex); |
|
1405 |
m_switches.append(SwitchRecord(jumpTable, m_bytecodeIndex, defaultOffset)); |
|
1406 |
||
1407 |
JITStubCall stubCall(this, cti_op_switch_string); |
|
1408 |
stubCall.addArgument(scrutinee); |
|
1409 |
stubCall.addArgument(Imm32(tableIndex)); |
|
1410 |
stubCall.call(); |
|
1411 |
jump(regT0); |
|
1412 |
} |
|
1413 |
||
1414 |
void JIT::emit_op_new_error(Instruction* currentInstruction) |
|
1415 |
{ |
|
1416 |
unsigned dst = currentInstruction[1].u.operand; |
|
1417 |
unsigned type = currentInstruction[2].u.operand; |
|
1418 |
unsigned message = currentInstruction[3].u.operand; |
|
1419 |
||
1420 |
JITStubCall stubCall(this, cti_op_new_error); |
|
1421 |
stubCall.addArgument(Imm32(type)); |
|
1422 |
stubCall.addArgument(m_codeBlock->getConstant(message)); |
|
1423 |
stubCall.addArgument(Imm32(m_bytecodeIndex)); |
|
1424 |
stubCall.call(dst); |
|
1425 |
} |
|
1426 |
||
1427 |
void JIT::emit_op_debug(Instruction* currentInstruction) |
|
1428 |
{ |
|
1429 |
JITStubCall stubCall(this, cti_op_debug); |
|
1430 |
stubCall.addArgument(Imm32(currentInstruction[1].u.operand)); |
|
1431 |
stubCall.addArgument(Imm32(currentInstruction[2].u.operand)); |
|
1432 |
stubCall.addArgument(Imm32(currentInstruction[3].u.operand)); |
|
1433 |
stubCall.call(); |
|
1434 |
} |
|
1435 |
||
1436 |
||
1437 |
void JIT::emit_op_enter(Instruction*) |
|
1438 |
{ |
|
1439 |
// Even though JIT code doesn't use them, we initialize our constant |
|
1440 |
// registers to zap stale pointers, to avoid unnecessarily prolonging |
|
1441 |
// object lifetime and increasing GC pressure. |
|
1442 |
for (int i = 0; i < m_codeBlock->m_numVars; ++i) |
|
1443 |
emitStore(i, jsUndefined()); |
|
1444 |
} |
|
1445 |
||
1446 |
void JIT::emit_op_enter_with_activation(Instruction* currentInstruction) |
|
1447 |
{ |
|
1448 |
emit_op_enter(currentInstruction); |
|
1449 |
||
1450 |
JITStubCall(this, cti_op_push_activation).call(currentInstruction[1].u.operand); |
|
1451 |
} |
|
1452 |
||
1453 |
void JIT::emit_op_create_arguments(Instruction*) |
|
1454 |
{ |
|
1455 |
Jump argsCreated = branch32(NotEqual, tagFor(RegisterFile::ArgumentsRegister, callFrameRegister), Imm32(JSValue::EmptyValueTag)); |
|
1456 |
||
1457 |
// If we get here the arguments pointer is a null cell - i.e. arguments need lazy creation. |
|
1458 |
if (m_codeBlock->m_numParameters == 1) |
|
1459 |
JITStubCall(this, cti_op_create_arguments_no_params).call(); |
|
1460 |
else |
|
1461 |
JITStubCall(this, cti_op_create_arguments).call(); |
|
1462 |
||
1463 |
argsCreated.link(this); |
|
1464 |
} |
|
1465 |
||
1466 |
void JIT::emit_op_init_arguments(Instruction*) |
|
1467 |
{ |
|
1468 |
emitStore(RegisterFile::ArgumentsRegister, JSValue(), callFrameRegister); |
|
1469 |
} |
|
1470 |
||
1471 |
void JIT::emit_op_convert_this(Instruction* currentInstruction) |
|
1472 |
{ |
|
1473 |
unsigned thisRegister = currentInstruction[1].u.operand; |
|
1474 |
||
1475 |
emitLoad(thisRegister, regT1, regT0); |
|
1476 |
||
1477 |
addSlowCase(branch32(NotEqual, regT1, Imm32(JSValue::CellTag))); |
|
1478 |
||
1479 |
loadPtr(Address(regT0, OBJECT_OFFSETOF(JSCell, m_structure)), regT2); |
|
1480 |
addSlowCase(branchTest32(NonZero, Address(regT2, OBJECT_OFFSETOF(Structure, m_typeInfo.m_flags)), Imm32(NeedsThisConversion))); |
|
1481 |
||
1482 |
map(m_bytecodeIndex + OPCODE_LENGTH(op_convert_this), thisRegister, regT1, regT0); |
|
1483 |
} |
|
1484 |
||
1485 |
void JIT::emitSlow_op_convert_this(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter) |
|
1486 |
{ |
|
1487 |
unsigned thisRegister = currentInstruction[1].u.operand; |
|
1488 |
||
1489 |
linkSlowCase(iter); |
|
1490 |
linkSlowCase(iter); |
|
1491 |
||
1492 |
JITStubCall stubCall(this, cti_op_convert_this); |
|
1493 |
stubCall.addArgument(regT1, regT0); |
|
1494 |
stubCall.call(thisRegister); |
|
1495 |
} |
|
1496 |
||
1497 |
void JIT::emit_op_profile_will_call(Instruction* currentInstruction) |
|
1498 |
{ |
|
1499 |
peek(regT2, OBJECT_OFFSETOF(JITStackFrame, enabledProfilerReference) / sizeof (void*)); |
|
1500 |
Jump noProfiler = branchTestPtr(Zero, Address(regT2)); |
|
1501 |
||
1502 |
JITStubCall stubCall(this, cti_op_profile_will_call); |
|
1503 |
stubCall.addArgument(currentInstruction[1].u.operand); |
|
1504 |
stubCall.call(); |
|
1505 |
noProfiler.link(this); |
|
1506 |
} |
|
1507 |
||
1508 |
void JIT::emit_op_profile_did_call(Instruction* currentInstruction) |
|
1509 |
{ |
|
1510 |
peek(regT2, OBJECT_OFFSETOF(JITStackFrame, enabledProfilerReference) / sizeof (void*)); |
|
1511 |
Jump noProfiler = branchTestPtr(Zero, Address(regT2)); |
|
1512 |
||
1513 |
JITStubCall stubCall(this, cti_op_profile_did_call); |
|
1514 |
stubCall.addArgument(currentInstruction[1].u.operand); |
|
1515 |
stubCall.call(); |
|
1516 |
noProfiler.link(this); |
|
1517 |
} |
|
1518 |
||
1519 |
#else // USE(JSVALUE32_64) |
|
1520 |
||
1521 |
#define RECORD_JUMP_TARGET(targetOffset) \ |
|
1522 |
do { m_labels[m_bytecodeIndex + (targetOffset)].used(); } while (false) |
|
1523 |
||
1524 |
void JIT::privateCompileCTIMachineTrampolines(RefPtr<ExecutablePool>* executablePool, JSGlobalData* globalData, CodePtr* ctiStringLengthTrampoline, CodePtr* ctiVirtualCallLink, CodePtr* ctiVirtualCall, CodePtr* ctiNativeCallThunk) |
|
1525 |
{ |
|
1526 |
#if ENABLE(JIT_OPTIMIZE_PROPERTY_ACCESS) |
|
1527 |
// (2) The second function provides fast property access for string length |
|
1528 |
Label stringLengthBegin = align(); |
|
1529 |
||
1530 |
// Check eax is a string |
|
1531 |
Jump string_failureCases1 = emitJumpIfNotJSCell(regT0); |
|
1532 |
Jump string_failureCases2 = branchPtr(NotEqual, Address(regT0), ImmPtr(m_globalData->jsStringVPtr)); |
|
1533 |
||
1534 |
// Checks out okay! - get the length from the Ustring. |
|
1535 |
loadPtr(Address(regT0, OBJECT_OFFSETOF(JSString, m_value) + OBJECT_OFFSETOF(UString, m_rep)), regT0); |
|
1536 |
load32(Address(regT0, OBJECT_OFFSETOF(UString::Rep, len)), regT0); |
|
1537 |
||
1538 |
Jump string_failureCases3 = branch32(Above, regT0, Imm32(JSImmediate::maxImmediateInt)); |
|
1539 |
||
1540 |
// regT0 contains a 64 bit value (is positive, is zero extended) so we don't need sign extend here. |
|
1541 |
emitFastArithIntToImmNoCheck(regT0, regT0); |
|
1542 |
||
1543 |
ret(); |
|
1544 |
#endif |
|
1545 |
||
1546 |
// (3) Trampolines for the slow cases of op_call / op_call_eval / op_construct. |
|
1547 |
COMPILE_ASSERT(sizeof(CodeType) == 4, CodeTypeEnumMustBe32Bit); |
|
1548 |
||
1549 |
// VirtualCallLink Trampoline |
|
1550 |
// regT0 holds callee, regT1 holds argCount. regT2 will hold the FunctionExecutable. |
|
1551 |
Label virtualCallLinkBegin = align(); |
|
1552 |
loadPtr(Address(regT0, OBJECT_OFFSETOF(JSFunction, m_executable)), regT2); |
|
1553 |
||
1554 |
Jump isNativeFunc2 = branch32(Equal, Address(regT2, OBJECT_OFFSETOF(FunctionExecutable, m_numParameters)), Imm32(0)); |
|
1555 |
||
1556 |
Jump hasCodeBlock2 = branch32(GreaterThan, Address(regT2, OBJECT_OFFSETOF(FunctionExecutable, m_numParameters)), Imm32(0)); |
|
1557 |
preserveReturnAddressAfterCall(regT3); |
|
1558 |
restoreArgumentReference(); |
|
1559 |
Call callJSFunction2 = call(); |
|
1560 |
loadPtr(Address(regT0, OBJECT_OFFSETOF(JSFunction, m_executable)), regT2); |
|
1561 |
emitGetJITStubArg(2, regT1); // argCount |
|
1562 |
restoreReturnAddressBeforeReturn(regT3); |
|
1563 |
hasCodeBlock2.link(this); |
|
1564 |
||
1565 |
// Check argCount matches callee arity. |
|
1566 |
Jump arityCheckOkay2 = branch32(Equal, Address(regT2, OBJECT_OFFSETOF(FunctionExecutable, m_numParameters)), regT1); |
|
1567 |
preserveReturnAddressAfterCall(regT3); |
|
1568 |
emitPutJITStubArg(regT3, 1); // return address |
|
1569 |
restoreArgumentReference(); |
|
1570 |
Call callArityCheck2 = call(); |
|
1571 |
move(regT1, callFrameRegister); |
|
1572 |
emitGetJITStubArg(2, regT1); // argCount |
|
1573 |
restoreReturnAddressBeforeReturn(regT3); |
|
1574 |
arityCheckOkay2.link(this); |
|
1575 |
||
1576 |
isNativeFunc2.link(this); |
|
1577 |
||
1578 |
compileOpCallInitializeCallFrame(); |
|
1579 |
preserveReturnAddressAfterCall(regT3); |
|
1580 |
emitPutJITStubArg(regT3, 1); // return address |
|
1581 |
restoreArgumentReference(); |
|
1582 |
Call callLazyLinkCall = call(); |
|
1583 |
restoreReturnAddressBeforeReturn(regT3); |
|
1584 |
jump(regT0); |
|
1585 |
||
1586 |
// VirtualCall Trampoline |
|
1587 |
// regT0 holds callee, regT1 holds argCount. regT2 will hold the FunctionExecutable. |
|
1588 |
Label virtualCallBegin = align(); |
|
1589 |
loadPtr(Address(regT0, OBJECT_OFFSETOF(JSFunction, m_executable)), regT2); |
|
1590 |
||
1591 |
Jump isNativeFunc3 = branch32(Equal, Address(regT2, OBJECT_OFFSETOF(FunctionExecutable, m_numParameters)), Imm32(0)); |
|
1592 |
||
1593 |
Jump hasCodeBlock3 = branch32(GreaterThan, Address(regT2, OBJECT_OFFSETOF(FunctionExecutable, m_numParameters)), Imm32(0)); |
|
1594 |
preserveReturnAddressAfterCall(regT3); |
|
1595 |
restoreArgumentReference(); |
|
1596 |
Call callJSFunction1 = call(); |
|
1597 |
emitGetJITStubArg(2, regT1); // argCount |
|
1598 |
restoreReturnAddressBeforeReturn(regT3); |
|
1599 |
loadPtr(Address(regT0, OBJECT_OFFSETOF(JSFunction, m_executable)), regT2); |
|
1600 |
hasCodeBlock3.link(this); |
|
1601 |
||
1602 |
// Check argCount matches callee arity. |
|
1603 |
Jump arityCheckOkay3 = branch32(Equal, Address(regT2, OBJECT_OFFSETOF(FunctionExecutable, m_numParameters)), regT1); |
|
1604 |
preserveReturnAddressAfterCall(regT3); |
|
1605 |
emitPutJITStubArg(regT3, 1); // return address |
|
1606 |
restoreArgumentReference(); |
|
1607 |
Call callArityCheck1 = call(); |
|
1608 |
move(regT1, callFrameRegister); |
|
1609 |
emitGetJITStubArg(2, regT1); // argCount |
|
1610 |
restoreReturnAddressBeforeReturn(regT3); |
|
1611 |
loadPtr(Address(regT0, OBJECT_OFFSETOF(JSFunction, m_executable)), regT2); |
|
1612 |
arityCheckOkay3.link(this); |
|
1613 |
||
1614 |
isNativeFunc3.link(this); |
|
1615 |
||
1616 |
compileOpCallInitializeCallFrame(); |
|
1617 |
loadPtr(Address(regT2, OBJECT_OFFSETOF(FunctionExecutable, m_jitCode)), regT0); |
|
1618 |
jump(regT0); |
|
1619 |
||
1620 |
Label nativeCallThunk = align(); |
|
1621 |
preserveReturnAddressAfterCall(regT0); |
|
1622 |
emitPutToCallFrameHeader(regT0, RegisterFile::ReturnPC); // Push return address |
|
1623 |
||
1624 |
// Load caller frame's scope chain into this callframe so that whatever we call can |
|
1625 |
// get to its global data. |
|
1626 |
emitGetFromCallFrameHeaderPtr(RegisterFile::CallerFrame, regT1); |
|
1627 |
emitGetFromCallFrameHeaderPtr(RegisterFile::ScopeChain, regT1, regT1); |
|
1628 |
emitPutToCallFrameHeader(regT1, RegisterFile::ScopeChain); |
|
1629 |
||
1630 |
||
1631 |
#if PLATFORM(X86_64) |
|
1632 |
emitGetFromCallFrameHeader32(RegisterFile::ArgumentCount, X86Registers::ecx); |
|
1633 |
||
1634 |
// Allocate stack space for our arglist |
|
1635 |
subPtr(Imm32(sizeof(ArgList)), stackPointerRegister); |
|
1636 |
COMPILE_ASSERT((sizeof(ArgList) & 0xf) == 0, ArgList_should_by_16byte_aligned); |
|
1637 |
||
1638 |
// Set up arguments |
|
1639 |
subPtr(Imm32(1), X86Registers::ecx); // Don't include 'this' in argcount |
|
1640 |
||
1641 |
// Push argcount |
|
1642 |
storePtr(X86Registers::ecx, Address(stackPointerRegister, OBJECT_OFFSETOF(ArgList, m_argCount))); |
|
1643 |
||
1644 |
// Calculate the start of the callframe header, and store in edx |
|
1645 |
addPtr(Imm32(-RegisterFile::CallFrameHeaderSize * (int32_t)sizeof(Register)), callFrameRegister, X86Registers::edx); |
|
1646 |
||
1647 |
// Calculate start of arguments as callframe header - sizeof(Register) * argcount (ecx) |
|
1648 |
mul32(Imm32(sizeof(Register)), X86Registers::ecx, X86Registers::ecx); |
|
1649 |
subPtr(X86Registers::ecx, X86Registers::edx); |
|
1650 |
||
1651 |
// push pointer to arguments |
|
1652 |
storePtr(X86Registers::edx, Address(stackPointerRegister, OBJECT_OFFSETOF(ArgList, m_args))); |
|
1653 |
||
1654 |
// ArgList is passed by reference so is stackPointerRegister |
|
1655 |
move(stackPointerRegister, X86Registers::ecx); |
|
1656 |
||
1657 |
// edx currently points to the first argument, edx-sizeof(Register) points to 'this' |
|
1658 |
loadPtr(Address(X86Registers::edx, -(int32_t)sizeof(Register)), X86Registers::edx); |
|
1659 |
||
1660 |
emitGetFromCallFrameHeaderPtr(RegisterFile::Callee, X86Registers::esi); |
|
1661 |
||
1662 |
move(callFrameRegister, X86Registers::edi); |
|
1663 |
||
1664 |
call(Address(X86Registers::esi, OBJECT_OFFSETOF(JSFunction, m_data))); |
|
1665 |
||
1666 |
addPtr(Imm32(sizeof(ArgList)), stackPointerRegister); |
|
1667 |
#elif PLATFORM(X86) |
|
1668 |
emitGetFromCallFrameHeader32(RegisterFile::ArgumentCount, regT0); |
|
1669 |
||
1670 |
/* We have two structs that we use to describe the stackframe we set up for our |
|
1671 |
* call to native code. NativeCallFrameStructure describes the how we set up the stack |
|
1672 |
* in advance of the call. NativeFunctionCalleeSignature describes the callframe |
|
1673 |
* as the native code expects it. We do this as we are using the fastcall calling |
|
1674 |
* convention which results in the callee popping its arguments off the stack, but |
|
1675 |
* not the rest of the callframe so we need a nice way to ensure we increment the |
|
1676 |
* stack pointer by the right amount after the call. |
|
1677 |
*/ |
|
1678 |
#if COMPILER(MSVC) || PLATFORM(LINUX) |
|
1679 |
struct NativeCallFrameStructure { |
|
1680 |
// CallFrame* callFrame; // passed in EDX |
|
1681 |
JSObject* callee; |
|
1682 |
JSValue thisValue; |
|
1683 |
ArgList* argPointer; |
|
1684 |
ArgList args; |
|
1685 |
JSValue result; |
|
1686 |
}; |
|
1687 |
struct NativeFunctionCalleeSignature { |
|
1688 |
JSObject* callee; |
|
1689 |
JSValue thisValue; |
|
1690 |
ArgList* argPointer; |
|
1691 |
}; |
|
1692 |
#else |
|
1693 |
struct NativeCallFrameStructure { |
|
1694 |
// CallFrame* callFrame; // passed in ECX |
|
1695 |
// JSObject* callee; // passed in EDX |
|
1696 |
JSValue thisValue; |
|
1697 |
ArgList* argPointer; |
|
1698 |
ArgList args; |
|
1699 |
}; |
|
1700 |
struct NativeFunctionCalleeSignature { |
|
1701 |
JSValue thisValue; |
|
1702 |
ArgList* argPointer; |
|
1703 |
}; |
|
1704 |
#endif |
|
1705 |
const int NativeCallFrameSize = (sizeof(NativeCallFrameStructure) + 15) & ~15; |
|
1706 |
// Allocate system stack frame |
|
1707 |
subPtr(Imm32(NativeCallFrameSize), stackPointerRegister); |
|
1708 |
||
1709 |
// Set up arguments |
|
1710 |
subPtr(Imm32(1), regT0); // Don't include 'this' in argcount |
|
1711 |
||
1712 |
// push argcount |
|
1713 |
storePtr(regT0, Address(stackPointerRegister, OBJECT_OFFSETOF(NativeCallFrameStructure, args) + OBJECT_OFFSETOF(ArgList, m_argCount))); |
|
1714 |
||
1715 |
// Calculate the start of the callframe header, and store in regT1 |
|
1716 |
addPtr(Imm32(-RegisterFile::CallFrameHeaderSize * (int)sizeof(Register)), callFrameRegister, regT1); |
|
1717 |
||
1718 |
// Calculate start of arguments as callframe header - sizeof(Register) * argcount (regT0) |
|
1719 |
mul32(Imm32(sizeof(Register)), regT0, regT0); |
|
1720 |
subPtr(regT0, regT1); |
|
1721 |
storePtr(regT1, Address(stackPointerRegister, OBJECT_OFFSETOF(NativeCallFrameStructure, args) + OBJECT_OFFSETOF(ArgList, m_args))); |
|
1722 |
||
1723 |
// ArgList is passed by reference so is stackPointerRegister + 4 * sizeof(Register) |
|
1724 |
addPtr(Imm32(OBJECT_OFFSETOF(NativeCallFrameStructure, args)), stackPointerRegister, regT0); |
|
1725 |
storePtr(regT0, Address(stackPointerRegister, OBJECT_OFFSETOF(NativeCallFrameStructure, argPointer))); |
|
1726 |
||
1727 |
// regT1 currently points to the first argument, regT1 - sizeof(Register) points to 'this' |
|
1728 |
loadPtr(Address(regT1, -(int)sizeof(Register)), regT1); |
|
1729 |
storePtr(regT1, Address(stackPointerRegister, OBJECT_OFFSETOF(NativeCallFrameStructure, thisValue))); |
|
1730 |
||
1731 |
#if COMPILER(MSVC) || PLATFORM(LINUX) |
|
1732 |
// ArgList is passed by reference so is stackPointerRegister + 4 * sizeof(Register) |
|
1733 |
addPtr(Imm32(OBJECT_OFFSETOF(NativeCallFrameStructure, result)), stackPointerRegister, X86Registers::ecx); |
|
1734 |
||
1735 |
// Plant callee |
|
1736 |
emitGetFromCallFrameHeaderPtr(RegisterFile::Callee, X86Registers::eax); |
|
1737 |
storePtr(X86Registers::eax, Address(stackPointerRegister, OBJECT_OFFSETOF(NativeCallFrameStructure, callee))); |
|
1738 |
||
1739 |
// Plant callframe |
|
1740 |
move(callFrameRegister, X86Registers::edx); |
|
1741 |
||
1742 |
call(Address(X86Registers::eax, OBJECT_OFFSETOF(JSFunction, m_data))); |
|
1743 |
||
1744 |
// JSValue is a non-POD type |
|
1745 |
loadPtr(Address(X86Registers::eax), X86Registers::eax); |
|
1746 |
#else |
|
1747 |
// Plant callee |
|
1748 |
emitGetFromCallFrameHeaderPtr(RegisterFile::Callee, X86Registers::edx); |
|
1749 |
||
1750 |
// Plant callframe |
|
1751 |
move(callFrameRegister, X86Registers::ecx); |
|
1752 |
call(Address(X86Registers::edx, OBJECT_OFFSETOF(JSFunction, m_data))); |
|
1753 |
#endif |
|
1754 |
||
1755 |
// We've put a few temporaries on the stack in addition to the actual arguments |
|
1756 |
// so pull them off now |
|
1757 |
addPtr(Imm32(NativeCallFrameSize - sizeof(NativeFunctionCalleeSignature)), stackPointerRegister); |
|
1758 |
||
1759 |
#elif PLATFORM(ARM_TRADITIONAL) |
|
1760 |
emitGetFromCallFrameHeader32(RegisterFile::ArgumentCount, regT0); |
|
1761 |
||
1762 |
// Allocate stack space for our arglist |
|
1763 |
COMPILE_ASSERT((sizeof(ArgList) & 0x7) == 0, ArgList_should_by_8byte_aligned); |
|
1764 |
subPtr(Imm32(sizeof(ArgList)), stackPointerRegister); |
|
1765 |
||
1766 |
// Set up arguments |
|
1767 |
subPtr(Imm32(1), regT0); // Don't include 'this' in argcount |
|
1768 |
||
1769 |
// Push argcount |
|
1770 |
storePtr(regT0, Address(stackPointerRegister, OBJECT_OFFSETOF(ArgList, m_argCount))); |
|
1771 |
||
1772 |
// Calculate the start of the callframe header, and store in regT1 |
|
1773 |
move(callFrameRegister, regT1); |
|
1774 |
sub32(Imm32(RegisterFile::CallFrameHeaderSize * (int32_t)sizeof(Register)), regT1); |
|
1775 |
||
1776 |
// Calculate start of arguments as callframe header - sizeof(Register) * argcount (regT1) |
|
1777 |
mul32(Imm32(sizeof(Register)), regT0, regT0); |
|
1778 |
subPtr(regT0, regT1); |
|
1779 |
||
1780 |
// push pointer to arguments |
|
1781 |
storePtr(regT1, Address(stackPointerRegister, OBJECT_OFFSETOF(ArgList, m_args))); |
|
1782 |
||
1783 |
// Setup arg3: regT1 currently points to the first argument, regT1-sizeof(Register) points to 'this' |
|
1784 |
loadPtr(Address(regT1, -(int32_t)sizeof(Register)), regT2); |
|
1785 |
||
1786 |
// Setup arg2: |
|
1787 |
emitGetFromCallFrameHeaderPtr(RegisterFile::Callee, regT1); |
|
1788 |
||
1789 |
// Setup arg1: |
|
1790 |
move(callFrameRegister, regT0); |
|
1791 |
||
1792 |
// Setup arg4: This is a plain hack |
|
1793 |
move(stackPointerRegister, ARMRegisters::S0); |
|
1794 |
||
1795 |
call(Address(regT1, OBJECT_OFFSETOF(JSFunction, m_data))); |
|
1796 |
||
1797 |
addPtr(Imm32(sizeof(ArgList)), stackPointerRegister); |
|
1798 |
||
1799 |
#elif ENABLE(JIT_OPTIMIZE_NATIVE_CALL) |
|
1800 |
#error "JIT_OPTIMIZE_NATIVE_CALL not yet supported on this platform." |
|
1801 |
#else |
|
1802 |
breakpoint(); |
|
1803 |
#endif |
|
1804 |
||
1805 |
// Check for an exception |
|
1806 |
loadPtr(&(globalData->exception), regT2); |
|
1807 |
Jump exceptionHandler = branchTestPtr(NonZero, regT2); |
|
1808 |
||
1809 |
// Grab the return address. |
|
1810 |
emitGetFromCallFrameHeaderPtr(RegisterFile::ReturnPC, regT1); |
|
1811 |
||
1812 |
// Restore our caller's "r". |
|
1813 |
emitGetFromCallFrameHeaderPtr(RegisterFile::CallerFrame, callFrameRegister); |
|
1814 |
||
1815 |
// Return. |
|
1816 |
restoreReturnAddressBeforeReturn(regT1); |
|
1817 |
ret(); |
|
1818 |
||
1819 |
// Handle an exception |
|
1820 |
exceptionHandler.link(this); |
|
1821 |
// Grab the return address. |
|
1822 |
emitGetFromCallFrameHeaderPtr(RegisterFile::ReturnPC, regT1); |
|
1823 |
move(ImmPtr(&globalData->exceptionLocation), regT2); |
|
1824 |
storePtr(regT1, regT2); |
|
1825 |
move(ImmPtr(FunctionPtr(ctiVMThrowTrampoline).value()), regT2); |
|
1826 |
emitGetFromCallFrameHeaderPtr(RegisterFile::CallerFrame, callFrameRegister); |
|
1827 |
poke(callFrameRegister, OBJECT_OFFSETOF(struct JITStackFrame, callFrame) / sizeof (void*)); |
|
1828 |
restoreReturnAddressBeforeReturn(regT2); |
|
1829 |
ret(); |
|
1830 |
||
1831 |
||
1832 |
#if ENABLE(JIT_OPTIMIZE_PROPERTY_ACCESS) |
|
1833 |
Call string_failureCases1Call = makeTailRecursiveCall(string_failureCases1); |
|
1834 |
Call string_failureCases2Call = makeTailRecursiveCall(string_failureCases2); |
|
1835 |
Call string_failureCases3Call = makeTailRecursiveCall(string_failureCases3); |
|
1836 |
#endif |
|
1837 |
||
1838 |
// All trampolines constructed! copy the code, link up calls, and set the pointers on the Machine object. |
|
1839 |
LinkBuffer patchBuffer(this, m_globalData->executableAllocator.poolForSize(m_assembler.size())); |
|
1840 |
||
1841 |
#if ENABLE(JIT_OPTIMIZE_PROPERTY_ACCESS) |
|
1842 |
patchBuffer.link(string_failureCases1Call, FunctionPtr(cti_op_get_by_id_string_fail)); |
|
1843 |
patchBuffer.link(string_failureCases2Call, FunctionPtr(cti_op_get_by_id_string_fail)); |
|
1844 |
patchBuffer.link(string_failureCases3Call, FunctionPtr(cti_op_get_by_id_string_fail)); |
|
1845 |
#endif |
|
1846 |
patchBuffer.link(callArityCheck1, FunctionPtr(cti_op_call_arityCheck)); |
|
1847 |
patchBuffer.link(callJSFunction1, FunctionPtr(cti_op_call_JSFunction)); |
|
1848 |
#if ENABLE(JIT_OPTIMIZE_CALL) |
|
1849 |
patchBuffer.link(callArityCheck2, FunctionPtr(cti_op_call_arityCheck)); |
|
1850 |
patchBuffer.link(callJSFunction2, FunctionPtr(cti_op_call_JSFunction)); |
|
1851 |
patchBuffer.link(callLazyLinkCall, FunctionPtr(cti_vm_lazyLinkCall)); |
|
1852 |
#endif |
|
1853 |
||
1854 |
CodeRef finalCode = patchBuffer.finalizeCode(); |
|
1855 |
*executablePool = finalCode.m_executablePool; |
|
1856 |
||
1857 |
*ctiVirtualCallLink = trampolineAt(finalCode, virtualCallLinkBegin); |
|
1858 |
*ctiVirtualCall = trampolineAt(finalCode, virtualCallBegin); |
|
1859 |
*ctiNativeCallThunk = trampolineAt(finalCode, nativeCallThunk); |
|
1860 |
#if ENABLE(JIT_OPTIMIZE_PROPERTY_ACCESS) |
|
1861 |
*ctiStringLengthTrampoline = trampolineAt(finalCode, stringLengthBegin); |
|
1862 |
#else |
|
1863 |
UNUSED_PARAM(ctiStringLengthTrampoline); |
|
1864 |
#endif |
|
1865 |
} |
|
1866 |
||
1867 |
void JIT::emit_op_mov(Instruction* currentInstruction) |
|
1868 |
{ |
|
1869 |
int dst = currentInstruction[1].u.operand; |
|
1870 |
int src = currentInstruction[2].u.operand; |
|
1871 |
||
1872 |
if (m_codeBlock->isConstantRegisterIndex(src)) { |
|
1873 |
storePtr(ImmPtr(JSValue::encode(getConstantOperand(src))), Address(callFrameRegister, dst * sizeof(Register))); |
|
1874 |
if (dst == m_lastResultBytecodeRegister) |
|
1875 |
killLastResultRegister(); |
|
1876 |
} else if ((src == m_lastResultBytecodeRegister) || (dst == m_lastResultBytecodeRegister)) { |
|
1877 |
// If either the src or dst is the cached register go though |
|
1878 |
// get/put registers to make sure we track this correctly. |
|
1879 |
emitGetVirtualRegister(src, regT0); |
|
1880 |
emitPutVirtualRegister(dst); |
|
1881 |
} else { |
|
1882 |
// Perform the copy via regT1; do not disturb any mapping in regT0. |
|
1883 |
loadPtr(Address(callFrameRegister, src * sizeof(Register)), regT1); |
|
1884 |
storePtr(regT1, Address(callFrameRegister, dst * sizeof(Register))); |
|
1885 |
} |
|
1886 |
} |
|
1887 |
||
1888 |
void JIT::emit_op_end(Instruction* currentInstruction) |
|
1889 |
{ |
|
1890 |
if (m_codeBlock->needsFullScopeChain()) |
|
1891 |
JITStubCall(this, cti_op_end).call(); |
|
1892 |
ASSERT(returnValueRegister != callFrameRegister); |
|
1893 |
emitGetVirtualRegister(currentInstruction[1].u.operand, returnValueRegister); |
|
1894 |
restoreReturnAddressBeforeReturn(Address(callFrameRegister, RegisterFile::ReturnPC * static_cast<int>(sizeof(Register)))); |
|
1895 |
ret(); |
|
1896 |
} |
|
1897 |
||
1898 |
void JIT::emit_op_jmp(Instruction* currentInstruction) |
|
1899 |
{ |
|
1900 |
unsigned target = currentInstruction[1].u.operand; |
|
1901 |
addJump(jump(), target); |
|
1902 |
RECORD_JUMP_TARGET(target); |
|
1903 |
} |
|
1904 |
||
1905 |
void JIT::emit_op_loop(Instruction* currentInstruction) |
|
1906 |
{ |
|
1907 |
emitTimeoutCheck(); |
|
1908 |
||
1909 |
unsigned target = currentInstruction[1].u.operand; |
|
1910 |
addJump(jump(), target); |
|
1911 |
} |
|
1912 |
||
1913 |
void JIT::emit_op_loop_if_less(Instruction* currentInstruction) |
|
1914 |
{ |
|
1915 |
emitTimeoutCheck(); |
|
1916 |
||
1917 |
unsigned op1 = currentInstruction[1].u.operand; |
|
1918 |
unsigned op2 = currentInstruction[2].u.operand; |
|
1919 |
unsigned target = currentInstruction[3].u.operand; |
|
1920 |
if (isOperandConstantImmediateInt(op2)) { |
|
1921 |
emitGetVirtualRegister(op1, regT0); |
|
1922 |
emitJumpSlowCaseIfNotImmediateInteger(regT0); |
|
1923 |
#if USE(JSVALUE64) |
|
1924 |
int32_t op2imm = getConstantOperandImmediateInt(op2); |
|
1925 |
#else |
|
1926 |
int32_t op2imm = static_cast<int32_t>(JSImmediate::rawValue(getConstantOperand(op2))); |
|
1927 |
#endif |
|
1928 |
addJump(branch32(LessThan, regT0, Imm32(op2imm)), target); |
|
1929 |
} else if (isOperandConstantImmediateInt(op1)) { |
|
1930 |
emitGetVirtualRegister(op2, regT0); |
|
1931 |
emitJumpSlowCaseIfNotImmediateInteger(regT0); |
|
1932 |
#if USE(JSVALUE64) |
|
1933 |
int32_t op1imm = getConstantOperandImmediateInt(op1); |
|
1934 |
#else |
|
1935 |
int32_t op1imm = static_cast<int32_t>(JSImmediate::rawValue(getConstantOperand(op1))); |
|
1936 |
#endif |
|
1937 |
addJump(branch32(GreaterThan, regT0, Imm32(op1imm)), target); |
|
1938 |
} else { |
|
1939 |
emitGetVirtualRegisters(op1, regT0, op2, regT1); |
|
1940 |
emitJumpSlowCaseIfNotImmediateInteger(regT0); |
|
1941 |
emitJumpSlowCaseIfNotImmediateInteger(regT1); |
|
1942 |
addJump(branch32(LessThan, regT0, regT1), target); |
|
1943 |
} |
|
1944 |
} |
|
1945 |
||
1946 |
void JIT::emit_op_loop_if_lesseq(Instruction* currentInstruction) |
|
1947 |
{ |
|
1948 |
emitTimeoutCheck(); |
|
1949 |
||
1950 |
unsigned op1 = currentInstruction[1].u.operand; |
|
1951 |
unsigned op2 = currentInstruction[2].u.operand; |
|
1952 |
unsigned target = currentInstruction[3].u.operand; |
|
1953 |
if (isOperandConstantImmediateInt(op2)) { |
|
1954 |
emitGetVirtualRegister(op1, regT0); |
|
1955 |
emitJumpSlowCaseIfNotImmediateInteger(regT0); |
|
1956 |
#if USE(JSVALUE64) |
|
1957 |
int32_t op2imm = getConstantOperandImmediateInt(op2); |
|
1958 |
#else |
|
1959 |
int32_t op2imm = static_cast<int32_t>(JSImmediate::rawValue(getConstantOperand(op2))); |
|
1960 |
#endif |
|
1961 |
addJump(branch32(LessThanOrEqual, regT0, Imm32(op2imm)), target); |
|
1962 |
} else { |
|
1963 |
emitGetVirtualRegisters(op1, regT0, op2, regT1); |
|
1964 |
emitJumpSlowCaseIfNotImmediateInteger(regT0); |
|
1965 |
emitJumpSlowCaseIfNotImmediateInteger(regT1); |
|
1966 |
addJump(branch32(LessThanOrEqual, regT0, regT1), target); |
|
1967 |
} |
|
1968 |
} |
|
1969 |
||
1970 |
void JIT::emit_op_new_object(Instruction* currentInstruction) |
|
1971 |
{ |
|
1972 |
JITStubCall(this, cti_op_new_object).call(currentInstruction[1].u.operand); |
|
1973 |
} |
|
1974 |
||
1975 |
void JIT::emit_op_instanceof(Instruction* currentInstruction) |
|
1976 |
{ |
|
1977 |
unsigned dst = currentInstruction[1].u.operand; |
|
1978 |
unsigned value = currentInstruction[2].u.operand; |
|
1979 |
unsigned baseVal = currentInstruction[3].u.operand; |
|
1980 |
unsigned proto = currentInstruction[4].u.operand; |
|
1981 |
||
1982 |
// Load the operands (baseVal, proto, and value respectively) into registers. |
|
1983 |
// We use regT0 for baseVal since we will be done with this first, and we can then use it for the result. |
|
1984 |
emitGetVirtualRegister(value, regT2); |
|
1985 |
emitGetVirtualRegister(baseVal, regT0); |
|
1986 |
emitGetVirtualRegister(proto, regT1); |
|
1987 |
||
1988 |
// Check that baseVal & proto are cells. |
|
1989 |
emitJumpSlowCaseIfNotJSCell(regT2, value); |
|
1990 |
emitJumpSlowCaseIfNotJSCell(regT0, baseVal); |
|
1991 |
emitJumpSlowCaseIfNotJSCell(regT1, proto); |
|
1992 |
||
1993 |
// Check that baseVal 'ImplementsDefaultHasInstance'. |
|
1994 |
loadPtr(Address(regT0, OBJECT_OFFSETOF(JSCell, m_structure)), regT0); |
|
1995 |
addSlowCase(branchTest32(Zero, Address(regT0, OBJECT_OFFSETOF(Structure, m_typeInfo.m_flags)), Imm32(ImplementsDefaultHasInstance))); |
|
1996 |
||
1997 |
// Optimistically load the result true, and start looping. |
|
1998 |
// Initially, regT1 still contains proto and regT2 still contains value. |
|
1999 |
// As we loop regT2 will be updated with its prototype, recursively walking the prototype chain. |
|
2000 |
move(ImmPtr(JSValue::encode(jsBoolean(true))), regT0); |
|
2001 |
Label loop(this); |
|
2002 |
||
2003 |
// Load the prototype of the object in regT2. If this is equal to regT1 - WIN! |
|
2004 |
// Otherwise, check if we've hit null - if we have then drop out of the loop, if not go again. |
|
2005 |
loadPtr(Address(regT2, OBJECT_OFFSETOF(JSCell, m_structure)), regT2); |
|
2006 |
loadPtr(Address(regT2, OBJECT_OFFSETOF(Structure, m_prototype)), regT2); |
|
2007 |
Jump isInstance = branchPtr(Equal, regT2, regT1); |
|
2008 |
emitJumpIfJSCell(regT2).linkTo(loop, this); |
|
2009 |
||
2010 |
// We get here either by dropping out of the loop, or if value was not an Object. Result is false. |
|
2011 |
move(ImmPtr(JSValue::encode(jsBoolean(false))), regT0); |
|
2012 |
||
2013 |
// isInstance jumps right down to here, to skip setting the result to false (it has already set true). |
|
2014 |
isInstance.link(this); |
|
2015 |
emitPutVirtualRegister(dst); |
|
2016 |
} |
|
2017 |
||
2018 |
void JIT::emit_op_new_func(Instruction* currentInstruction) |
|
2019 |
{ |
|
2020 |
JITStubCall stubCall(this, cti_op_new_func); |
|
2021 |
stubCall.addArgument(ImmPtr(m_codeBlock->functionDecl(currentInstruction[2].u.operand))); |
|
2022 |
stubCall.call(currentInstruction[1].u.operand); |
|
2023 |
} |
|
2024 |
||
2025 |
void JIT::emit_op_call(Instruction* currentInstruction) |
|
2026 |
{ |
|
2027 |
compileOpCall(op_call, currentInstruction, m_callLinkInfoIndex++); |
|
2028 |
} |
|
2029 |
||
2030 |
void JIT::emit_op_call_eval(Instruction* currentInstruction) |
|
2031 |
{ |
|
2032 |
compileOpCall(op_call_eval, currentInstruction, m_callLinkInfoIndex++); |
|
2033 |
} |
|
2034 |
||
2035 |
void JIT::emit_op_load_varargs(Instruction* currentInstruction) |
|
2036 |
{ |
|
2037 |
int argCountDst = currentInstruction[1].u.operand; |
|
2038 |
int argsOffset = currentInstruction[2].u.operand; |
|
2039 |
||
2040 |
JITStubCall stubCall(this, cti_op_load_varargs); |
|
2041 |
stubCall.addArgument(Imm32(argsOffset)); |
|
2042 |
stubCall.call(); |
|
2043 |
// Stores a naked int32 in the register file. |
|
2044 |
store32(returnValueRegister, Address(callFrameRegister, argCountDst * sizeof(Register))); |
|
2045 |
} |
|
2046 |
||
2047 |
void JIT::emit_op_call_varargs(Instruction* currentInstruction) |
|
2048 |
{ |
|
2049 |
compileOpCallVarargs(currentInstruction); |
|
2050 |
} |
|
2051 |
||
2052 |
void JIT::emit_op_construct(Instruction* currentInstruction) |
|
2053 |
{ |
|
2054 |
compileOpCall(op_construct, currentInstruction, m_callLinkInfoIndex++); |
|
2055 |
} |
|
2056 |
||
2057 |
void JIT::emit_op_get_global_var(Instruction* currentInstruction) |
|
2058 |
{ |
|
2059 |
JSVariableObject* globalObject = static_cast<JSVariableObject*>(currentInstruction[2].u.jsCell); |
|
2060 |
move(ImmPtr(globalObject), regT0); |
|
2061 |
emitGetVariableObjectRegister(regT0, currentInstruction[3].u.operand, regT0); |
|
2062 |
emitPutVirtualRegister(currentInstruction[1].u.operand); |
|
2063 |
} |
|
2064 |
||
2065 |
void JIT::emit_op_put_global_var(Instruction* currentInstruction) |
|
2066 |
{ |
|
2067 |
emitGetVirtualRegister(currentInstruction[3].u.operand, regT1); |
|
2068 |
JSVariableObject* globalObject = static_cast<JSVariableObject*>(currentInstruction[1].u.jsCell); |
|
2069 |
move(ImmPtr(globalObject), regT0); |
|
2070 |
emitPutVariableObjectRegister(regT1, regT0, currentInstruction[2].u.operand); |
|
2071 |
} |
|
2072 |
||
2073 |
void JIT::emit_op_get_scoped_var(Instruction* currentInstruction) |
|
2074 |
{ |
|
2075 |
int skip = currentInstruction[3].u.operand + m_codeBlock->needsFullScopeChain(); |
|
2076 |
||
2077 |
emitGetFromCallFrameHeaderPtr(RegisterFile::ScopeChain, regT0); |
|
2078 |
while (skip--) |
|
2079 |
loadPtr(Address(regT0, OBJECT_OFFSETOF(ScopeChainNode, next)), regT0); |
|
2080 |
||
2081 |
loadPtr(Address(regT0, OBJECT_OFFSETOF(ScopeChainNode, object)), regT0); |
|
2082 |
emitGetVariableObjectRegister(regT0, currentInstruction[2].u.operand, regT0); |
|
2083 |
emitPutVirtualRegister(currentInstruction[1].u.operand); |
|
2084 |
} |
|
2085 |
||
2086 |
void JIT::emit_op_put_scoped_var(Instruction* currentInstruction) |
|
2087 |
{ |
|
2088 |
int skip = currentInstruction[2].u.operand + m_codeBlock->needsFullScopeChain(); |
|
2089 |
||
2090 |
emitGetFromCallFrameHeaderPtr(RegisterFile::ScopeChain, regT1); |
|
2091 |
emitGetVirtualRegister(currentInstruction[3].u.operand, regT0); |
|
2092 |
while (skip--) |
|
2093 |
loadPtr(Address(regT1, OBJECT_OFFSETOF(ScopeChainNode, next)), regT1); |
|
2094 |
||
2095 |
loadPtr(Address(regT1, OBJECT_OFFSETOF(ScopeChainNode, object)), regT1); |
|
2096 |
emitPutVariableObjectRegister(regT0, regT1, currentInstruction[1].u.operand); |
|
2097 |
} |
|
2098 |
||
2099 |
void JIT::emit_op_tear_off_activation(Instruction* currentInstruction) |
|
2100 |
{ |
|
2101 |
JITStubCall stubCall(this, cti_op_tear_off_activation); |
|
2102 |
stubCall.addArgument(currentInstruction[1].u.operand, regT2); |
|
2103 |
stubCall.call(); |
|
2104 |
} |
|
2105 |
||
2106 |
void JIT::emit_op_tear_off_arguments(Instruction*) |
|
2107 |
{ |
|
2108 |
JITStubCall(this, cti_op_tear_off_arguments).call(); |
|
2109 |
} |
|
2110 |
||
2111 |
void JIT::emit_op_ret(Instruction* currentInstruction) |
|
2112 |
{ |
|
2113 |
// We could JIT generate the deref, only calling out to C when the refcount hits zero. |
|
2114 |
if (m_codeBlock->needsFullScopeChain()) |
|
2115 |
JITStubCall(this, cti_op_ret_scopeChain).call(); |
|
2116 |
||
2117 |
ASSERT(callFrameRegister != regT1); |
|
2118 |
ASSERT(regT1 != returnValueRegister); |
|
2119 |
ASSERT(returnValueRegister != callFrameRegister); |
|
2120 |
||
2121 |
// Return the result in %eax. |
|
2122 |
emitGetVirtualRegister(currentInstruction[1].u.operand, returnValueRegister); |
|
2123 |
||
2124 |
// Grab the return address. |
|
2125 |
emitGetFromCallFrameHeaderPtr(RegisterFile::ReturnPC, regT1); |
|
2126 |
||
2127 |
// Restore our caller's "r". |
|
2128 |
emitGetFromCallFrameHeaderPtr(RegisterFile::CallerFrame, callFrameRegister); |
|
2129 |
||
2130 |
// Return. |
|
2131 |
restoreReturnAddressBeforeReturn(regT1); |
|
2132 |
ret(); |
|
2133 |
} |
|
2134 |
||
2135 |
void JIT::emit_op_new_array(Instruction* currentInstruction) |
|
2136 |
{ |
|
2137 |
JITStubCall stubCall(this, cti_op_new_array); |
|
2138 |
stubCall.addArgument(Imm32(currentInstruction[2].u.operand)); |
|
2139 |
stubCall.addArgument(Imm32(currentInstruction[3].u.operand)); |
|
2140 |
stubCall.call(currentInstruction[1].u.operand); |
|
2141 |
} |
|
2142 |
||
2143 |
void JIT::emit_op_resolve(Instruction* currentInstruction) |
|
2144 |
{ |
|
2145 |
JITStubCall stubCall(this, cti_op_resolve); |
|
2146 |
stubCall.addArgument(ImmPtr(&m_codeBlock->identifier(currentInstruction[2].u.operand))); |
|
2147 |
stubCall.call(currentInstruction[1].u.operand); |
|
2148 |
} |
|
2149 |
||
2150 |
void JIT::emit_op_construct_verify(Instruction* currentInstruction) |
|
2151 |
{ |
|
2152 |
emitGetVirtualRegister(currentInstruction[1].u.operand, regT0); |
|
2153 |
||
2154 |
emitJumpSlowCaseIfNotJSCell(regT0); |
|
2155 |
loadPtr(Address(regT0, OBJECT_OFFSETOF(JSCell, m_structure)), regT2); |
|
2156 |
addSlowCase(branch32(NotEqual, Address(regT2, OBJECT_OFFSETOF(Structure, m_typeInfo) + OBJECT_OFFSETOF(TypeInfo, m_type)), Imm32(ObjectType))); |
|
2157 |
||
2158 |
} |
|
2159 |
||
2160 |
void JIT::emit_op_to_primitive(Instruction* currentInstruction) |
|
2161 |
{ |
|
2162 |
int dst = currentInstruction[1].u.operand; |
|
2163 |
int src = currentInstruction[2].u.operand; |
|
2164 |
||
2165 |
emitGetVirtualRegister(src, regT0); |
|
2166 |
||
2167 |
Jump isImm = emitJumpIfNotJSCell(regT0); |
|
2168 |
addSlowCase(branchPtr(NotEqual, Address(regT0), ImmPtr(m_globalData->jsStringVPtr))); |
|
2169 |
isImm.link(this); |
|
2170 |
||
2171 |
if (dst != src) |
|
2172 |
emitPutVirtualRegister(dst); |
|
2173 |
||
2174 |
} |
|
2175 |
||
2176 |
void JIT::emit_op_strcat(Instruction* currentInstruction) |
|
2177 |
{ |
|
2178 |
JITStubCall stubCall(this, cti_op_strcat); |
|
2179 |
stubCall.addArgument(Imm32(currentInstruction[2].u.operand)); |
|
2180 |
stubCall.addArgument(Imm32(currentInstruction[3].u.operand)); |
|
2181 |
stubCall.call(currentInstruction[1].u.operand); |
|
2182 |
} |
|
2183 |
||
2184 |
void JIT::emit_op_loop_if_true(Instruction* currentInstruction) |
|
2185 |
{ |
|
2186 |
emitTimeoutCheck(); |
|
2187 |
||
2188 |
unsigned target = currentInstruction[2].u.operand; |
|
2189 |
emitGetVirtualRegister(currentInstruction[1].u.operand, regT0); |
|
2190 |
||
2191 |
Jump isZero = branchPtr(Equal, regT0, ImmPtr(JSValue::encode(jsNumber(m_globalData, 0)))); |
|
2192 |
addJump(emitJumpIfImmediateInteger(regT0), target); |
|
2193 |
||
2194 |
addJump(branchPtr(Equal, regT0, ImmPtr(JSValue::encode(jsBoolean(true)))), target); |
|
2195 |
addSlowCase(branchPtr(NotEqual, regT0, ImmPtr(JSValue::encode(jsBoolean(false))))); |
|
2196 |
||
2197 |
isZero.link(this); |
|
2198 |
}; |
|
2199 |
void JIT::emit_op_resolve_base(Instruction* currentInstruction) |
|
2200 |
{ |
|
2201 |
JITStubCall stubCall(this, cti_op_resolve_base); |
|
2202 |
stubCall.addArgument(ImmPtr(&m_codeBlock->identifier(currentInstruction[2].u.operand))); |
|
2203 |
stubCall.call(currentInstruction[1].u.operand); |
|
2204 |
} |
|
2205 |
||
2206 |
void JIT::emit_op_resolve_skip(Instruction* currentInstruction) |
|
2207 |
{ |
|
2208 |
JITStubCall stubCall(this, cti_op_resolve_skip); |
|
2209 |
stubCall.addArgument(ImmPtr(&m_codeBlock->identifier(currentInstruction[2].u.operand))); |
|
2210 |
stubCall.addArgument(Imm32(currentInstruction[3].u.operand + m_codeBlock->needsFullScopeChain())); |
|
2211 |
stubCall.call(currentInstruction[1].u.operand); |
|
2212 |
} |
|
2213 |
||
2214 |
void JIT::emit_op_resolve_global(Instruction* currentInstruction) |
|
2215 |
{ |
|
2216 |
// Fast case |
|
2217 |
void* globalObject = currentInstruction[2].u.jsCell; |
|
2218 |
Identifier* ident = &m_codeBlock->identifier(currentInstruction[3].u.operand); |
|
2219 |
||
2220 |
unsigned currentIndex = m_globalResolveInfoIndex++; |
|
2221 |
void* structureAddress = &(m_codeBlock->globalResolveInfo(currentIndex).structure); |
|
2222 |
void* offsetAddr = &(m_codeBlock->globalResolveInfo(currentIndex).offset); |
|
2223 |
||
2224 |
// Check Structure of global object |
|
2225 |
move(ImmPtr(globalObject), regT0); |
|
2226 |
loadPtr(structureAddress, regT1); |
|
2227 |
Jump noMatch = branchPtr(NotEqual, regT1, Address(regT0, OBJECT_OFFSETOF(JSCell, m_structure))); // Structures don't match |
|
2228 |
||
2229 |
// Load cached property |
|
2230 |
// Assume that the global object always uses external storage. |
|
2231 |
loadPtr(Address(regT0, OBJECT_OFFSETOF(JSGlobalObject, m_externalStorage)), regT0); |
|
2232 |
load32(offsetAddr, regT1); |
|
2233 |
loadPtr(BaseIndex(regT0, regT1, ScalePtr), regT0); |
|
2234 |
emitPutVirtualRegister(currentInstruction[1].u.operand); |
|
2235 |
Jump end = jump(); |
|
2236 |
||
2237 |
// Slow case |
|
2238 |
noMatch.link(this); |
|
2239 |
JITStubCall stubCall(this, cti_op_resolve_global); |
|
2240 |
stubCall.addArgument(ImmPtr(globalObject)); |
|
2241 |
stubCall.addArgument(ImmPtr(ident)); |
|
2242 |
stubCall.addArgument(Imm32(currentIndex)); |
|
2243 |
stubCall.call(currentInstruction[1].u.operand); |
|
2244 |
end.link(this); |
|
2245 |
} |
|
2246 |
||
2247 |
void JIT::emit_op_not(Instruction* currentInstruction) |
|
2248 |
{ |
|
2249 |
emitGetVirtualRegister(currentInstruction[2].u.operand, regT0); |
|
2250 |
xorPtr(Imm32(static_cast<int32_t>(JSImmediate::FullTagTypeBool)), regT0); |
|
2251 |
addSlowCase(branchTestPtr(NonZero, regT0, Imm32(static_cast<int32_t>(~JSImmediate::ExtendedPayloadBitBoolValue)))); |
|
2252 |
xorPtr(Imm32(static_cast<int32_t>(JSImmediate::FullTagTypeBool | JSImmediate::ExtendedPayloadBitBoolValue)), regT0); |
|
2253 |
emitPutVirtualRegister(currentInstruction[1].u.operand); |
|
2254 |
} |
|
2255 |
||
2256 |
void JIT::emit_op_jfalse(Instruction* currentInstruction) |
|
2257 |
{ |
|
2258 |
unsigned target = currentInstruction[2].u.operand; |
|
2259 |
emitGetVirtualRegister(currentInstruction[1].u.operand, regT0); |
|
2260 |
||
2261 |
addJump(branchPtr(Equal, regT0, ImmPtr(JSValue::encode(jsNumber(m_globalData, 0)))), target); |
|
2262 |
Jump isNonZero = emitJumpIfImmediateInteger(regT0); |
|
2263 |
||
2264 |
addJump(branchPtr(Equal, regT0, ImmPtr(JSValue::encode(jsBoolean(false)))), target); |
|
2265 |
addSlowCase(branchPtr(NotEqual, regT0, ImmPtr(JSValue::encode(jsBoolean(true))))); |
|
2266 |
||
2267 |
isNonZero.link(this); |
|
2268 |
RECORD_JUMP_TARGET(target); |
|
2269 |
}; |
|
2270 |
void JIT::emit_op_jeq_null(Instruction* currentInstruction) |
|
2271 |
{ |
|
2272 |
unsigned src = currentInstruction[1].u.operand; |
|
2273 |
unsigned target = currentInstruction[2].u.operand; |
|
2274 |
||
2275 |
emitGetVirtualRegister(src, regT0); |
|
2276 |
Jump isImmediate = emitJumpIfNotJSCell(regT0); |
|
2277 |
||
2278 |
// First, handle JSCell cases - check MasqueradesAsUndefined bit on the structure. |
|
2279 |
loadPtr(Address(regT0, OBJECT_OFFSETOF(JSCell, m_structure)), regT2); |
|
2280 |
addJump(branchTest32(NonZero, Address(regT2, OBJECT_OFFSETOF(Structure, m_typeInfo.m_flags)), Imm32(MasqueradesAsUndefined)), target); |
|
2281 |
Jump wasNotImmediate = jump(); |
|
2282 |
||
2283 |
// Now handle the immediate cases - undefined & null |
|
2284 |
isImmediate.link(this); |
|
2285 |
andPtr(Imm32(~JSImmediate::ExtendedTagBitUndefined), regT0); |
|
2286 |
addJump(branchPtr(Equal, regT0, ImmPtr(JSValue::encode(jsNull()))), target); |
|
2287 |
||
2288 |
wasNotImmediate.link(this); |
|
2289 |
RECORD_JUMP_TARGET(target); |
|
2290 |
}; |
|
2291 |
void JIT::emit_op_jneq_null(Instruction* currentInstruction) |
|
2292 |
{ |
|
2293 |
unsigned src = currentInstruction[1].u.operand; |
|
2294 |
unsigned target = currentInstruction[2].u.operand; |
|
2295 |
||
2296 |
emitGetVirtualRegister(src, regT0); |
|
2297 |
Jump isImmediate = emitJumpIfNotJSCell(regT0); |
|
2298 |
||
2299 |
// First, handle JSCell cases - check MasqueradesAsUndefined bit on the structure. |
|
2300 |
loadPtr(Address(regT0, OBJECT_OFFSETOF(JSCell, m_structure)), regT2); |
|
2301 |
addJump(branchTest32(Zero, Address(regT2, OBJECT_OFFSETOF(Structure, m_typeInfo.m_flags)), Imm32(MasqueradesAsUndefined)), target); |
|
2302 |
Jump wasNotImmediate = jump(); |
|
2303 |
||
2304 |
// Now handle the immediate cases - undefined & null |
|
2305 |
isImmediate.link(this); |
|
2306 |
andPtr(Imm32(~JSImmediate::ExtendedTagBitUndefined), regT0); |
|
2307 |
addJump(branchPtr(NotEqual, regT0, ImmPtr(JSValue::encode(jsNull()))), target); |
|
2308 |
||
2309 |
wasNotImmediate.link(this); |
|
2310 |
RECORD_JUMP_TARGET(target); |
|
2311 |
} |
|
2312 |
||
2313 |
void JIT::emit_op_jneq_ptr(Instruction* currentInstruction) |
|
2314 |
{ |
|
2315 |
unsigned src = currentInstruction[1].u.operand; |
|
2316 |
JSCell* ptr = currentInstruction[2].u.jsCell; |
|
2317 |
unsigned target = currentInstruction[3].u.operand; |
|
2318 |
||
2319 |
emitGetVirtualRegister(src, regT0); |
|
2320 |
addJump(branchPtr(NotEqual, regT0, ImmPtr(JSValue::encode(JSValue(ptr)))), target); |
|
2321 |
||
2322 |
RECORD_JUMP_TARGET(target); |
|
2323 |
} |
|
2324 |
||
2325 |
void JIT::emit_op_jsr(Instruction* currentInstruction) |
|
2326 |
{ |
|
2327 |
int retAddrDst = currentInstruction[1].u.operand; |
|
2328 |
int target = currentInstruction[2].u.operand; |
|
2329 |
DataLabelPtr storeLocation = storePtrWithPatch(ImmPtr(0), Address(callFrameRegister, sizeof(Register) * retAddrDst)); |
|
2330 |
addJump(jump(), target); |
|
2331 |
m_jsrSites.append(JSRInfo(storeLocation, label())); |
|
2332 |
killLastResultRegister(); |
|
2333 |
RECORD_JUMP_TARGET(target); |
|
2334 |
} |
|
2335 |
||
2336 |
void JIT::emit_op_sret(Instruction* currentInstruction) |
|
2337 |
{ |
|
2338 |
jump(Address(callFrameRegister, sizeof(Register) * currentInstruction[1].u.operand)); |
|
2339 |
killLastResultRegister(); |
|
2340 |
} |
|
2341 |
||
2342 |
void JIT::emit_op_eq(Instruction* currentInstruction) |
|
2343 |
{ |
|
2344 |
emitGetVirtualRegisters(currentInstruction[2].u.operand, regT0, currentInstruction[3].u.operand, regT1); |
|
2345 |
emitJumpSlowCaseIfNotImmediateIntegers(regT0, regT1, regT2); |
|
2346 |
set32(Equal, regT1, regT0, regT0); |
|
2347 |
emitTagAsBoolImmediate(regT0); |
|
2348 |
emitPutVirtualRegister(currentInstruction[1].u.operand); |
|
2349 |
} |
|
2350 |
||
2351 |
void JIT::emit_op_bitnot(Instruction* currentInstruction) |
|
2352 |
{ |
|
2353 |
emitGetVirtualRegister(currentInstruction[2].u.operand, regT0); |
|
2354 |
emitJumpSlowCaseIfNotImmediateInteger(regT0); |
|
2355 |
#if USE(JSVALUE64) |
|
2356 |
not32(regT0); |
|
2357 |
emitFastArithIntToImmNoCheck(regT0, regT0); |
|
2358 |
#else |
|
2359 |
xorPtr(Imm32(~JSImmediate::TagTypeNumber), regT0); |
|
2360 |
#endif |
|
2361 |
emitPutVirtualRegister(currentInstruction[1].u.operand); |
|
2362 |
} |
|
2363 |
||
2364 |
void JIT::emit_op_resolve_with_base(Instruction* currentInstruction) |
|
2365 |
{ |
|
2366 |
JITStubCall stubCall(this, cti_op_resolve_with_base); |
|
2367 |
stubCall.addArgument(ImmPtr(&m_codeBlock->identifier(currentInstruction[3].u.operand))); |
|
2368 |
stubCall.addArgument(Imm32(currentInstruction[1].u.operand)); |
|
2369 |
stubCall.call(currentInstruction[2].u.operand); |
|
2370 |
} |
|
2371 |
||
2372 |
void JIT::emit_op_new_func_exp(Instruction* currentInstruction) |
|
2373 |
{ |
|
2374 |
JITStubCall stubCall(this, cti_op_new_func_exp); |
|
2375 |
stubCall.addArgument(ImmPtr(m_codeBlock->functionExpr(currentInstruction[2].u.operand))); |
|
2376 |
stubCall.call(currentInstruction[1].u.operand); |
|
2377 |
} |
|
2378 |
||
2379 |
void JIT::emit_op_jtrue(Instruction* currentInstruction) |
|
2380 |
{ |
|
2381 |
unsigned target = currentInstruction[2].u.operand; |
|
2382 |
emitGetVirtualRegister(currentInstruction[1].u.operand, regT0); |
|
2383 |
||
2384 |
Jump isZero = branchPtr(Equal, regT0, ImmPtr(JSValue::encode(jsNumber(m_globalData, 0)))); |
|
2385 |
addJump(emitJumpIfImmediateInteger(regT0), target); |
|
2386 |
||
2387 |
addJump(branchPtr(Equal, regT0, ImmPtr(JSValue::encode(jsBoolean(true)))), target); |
|
2388 |
addSlowCase(branchPtr(NotEqual, regT0, ImmPtr(JSValue::encode(jsBoolean(false))))); |
|
2389 |
||
2390 |
isZero.link(this); |
|
2391 |
RECORD_JUMP_TARGET(target); |
|
2392 |
} |
|
2393 |
||
2394 |
void JIT::emit_op_neq(Instruction* currentInstruction) |
|
2395 |
{ |
|
2396 |
emitGetVirtualRegisters(currentInstruction[2].u.operand, regT0, currentInstruction[3].u.operand, regT1); |
|
2397 |
emitJumpSlowCaseIfNotImmediateIntegers(regT0, regT1, regT2); |
|
2398 |
set32(NotEqual, regT1, regT0, regT0); |
|
2399 |
emitTagAsBoolImmediate(regT0); |
|
2400 |
||
2401 |
emitPutVirtualRegister(currentInstruction[1].u.operand); |
|
2402 |
||
2403 |
} |
|
2404 |
||
2405 |
void JIT::emit_op_bitxor(Instruction* currentInstruction) |
|
2406 |
{ |
|
2407 |
emitGetVirtualRegisters(currentInstruction[2].u.operand, regT0, currentInstruction[3].u.operand, regT1); |
|
2408 |
emitJumpSlowCaseIfNotImmediateIntegers(regT0, regT1, regT2); |
|
2409 |
xorPtr(regT1, regT0); |
|
2410 |
emitFastArithReTagImmediate(regT0, regT0); |
|
2411 |
emitPutVirtualRegister(currentInstruction[1].u.operand); |
|
2412 |
} |
|
2413 |
||
2414 |
void JIT::emit_op_new_regexp(Instruction* currentInstruction) |
|
2415 |
{ |
|
2416 |
JITStubCall stubCall(this, cti_op_new_regexp); |
|
2417 |
stubCall.addArgument(ImmPtr(m_codeBlock->regexp(currentInstruction[2].u.operand))); |
|
2418 |
stubCall.call(currentInstruction[1].u.operand); |
|
2419 |
} |
|
2420 |
||
2421 |
void JIT::emit_op_bitor(Instruction* currentInstruction) |
|
2422 |
{ |
|
2423 |
emitGetVirtualRegisters(currentInstruction[2].u.operand, regT0, currentInstruction[3].u.operand, regT1); |
|
2424 |
emitJumpSlowCaseIfNotImmediateIntegers(regT0, regT1, regT2); |
|
2425 |
orPtr(regT1, regT0); |
|
2426 |
emitPutVirtualRegister(currentInstruction[1].u.operand); |
|
2427 |
} |
|
2428 |
||
2429 |
void JIT::emit_op_throw(Instruction* currentInstruction) |
|
2430 |
{ |
|
2431 |
JITStubCall stubCall(this, cti_op_throw); |
|
2432 |
stubCall.addArgument(currentInstruction[1].u.operand, regT2); |
|
2433 |
stubCall.call(); |
|
2434 |
ASSERT(regT0 == returnValueRegister); |
|
2435 |
#ifndef NDEBUG |
|
2436 |
// cti_op_throw always changes it's return address, |
|
2437 |
// this point in the code should never be reached. |
|
2438 |
breakpoint(); |
|
2439 |
#endif |
|
2440 |
} |
|
2441 |
||
2442 |
void JIT::emit_op_get_pnames(Instruction* currentInstruction) |
|
2443 |
{ |
|
2444 |
int dst = currentInstruction[1].u.operand; |
|
2445 |
int base = currentInstruction[2].u.operand; |
|
2446 |
int i = currentInstruction[3].u.operand; |
|
2447 |
int size = currentInstruction[4].u.operand; |
|
2448 |
int breakTarget = currentInstruction[5].u.operand; |
|
2449 |
||
2450 |
JumpList isNotObject; |
|
2451 |
||
2452 |
emitGetVirtualRegister(base, regT0); |
|
2453 |
if (!m_codeBlock->isKnownNotImmediate(base)) |
|
2454 |
isNotObject.append(emitJumpIfNotJSCell(regT0)); |
|
2455 |
if (base != m_codeBlock->thisRegister()) { |
|
2456 |
loadPtr(Address(regT0, OBJECT_OFFSETOF(JSCell, m_structure)), regT2); |
|
2457 |
isNotObject.append(branch32(NotEqual, Address(regT2, OBJECT_OFFSETOF(Structure, m_typeInfo.m_type)), Imm32(ObjectType))); |
|
2458 |
} |
|
2459 |
||
2460 |
// We could inline the case where you have a valid cache, but |
|
2461 |
// this call doesn't seem to be hot. |
|
2462 |
Label isObject(this); |
|
2463 |
JITStubCall getPnamesStubCall(this, cti_op_get_pnames); |
|
2464 |
getPnamesStubCall.addArgument(regT0); |
|
2465 |
getPnamesStubCall.call(dst); |
|
2466 |
load32(Address(regT0, OBJECT_OFFSETOF(JSPropertyNameIterator, m_jsStringsSize)), regT3); |
|
2467 |
store32(Imm32(0), addressFor(i)); |
|
2468 |
store32(regT3, addressFor(size)); |
|
2469 |
Jump end = jump(); |
|
2470 |
||
2471 |
isNotObject.link(this); |
|
2472 |
move(regT0, regT1); |
|
2473 |
and32(Imm32(~JSImmediate::ExtendedTagBitUndefined), regT1); |
|
2474 |
addJump(branch32(Equal, regT1, Imm32(JSImmediate::FullTagTypeNull)), breakTarget); |
|
2475 |
||
2476 |
JITStubCall toObjectStubCall(this, cti_to_object); |
|
2477 |
toObjectStubCall.addArgument(regT0); |
|
2478 |
toObjectStubCall.call(base); |
|
2479 |
jump().linkTo(isObject, this); |
|
2480 |
||
2481 |
end.link(this); |
|
2482 |
} |
|
2483 |
||
2484 |
void JIT::emit_op_next_pname(Instruction* currentInstruction) |
|
2485 |
{ |
|
2486 |
int dst = currentInstruction[1].u.operand; |
|
2487 |
int base = currentInstruction[2].u.operand; |
|
2488 |
int i = currentInstruction[3].u.operand; |
|
2489 |
int size = currentInstruction[4].u.operand; |
|
2490 |
int it = currentInstruction[5].u.operand; |
|
2491 |
int target = currentInstruction[6].u.operand; |
|
2492 |
||
2493 |
JumpList callHasProperty; |
|
2494 |
||
2495 |
Label begin(this); |
|
2496 |
load32(addressFor(i), regT0); |
|
2497 |
Jump end = branch32(Equal, regT0, addressFor(size)); |
|
2498 |
||
2499 |
// Grab key @ i |
|
2500 |
loadPtr(addressFor(it), regT1); |
|
2501 |
loadPtr(Address(regT1, OBJECT_OFFSETOF(JSPropertyNameIterator, m_jsStrings)), regT2); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2502 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2503 |
#if USE(JSVALUE64) |
0 | 2504 |
loadPtr(BaseIndex(regT2, regT0, TimesEight), regT2); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2505 |
#else |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2506 |
loadPtr(BaseIndex(regT2, regT0, TimesFour), regT2); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2507 |
#endif |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2508 |
|
0 | 2509 |
emitPutVirtualRegister(dst, regT2); |
2510 |
||
2511 |
// Increment i |
|
2512 |
add32(Imm32(1), regT0); |
|
2513 |
store32(regT0, addressFor(i)); |
|
2514 |
||
2515 |
// Verify that i is valid: |
|
2516 |
emitGetVirtualRegister(base, regT0); |
|
2517 |
||
2518 |
// Test base's structure |
|
2519 |
loadPtr(Address(regT0, OBJECT_OFFSETOF(JSCell, m_structure)), regT2); |
|
2520 |
callHasProperty.append(branchPtr(NotEqual, regT2, Address(Address(regT1, OBJECT_OFFSETOF(JSPropertyNameIterator, m_cachedStructure))))); |
|
2521 |
||
2522 |
// Test base's prototype chain |
|
2523 |
loadPtr(Address(Address(regT1, OBJECT_OFFSETOF(JSPropertyNameIterator, m_cachedPrototypeChain))), regT3); |
|
2524 |
loadPtr(Address(regT3, OBJECT_OFFSETOF(StructureChain, m_vector)), regT3); |
|
2525 |
addJump(branchTestPtr(Zero, Address(regT3)), target); |
|
2526 |
||
2527 |
Label checkPrototype(this); |
|
2528 |
loadPtr(Address(regT2, OBJECT_OFFSETOF(Structure, m_prototype)), regT2); |
|
2529 |
callHasProperty.append(emitJumpIfNotJSCell(regT2)); |
|
2530 |
loadPtr(Address(regT2, OBJECT_OFFSETOF(JSCell, m_structure)), regT2); |
|
2531 |
callHasProperty.append(branchPtr(NotEqual, regT2, Address(regT3))); |
|
2532 |
addPtr(Imm32(sizeof(Structure*)), regT3); |
|
2533 |
branchTestPtr(NonZero, Address(regT3)).linkTo(checkPrototype, this); |
|
2534 |
||
2535 |
// Continue loop. |
|
2536 |
addJump(jump(), target); |
|
2537 |
||
2538 |
// Slow case: Ask the object if i is valid. |
|
2539 |
callHasProperty.link(this); |
|
2540 |
emitGetVirtualRegister(dst, regT1); |
|
2541 |
JITStubCall stubCall(this, cti_has_property); |
|
2542 |
stubCall.addArgument(regT0); |
|
2543 |
stubCall.addArgument(regT1); |
|
2544 |
stubCall.call(); |
|
2545 |
||
2546 |
// Test for valid key. |
|
2547 |
addJump(branchTest32(NonZero, regT0), target); |
|
2548 |
jump().linkTo(begin, this); |
|
2549 |
||
2550 |
// End of loop. |
|
2551 |
end.link(this); |
|
2552 |
} |
|
2553 |
||
2554 |
void JIT::emit_op_push_scope(Instruction* currentInstruction) |
|
2555 |
{ |
|
2556 |
JITStubCall stubCall(this, cti_op_push_scope); |
|
2557 |
stubCall.addArgument(currentInstruction[1].u.operand, regT2); |
|
2558 |
stubCall.call(currentInstruction[1].u.operand); |
|
2559 |
} |
|
2560 |
||
2561 |
void JIT::emit_op_pop_scope(Instruction*) |
|
2562 |
{ |
|
2563 |
JITStubCall(this, cti_op_pop_scope).call(); |
|
2564 |
} |
|
2565 |
||
2566 |
void JIT::compileOpStrictEq(Instruction* currentInstruction, CompileOpStrictEqType type) |
|
2567 |
{ |
|
2568 |
unsigned dst = currentInstruction[1].u.operand; |
|
2569 |
unsigned src1 = currentInstruction[2].u.operand; |
|
2570 |
unsigned src2 = currentInstruction[3].u.operand; |
|
2571 |
||
2572 |
emitGetVirtualRegisters(src1, regT0, src2, regT1); |
|
2573 |
||
2574 |
// Jump to a slow case if either operand is a number, or if both are JSCell*s. |
|
2575 |
move(regT0, regT2); |
|
2576 |
orPtr(regT1, regT2); |
|
2577 |
addSlowCase(emitJumpIfJSCell(regT2)); |
|
2578 |
addSlowCase(emitJumpIfImmediateNumber(regT2)); |
|
2579 |
||
2580 |
if (type == OpStrictEq) |
|
2581 |
set32(Equal, regT1, regT0, regT0); |
|
2582 |
else |
|
2583 |
set32(NotEqual, regT1, regT0, regT0); |
|
2584 |
emitTagAsBoolImmediate(regT0); |
|
2585 |
||
2586 |
emitPutVirtualRegister(dst); |
|
2587 |
} |
|
2588 |
||
2589 |
void JIT::emit_op_stricteq(Instruction* currentInstruction) |
|
2590 |
{ |
|
2591 |
compileOpStrictEq(currentInstruction, OpStrictEq); |
|
2592 |
} |
|
2593 |
||
2594 |
void JIT::emit_op_nstricteq(Instruction* currentInstruction) |
|
2595 |
{ |
|
2596 |
compileOpStrictEq(currentInstruction, OpNStrictEq); |
|
2597 |
} |
|
2598 |
||
2599 |
void JIT::emit_op_to_jsnumber(Instruction* currentInstruction) |
|
2600 |
{ |
|
2601 |
int srcVReg = currentInstruction[2].u.operand; |
|
2602 |
emitGetVirtualRegister(srcVReg, regT0); |
|
2603 |
||
2604 |
Jump wasImmediate = emitJumpIfImmediateInteger(regT0); |
|
2605 |
||
2606 |
emitJumpSlowCaseIfNotJSCell(regT0, srcVReg); |
|
2607 |
loadPtr(Address(regT0, OBJECT_OFFSETOF(JSCell, m_structure)), regT2); |
|
2608 |
addSlowCase(branch32(NotEqual, Address(regT2, OBJECT_OFFSETOF(Structure, m_typeInfo.m_type)), Imm32(NumberType))); |
|
2609 |
||
2610 |
wasImmediate.link(this); |
|
2611 |
||
2612 |
emitPutVirtualRegister(currentInstruction[1].u.operand); |
|
2613 |
} |
|
2614 |
||
2615 |
void JIT::emit_op_push_new_scope(Instruction* currentInstruction) |
|
2616 |
{ |
|
2617 |
JITStubCall stubCall(this, cti_op_push_new_scope); |
|
2618 |
stubCall.addArgument(ImmPtr(&m_codeBlock->identifier(currentInstruction[2].u.operand))); |
|
2619 |
stubCall.addArgument(currentInstruction[3].u.operand, regT2); |
|
2620 |
stubCall.call(currentInstruction[1].u.operand); |
|
2621 |
} |
|
2622 |
||
2623 |
void JIT::emit_op_catch(Instruction* currentInstruction) |
|
2624 |
{ |
|
2625 |
killLastResultRegister(); // FIXME: Implicitly treat op_catch as a labeled statement, and remove this line of code. |
|
2626 |
peek(callFrameRegister, OBJECT_OFFSETOF(struct JITStackFrame, callFrame) / sizeof (void*)); |
|
2627 |
emitPutVirtualRegister(currentInstruction[1].u.operand); |
|
2628 |
} |
|
2629 |
||
2630 |
void JIT::emit_op_jmp_scopes(Instruction* currentInstruction) |
|
2631 |
{ |
|
2632 |
JITStubCall stubCall(this, cti_op_jmp_scopes); |
|
2633 |
stubCall.addArgument(Imm32(currentInstruction[1].u.operand)); |
|
2634 |
stubCall.call(); |
|
2635 |
addJump(jump(), currentInstruction[2].u.operand); |
|
2636 |
RECORD_JUMP_TARGET(currentInstruction[2].u.operand); |
|
2637 |
} |
|
2638 |
||
2639 |
void JIT::emit_op_switch_imm(Instruction* currentInstruction) |
|
2640 |
{ |
|
2641 |
unsigned tableIndex = currentInstruction[1].u.operand; |
|
2642 |
unsigned defaultOffset = currentInstruction[2].u.operand; |
|
2643 |
unsigned scrutinee = currentInstruction[3].u.operand; |
|
2644 |
||
2645 |
// create jump table for switch destinations, track this switch statement. |
|
2646 |
SimpleJumpTable* jumpTable = &m_codeBlock->immediateSwitchJumpTable(tableIndex); |
|
2647 |
m_switches.append(SwitchRecord(jumpTable, m_bytecodeIndex, defaultOffset, SwitchRecord::Immediate)); |
|
2648 |
jumpTable->ctiOffsets.grow(jumpTable->branchOffsets.size()); |
|
2649 |
||
2650 |
JITStubCall stubCall(this, cti_op_switch_imm); |
|
2651 |
stubCall.addArgument(scrutinee, regT2); |
|
2652 |
stubCall.addArgument(Imm32(tableIndex)); |
|
2653 |
stubCall.call(); |
|
2654 |
jump(regT0); |
|
2655 |
} |
|
2656 |
||
2657 |
void JIT::emit_op_switch_char(Instruction* currentInstruction) |
|
2658 |
{ |
|
2659 |
unsigned tableIndex = currentInstruction[1].u.operand; |
|
2660 |
unsigned defaultOffset = currentInstruction[2].u.operand; |
|
2661 |
unsigned scrutinee = currentInstruction[3].u.operand; |
|
2662 |
||
2663 |
// create jump table for switch destinations, track this switch statement. |
|
2664 |
SimpleJumpTable* jumpTable = &m_codeBlock->characterSwitchJumpTable(tableIndex); |
|
2665 |
m_switches.append(SwitchRecord(jumpTable, m_bytecodeIndex, defaultOffset, SwitchRecord::Character)); |
|
2666 |
jumpTable->ctiOffsets.grow(jumpTable->branchOffsets.size()); |
|
2667 |
||
2668 |
JITStubCall stubCall(this, cti_op_switch_char); |
|
2669 |
stubCall.addArgument(scrutinee, regT2); |
|
2670 |
stubCall.addArgument(Imm32(tableIndex)); |
|
2671 |
stubCall.call(); |
|
2672 |
jump(regT0); |
|
2673 |
} |
|
2674 |
||
2675 |
void JIT::emit_op_switch_string(Instruction* currentInstruction) |
|
2676 |
{ |
|
2677 |
unsigned tableIndex = currentInstruction[1].u.operand; |
|
2678 |
unsigned defaultOffset = currentInstruction[2].u.operand; |
|
2679 |
unsigned scrutinee = currentInstruction[3].u.operand; |
|
2680 |
||
2681 |
// create jump table for switch destinations, track this switch statement. |
|
2682 |
StringJumpTable* jumpTable = &m_codeBlock->stringSwitchJumpTable(tableIndex); |
|
2683 |
m_switches.append(SwitchRecord(jumpTable, m_bytecodeIndex, defaultOffset)); |
|
2684 |
||
2685 |
JITStubCall stubCall(this, cti_op_switch_string); |
|
2686 |
stubCall.addArgument(scrutinee, regT2); |
|
2687 |
stubCall.addArgument(Imm32(tableIndex)); |
|
2688 |
stubCall.call(); |
|
2689 |
jump(regT0); |
|
2690 |
} |
|
2691 |
||
2692 |
void JIT::emit_op_new_error(Instruction* currentInstruction) |
|
2693 |
{ |
|
2694 |
JITStubCall stubCall(this, cti_op_new_error); |
|
2695 |
stubCall.addArgument(Imm32(currentInstruction[2].u.operand)); |
|
2696 |
stubCall.addArgument(ImmPtr(JSValue::encode(m_codeBlock->getConstant(currentInstruction[3].u.operand)))); |
|
2697 |
stubCall.addArgument(Imm32(m_bytecodeIndex)); |
|
2698 |
stubCall.call(currentInstruction[1].u.operand); |
|
2699 |
} |
|
2700 |
||
2701 |
void JIT::emit_op_debug(Instruction* currentInstruction) |
|
2702 |
{ |
|
2703 |
JITStubCall stubCall(this, cti_op_debug); |
|
2704 |
stubCall.addArgument(Imm32(currentInstruction[1].u.operand)); |
|
2705 |
stubCall.addArgument(Imm32(currentInstruction[2].u.operand)); |
|
2706 |
stubCall.addArgument(Imm32(currentInstruction[3].u.operand)); |
|
2707 |
stubCall.call(); |
|
2708 |
} |
|
2709 |
||
2710 |
void JIT::emit_op_eq_null(Instruction* currentInstruction) |
|
2711 |
{ |
|
2712 |
unsigned dst = currentInstruction[1].u.operand; |
|
2713 |
unsigned src1 = currentInstruction[2].u.operand; |
|
2714 |
||
2715 |
emitGetVirtualRegister(src1, regT0); |
|
2716 |
Jump isImmediate = emitJumpIfNotJSCell(regT0); |
|
2717 |
||
2718 |
loadPtr(Address(regT0, OBJECT_OFFSETOF(JSCell, m_structure)), regT2); |
|
2719 |
setTest32(NonZero, Address(regT2, OBJECT_OFFSETOF(Structure, m_typeInfo.m_flags)), Imm32(MasqueradesAsUndefined), regT0); |
|
2720 |
||
2721 |
Jump wasNotImmediate = jump(); |
|
2722 |
||
2723 |
isImmediate.link(this); |
|
2724 |
||
2725 |
andPtr(Imm32(~JSImmediate::ExtendedTagBitUndefined), regT0); |
|
2726 |
setPtr(Equal, regT0, Imm32(JSImmediate::FullTagTypeNull), regT0); |
|
2727 |
||
2728 |
wasNotImmediate.link(this); |
|
2729 |
||
2730 |
emitTagAsBoolImmediate(regT0); |
|
2731 |
emitPutVirtualRegister(dst); |
|
2732 |
||
2733 |
} |
|
2734 |
||
2735 |
void JIT::emit_op_neq_null(Instruction* currentInstruction) |
|
2736 |
{ |
|
2737 |
unsigned dst = currentInstruction[1].u.operand; |
|
2738 |
unsigned src1 = currentInstruction[2].u.operand; |
|
2739 |
||
2740 |
emitGetVirtualRegister(src1, regT0); |
|
2741 |
Jump isImmediate = emitJumpIfNotJSCell(regT0); |
|
2742 |
||
2743 |
loadPtr(Address(regT0, OBJECT_OFFSETOF(JSCell, m_structure)), regT2); |
|
2744 |
setTest32(Zero, Address(regT2, OBJECT_OFFSETOF(Structure, m_typeInfo.m_flags)), Imm32(MasqueradesAsUndefined), regT0); |
|
2745 |
||
2746 |
Jump wasNotImmediate = jump(); |
|
2747 |
||
2748 |
isImmediate.link(this); |
|
2749 |
||
2750 |
andPtr(Imm32(~JSImmediate::ExtendedTagBitUndefined), regT0); |
|
2751 |
setPtr(NotEqual, regT0, Imm32(JSImmediate::FullTagTypeNull), regT0); |
|
2752 |
||
2753 |
wasNotImmediate.link(this); |
|
2754 |
||
2755 |
emitTagAsBoolImmediate(regT0); |
|
2756 |
emitPutVirtualRegister(dst); |
|
2757 |
||
2758 |
} |
|
2759 |
||
2760 |
void JIT::emit_op_enter(Instruction*) |
|
2761 |
{ |
|
2762 |
// Even though CTI doesn't use them, we initialize our constant |
|
2763 |
// registers to zap stale pointers, to avoid unnecessarily prolonging |
|
2764 |
// object lifetime and increasing GC pressure. |
|
2765 |
size_t count = m_codeBlock->m_numVars; |
|
2766 |
for (size_t j = 0; j < count; ++j) |
|
2767 |
emitInitRegister(j); |
|
2768 |
||
2769 |
} |
|
2770 |
||
2771 |
void JIT::emit_op_enter_with_activation(Instruction* currentInstruction) |
|
2772 |
{ |
|
2773 |
// Even though CTI doesn't use them, we initialize our constant |
|
2774 |
// registers to zap stale pointers, to avoid unnecessarily prolonging |
|
2775 |
// object lifetime and increasing GC pressure. |
|
2776 |
size_t count = m_codeBlock->m_numVars; |
|
2777 |
for (size_t j = 0; j < count; ++j) |
|
2778 |
emitInitRegister(j); |
|
2779 |
||
2780 |
JITStubCall(this, cti_op_push_activation).call(currentInstruction[1].u.operand); |
|
2781 |
} |
|
2782 |
||
2783 |
void JIT::emit_op_create_arguments(Instruction*) |
|
2784 |
{ |
|
2785 |
Jump argsCreated = branchTestPtr(NonZero, Address(callFrameRegister, sizeof(Register) * RegisterFile::ArgumentsRegister)); |
|
2786 |
if (m_codeBlock->m_numParameters == 1) |
|
2787 |
JITStubCall(this, cti_op_create_arguments_no_params).call(); |
|
2788 |
else |
|
2789 |
JITStubCall(this, cti_op_create_arguments).call(); |
|
2790 |
argsCreated.link(this); |
|
2791 |
} |
|
2792 |
||
2793 |
void JIT::emit_op_init_arguments(Instruction*) |
|
2794 |
{ |
|
2795 |
storePtr(ImmPtr(0), Address(callFrameRegister, sizeof(Register) * RegisterFile::ArgumentsRegister)); |
|
2796 |
} |
|
2797 |
||
2798 |
void JIT::emit_op_convert_this(Instruction* currentInstruction) |
|
2799 |
{ |
|
2800 |
emitGetVirtualRegister(currentInstruction[1].u.operand, regT0); |
|
2801 |
||
2802 |
emitJumpSlowCaseIfNotJSCell(regT0); |
|
2803 |
loadPtr(Address(regT0, OBJECT_OFFSETOF(JSCell, m_structure)), regT1); |
|
2804 |
addSlowCase(branchTest32(NonZero, Address(regT1, OBJECT_OFFSETOF(Structure, m_typeInfo.m_flags)), Imm32(NeedsThisConversion))); |
|
2805 |
||
2806 |
} |
|
2807 |
||
2808 |
void JIT::emit_op_profile_will_call(Instruction* currentInstruction) |
|
2809 |
{ |
|
2810 |
peek(regT1, OBJECT_OFFSETOF(JITStackFrame, enabledProfilerReference) / sizeof (void*)); |
|
2811 |
Jump noProfiler = branchTestPtr(Zero, Address(regT1)); |
|
2812 |
||
2813 |
JITStubCall stubCall(this, cti_op_profile_will_call); |
|
2814 |
stubCall.addArgument(currentInstruction[1].u.operand, regT1); |
|
2815 |
stubCall.call(); |
|
2816 |
noProfiler.link(this); |
|
2817 |
||
2818 |
} |
|
2819 |
||
2820 |
void JIT::emit_op_profile_did_call(Instruction* currentInstruction) |
|
2821 |
{ |
|
2822 |
peek(regT1, OBJECT_OFFSETOF(JITStackFrame, enabledProfilerReference) / sizeof (void*)); |
|
2823 |
Jump noProfiler = branchTestPtr(Zero, Address(regT1)); |
|
2824 |
||
2825 |
JITStubCall stubCall(this, cti_op_profile_did_call); |
|
2826 |
stubCall.addArgument(currentInstruction[1].u.operand, regT1); |
|
2827 |
stubCall.call(); |
|
2828 |
noProfiler.link(this); |
|
2829 |
} |
|
2830 |
||
2831 |
||
2832 |
// Slow cases |
|
2833 |
||
2834 |
void JIT::emitSlow_op_convert_this(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter) |
|
2835 |
{ |
|
2836 |
linkSlowCase(iter); |
|
2837 |
linkSlowCase(iter); |
|
2838 |
JITStubCall stubCall(this, cti_op_convert_this); |
|
2839 |
stubCall.addArgument(regT0); |
|
2840 |
stubCall.call(currentInstruction[1].u.operand); |
|
2841 |
} |
|
2842 |
||
2843 |
void JIT::emitSlow_op_construct_verify(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter) |
|
2844 |
{ |
|
2845 |
linkSlowCase(iter); |
|
2846 |
linkSlowCase(iter); |
|
2847 |
emitGetVirtualRegister(currentInstruction[2].u.operand, regT0); |
|
2848 |
emitPutVirtualRegister(currentInstruction[1].u.operand); |
|
2849 |
} |
|
2850 |
||
2851 |
void JIT::emitSlow_op_to_primitive(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter) |
|
2852 |
{ |
|
2853 |
linkSlowCase(iter); |
|
2854 |
||
2855 |
JITStubCall stubCall(this, cti_op_to_primitive); |
|
2856 |
stubCall.addArgument(regT0); |
|
2857 |
stubCall.call(currentInstruction[1].u.operand); |
|
2858 |
} |
|
2859 |
||
2860 |
void JIT::emitSlow_op_get_by_val(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter) |
|
2861 |
{ |
|
2862 |
unsigned dst = currentInstruction[1].u.operand; |
|
2863 |
unsigned base = currentInstruction[2].u.operand; |
|
2864 |
unsigned property = currentInstruction[3].u.operand; |
|
2865 |
||
2866 |
linkSlowCase(iter); // property int32 check |
|
2867 |
linkSlowCaseIfNotJSCell(iter, base); // base cell check |
|
2868 |
linkSlowCase(iter); // base array check |
|
2869 |
linkSlowCase(iter); // vector length check |
|
2870 |
linkSlowCase(iter); // empty value |
|
2871 |
||
2872 |
JITStubCall stubCall(this, cti_op_get_by_val); |
|
2873 |
stubCall.addArgument(base, regT2); |
|
2874 |
stubCall.addArgument(property, regT2); |
|
2875 |
stubCall.call(dst); |
|
2876 |
} |
|
2877 |
||
2878 |
void JIT::emitSlow_op_loop_if_less(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter) |
|
2879 |
{ |
|
2880 |
unsigned op1 = currentInstruction[1].u.operand; |
|
2881 |
unsigned op2 = currentInstruction[2].u.operand; |
|
2882 |
unsigned target = currentInstruction[3].u.operand; |
|
2883 |
if (isOperandConstantImmediateInt(op2)) { |
|
2884 |
linkSlowCase(iter); |
|
2885 |
JITStubCall stubCall(this, cti_op_loop_if_less); |
|
2886 |
stubCall.addArgument(regT0); |
|
2887 |
stubCall.addArgument(op2, regT2); |
|
2888 |
stubCall.call(); |
|
2889 |
emitJumpSlowToHot(branchTest32(NonZero, regT0), target); |
|
2890 |
} else if (isOperandConstantImmediateInt(op1)) { |
|
2891 |
linkSlowCase(iter); |
|
2892 |
JITStubCall stubCall(this, cti_op_loop_if_less); |
|
2893 |
stubCall.addArgument(op1, regT2); |
|
2894 |
stubCall.addArgument(regT0); |
|
2895 |
stubCall.call(); |
|
2896 |
emitJumpSlowToHot(branchTest32(NonZero, regT0), target); |
|
2897 |
} else { |
|
2898 |
linkSlowCase(iter); |
|
2899 |
linkSlowCase(iter); |
|
2900 |
JITStubCall stubCall(this, cti_op_loop_if_less); |
|
2901 |
stubCall.addArgument(regT0); |
|
2902 |
stubCall.addArgument(regT1); |
|
2903 |
stubCall.call(); |
|
2904 |
emitJumpSlowToHot(branchTest32(NonZero, regT0), target); |
|
2905 |
} |
|
2906 |
} |
|
2907 |
||
2908 |
void JIT::emitSlow_op_loop_if_lesseq(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter) |
|
2909 |
{ |
|
2910 |
unsigned op2 = currentInstruction[2].u.operand; |
|
2911 |
unsigned target = currentInstruction[3].u.operand; |
|
2912 |
if (isOperandConstantImmediateInt(op2)) { |
|
2913 |
linkSlowCase(iter); |
|
2914 |
JITStubCall stubCall(this, cti_op_loop_if_lesseq); |
|
2915 |
stubCall.addArgument(regT0); |
|
2916 |
stubCall.addArgument(currentInstruction[2].u.operand, regT2); |
|
2917 |
stubCall.call(); |
|
2918 |
emitJumpSlowToHot(branchTest32(NonZero, regT0), target); |
|
2919 |
} else { |
|
2920 |
linkSlowCase(iter); |
|
2921 |
linkSlowCase(iter); |
|
2922 |
JITStubCall stubCall(this, cti_op_loop_if_lesseq); |
|
2923 |
stubCall.addArgument(regT0); |
|
2924 |
stubCall.addArgument(regT1); |
|
2925 |
stubCall.call(); |
|
2926 |
emitJumpSlowToHot(branchTest32(NonZero, regT0), target); |
|
2927 |
} |
|
2928 |
} |
|
2929 |
||
2930 |
void JIT::emitSlow_op_put_by_val(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter) |
|
2931 |
{ |
|
2932 |
unsigned base = currentInstruction[1].u.operand; |
|
2933 |
unsigned property = currentInstruction[2].u.operand; |
|
2934 |
unsigned value = currentInstruction[3].u.operand; |
|
2935 |
||
2936 |
linkSlowCase(iter); // property int32 check |
|
2937 |
linkSlowCaseIfNotJSCell(iter, base); // base cell check |
|
2938 |
linkSlowCase(iter); // base not array check |
|
2939 |
linkSlowCase(iter); // in vector check |
|
2940 |
||
2941 |
JITStubCall stubPutByValCall(this, cti_op_put_by_val); |
|
2942 |
stubPutByValCall.addArgument(regT0); |
|
2943 |
stubPutByValCall.addArgument(property, regT2); |
|
2944 |
stubPutByValCall.addArgument(value, regT2); |
|
2945 |
stubPutByValCall.call(); |
|
2946 |
} |
|
2947 |
||
2948 |
void JIT::emitSlow_op_loop_if_true(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter) |
|
2949 |
{ |
|
2950 |
linkSlowCase(iter); |
|
2951 |
JITStubCall stubCall(this, cti_op_jtrue); |
|
2952 |
stubCall.addArgument(regT0); |
|
2953 |
stubCall.call(); |
|
2954 |
emitJumpSlowToHot(branchTest32(NonZero, regT0), currentInstruction[2].u.operand); |
|
2955 |
} |
|
2956 |
||
2957 |
void JIT::emitSlow_op_not(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter) |
|
2958 |
{ |
|
2959 |
linkSlowCase(iter); |
|
2960 |
xorPtr(Imm32(static_cast<int32_t>(JSImmediate::FullTagTypeBool)), regT0); |
|
2961 |
JITStubCall stubCall(this, cti_op_not); |
|
2962 |
stubCall.addArgument(regT0); |
|
2963 |
stubCall.call(currentInstruction[1].u.operand); |
|
2964 |
} |
|
2965 |
||
2966 |
void JIT::emitSlow_op_jfalse(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter) |
|
2967 |
{ |
|
2968 |
linkSlowCase(iter); |
|
2969 |
JITStubCall stubCall(this, cti_op_jtrue); |
|
2970 |
stubCall.addArgument(regT0); |
|
2971 |
stubCall.call(); |
|
2972 |
emitJumpSlowToHot(branchTest32(Zero, regT0), currentInstruction[2].u.operand); // inverted! |
|
2973 |
} |
|
2974 |
||
2975 |
void JIT::emitSlow_op_bitnot(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter) |
|
2976 |
{ |
|
2977 |
linkSlowCase(iter); |
|
2978 |
JITStubCall stubCall(this, cti_op_bitnot); |
|
2979 |
stubCall.addArgument(regT0); |
|
2980 |
stubCall.call(currentInstruction[1].u.operand); |
|
2981 |
} |
|
2982 |
||
2983 |
void JIT::emitSlow_op_jtrue(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter) |
|
2984 |
{ |
|
2985 |
linkSlowCase(iter); |
|
2986 |
JITStubCall stubCall(this, cti_op_jtrue); |
|
2987 |
stubCall.addArgument(regT0); |
|
2988 |
stubCall.call(); |
|
2989 |
emitJumpSlowToHot(branchTest32(NonZero, regT0), currentInstruction[2].u.operand); |
|
2990 |
} |
|
2991 |
||
2992 |
void JIT::emitSlow_op_bitxor(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter) |
|
2993 |
{ |
|
2994 |
linkSlowCase(iter); |
|
2995 |
JITStubCall stubCall(this, cti_op_bitxor); |
|
2996 |
stubCall.addArgument(regT0); |
|
2997 |
stubCall.addArgument(regT1); |
|
2998 |
stubCall.call(currentInstruction[1].u.operand); |
|
2999 |
} |
|
3000 |
||
3001 |
void JIT::emitSlow_op_bitor(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter) |
|
3002 |
{ |
|
3003 |
linkSlowCase(iter); |
|
3004 |
JITStubCall stubCall(this, cti_op_bitor); |
|
3005 |
stubCall.addArgument(regT0); |
|
3006 |
stubCall.addArgument(regT1); |
|
3007 |
stubCall.call(currentInstruction[1].u.operand); |
|
3008 |
} |
|
3009 |
||
3010 |
void JIT::emitSlow_op_eq(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter) |
|
3011 |
{ |
|
3012 |
linkSlowCase(iter); |
|
3013 |
JITStubCall stubCall(this, cti_op_eq); |
|
3014 |
stubCall.addArgument(regT0); |
|
3015 |
stubCall.addArgument(regT1); |
|
3016 |
stubCall.call(); |
|
3017 |
emitTagAsBoolImmediate(regT0); |
|
3018 |
emitPutVirtualRegister(currentInstruction[1].u.operand); |
|
3019 |
} |
|
3020 |
||
3021 |
void JIT::emitSlow_op_neq(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter) |
|
3022 |
{ |
|
3023 |
linkSlowCase(iter); |
|
3024 |
JITStubCall stubCall(this, cti_op_eq); |
|
3025 |
stubCall.addArgument(regT0); |
|
3026 |
stubCall.addArgument(regT1); |
|
3027 |
stubCall.call(); |
|
3028 |
xor32(Imm32(0x1), regT0); |
|
3029 |
emitTagAsBoolImmediate(regT0); |
|
3030 |
emitPutVirtualRegister(currentInstruction[1].u.operand); |
|
3031 |
} |
|
3032 |
||
3033 |
void JIT::emitSlow_op_stricteq(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter) |
|
3034 |
{ |
|
3035 |
linkSlowCase(iter); |
|
3036 |
linkSlowCase(iter); |
|
3037 |
JITStubCall stubCall(this, cti_op_stricteq); |
|
3038 |
stubCall.addArgument(regT0); |
|
3039 |
stubCall.addArgument(regT1); |
|
3040 |
stubCall.call(currentInstruction[1].u.operand); |
|
3041 |
} |
|
3042 |
||
3043 |
void JIT::emitSlow_op_nstricteq(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter) |
|
3044 |
{ |
|
3045 |
linkSlowCase(iter); |
|
3046 |
linkSlowCase(iter); |
|
3047 |
JITStubCall stubCall(this, cti_op_nstricteq); |
|
3048 |
stubCall.addArgument(regT0); |
|
3049 |
stubCall.addArgument(regT1); |
|
3050 |
stubCall.call(currentInstruction[1].u.operand); |
|
3051 |
} |
|
3052 |
||
3053 |
void JIT::emitSlow_op_instanceof(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter) |
|
3054 |
{ |
|
3055 |
unsigned dst = currentInstruction[1].u.operand; |
|
3056 |
unsigned value = currentInstruction[2].u.operand; |
|
3057 |
unsigned baseVal = currentInstruction[3].u.operand; |
|
3058 |
unsigned proto = currentInstruction[4].u.operand; |
|
3059 |
||
3060 |
linkSlowCaseIfNotJSCell(iter, value); |
|
3061 |
linkSlowCaseIfNotJSCell(iter, baseVal); |
|
3062 |
linkSlowCaseIfNotJSCell(iter, proto); |
|
3063 |
linkSlowCase(iter); |
|
3064 |
JITStubCall stubCall(this, cti_op_instanceof); |
|
3065 |
stubCall.addArgument(value, regT2); |
|
3066 |
stubCall.addArgument(baseVal, regT2); |
|
3067 |
stubCall.addArgument(proto, regT2); |
|
3068 |
stubCall.call(dst); |
|
3069 |
} |
|
3070 |
||
3071 |
void JIT::emitSlow_op_call(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter) |
|
3072 |
{ |
|
3073 |
compileOpCallSlowCase(currentInstruction, iter, m_callLinkInfoIndex++, op_call); |
|
3074 |
} |
|
3075 |
||
3076 |
void JIT::emitSlow_op_call_eval(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter) |
|
3077 |
{ |
|
3078 |
compileOpCallSlowCase(currentInstruction, iter, m_callLinkInfoIndex++, op_call_eval); |
|
3079 |
} |
|
3080 |
||
3081 |
void JIT::emitSlow_op_call_varargs(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter) |
|
3082 |
{ |
|
3083 |
compileOpCallVarargsSlowCase(currentInstruction, iter); |
|
3084 |
} |
|
3085 |
||
3086 |
void JIT::emitSlow_op_construct(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter) |
|
3087 |
{ |
|
3088 |
compileOpCallSlowCase(currentInstruction, iter, m_callLinkInfoIndex++, op_construct); |
|
3089 |
} |
|
3090 |
||
3091 |
void JIT::emitSlow_op_to_jsnumber(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter) |
|
3092 |
{ |
|
3093 |
linkSlowCaseIfNotJSCell(iter, currentInstruction[2].u.operand); |
|
3094 |
linkSlowCase(iter); |
|
3095 |
||
3096 |
JITStubCall stubCall(this, cti_op_to_jsnumber); |
|
3097 |
stubCall.addArgument(regT0); |
|
3098 |
stubCall.call(currentInstruction[1].u.operand); |
|
3099 |
} |
|
3100 |
||
3101 |
#endif // USE(JSVALUE32_64) |
|
3102 |
||
3103 |
} // namespace JSC |
|
3104 |
||
3105 |
#endif // ENABLE(JIT) |