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 |
move(ctiReturnRegister, ARMRegisters::lr);
|
|
1796 |
call(Address(regT1, OBJECT_OFFSETOF(JSFunction, m_data)));
|
|
1797 |
|
|
1798 |
addPtr(Imm32(sizeof(ArgList)), stackPointerRegister);
|
|
1799 |
|
|
1800 |
#elif ENABLE(JIT_OPTIMIZE_NATIVE_CALL)
|
|
1801 |
#error "JIT_OPTIMIZE_NATIVE_CALL not yet supported on this platform."
|
|
1802 |
#else
|
|
1803 |
breakpoint();
|
|
1804 |
#endif
|
|
1805 |
|
|
1806 |
// Check for an exception
|
|
1807 |
loadPtr(&(globalData->exception), regT2);
|
|
1808 |
Jump exceptionHandler = branchTestPtr(NonZero, regT2);
|
|
1809 |
|
|
1810 |
// Grab the return address.
|
|
1811 |
emitGetFromCallFrameHeaderPtr(RegisterFile::ReturnPC, regT1);
|
|
1812 |
|
|
1813 |
// Restore our caller's "r".
|
|
1814 |
emitGetFromCallFrameHeaderPtr(RegisterFile::CallerFrame, callFrameRegister);
|
|
1815 |
|
|
1816 |
// Return.
|
|
1817 |
restoreReturnAddressBeforeReturn(regT1);
|
|
1818 |
ret();
|
|
1819 |
|
|
1820 |
// Handle an exception
|
|
1821 |
exceptionHandler.link(this);
|
|
1822 |
// Grab the return address.
|
|
1823 |
emitGetFromCallFrameHeaderPtr(RegisterFile::ReturnPC, regT1);
|
|
1824 |
move(ImmPtr(&globalData->exceptionLocation), regT2);
|
|
1825 |
storePtr(regT1, regT2);
|
|
1826 |
move(ImmPtr(FunctionPtr(ctiVMThrowTrampoline).value()), regT2);
|
|
1827 |
emitGetFromCallFrameHeaderPtr(RegisterFile::CallerFrame, callFrameRegister);
|
|
1828 |
poke(callFrameRegister, OBJECT_OFFSETOF(struct JITStackFrame, callFrame) / sizeof (void*));
|
|
1829 |
restoreReturnAddressBeforeReturn(regT2);
|
|
1830 |
ret();
|
|
1831 |
|
|
1832 |
|
|
1833 |
#if ENABLE(JIT_OPTIMIZE_PROPERTY_ACCESS)
|
|
1834 |
Call string_failureCases1Call = makeTailRecursiveCall(string_failureCases1);
|
|
1835 |
Call string_failureCases2Call = makeTailRecursiveCall(string_failureCases2);
|
|
1836 |
Call string_failureCases3Call = makeTailRecursiveCall(string_failureCases3);
|
|
1837 |
#endif
|
|
1838 |
|
|
1839 |
// All trampolines constructed! copy the code, link up calls, and set the pointers on the Machine object.
|
|
1840 |
LinkBuffer patchBuffer(this, m_globalData->executableAllocator.poolForSize(m_assembler.size()));
|
|
1841 |
|
|
1842 |
#if ENABLE(JIT_OPTIMIZE_PROPERTY_ACCESS)
|
|
1843 |
patchBuffer.link(string_failureCases1Call, FunctionPtr(cti_op_get_by_id_string_fail));
|
|
1844 |
patchBuffer.link(string_failureCases2Call, FunctionPtr(cti_op_get_by_id_string_fail));
|
|
1845 |
patchBuffer.link(string_failureCases3Call, FunctionPtr(cti_op_get_by_id_string_fail));
|
|
1846 |
#endif
|
|
1847 |
patchBuffer.link(callArityCheck1, FunctionPtr(cti_op_call_arityCheck));
|
|
1848 |
patchBuffer.link(callJSFunction1, FunctionPtr(cti_op_call_JSFunction));
|
|
1849 |
#if ENABLE(JIT_OPTIMIZE_CALL)
|
|
1850 |
patchBuffer.link(callArityCheck2, FunctionPtr(cti_op_call_arityCheck));
|
|
1851 |
patchBuffer.link(callJSFunction2, FunctionPtr(cti_op_call_JSFunction));
|
|
1852 |
patchBuffer.link(callLazyLinkCall, FunctionPtr(cti_vm_lazyLinkCall));
|
|
1853 |
#endif
|
|
1854 |
|
|
1855 |
CodeRef finalCode = patchBuffer.finalizeCode();
|
|
1856 |
*executablePool = finalCode.m_executablePool;
|
|
1857 |
|
|
1858 |
*ctiVirtualCallLink = trampolineAt(finalCode, virtualCallLinkBegin);
|
|
1859 |
*ctiVirtualCall = trampolineAt(finalCode, virtualCallBegin);
|
|
1860 |
*ctiNativeCallThunk = trampolineAt(finalCode, nativeCallThunk);
|
|
1861 |
#if ENABLE(JIT_OPTIMIZE_PROPERTY_ACCESS)
|
|
1862 |
*ctiStringLengthTrampoline = trampolineAt(finalCode, stringLengthBegin);
|
|
1863 |
#else
|
|
1864 |
UNUSED_PARAM(ctiStringLengthTrampoline);
|
|
1865 |
#endif
|
|
1866 |
}
|
|
1867 |
|
|
1868 |
void JIT::emit_op_mov(Instruction* currentInstruction)
|
|
1869 |
{
|
|
1870 |
int dst = currentInstruction[1].u.operand;
|
|
1871 |
int src = currentInstruction[2].u.operand;
|
|
1872 |
|
|
1873 |
if (m_codeBlock->isConstantRegisterIndex(src)) {
|
|
1874 |
storePtr(ImmPtr(JSValue::encode(getConstantOperand(src))), Address(callFrameRegister, dst * sizeof(Register)));
|
|
1875 |
if (dst == m_lastResultBytecodeRegister)
|
|
1876 |
killLastResultRegister();
|
|
1877 |
} else if ((src == m_lastResultBytecodeRegister) || (dst == m_lastResultBytecodeRegister)) {
|
|
1878 |
// If either the src or dst is the cached register go though
|
|
1879 |
// get/put registers to make sure we track this correctly.
|
|
1880 |
emitGetVirtualRegister(src, regT0);
|
|
1881 |
emitPutVirtualRegister(dst);
|
|
1882 |
} else {
|
|
1883 |
// Perform the copy via regT1; do not disturb any mapping in regT0.
|
|
1884 |
loadPtr(Address(callFrameRegister, src * sizeof(Register)), regT1);
|
|
1885 |
storePtr(regT1, Address(callFrameRegister, dst * sizeof(Register)));
|
|
1886 |
}
|
|
1887 |
}
|
|
1888 |
|
|
1889 |
void JIT::emit_op_end(Instruction* currentInstruction)
|
|
1890 |
{
|
|
1891 |
if (m_codeBlock->needsFullScopeChain())
|
|
1892 |
JITStubCall(this, cti_op_end).call();
|
|
1893 |
ASSERT(returnValueRegister != callFrameRegister);
|
|
1894 |
emitGetVirtualRegister(currentInstruction[1].u.operand, returnValueRegister);
|
|
1895 |
restoreReturnAddressBeforeReturn(Address(callFrameRegister, RegisterFile::ReturnPC * static_cast<int>(sizeof(Register))));
|
|
1896 |
ret();
|
|
1897 |
}
|
|
1898 |
|
|
1899 |
void JIT::emit_op_jmp(Instruction* currentInstruction)
|
|
1900 |
{
|
|
1901 |
unsigned target = currentInstruction[1].u.operand;
|
|
1902 |
addJump(jump(), target);
|
|
1903 |
RECORD_JUMP_TARGET(target);
|
|
1904 |
}
|
|
1905 |
|
|
1906 |
void JIT::emit_op_loop(Instruction* currentInstruction)
|
|
1907 |
{
|
|
1908 |
emitTimeoutCheck();
|
|
1909 |
|
|
1910 |
unsigned target = currentInstruction[1].u.operand;
|
|
1911 |
addJump(jump(), target);
|
|
1912 |
}
|
|
1913 |
|
|
1914 |
void JIT::emit_op_loop_if_less(Instruction* currentInstruction)
|
|
1915 |
{
|
|
1916 |
emitTimeoutCheck();
|
|
1917 |
|
|
1918 |
unsigned op1 = currentInstruction[1].u.operand;
|
|
1919 |
unsigned op2 = currentInstruction[2].u.operand;
|
|
1920 |
unsigned target = currentInstruction[3].u.operand;
|
|
1921 |
if (isOperandConstantImmediateInt(op2)) {
|
|
1922 |
emitGetVirtualRegister(op1, regT0);
|
|
1923 |
emitJumpSlowCaseIfNotImmediateInteger(regT0);
|
|
1924 |
#if USE(JSVALUE64)
|
|
1925 |
int32_t op2imm = getConstantOperandImmediateInt(op2);
|
|
1926 |
#else
|
|
1927 |
int32_t op2imm = static_cast<int32_t>(JSImmediate::rawValue(getConstantOperand(op2)));
|
|
1928 |
#endif
|
|
1929 |
addJump(branch32(LessThan, regT0, Imm32(op2imm)), target);
|
|
1930 |
} else if (isOperandConstantImmediateInt(op1)) {
|
|
1931 |
emitGetVirtualRegister(op2, regT0);
|
|
1932 |
emitJumpSlowCaseIfNotImmediateInteger(regT0);
|
|
1933 |
#if USE(JSVALUE64)
|
|
1934 |
int32_t op1imm = getConstantOperandImmediateInt(op1);
|
|
1935 |
#else
|
|
1936 |
int32_t op1imm = static_cast<int32_t>(JSImmediate::rawValue(getConstantOperand(op1)));
|
|
1937 |
#endif
|
|
1938 |
addJump(branch32(GreaterThan, regT0, Imm32(op1imm)), target);
|
|
1939 |
} else {
|
|
1940 |
emitGetVirtualRegisters(op1, regT0, op2, regT1);
|
|
1941 |
emitJumpSlowCaseIfNotImmediateInteger(regT0);
|
|
1942 |
emitJumpSlowCaseIfNotImmediateInteger(regT1);
|
|
1943 |
addJump(branch32(LessThan, regT0, regT1), target);
|
|
1944 |
}
|
|
1945 |
}
|
|
1946 |
|
|
1947 |
void JIT::emit_op_loop_if_lesseq(Instruction* currentInstruction)
|
|
1948 |
{
|
|
1949 |
emitTimeoutCheck();
|
|
1950 |
|
|
1951 |
unsigned op1 = currentInstruction[1].u.operand;
|
|
1952 |
unsigned op2 = currentInstruction[2].u.operand;
|
|
1953 |
unsigned target = currentInstruction[3].u.operand;
|
|
1954 |
if (isOperandConstantImmediateInt(op2)) {
|
|
1955 |
emitGetVirtualRegister(op1, regT0);
|
|
1956 |
emitJumpSlowCaseIfNotImmediateInteger(regT0);
|
|
1957 |
#if USE(JSVALUE64)
|
|
1958 |
int32_t op2imm = getConstantOperandImmediateInt(op2);
|
|
1959 |
#else
|
|
1960 |
int32_t op2imm = static_cast<int32_t>(JSImmediate::rawValue(getConstantOperand(op2)));
|
|
1961 |
#endif
|
|
1962 |
addJump(branch32(LessThanOrEqual, regT0, Imm32(op2imm)), target);
|
|
1963 |
} else {
|
|
1964 |
emitGetVirtualRegisters(op1, regT0, op2, regT1);
|
|
1965 |
emitJumpSlowCaseIfNotImmediateInteger(regT0);
|
|
1966 |
emitJumpSlowCaseIfNotImmediateInteger(regT1);
|
|
1967 |
addJump(branch32(LessThanOrEqual, regT0, regT1), target);
|
|
1968 |
}
|
|
1969 |
}
|
|
1970 |
|
|
1971 |
void JIT::emit_op_new_object(Instruction* currentInstruction)
|
|
1972 |
{
|
|
1973 |
JITStubCall(this, cti_op_new_object).call(currentInstruction[1].u.operand);
|
|
1974 |
}
|
|
1975 |
|
|
1976 |
void JIT::emit_op_instanceof(Instruction* currentInstruction)
|
|
1977 |
{
|
|
1978 |
unsigned dst = currentInstruction[1].u.operand;
|
|
1979 |
unsigned value = currentInstruction[2].u.operand;
|
|
1980 |
unsigned baseVal = currentInstruction[3].u.operand;
|
|
1981 |
unsigned proto = currentInstruction[4].u.operand;
|
|
1982 |
|
|
1983 |
// Load the operands (baseVal, proto, and value respectively) into registers.
|
|
1984 |
// We use regT0 for baseVal since we will be done with this first, and we can then use it for the result.
|
|
1985 |
emitGetVirtualRegister(value, regT2);
|
|
1986 |
emitGetVirtualRegister(baseVal, regT0);
|
|
1987 |
emitGetVirtualRegister(proto, regT1);
|
|
1988 |
|
|
1989 |
// Check that baseVal & proto are cells.
|
|
1990 |
emitJumpSlowCaseIfNotJSCell(regT2, value);
|
|
1991 |
emitJumpSlowCaseIfNotJSCell(regT0, baseVal);
|
|
1992 |
emitJumpSlowCaseIfNotJSCell(regT1, proto);
|
|
1993 |
|
|
1994 |
// Check that baseVal 'ImplementsDefaultHasInstance'.
|
|
1995 |
loadPtr(Address(regT0, OBJECT_OFFSETOF(JSCell, m_structure)), regT0);
|
|
1996 |
addSlowCase(branchTest32(Zero, Address(regT0, OBJECT_OFFSETOF(Structure, m_typeInfo.m_flags)), Imm32(ImplementsDefaultHasInstance)));
|
|
1997 |
|
|
1998 |
// Optimistically load the result true, and start looping.
|
|
1999 |
// Initially, regT1 still contains proto and regT2 still contains value.
|
|
2000 |
// As we loop regT2 will be updated with its prototype, recursively walking the prototype chain.
|
|
2001 |
move(ImmPtr(JSValue::encode(jsBoolean(true))), regT0);
|
|
2002 |
Label loop(this);
|
|
2003 |
|
|
2004 |
// Load the prototype of the object in regT2. If this is equal to regT1 - WIN!
|
|
2005 |
// Otherwise, check if we've hit null - if we have then drop out of the loop, if not go again.
|
|
2006 |
loadPtr(Address(regT2, OBJECT_OFFSETOF(JSCell, m_structure)), regT2);
|
|
2007 |
loadPtr(Address(regT2, OBJECT_OFFSETOF(Structure, m_prototype)), regT2);
|
|
2008 |
Jump isInstance = branchPtr(Equal, regT2, regT1);
|
|
2009 |
emitJumpIfJSCell(regT2).linkTo(loop, this);
|
|
2010 |
|
|
2011 |
// We get here either by dropping out of the loop, or if value was not an Object. Result is false.
|
|
2012 |
move(ImmPtr(JSValue::encode(jsBoolean(false))), regT0);
|
|
2013 |
|
|
2014 |
// isInstance jumps right down to here, to skip setting the result to false (it has already set true).
|
|
2015 |
isInstance.link(this);
|
|
2016 |
emitPutVirtualRegister(dst);
|
|
2017 |
}
|
|
2018 |
|
|
2019 |
void JIT::emit_op_new_func(Instruction* currentInstruction)
|
|
2020 |
{
|
|
2021 |
JITStubCall stubCall(this, cti_op_new_func);
|
|
2022 |
stubCall.addArgument(ImmPtr(m_codeBlock->functionDecl(currentInstruction[2].u.operand)));
|
|
2023 |
stubCall.call(currentInstruction[1].u.operand);
|
|
2024 |
}
|
|
2025 |
|
|
2026 |
void JIT::emit_op_call(Instruction* currentInstruction)
|
|
2027 |
{
|
|
2028 |
compileOpCall(op_call, currentInstruction, m_callLinkInfoIndex++);
|
|
2029 |
}
|
|
2030 |
|
|
2031 |
void JIT::emit_op_call_eval(Instruction* currentInstruction)
|
|
2032 |
{
|
|
2033 |
compileOpCall(op_call_eval, currentInstruction, m_callLinkInfoIndex++);
|
|
2034 |
}
|
|
2035 |
|
|
2036 |
void JIT::emit_op_load_varargs(Instruction* currentInstruction)
|
|
2037 |
{
|
|
2038 |
int argCountDst = currentInstruction[1].u.operand;
|
|
2039 |
int argsOffset = currentInstruction[2].u.operand;
|
|
2040 |
|
|
2041 |
JITStubCall stubCall(this, cti_op_load_varargs);
|
|
2042 |
stubCall.addArgument(Imm32(argsOffset));
|
|
2043 |
stubCall.call();
|
|
2044 |
// Stores a naked int32 in the register file.
|
|
2045 |
store32(returnValueRegister, Address(callFrameRegister, argCountDst * sizeof(Register)));
|
|
2046 |
}
|
|
2047 |
|
|
2048 |
void JIT::emit_op_call_varargs(Instruction* currentInstruction)
|
|
2049 |
{
|
|
2050 |
compileOpCallVarargs(currentInstruction);
|
|
2051 |
}
|
|
2052 |
|
|
2053 |
void JIT::emit_op_construct(Instruction* currentInstruction)
|
|
2054 |
{
|
|
2055 |
compileOpCall(op_construct, currentInstruction, m_callLinkInfoIndex++);
|
|
2056 |
}
|
|
2057 |
|
|
2058 |
void JIT::emit_op_get_global_var(Instruction* currentInstruction)
|
|
2059 |
{
|
|
2060 |
JSVariableObject* globalObject = static_cast<JSVariableObject*>(currentInstruction[2].u.jsCell);
|
|
2061 |
move(ImmPtr(globalObject), regT0);
|
|
2062 |
emitGetVariableObjectRegister(regT0, currentInstruction[3].u.operand, regT0);
|
|
2063 |
emitPutVirtualRegister(currentInstruction[1].u.operand);
|
|
2064 |
}
|
|
2065 |
|
|
2066 |
void JIT::emit_op_put_global_var(Instruction* currentInstruction)
|
|
2067 |
{
|
|
2068 |
emitGetVirtualRegister(currentInstruction[3].u.operand, regT1);
|
|
2069 |
JSVariableObject* globalObject = static_cast<JSVariableObject*>(currentInstruction[1].u.jsCell);
|
|
2070 |
move(ImmPtr(globalObject), regT0);
|
|
2071 |
emitPutVariableObjectRegister(regT1, regT0, currentInstruction[2].u.operand);
|
|
2072 |
}
|
|
2073 |
|
|
2074 |
void JIT::emit_op_get_scoped_var(Instruction* currentInstruction)
|
|
2075 |
{
|
|
2076 |
int skip = currentInstruction[3].u.operand + m_codeBlock->needsFullScopeChain();
|
|
2077 |
|
|
2078 |
emitGetFromCallFrameHeaderPtr(RegisterFile::ScopeChain, regT0);
|
|
2079 |
while (skip--)
|
|
2080 |
loadPtr(Address(regT0, OBJECT_OFFSETOF(ScopeChainNode, next)), regT0);
|
|
2081 |
|
|
2082 |
loadPtr(Address(regT0, OBJECT_OFFSETOF(ScopeChainNode, object)), regT0);
|
|
2083 |
emitGetVariableObjectRegister(regT0, currentInstruction[2].u.operand, regT0);
|
|
2084 |
emitPutVirtualRegister(currentInstruction[1].u.operand);
|
|
2085 |
}
|
|
2086 |
|
|
2087 |
void JIT::emit_op_put_scoped_var(Instruction* currentInstruction)
|
|
2088 |
{
|
|
2089 |
int skip = currentInstruction[2].u.operand + m_codeBlock->needsFullScopeChain();
|
|
2090 |
|
|
2091 |
emitGetFromCallFrameHeaderPtr(RegisterFile::ScopeChain, regT1);
|
|
2092 |
emitGetVirtualRegister(currentInstruction[3].u.operand, regT0);
|
|
2093 |
while (skip--)
|
|
2094 |
loadPtr(Address(regT1, OBJECT_OFFSETOF(ScopeChainNode, next)), regT1);
|
|
2095 |
|
|
2096 |
loadPtr(Address(regT1, OBJECT_OFFSETOF(ScopeChainNode, object)), regT1);
|
|
2097 |
emitPutVariableObjectRegister(regT0, regT1, currentInstruction[1].u.operand);
|
|
2098 |
}
|
|
2099 |
|
|
2100 |
void JIT::emit_op_tear_off_activation(Instruction* currentInstruction)
|
|
2101 |
{
|
|
2102 |
JITStubCall stubCall(this, cti_op_tear_off_activation);
|
|
2103 |
stubCall.addArgument(currentInstruction[1].u.operand, regT2);
|
|
2104 |
stubCall.call();
|
|
2105 |
}
|
|
2106 |
|
|
2107 |
void JIT::emit_op_tear_off_arguments(Instruction*)
|
|
2108 |
{
|
|
2109 |
JITStubCall(this, cti_op_tear_off_arguments).call();
|
|
2110 |
}
|
|
2111 |
|
|
2112 |
void JIT::emit_op_ret(Instruction* currentInstruction)
|
|
2113 |
{
|
|
2114 |
// We could JIT generate the deref, only calling out to C when the refcount hits zero.
|
|
2115 |
if (m_codeBlock->needsFullScopeChain())
|
|
2116 |
JITStubCall(this, cti_op_ret_scopeChain).call();
|
|
2117 |
|
|
2118 |
ASSERT(callFrameRegister != regT1);
|
|
2119 |
ASSERT(regT1 != returnValueRegister);
|
|
2120 |
ASSERT(returnValueRegister != callFrameRegister);
|
|
2121 |
|
|
2122 |
// Return the result in %eax.
|
|
2123 |
emitGetVirtualRegister(currentInstruction[1].u.operand, returnValueRegister);
|
|
2124 |
|
|
2125 |
// Grab the return address.
|
|
2126 |
emitGetFromCallFrameHeaderPtr(RegisterFile::ReturnPC, regT1);
|
|
2127 |
|
|
2128 |
// Restore our caller's "r".
|
|
2129 |
emitGetFromCallFrameHeaderPtr(RegisterFile::CallerFrame, callFrameRegister);
|
|
2130 |
|
|
2131 |
// Return.
|
|
2132 |
restoreReturnAddressBeforeReturn(regT1);
|
|
2133 |
ret();
|
|
2134 |
}
|
|
2135 |
|
|
2136 |
void JIT::emit_op_new_array(Instruction* currentInstruction)
|
|
2137 |
{
|
|
2138 |
JITStubCall stubCall(this, cti_op_new_array);
|
|
2139 |
stubCall.addArgument(Imm32(currentInstruction[2].u.operand));
|
|
2140 |
stubCall.addArgument(Imm32(currentInstruction[3].u.operand));
|
|
2141 |
stubCall.call(currentInstruction[1].u.operand);
|
|
2142 |
}
|
|
2143 |
|
|
2144 |
void JIT::emit_op_resolve(Instruction* currentInstruction)
|
|
2145 |
{
|
|
2146 |
JITStubCall stubCall(this, cti_op_resolve);
|
|
2147 |
stubCall.addArgument(ImmPtr(&m_codeBlock->identifier(currentInstruction[2].u.operand)));
|
|
2148 |
stubCall.call(currentInstruction[1].u.operand);
|
|
2149 |
}
|
|
2150 |
|
|
2151 |
void JIT::emit_op_construct_verify(Instruction* currentInstruction)
|
|
2152 |
{
|
|
2153 |
emitGetVirtualRegister(currentInstruction[1].u.operand, regT0);
|
|
2154 |
|
|
2155 |
emitJumpSlowCaseIfNotJSCell(regT0);
|
|
2156 |
loadPtr(Address(regT0, OBJECT_OFFSETOF(JSCell, m_structure)), regT2);
|
|
2157 |
addSlowCase(branch32(NotEqual, Address(regT2, OBJECT_OFFSETOF(Structure, m_typeInfo) + OBJECT_OFFSETOF(TypeInfo, m_type)), Imm32(ObjectType)));
|
|
2158 |
|
|
2159 |
}
|
|
2160 |
|
|
2161 |
void JIT::emit_op_to_primitive(Instruction* currentInstruction)
|
|
2162 |
{
|
|
2163 |
int dst = currentInstruction[1].u.operand;
|
|
2164 |
int src = currentInstruction[2].u.operand;
|
|
2165 |
|
|
2166 |
emitGetVirtualRegister(src, regT0);
|
|
2167 |
|
|
2168 |
Jump isImm = emitJumpIfNotJSCell(regT0);
|
|
2169 |
addSlowCase(branchPtr(NotEqual, Address(regT0), ImmPtr(m_globalData->jsStringVPtr)));
|
|
2170 |
isImm.link(this);
|
|
2171 |
|
|
2172 |
if (dst != src)
|
|
2173 |
emitPutVirtualRegister(dst);
|
|
2174 |
|
|
2175 |
}
|
|
2176 |
|
|
2177 |
void JIT::emit_op_strcat(Instruction* currentInstruction)
|
|
2178 |
{
|
|
2179 |
JITStubCall stubCall(this, cti_op_strcat);
|
|
2180 |
stubCall.addArgument(Imm32(currentInstruction[2].u.operand));
|
|
2181 |
stubCall.addArgument(Imm32(currentInstruction[3].u.operand));
|
|
2182 |
stubCall.call(currentInstruction[1].u.operand);
|
|
2183 |
}
|
|
2184 |
|
|
2185 |
void JIT::emit_op_loop_if_true(Instruction* currentInstruction)
|
|
2186 |
{
|
|
2187 |
emitTimeoutCheck();
|
|
2188 |
|
|
2189 |
unsigned target = currentInstruction[2].u.operand;
|
|
2190 |
emitGetVirtualRegister(currentInstruction[1].u.operand, regT0);
|
|
2191 |
|
|
2192 |
Jump isZero = branchPtr(Equal, regT0, ImmPtr(JSValue::encode(jsNumber(m_globalData, 0))));
|
|
2193 |
addJump(emitJumpIfImmediateInteger(regT0), target);
|
|
2194 |
|
|
2195 |
addJump(branchPtr(Equal, regT0, ImmPtr(JSValue::encode(jsBoolean(true)))), target);
|
|
2196 |
addSlowCase(branchPtr(NotEqual, regT0, ImmPtr(JSValue::encode(jsBoolean(false)))));
|
|
2197 |
|
|
2198 |
isZero.link(this);
|
|
2199 |
};
|
|
2200 |
void JIT::emit_op_resolve_base(Instruction* currentInstruction)
|
|
2201 |
{
|
|
2202 |
JITStubCall stubCall(this, cti_op_resolve_base);
|
|
2203 |
stubCall.addArgument(ImmPtr(&m_codeBlock->identifier(currentInstruction[2].u.operand)));
|
|
2204 |
stubCall.call(currentInstruction[1].u.operand);
|
|
2205 |
}
|
|
2206 |
|
|
2207 |
void JIT::emit_op_resolve_skip(Instruction* currentInstruction)
|
|
2208 |
{
|
|
2209 |
JITStubCall stubCall(this, cti_op_resolve_skip);
|
|
2210 |
stubCall.addArgument(ImmPtr(&m_codeBlock->identifier(currentInstruction[2].u.operand)));
|
|
2211 |
stubCall.addArgument(Imm32(currentInstruction[3].u.operand + m_codeBlock->needsFullScopeChain()));
|
|
2212 |
stubCall.call(currentInstruction[1].u.operand);
|
|
2213 |
}
|
|
2214 |
|
|
2215 |
void JIT::emit_op_resolve_global(Instruction* currentInstruction)
|
|
2216 |
{
|
|
2217 |
// Fast case
|
|
2218 |
void* globalObject = currentInstruction[2].u.jsCell;
|
|
2219 |
Identifier* ident = &m_codeBlock->identifier(currentInstruction[3].u.operand);
|
|
2220 |
|
|
2221 |
unsigned currentIndex = m_globalResolveInfoIndex++;
|
|
2222 |
void* structureAddress = &(m_codeBlock->globalResolveInfo(currentIndex).structure);
|
|
2223 |
void* offsetAddr = &(m_codeBlock->globalResolveInfo(currentIndex).offset);
|
|
2224 |
|
|
2225 |
// Check Structure of global object
|
|
2226 |
move(ImmPtr(globalObject), regT0);
|
|
2227 |
loadPtr(structureAddress, regT1);
|
|
2228 |
Jump noMatch = branchPtr(NotEqual, regT1, Address(regT0, OBJECT_OFFSETOF(JSCell, m_structure))); // Structures don't match
|
|
2229 |
|
|
2230 |
// Load cached property
|
|
2231 |
// Assume that the global object always uses external storage.
|
|
2232 |
loadPtr(Address(regT0, OBJECT_OFFSETOF(JSGlobalObject, m_externalStorage)), regT0);
|
|
2233 |
load32(offsetAddr, regT1);
|
|
2234 |
loadPtr(BaseIndex(regT0, regT1, ScalePtr), regT0);
|
|
2235 |
emitPutVirtualRegister(currentInstruction[1].u.operand);
|
|
2236 |
Jump end = jump();
|
|
2237 |
|
|
2238 |
// Slow case
|
|
2239 |
noMatch.link(this);
|
|
2240 |
JITStubCall stubCall(this, cti_op_resolve_global);
|
|
2241 |
stubCall.addArgument(ImmPtr(globalObject));
|
|
2242 |
stubCall.addArgument(ImmPtr(ident));
|
|
2243 |
stubCall.addArgument(Imm32(currentIndex));
|
|
2244 |
stubCall.call(currentInstruction[1].u.operand);
|
|
2245 |
end.link(this);
|
|
2246 |
}
|
|
2247 |
|
|
2248 |
void JIT::emit_op_not(Instruction* currentInstruction)
|
|
2249 |
{
|
|
2250 |
emitGetVirtualRegister(currentInstruction[2].u.operand, regT0);
|
|
2251 |
xorPtr(Imm32(static_cast<int32_t>(JSImmediate::FullTagTypeBool)), regT0);
|
|
2252 |
addSlowCase(branchTestPtr(NonZero, regT0, Imm32(static_cast<int32_t>(~JSImmediate::ExtendedPayloadBitBoolValue))));
|
|
2253 |
xorPtr(Imm32(static_cast<int32_t>(JSImmediate::FullTagTypeBool | JSImmediate::ExtendedPayloadBitBoolValue)), regT0);
|
|
2254 |
emitPutVirtualRegister(currentInstruction[1].u.operand);
|
|
2255 |
}
|
|
2256 |
|
|
2257 |
void JIT::emit_op_jfalse(Instruction* currentInstruction)
|
|
2258 |
{
|
|
2259 |
unsigned target = currentInstruction[2].u.operand;
|
|
2260 |
emitGetVirtualRegister(currentInstruction[1].u.operand, regT0);
|
|
2261 |
|
|
2262 |
addJump(branchPtr(Equal, regT0, ImmPtr(JSValue::encode(jsNumber(m_globalData, 0)))), target);
|
|
2263 |
Jump isNonZero = emitJumpIfImmediateInteger(regT0);
|
|
2264 |
|
|
2265 |
addJump(branchPtr(Equal, regT0, ImmPtr(JSValue::encode(jsBoolean(false)))), target);
|
|
2266 |
addSlowCase(branchPtr(NotEqual, regT0, ImmPtr(JSValue::encode(jsBoolean(true)))));
|
|
2267 |
|
|
2268 |
isNonZero.link(this);
|
|
2269 |
RECORD_JUMP_TARGET(target);
|
|
2270 |
};
|
|
2271 |
void JIT::emit_op_jeq_null(Instruction* currentInstruction)
|
|
2272 |
{
|
|
2273 |
unsigned src = currentInstruction[1].u.operand;
|
|
2274 |
unsigned target = currentInstruction[2].u.operand;
|
|
2275 |
|
|
2276 |
emitGetVirtualRegister(src, regT0);
|
|
2277 |
Jump isImmediate = emitJumpIfNotJSCell(regT0);
|
|
2278 |
|
|
2279 |
// First, handle JSCell cases - check MasqueradesAsUndefined bit on the structure.
|
|
2280 |
loadPtr(Address(regT0, OBJECT_OFFSETOF(JSCell, m_structure)), regT2);
|
|
2281 |
addJump(branchTest32(NonZero, Address(regT2, OBJECT_OFFSETOF(Structure, m_typeInfo.m_flags)), Imm32(MasqueradesAsUndefined)), target);
|
|
2282 |
Jump wasNotImmediate = jump();
|
|
2283 |
|
|
2284 |
// Now handle the immediate cases - undefined & null
|
|
2285 |
isImmediate.link(this);
|
|
2286 |
andPtr(Imm32(~JSImmediate::ExtendedTagBitUndefined), regT0);
|
|
2287 |
addJump(branchPtr(Equal, regT0, ImmPtr(JSValue::encode(jsNull()))), target);
|
|
2288 |
|
|
2289 |
wasNotImmediate.link(this);
|
|
2290 |
RECORD_JUMP_TARGET(target);
|
|
2291 |
};
|
|
2292 |
void JIT::emit_op_jneq_null(Instruction* currentInstruction)
|
|
2293 |
{
|
|
2294 |
unsigned src = currentInstruction[1].u.operand;
|
|
2295 |
unsigned target = currentInstruction[2].u.operand;
|
|
2296 |
|
|
2297 |
emitGetVirtualRegister(src, regT0);
|
|
2298 |
Jump isImmediate = emitJumpIfNotJSCell(regT0);
|
|
2299 |
|
|
2300 |
// First, handle JSCell cases - check MasqueradesAsUndefined bit on the structure.
|
|
2301 |
loadPtr(Address(regT0, OBJECT_OFFSETOF(JSCell, m_structure)), regT2);
|
|
2302 |
addJump(branchTest32(Zero, Address(regT2, OBJECT_OFFSETOF(Structure, m_typeInfo.m_flags)), Imm32(MasqueradesAsUndefined)), target);
|
|
2303 |
Jump wasNotImmediate = jump();
|
|
2304 |
|
|
2305 |
// Now handle the immediate cases - undefined & null
|
|
2306 |
isImmediate.link(this);
|
|
2307 |
andPtr(Imm32(~JSImmediate::ExtendedTagBitUndefined), regT0);
|
|
2308 |
addJump(branchPtr(NotEqual, regT0, ImmPtr(JSValue::encode(jsNull()))), target);
|
|
2309 |
|
|
2310 |
wasNotImmediate.link(this);
|
|
2311 |
RECORD_JUMP_TARGET(target);
|
|
2312 |
}
|
|
2313 |
|
|
2314 |
void JIT::emit_op_jneq_ptr(Instruction* currentInstruction)
|
|
2315 |
{
|
|
2316 |
unsigned src = currentInstruction[1].u.operand;
|
|
2317 |
JSCell* ptr = currentInstruction[2].u.jsCell;
|
|
2318 |
unsigned target = currentInstruction[3].u.operand;
|
|
2319 |
|
|
2320 |
emitGetVirtualRegister(src, regT0);
|
|
2321 |
addJump(branchPtr(NotEqual, regT0, ImmPtr(JSValue::encode(JSValue(ptr)))), target);
|
|
2322 |
|
|
2323 |
RECORD_JUMP_TARGET(target);
|
|
2324 |
}
|
|
2325 |
|
|
2326 |
void JIT::emit_op_jsr(Instruction* currentInstruction)
|
|
2327 |
{
|
|
2328 |
int retAddrDst = currentInstruction[1].u.operand;
|
|
2329 |
int target = currentInstruction[2].u.operand;
|
|
2330 |
DataLabelPtr storeLocation = storePtrWithPatch(ImmPtr(0), Address(callFrameRegister, sizeof(Register) * retAddrDst));
|
|
2331 |
addJump(jump(), target);
|
|
2332 |
m_jsrSites.append(JSRInfo(storeLocation, label()));
|
|
2333 |
killLastResultRegister();
|
|
2334 |
RECORD_JUMP_TARGET(target);
|
|
2335 |
}
|
|
2336 |
|
|
2337 |
void JIT::emit_op_sret(Instruction* currentInstruction)
|
|
2338 |
{
|
|
2339 |
jump(Address(callFrameRegister, sizeof(Register) * currentInstruction[1].u.operand));
|
|
2340 |
killLastResultRegister();
|
|
2341 |
}
|
|
2342 |
|
|
2343 |
void JIT::emit_op_eq(Instruction* currentInstruction)
|
|
2344 |
{
|
|
2345 |
emitGetVirtualRegisters(currentInstruction[2].u.operand, regT0, currentInstruction[3].u.operand, regT1);
|
|
2346 |
emitJumpSlowCaseIfNotImmediateIntegers(regT0, regT1, regT2);
|
|
2347 |
set32(Equal, regT1, regT0, regT0);
|
|
2348 |
emitTagAsBoolImmediate(regT0);
|
|
2349 |
emitPutVirtualRegister(currentInstruction[1].u.operand);
|
|
2350 |
}
|
|
2351 |
|
|
2352 |
void JIT::emit_op_bitnot(Instruction* currentInstruction)
|
|
2353 |
{
|
|
2354 |
emitGetVirtualRegister(currentInstruction[2].u.operand, regT0);
|
|
2355 |
emitJumpSlowCaseIfNotImmediateInteger(regT0);
|
|
2356 |
#if USE(JSVALUE64)
|
|
2357 |
not32(regT0);
|
|
2358 |
emitFastArithIntToImmNoCheck(regT0, regT0);
|
|
2359 |
#else
|
|
2360 |
xorPtr(Imm32(~JSImmediate::TagTypeNumber), regT0);
|
|
2361 |
#endif
|
|
2362 |
emitPutVirtualRegister(currentInstruction[1].u.operand);
|
|
2363 |
}
|
|
2364 |
|
|
2365 |
void JIT::emit_op_resolve_with_base(Instruction* currentInstruction)
|
|
2366 |
{
|
|
2367 |
JITStubCall stubCall(this, cti_op_resolve_with_base);
|
|
2368 |
stubCall.addArgument(ImmPtr(&m_codeBlock->identifier(currentInstruction[3].u.operand)));
|
|
2369 |
stubCall.addArgument(Imm32(currentInstruction[1].u.operand));
|
|
2370 |
stubCall.call(currentInstruction[2].u.operand);
|
|
2371 |
}
|
|
2372 |
|
|
2373 |
void JIT::emit_op_new_func_exp(Instruction* currentInstruction)
|
|
2374 |
{
|
|
2375 |
JITStubCall stubCall(this, cti_op_new_func_exp);
|
|
2376 |
stubCall.addArgument(ImmPtr(m_codeBlock->functionExpr(currentInstruction[2].u.operand)));
|
|
2377 |
stubCall.call(currentInstruction[1].u.operand);
|
|
2378 |
}
|
|
2379 |
|
|
2380 |
void JIT::emit_op_jtrue(Instruction* currentInstruction)
|
|
2381 |
{
|
|
2382 |
unsigned target = currentInstruction[2].u.operand;
|
|
2383 |
emitGetVirtualRegister(currentInstruction[1].u.operand, regT0);
|
|
2384 |
|
|
2385 |
Jump isZero = branchPtr(Equal, regT0, ImmPtr(JSValue::encode(jsNumber(m_globalData, 0))));
|
|
2386 |
addJump(emitJumpIfImmediateInteger(regT0), target);
|
|
2387 |
|
|
2388 |
addJump(branchPtr(Equal, regT0, ImmPtr(JSValue::encode(jsBoolean(true)))), target);
|
|
2389 |
addSlowCase(branchPtr(NotEqual, regT0, ImmPtr(JSValue::encode(jsBoolean(false)))));
|
|
2390 |
|
|
2391 |
isZero.link(this);
|
|
2392 |
RECORD_JUMP_TARGET(target);
|
|
2393 |
}
|
|
2394 |
|
|
2395 |
void JIT::emit_op_neq(Instruction* currentInstruction)
|
|
2396 |
{
|
|
2397 |
emitGetVirtualRegisters(currentInstruction[2].u.operand, regT0, currentInstruction[3].u.operand, regT1);
|
|
2398 |
emitJumpSlowCaseIfNotImmediateIntegers(regT0, regT1, regT2);
|
|
2399 |
set32(NotEqual, regT1, regT0, regT0);
|
|
2400 |
emitTagAsBoolImmediate(regT0);
|
|
2401 |
|
|
2402 |
emitPutVirtualRegister(currentInstruction[1].u.operand);
|
|
2403 |
|
|
2404 |
}
|
|
2405 |
|
|
2406 |
void JIT::emit_op_bitxor(Instruction* currentInstruction)
|
|
2407 |
{
|
|
2408 |
emitGetVirtualRegisters(currentInstruction[2].u.operand, regT0, currentInstruction[3].u.operand, regT1);
|
|
2409 |
emitJumpSlowCaseIfNotImmediateIntegers(regT0, regT1, regT2);
|
|
2410 |
xorPtr(regT1, regT0);
|
|
2411 |
emitFastArithReTagImmediate(regT0, regT0);
|
|
2412 |
emitPutVirtualRegister(currentInstruction[1].u.operand);
|
|
2413 |
}
|
|
2414 |
|
|
2415 |
void JIT::emit_op_new_regexp(Instruction* currentInstruction)
|
|
2416 |
{
|
|
2417 |
JITStubCall stubCall(this, cti_op_new_regexp);
|
|
2418 |
stubCall.addArgument(ImmPtr(m_codeBlock->regexp(currentInstruction[2].u.operand)));
|
|
2419 |
stubCall.call(currentInstruction[1].u.operand);
|
|
2420 |
}
|
|
2421 |
|
|
2422 |
void JIT::emit_op_bitor(Instruction* currentInstruction)
|
|
2423 |
{
|
|
2424 |
emitGetVirtualRegisters(currentInstruction[2].u.operand, regT0, currentInstruction[3].u.operand, regT1);
|
|
2425 |
emitJumpSlowCaseIfNotImmediateIntegers(regT0, regT1, regT2);
|
|
2426 |
orPtr(regT1, regT0);
|
|
2427 |
emitPutVirtualRegister(currentInstruction[1].u.operand);
|
|
2428 |
}
|
|
2429 |
|
|
2430 |
void JIT::emit_op_throw(Instruction* currentInstruction)
|
|
2431 |
{
|
|
2432 |
JITStubCall stubCall(this, cti_op_throw);
|
|
2433 |
stubCall.addArgument(currentInstruction[1].u.operand, regT2);
|
|
2434 |
stubCall.call();
|
|
2435 |
ASSERT(regT0 == returnValueRegister);
|
|
2436 |
#ifndef NDEBUG
|
|
2437 |
// cti_op_throw always changes it's return address,
|
|
2438 |
// this point in the code should never be reached.
|
|
2439 |
breakpoint();
|
|
2440 |
#endif
|
|
2441 |
}
|
|
2442 |
|
|
2443 |
void JIT::emit_op_get_pnames(Instruction* currentInstruction)
|
|
2444 |
{
|
|
2445 |
int dst = currentInstruction[1].u.operand;
|
|
2446 |
int base = currentInstruction[2].u.operand;
|
|
2447 |
int i = currentInstruction[3].u.operand;
|
|
2448 |
int size = currentInstruction[4].u.operand;
|
|
2449 |
int breakTarget = currentInstruction[5].u.operand;
|
|
2450 |
|
|
2451 |
JumpList isNotObject;
|
|
2452 |
|
|
2453 |
emitGetVirtualRegister(base, regT0);
|
|
2454 |
if (!m_codeBlock->isKnownNotImmediate(base))
|
|
2455 |
isNotObject.append(emitJumpIfNotJSCell(regT0));
|
|
2456 |
if (base != m_codeBlock->thisRegister()) {
|
|
2457 |
loadPtr(Address(regT0, OBJECT_OFFSETOF(JSCell, m_structure)), regT2);
|
|
2458 |
isNotObject.append(branch32(NotEqual, Address(regT2, OBJECT_OFFSETOF(Structure, m_typeInfo.m_type)), Imm32(ObjectType)));
|
|
2459 |
}
|
|
2460 |
|
|
2461 |
// We could inline the case where you have a valid cache, but
|
|
2462 |
// this call doesn't seem to be hot.
|
|
2463 |
Label isObject(this);
|
|
2464 |
JITStubCall getPnamesStubCall(this, cti_op_get_pnames);
|
|
2465 |
getPnamesStubCall.addArgument(regT0);
|
|
2466 |
getPnamesStubCall.call(dst);
|
|
2467 |
load32(Address(regT0, OBJECT_OFFSETOF(JSPropertyNameIterator, m_jsStringsSize)), regT3);
|
|
2468 |
store32(Imm32(0), addressFor(i));
|
|
2469 |
store32(regT3, addressFor(size));
|
|
2470 |
Jump end = jump();
|
|
2471 |
|
|
2472 |
isNotObject.link(this);
|
|
2473 |
move(regT0, regT1);
|
|
2474 |
and32(Imm32(~JSImmediate::ExtendedTagBitUndefined), regT1);
|
|
2475 |
addJump(branch32(Equal, regT1, Imm32(JSImmediate::FullTagTypeNull)), breakTarget);
|
|
2476 |
|
|
2477 |
JITStubCall toObjectStubCall(this, cti_to_object);
|
|
2478 |
toObjectStubCall.addArgument(regT0);
|
|
2479 |
toObjectStubCall.call(base);
|
|
2480 |
jump().linkTo(isObject, this);
|
|
2481 |
|
|
2482 |
end.link(this);
|
|
2483 |
}
|
|
2484 |
|
|
2485 |
void JIT::emit_op_next_pname(Instruction* currentInstruction)
|
|
2486 |
{
|
|
2487 |
int dst = currentInstruction[1].u.operand;
|
|
2488 |
int base = currentInstruction[2].u.operand;
|
|
2489 |
int i = currentInstruction[3].u.operand;
|
|
2490 |
int size = currentInstruction[4].u.operand;
|
|
2491 |
int it = currentInstruction[5].u.operand;
|
|
2492 |
int target = currentInstruction[6].u.operand;
|
|
2493 |
|
|
2494 |
JumpList callHasProperty;
|
|
2495 |
|
|
2496 |
Label begin(this);
|
|
2497 |
load32(addressFor(i), regT0);
|
|
2498 |
Jump end = branch32(Equal, regT0, addressFor(size));
|
|
2499 |
|
|
2500 |
// Grab key @ i
|
|
2501 |
loadPtr(addressFor(it), regT1);
|
|
2502 |
loadPtr(Address(regT1, OBJECT_OFFSETOF(JSPropertyNameIterator, m_jsStrings)), regT2);
|
|
2503 |
loadPtr(BaseIndex(regT2, regT0, TimesEight), regT2);
|
|
2504 |
emitPutVirtualRegister(dst, regT2);
|
|
2505 |
|
|
2506 |
// Increment i
|
|
2507 |
add32(Imm32(1), regT0);
|
|
2508 |
store32(regT0, addressFor(i));
|
|
2509 |
|
|
2510 |
// Verify that i is valid:
|
|
2511 |
emitGetVirtualRegister(base, regT0);
|
|
2512 |
|
|
2513 |
// Test base's structure
|
|
2514 |
loadPtr(Address(regT0, OBJECT_OFFSETOF(JSCell, m_structure)), regT2);
|
|
2515 |
callHasProperty.append(branchPtr(NotEqual, regT2, Address(Address(regT1, OBJECT_OFFSETOF(JSPropertyNameIterator, m_cachedStructure)))));
|
|
2516 |
|
|
2517 |
// Test base's prototype chain
|
|
2518 |
loadPtr(Address(Address(regT1, OBJECT_OFFSETOF(JSPropertyNameIterator, m_cachedPrototypeChain))), regT3);
|
|
2519 |
loadPtr(Address(regT3, OBJECT_OFFSETOF(StructureChain, m_vector)), regT3);
|
|
2520 |
addJump(branchTestPtr(Zero, Address(regT3)), target);
|
|
2521 |
|
|
2522 |
Label checkPrototype(this);
|
|
2523 |
loadPtr(Address(regT2, OBJECT_OFFSETOF(Structure, m_prototype)), regT2);
|
|
2524 |
callHasProperty.append(emitJumpIfNotJSCell(regT2));
|
|
2525 |
loadPtr(Address(regT2, OBJECT_OFFSETOF(JSCell, m_structure)), regT2);
|
|
2526 |
callHasProperty.append(branchPtr(NotEqual, regT2, Address(regT3)));
|
|
2527 |
addPtr(Imm32(sizeof(Structure*)), regT3);
|
|
2528 |
branchTestPtr(NonZero, Address(regT3)).linkTo(checkPrototype, this);
|
|
2529 |
|
|
2530 |
// Continue loop.
|
|
2531 |
addJump(jump(), target);
|
|
2532 |
|
|
2533 |
// Slow case: Ask the object if i is valid.
|
|
2534 |
callHasProperty.link(this);
|
|
2535 |
emitGetVirtualRegister(dst, regT1);
|
|
2536 |
JITStubCall stubCall(this, cti_has_property);
|
|
2537 |
stubCall.addArgument(regT0);
|
|
2538 |
stubCall.addArgument(regT1);
|
|
2539 |
stubCall.call();
|
|
2540 |
|
|
2541 |
// Test for valid key.
|
|
2542 |
addJump(branchTest32(NonZero, regT0), target);
|
|
2543 |
jump().linkTo(begin, this);
|
|
2544 |
|
|
2545 |
// End of loop.
|
|
2546 |
end.link(this);
|
|
2547 |
}
|
|
2548 |
|
|
2549 |
void JIT::emit_op_push_scope(Instruction* currentInstruction)
|
|
2550 |
{
|
|
2551 |
JITStubCall stubCall(this, cti_op_push_scope);
|
|
2552 |
stubCall.addArgument(currentInstruction[1].u.operand, regT2);
|
|
2553 |
stubCall.call(currentInstruction[1].u.operand);
|
|
2554 |
}
|
|
2555 |
|
|
2556 |
void JIT::emit_op_pop_scope(Instruction*)
|
|
2557 |
{
|
|
2558 |
JITStubCall(this, cti_op_pop_scope).call();
|
|
2559 |
}
|
|
2560 |
|
|
2561 |
void JIT::compileOpStrictEq(Instruction* currentInstruction, CompileOpStrictEqType type)
|
|
2562 |
{
|
|
2563 |
unsigned dst = currentInstruction[1].u.operand;
|
|
2564 |
unsigned src1 = currentInstruction[2].u.operand;
|
|
2565 |
unsigned src2 = currentInstruction[3].u.operand;
|
|
2566 |
|
|
2567 |
emitGetVirtualRegisters(src1, regT0, src2, regT1);
|
|
2568 |
|
|
2569 |
// Jump to a slow case if either operand is a number, or if both are JSCell*s.
|
|
2570 |
move(regT0, regT2);
|
|
2571 |
orPtr(regT1, regT2);
|
|
2572 |
addSlowCase(emitJumpIfJSCell(regT2));
|
|
2573 |
addSlowCase(emitJumpIfImmediateNumber(regT2));
|
|
2574 |
|
|
2575 |
if (type == OpStrictEq)
|
|
2576 |
set32(Equal, regT1, regT0, regT0);
|
|
2577 |
else
|
|
2578 |
set32(NotEqual, regT1, regT0, regT0);
|
|
2579 |
emitTagAsBoolImmediate(regT0);
|
|
2580 |
|
|
2581 |
emitPutVirtualRegister(dst);
|
|
2582 |
}
|
|
2583 |
|
|
2584 |
void JIT::emit_op_stricteq(Instruction* currentInstruction)
|
|
2585 |
{
|
|
2586 |
compileOpStrictEq(currentInstruction, OpStrictEq);
|
|
2587 |
}
|
|
2588 |
|
|
2589 |
void JIT::emit_op_nstricteq(Instruction* currentInstruction)
|
|
2590 |
{
|
|
2591 |
compileOpStrictEq(currentInstruction, OpNStrictEq);
|
|
2592 |
}
|
|
2593 |
|
|
2594 |
void JIT::emit_op_to_jsnumber(Instruction* currentInstruction)
|
|
2595 |
{
|
|
2596 |
int srcVReg = currentInstruction[2].u.operand;
|
|
2597 |
emitGetVirtualRegister(srcVReg, regT0);
|
|
2598 |
|
|
2599 |
Jump wasImmediate = emitJumpIfImmediateInteger(regT0);
|
|
2600 |
|
|
2601 |
emitJumpSlowCaseIfNotJSCell(regT0, srcVReg);
|
|
2602 |
loadPtr(Address(regT0, OBJECT_OFFSETOF(JSCell, m_structure)), regT2);
|
|
2603 |
addSlowCase(branch32(NotEqual, Address(regT2, OBJECT_OFFSETOF(Structure, m_typeInfo.m_type)), Imm32(NumberType)));
|
|
2604 |
|
|
2605 |
wasImmediate.link(this);
|
|
2606 |
|
|
2607 |
emitPutVirtualRegister(currentInstruction[1].u.operand);
|
|
2608 |
}
|
|
2609 |
|
|
2610 |
void JIT::emit_op_push_new_scope(Instruction* currentInstruction)
|
|
2611 |
{
|
|
2612 |
JITStubCall stubCall(this, cti_op_push_new_scope);
|
|
2613 |
stubCall.addArgument(ImmPtr(&m_codeBlock->identifier(currentInstruction[2].u.operand)));
|
|
2614 |
stubCall.addArgument(currentInstruction[3].u.operand, regT2);
|
|
2615 |
stubCall.call(currentInstruction[1].u.operand);
|
|
2616 |
}
|
|
2617 |
|
|
2618 |
void JIT::emit_op_catch(Instruction* currentInstruction)
|
|
2619 |
{
|
|
2620 |
killLastResultRegister(); // FIXME: Implicitly treat op_catch as a labeled statement, and remove this line of code.
|
|
2621 |
peek(callFrameRegister, OBJECT_OFFSETOF(struct JITStackFrame, callFrame) / sizeof (void*));
|
|
2622 |
emitPutVirtualRegister(currentInstruction[1].u.operand);
|
|
2623 |
}
|
|
2624 |
|
|
2625 |
void JIT::emit_op_jmp_scopes(Instruction* currentInstruction)
|
|
2626 |
{
|
|
2627 |
JITStubCall stubCall(this, cti_op_jmp_scopes);
|
|
2628 |
stubCall.addArgument(Imm32(currentInstruction[1].u.operand));
|
|
2629 |
stubCall.call();
|
|
2630 |
addJump(jump(), currentInstruction[2].u.operand);
|
|
2631 |
RECORD_JUMP_TARGET(currentInstruction[2].u.operand);
|
|
2632 |
}
|
|
2633 |
|
|
2634 |
void JIT::emit_op_switch_imm(Instruction* currentInstruction)
|
|
2635 |
{
|
|
2636 |
unsigned tableIndex = currentInstruction[1].u.operand;
|
|
2637 |
unsigned defaultOffset = currentInstruction[2].u.operand;
|
|
2638 |
unsigned scrutinee = currentInstruction[3].u.operand;
|
|
2639 |
|
|
2640 |
// create jump table for switch destinations, track this switch statement.
|
|
2641 |
SimpleJumpTable* jumpTable = &m_codeBlock->immediateSwitchJumpTable(tableIndex);
|
|
2642 |
m_switches.append(SwitchRecord(jumpTable, m_bytecodeIndex, defaultOffset, SwitchRecord::Immediate));
|
|
2643 |
jumpTable->ctiOffsets.grow(jumpTable->branchOffsets.size());
|
|
2644 |
|
|
2645 |
JITStubCall stubCall(this, cti_op_switch_imm);
|
|
2646 |
stubCall.addArgument(scrutinee, regT2);
|
|
2647 |
stubCall.addArgument(Imm32(tableIndex));
|
|
2648 |
stubCall.call();
|
|
2649 |
jump(regT0);
|
|
2650 |
}
|
|
2651 |
|
|
2652 |
void JIT::emit_op_switch_char(Instruction* currentInstruction)
|
|
2653 |
{
|
|
2654 |
unsigned tableIndex = currentInstruction[1].u.operand;
|
|
2655 |
unsigned defaultOffset = currentInstruction[2].u.operand;
|
|
2656 |
unsigned scrutinee = currentInstruction[3].u.operand;
|
|
2657 |
|
|
2658 |
// create jump table for switch destinations, track this switch statement.
|
|
2659 |
SimpleJumpTable* jumpTable = &m_codeBlock->characterSwitchJumpTable(tableIndex);
|
|
2660 |
m_switches.append(SwitchRecord(jumpTable, m_bytecodeIndex, defaultOffset, SwitchRecord::Character));
|
|
2661 |
jumpTable->ctiOffsets.grow(jumpTable->branchOffsets.size());
|
|
2662 |
|
|
2663 |
JITStubCall stubCall(this, cti_op_switch_char);
|
|
2664 |
stubCall.addArgument(scrutinee, regT2);
|
|
2665 |
stubCall.addArgument(Imm32(tableIndex));
|
|
2666 |
stubCall.call();
|
|
2667 |
jump(regT0);
|
|
2668 |
}
|
|
2669 |
|
|
2670 |
void JIT::emit_op_switch_string(Instruction* currentInstruction)
|
|
2671 |
{
|
|
2672 |
unsigned tableIndex = currentInstruction[1].u.operand;
|
|
2673 |
unsigned defaultOffset = currentInstruction[2].u.operand;
|
|
2674 |
unsigned scrutinee = currentInstruction[3].u.operand;
|
|
2675 |
|
|
2676 |
// create jump table for switch destinations, track this switch statement.
|
|
2677 |
StringJumpTable* jumpTable = &m_codeBlock->stringSwitchJumpTable(tableIndex);
|
|
2678 |
m_switches.append(SwitchRecord(jumpTable, m_bytecodeIndex, defaultOffset));
|
|
2679 |
|
|
2680 |
JITStubCall stubCall(this, cti_op_switch_string);
|
|
2681 |
stubCall.addArgument(scrutinee, regT2);
|
|
2682 |
stubCall.addArgument(Imm32(tableIndex));
|
|
2683 |
stubCall.call();
|
|
2684 |
jump(regT0);
|
|
2685 |
}
|
|
2686 |
|
|
2687 |
void JIT::emit_op_new_error(Instruction* currentInstruction)
|
|
2688 |
{
|
|
2689 |
JITStubCall stubCall(this, cti_op_new_error);
|
|
2690 |
stubCall.addArgument(Imm32(currentInstruction[2].u.operand));
|
|
2691 |
stubCall.addArgument(ImmPtr(JSValue::encode(m_codeBlock->getConstant(currentInstruction[3].u.operand))));
|
|
2692 |
stubCall.addArgument(Imm32(m_bytecodeIndex));
|
|
2693 |
stubCall.call(currentInstruction[1].u.operand);
|
|
2694 |
}
|
|
2695 |
|
|
2696 |
void JIT::emit_op_debug(Instruction* currentInstruction)
|
|
2697 |
{
|
|
2698 |
JITStubCall stubCall(this, cti_op_debug);
|
|
2699 |
stubCall.addArgument(Imm32(currentInstruction[1].u.operand));
|
|
2700 |
stubCall.addArgument(Imm32(currentInstruction[2].u.operand));
|
|
2701 |
stubCall.addArgument(Imm32(currentInstruction[3].u.operand));
|
|
2702 |
stubCall.call();
|
|
2703 |
}
|
|
2704 |
|
|
2705 |
void JIT::emit_op_eq_null(Instruction* currentInstruction)
|
|
2706 |
{
|
|
2707 |
unsigned dst = currentInstruction[1].u.operand;
|
|
2708 |
unsigned src1 = currentInstruction[2].u.operand;
|
|
2709 |
|
|
2710 |
emitGetVirtualRegister(src1, regT0);
|
|
2711 |
Jump isImmediate = emitJumpIfNotJSCell(regT0);
|
|
2712 |
|
|
2713 |
loadPtr(Address(regT0, OBJECT_OFFSETOF(JSCell, m_structure)), regT2);
|
|
2714 |
setTest32(NonZero, Address(regT2, OBJECT_OFFSETOF(Structure, m_typeInfo.m_flags)), Imm32(MasqueradesAsUndefined), regT0);
|
|
2715 |
|
|
2716 |
Jump wasNotImmediate = jump();
|
|
2717 |
|
|
2718 |
isImmediate.link(this);
|
|
2719 |
|
|
2720 |
andPtr(Imm32(~JSImmediate::ExtendedTagBitUndefined), regT0);
|
|
2721 |
setPtr(Equal, regT0, Imm32(JSImmediate::FullTagTypeNull), regT0);
|
|
2722 |
|
|
2723 |
wasNotImmediate.link(this);
|
|
2724 |
|
|
2725 |
emitTagAsBoolImmediate(regT0);
|
|
2726 |
emitPutVirtualRegister(dst);
|
|
2727 |
|
|
2728 |
}
|
|
2729 |
|
|
2730 |
void JIT::emit_op_neq_null(Instruction* currentInstruction)
|
|
2731 |
{
|
|
2732 |
unsigned dst = currentInstruction[1].u.operand;
|
|
2733 |
unsigned src1 = currentInstruction[2].u.operand;
|
|
2734 |
|
|
2735 |
emitGetVirtualRegister(src1, regT0);
|
|
2736 |
Jump isImmediate = emitJumpIfNotJSCell(regT0);
|
|
2737 |
|
|
2738 |
loadPtr(Address(regT0, OBJECT_OFFSETOF(JSCell, m_structure)), regT2);
|
|
2739 |
setTest32(Zero, Address(regT2, OBJECT_OFFSETOF(Structure, m_typeInfo.m_flags)), Imm32(MasqueradesAsUndefined), regT0);
|
|
2740 |
|
|
2741 |
Jump wasNotImmediate = jump();
|
|
2742 |
|
|
2743 |
isImmediate.link(this);
|
|
2744 |
|
|
2745 |
andPtr(Imm32(~JSImmediate::ExtendedTagBitUndefined), regT0);
|
|
2746 |
setPtr(NotEqual, regT0, Imm32(JSImmediate::FullTagTypeNull), regT0);
|
|
2747 |
|
|
2748 |
wasNotImmediate.link(this);
|
|
2749 |
|
|
2750 |
emitTagAsBoolImmediate(regT0);
|
|
2751 |
emitPutVirtualRegister(dst);
|
|
2752 |
|
|
2753 |
}
|
|
2754 |
|
|
2755 |
void JIT::emit_op_enter(Instruction*)
|
|
2756 |
{
|
|
2757 |
// Even though CTI doesn't use them, we initialize our constant
|
|
2758 |
// registers to zap stale pointers, to avoid unnecessarily prolonging
|
|
2759 |
// object lifetime and increasing GC pressure.
|
|
2760 |
size_t count = m_codeBlock->m_numVars;
|
|
2761 |
for (size_t j = 0; j < count; ++j)
|
|
2762 |
emitInitRegister(j);
|
|
2763 |
|
|
2764 |
}
|
|
2765 |
|
|
2766 |
void JIT::emit_op_enter_with_activation(Instruction* currentInstruction)
|
|
2767 |
{
|
|
2768 |
// Even though CTI doesn't use them, we initialize our constant
|
|
2769 |
// registers to zap stale pointers, to avoid unnecessarily prolonging
|
|
2770 |
// object lifetime and increasing GC pressure.
|
|
2771 |
size_t count = m_codeBlock->m_numVars;
|
|
2772 |
for (size_t j = 0; j < count; ++j)
|
|
2773 |
emitInitRegister(j);
|
|
2774 |
|
|
2775 |
JITStubCall(this, cti_op_push_activation).call(currentInstruction[1].u.operand);
|
|
2776 |
}
|
|
2777 |
|
|
2778 |
void JIT::emit_op_create_arguments(Instruction*)
|
|
2779 |
{
|
|
2780 |
Jump argsCreated = branchTestPtr(NonZero, Address(callFrameRegister, sizeof(Register) * RegisterFile::ArgumentsRegister));
|
|
2781 |
if (m_codeBlock->m_numParameters == 1)
|
|
2782 |
JITStubCall(this, cti_op_create_arguments_no_params).call();
|
|
2783 |
else
|
|
2784 |
JITStubCall(this, cti_op_create_arguments).call();
|
|
2785 |
argsCreated.link(this);
|
|
2786 |
}
|
|
2787 |
|
|
2788 |
void JIT::emit_op_init_arguments(Instruction*)
|
|
2789 |
{
|
|
2790 |
storePtr(ImmPtr(0), Address(callFrameRegister, sizeof(Register) * RegisterFile::ArgumentsRegister));
|
|
2791 |
}
|
|
2792 |
|
|
2793 |
void JIT::emit_op_convert_this(Instruction* currentInstruction)
|
|
2794 |
{
|
|
2795 |
emitGetVirtualRegister(currentInstruction[1].u.operand, regT0);
|
|
2796 |
|
|
2797 |
emitJumpSlowCaseIfNotJSCell(regT0);
|
|
2798 |
loadPtr(Address(regT0, OBJECT_OFFSETOF(JSCell, m_structure)), regT1);
|
|
2799 |
addSlowCase(branchTest32(NonZero, Address(regT1, OBJECT_OFFSETOF(Structure, m_typeInfo.m_flags)), Imm32(NeedsThisConversion)));
|
|
2800 |
|
|
2801 |
}
|
|
2802 |
|
|
2803 |
void JIT::emit_op_profile_will_call(Instruction* currentInstruction)
|
|
2804 |
{
|
|
2805 |
peek(regT1, OBJECT_OFFSETOF(JITStackFrame, enabledProfilerReference) / sizeof (void*));
|
|
2806 |
Jump noProfiler = branchTestPtr(Zero, Address(regT1));
|
|
2807 |
|
|
2808 |
JITStubCall stubCall(this, cti_op_profile_will_call);
|
|
2809 |
stubCall.addArgument(currentInstruction[1].u.operand, regT1);
|
|
2810 |
stubCall.call();
|
|
2811 |
noProfiler.link(this);
|
|
2812 |
|
|
2813 |
}
|
|
2814 |
|
|
2815 |
void JIT::emit_op_profile_did_call(Instruction* currentInstruction)
|
|
2816 |
{
|
|
2817 |
peek(regT1, OBJECT_OFFSETOF(JITStackFrame, enabledProfilerReference) / sizeof (void*));
|
|
2818 |
Jump noProfiler = branchTestPtr(Zero, Address(regT1));
|
|
2819 |
|
|
2820 |
JITStubCall stubCall(this, cti_op_profile_did_call);
|
|
2821 |
stubCall.addArgument(currentInstruction[1].u.operand, regT1);
|
|
2822 |
stubCall.call();
|
|
2823 |
noProfiler.link(this);
|
|
2824 |
}
|
|
2825 |
|
|
2826 |
|
|
2827 |
// Slow cases
|
|
2828 |
|
|
2829 |
void JIT::emitSlow_op_convert_this(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
|
|
2830 |
{
|
|
2831 |
linkSlowCase(iter);
|
|
2832 |
linkSlowCase(iter);
|
|
2833 |
JITStubCall stubCall(this, cti_op_convert_this);
|
|
2834 |
stubCall.addArgument(regT0);
|
|
2835 |
stubCall.call(currentInstruction[1].u.operand);
|
|
2836 |
}
|
|
2837 |
|
|
2838 |
void JIT::emitSlow_op_construct_verify(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
|
|
2839 |
{
|
|
2840 |
linkSlowCase(iter);
|
|
2841 |
linkSlowCase(iter);
|
|
2842 |
emitGetVirtualRegister(currentInstruction[2].u.operand, regT0);
|
|
2843 |
emitPutVirtualRegister(currentInstruction[1].u.operand);
|
|
2844 |
}
|
|
2845 |
|
|
2846 |
void JIT::emitSlow_op_to_primitive(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
|
|
2847 |
{
|
|
2848 |
linkSlowCase(iter);
|
|
2849 |
|
|
2850 |
JITStubCall stubCall(this, cti_op_to_primitive);
|
|
2851 |
stubCall.addArgument(regT0);
|
|
2852 |
stubCall.call(currentInstruction[1].u.operand);
|
|
2853 |
}
|
|
2854 |
|
|
2855 |
void JIT::emitSlow_op_get_by_val(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
|
|
2856 |
{
|
|
2857 |
unsigned dst = currentInstruction[1].u.operand;
|
|
2858 |
unsigned base = currentInstruction[2].u.operand;
|
|
2859 |
unsigned property = currentInstruction[3].u.operand;
|
|
2860 |
|
|
2861 |
linkSlowCase(iter); // property int32 check
|
|
2862 |
linkSlowCaseIfNotJSCell(iter, base); // base cell check
|
|
2863 |
linkSlowCase(iter); // base array check
|
|
2864 |
linkSlowCase(iter); // vector length check
|
|
2865 |
linkSlowCase(iter); // empty value
|
|
2866 |
|
|
2867 |
JITStubCall stubCall(this, cti_op_get_by_val);
|
|
2868 |
stubCall.addArgument(base, regT2);
|
|
2869 |
stubCall.addArgument(property, regT2);
|
|
2870 |
stubCall.call(dst);
|
|
2871 |
}
|
|
2872 |
|
|
2873 |
void JIT::emitSlow_op_loop_if_less(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
|
|
2874 |
{
|
|
2875 |
unsigned op1 = currentInstruction[1].u.operand;
|
|
2876 |
unsigned op2 = currentInstruction[2].u.operand;
|
|
2877 |
unsigned target = currentInstruction[3].u.operand;
|
|
2878 |
if (isOperandConstantImmediateInt(op2)) {
|
|
2879 |
linkSlowCase(iter);
|
|
2880 |
JITStubCall stubCall(this, cti_op_loop_if_less);
|
|
2881 |
stubCall.addArgument(regT0);
|
|
2882 |
stubCall.addArgument(op2, regT2);
|
|
2883 |
stubCall.call();
|
|
2884 |
emitJumpSlowToHot(branchTest32(NonZero, regT0), target);
|
|
2885 |
} else if (isOperandConstantImmediateInt(op1)) {
|
|
2886 |
linkSlowCase(iter);
|
|
2887 |
JITStubCall stubCall(this, cti_op_loop_if_less);
|
|
2888 |
stubCall.addArgument(op1, regT2);
|
|
2889 |
stubCall.addArgument(regT0);
|
|
2890 |
stubCall.call();
|
|
2891 |
emitJumpSlowToHot(branchTest32(NonZero, regT0), target);
|
|
2892 |
} else {
|
|
2893 |
linkSlowCase(iter);
|
|
2894 |
linkSlowCase(iter);
|
|
2895 |
JITStubCall stubCall(this, cti_op_loop_if_less);
|
|
2896 |
stubCall.addArgument(regT0);
|
|
2897 |
stubCall.addArgument(regT1);
|
|
2898 |
stubCall.call();
|
|
2899 |
emitJumpSlowToHot(branchTest32(NonZero, regT0), target);
|
|
2900 |
}
|
|
2901 |
}
|
|
2902 |
|
|
2903 |
void JIT::emitSlow_op_loop_if_lesseq(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
|
|
2904 |
{
|
|
2905 |
unsigned op2 = currentInstruction[2].u.operand;
|
|
2906 |
unsigned target = currentInstruction[3].u.operand;
|
|
2907 |
if (isOperandConstantImmediateInt(op2)) {
|
|
2908 |
linkSlowCase(iter);
|
|
2909 |
JITStubCall stubCall(this, cti_op_loop_if_lesseq);
|
|
2910 |
stubCall.addArgument(regT0);
|
|
2911 |
stubCall.addArgument(currentInstruction[2].u.operand, regT2);
|
|
2912 |
stubCall.call();
|
|
2913 |
emitJumpSlowToHot(branchTest32(NonZero, regT0), target);
|
|
2914 |
} else {
|
|
2915 |
linkSlowCase(iter);
|
|
2916 |
linkSlowCase(iter);
|
|
2917 |
JITStubCall stubCall(this, cti_op_loop_if_lesseq);
|
|
2918 |
stubCall.addArgument(regT0);
|
|
2919 |
stubCall.addArgument(regT1);
|
|
2920 |
stubCall.call();
|
|
2921 |
emitJumpSlowToHot(branchTest32(NonZero, regT0), target);
|
|
2922 |
}
|
|
2923 |
}
|
|
2924 |
|
|
2925 |
void JIT::emitSlow_op_put_by_val(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
|
|
2926 |
{
|
|
2927 |
unsigned base = currentInstruction[1].u.operand;
|
|
2928 |
unsigned property = currentInstruction[2].u.operand;
|
|
2929 |
unsigned value = currentInstruction[3].u.operand;
|
|
2930 |
|
|
2931 |
linkSlowCase(iter); // property int32 check
|
|
2932 |
linkSlowCaseIfNotJSCell(iter, base); // base cell check
|
|
2933 |
linkSlowCase(iter); // base not array check
|
|
2934 |
linkSlowCase(iter); // in vector check
|
|
2935 |
|
|
2936 |
JITStubCall stubPutByValCall(this, cti_op_put_by_val);
|
|
2937 |
stubPutByValCall.addArgument(regT0);
|
|
2938 |
stubPutByValCall.addArgument(property, regT2);
|
|
2939 |
stubPutByValCall.addArgument(value, regT2);
|
|
2940 |
stubPutByValCall.call();
|
|
2941 |
}
|
|
2942 |
|
|
2943 |
void JIT::emitSlow_op_loop_if_true(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
|
|
2944 |
{
|
|
2945 |
linkSlowCase(iter);
|
|
2946 |
JITStubCall stubCall(this, cti_op_jtrue);
|
|
2947 |
stubCall.addArgument(regT0);
|
|
2948 |
stubCall.call();
|
|
2949 |
emitJumpSlowToHot(branchTest32(NonZero, regT0), currentInstruction[2].u.operand);
|
|
2950 |
}
|
|
2951 |
|
|
2952 |
void JIT::emitSlow_op_not(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
|
|
2953 |
{
|
|
2954 |
linkSlowCase(iter);
|
|
2955 |
xorPtr(Imm32(static_cast<int32_t>(JSImmediate::FullTagTypeBool)), regT0);
|
|
2956 |
JITStubCall stubCall(this, cti_op_not);
|
|
2957 |
stubCall.addArgument(regT0);
|
|
2958 |
stubCall.call(currentInstruction[1].u.operand);
|
|
2959 |
}
|
|
2960 |
|
|
2961 |
void JIT::emitSlow_op_jfalse(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
|
|
2962 |
{
|
|
2963 |
linkSlowCase(iter);
|
|
2964 |
JITStubCall stubCall(this, cti_op_jtrue);
|
|
2965 |
stubCall.addArgument(regT0);
|
|
2966 |
stubCall.call();
|
|
2967 |
emitJumpSlowToHot(branchTest32(Zero, regT0), currentInstruction[2].u.operand); // inverted!
|
|
2968 |
}
|
|
2969 |
|
|
2970 |
void JIT::emitSlow_op_bitnot(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
|
|
2971 |
{
|
|
2972 |
linkSlowCase(iter);
|
|
2973 |
JITStubCall stubCall(this, cti_op_bitnot);
|
|
2974 |
stubCall.addArgument(regT0);
|
|
2975 |
stubCall.call(currentInstruction[1].u.operand);
|
|
2976 |
}
|
|
2977 |
|
|
2978 |
void JIT::emitSlow_op_jtrue(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
|
|
2979 |
{
|
|
2980 |
linkSlowCase(iter);
|
|
2981 |
JITStubCall stubCall(this, cti_op_jtrue);
|
|
2982 |
stubCall.addArgument(regT0);
|
|
2983 |
stubCall.call();
|
|
2984 |
emitJumpSlowToHot(branchTest32(NonZero, regT0), currentInstruction[2].u.operand);
|
|
2985 |
}
|
|
2986 |
|
|
2987 |
void JIT::emitSlow_op_bitxor(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
|
|
2988 |
{
|
|
2989 |
linkSlowCase(iter);
|
|
2990 |
JITStubCall stubCall(this, cti_op_bitxor);
|
|
2991 |
stubCall.addArgument(regT0);
|
|
2992 |
stubCall.addArgument(regT1);
|
|
2993 |
stubCall.call(currentInstruction[1].u.operand);
|
|
2994 |
}
|
|
2995 |
|
|
2996 |
void JIT::emitSlow_op_bitor(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
|
|
2997 |
{
|
|
2998 |
linkSlowCase(iter);
|
|
2999 |
JITStubCall stubCall(this, cti_op_bitor);
|
|
3000 |
stubCall.addArgument(regT0);
|
|
3001 |
stubCall.addArgument(regT1);
|
|
3002 |
stubCall.call(currentInstruction[1].u.operand);
|
|
3003 |
}
|
|
3004 |
|
|
3005 |
void JIT::emitSlow_op_eq(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
|
|
3006 |
{
|
|
3007 |
linkSlowCase(iter);
|
|
3008 |
JITStubCall stubCall(this, cti_op_eq);
|
|
3009 |
stubCall.addArgument(regT0);
|
|
3010 |
stubCall.addArgument(regT1);
|
|
3011 |
stubCall.call();
|
|
3012 |
emitTagAsBoolImmediate(regT0);
|
|
3013 |
emitPutVirtualRegister(currentInstruction[1].u.operand);
|
|
3014 |
}
|
|
3015 |
|
|
3016 |
void JIT::emitSlow_op_neq(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
|
|
3017 |
{
|
|
3018 |
linkSlowCase(iter);
|
|
3019 |
JITStubCall stubCall(this, cti_op_eq);
|
|
3020 |
stubCall.addArgument(regT0);
|
|
3021 |
stubCall.addArgument(regT1);
|
|
3022 |
stubCall.call();
|
|
3023 |
xor32(Imm32(0x1), regT0);
|
|
3024 |
emitTagAsBoolImmediate(regT0);
|
|
3025 |
emitPutVirtualRegister(currentInstruction[1].u.operand);
|
|
3026 |
}
|
|
3027 |
|
|
3028 |
void JIT::emitSlow_op_stricteq(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
|
|
3029 |
{
|
|
3030 |
linkSlowCase(iter);
|
|
3031 |
linkSlowCase(iter);
|
|
3032 |
JITStubCall stubCall(this, cti_op_stricteq);
|
|
3033 |
stubCall.addArgument(regT0);
|
|
3034 |
stubCall.addArgument(regT1);
|
|
3035 |
stubCall.call(currentInstruction[1].u.operand);
|
|
3036 |
}
|
|
3037 |
|
|
3038 |
void JIT::emitSlow_op_nstricteq(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
|
|
3039 |
{
|
|
3040 |
linkSlowCase(iter);
|
|
3041 |
linkSlowCase(iter);
|
|
3042 |
JITStubCall stubCall(this, cti_op_nstricteq);
|
|
3043 |
stubCall.addArgument(regT0);
|
|
3044 |
stubCall.addArgument(regT1);
|
|
3045 |
stubCall.call(currentInstruction[1].u.operand);
|
|
3046 |
}
|
|
3047 |
|
|
3048 |
void JIT::emitSlow_op_instanceof(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
|
|
3049 |
{
|
|
3050 |
unsigned dst = currentInstruction[1].u.operand;
|
|
3051 |
unsigned value = currentInstruction[2].u.operand;
|
|
3052 |
unsigned baseVal = currentInstruction[3].u.operand;
|
|
3053 |
unsigned proto = currentInstruction[4].u.operand;
|
|
3054 |
|
|
3055 |
linkSlowCaseIfNotJSCell(iter, value);
|
|
3056 |
linkSlowCaseIfNotJSCell(iter, baseVal);
|
|
3057 |
linkSlowCaseIfNotJSCell(iter, proto);
|
|
3058 |
linkSlowCase(iter);
|
|
3059 |
JITStubCall stubCall(this, cti_op_instanceof);
|
|
3060 |
stubCall.addArgument(value, regT2);
|
|
3061 |
stubCall.addArgument(baseVal, regT2);
|
|
3062 |
stubCall.addArgument(proto, regT2);
|
|
3063 |
stubCall.call(dst);
|
|
3064 |
}
|
|
3065 |
|
|
3066 |
void JIT::emitSlow_op_call(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
|
|
3067 |
{
|
|
3068 |
compileOpCallSlowCase(currentInstruction, iter, m_callLinkInfoIndex++, op_call);
|
|
3069 |
}
|
|
3070 |
|
|
3071 |
void JIT::emitSlow_op_call_eval(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
|
|
3072 |
{
|
|
3073 |
compileOpCallSlowCase(currentInstruction, iter, m_callLinkInfoIndex++, op_call_eval);
|
|
3074 |
}
|
|
3075 |
|
|
3076 |
void JIT::emitSlow_op_call_varargs(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
|
|
3077 |
{
|
|
3078 |
compileOpCallVarargsSlowCase(currentInstruction, iter);
|
|
3079 |
}
|
|
3080 |
|
|
3081 |
void JIT::emitSlow_op_construct(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
|
|
3082 |
{
|
|
3083 |
compileOpCallSlowCase(currentInstruction, iter, m_callLinkInfoIndex++, op_construct);
|
|
3084 |
}
|
|
3085 |
|
|
3086 |
void JIT::emitSlow_op_to_jsnumber(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
|
|
3087 |
{
|
|
3088 |
linkSlowCaseIfNotJSCell(iter, currentInstruction[2].u.operand);
|
|
3089 |
linkSlowCase(iter);
|
|
3090 |
|
|
3091 |
JITStubCall stubCall(this, cti_op_to_jsnumber);
|
|
3092 |
stubCall.addArgument(regT0);
|
|
3093 |
stubCall.call(currentInstruction[1].u.operand);
|
|
3094 |
}
|
|
3095 |
|
|
3096 |
#endif // USE(JSVALUE32_64)
|
|
3097 |
|
|
3098 |
} // namespace JSC
|
|
3099 |
|
|
3100 |
#endif // ENABLE(JIT)
|