2 * Copyright (C) 2008, 2009 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
29 // This probably does not belong here; adding here for now as a quick Windows build fix.
30 #if ENABLE(ASSEMBLER) && PLATFORM(X86) && !PLATFORM(MAC)
31 #include "MacroAssembler.h"
32 JSC::MacroAssemblerX86Common::SSE2CheckState
JSC::MacroAssemblerX86Common::s_sse2CheckState
= NotCheckedSSE2
;
37 #include "CodeBlock.h"
38 #include "Interpreter.h"
39 #include "JITInlineMethods.h"
41 #include "JITStubCall.h"
43 #include "JSFunction.h"
44 #include "LinkBuffer.h"
45 #include "RepatchBuffer.h"
46 #include "ResultType.h"
47 #include "SamplingTool.h"
57 void ctiPatchNearCallByReturnAddress(CodeBlock
* codeblock
, ReturnAddressPtr returnAddress
, MacroAssemblerCodePtr newCalleeFunction
)
59 RepatchBuffer
repatchBuffer(codeblock
);
60 repatchBuffer
.relinkNearCallerToTrampoline(returnAddress
, newCalleeFunction
);
63 void ctiPatchCallByReturnAddress(CodeBlock
* codeblock
, ReturnAddressPtr returnAddress
, MacroAssemblerCodePtr newCalleeFunction
)
65 RepatchBuffer
repatchBuffer(codeblock
);
66 repatchBuffer
.relinkCallerToTrampoline(returnAddress
, newCalleeFunction
);
69 void ctiPatchCallByReturnAddress(CodeBlock
* codeblock
, ReturnAddressPtr returnAddress
, FunctionPtr newCalleeFunction
)
71 RepatchBuffer
repatchBuffer(codeblock
);
72 repatchBuffer
.relinkCallerToFunction(returnAddress
, newCalleeFunction
);
75 JIT::JIT(JSGlobalData
* globalData
, CodeBlock
* codeBlock
)
76 : m_interpreter(globalData
->interpreter
)
77 , m_globalData(globalData
)
78 , m_codeBlock(codeBlock
)
79 , m_labels(codeBlock
? codeBlock
->instructions().size() : 0)
80 , m_propertyAccessCompilationInfo(codeBlock
? codeBlock
->numberOfStructureStubInfos() : 0)
81 , m_callStructureStubCompilationInfo(codeBlock
? codeBlock
->numberOfCallLinkInfos() : 0)
82 , m_bytecodeIndex((unsigned)-1)
84 , m_jumpTargetIndex(0)
85 , m_mappedBytecodeIndex((unsigned)-1)
86 , m_mappedVirtualRegisterIndex((unsigned)-1)
87 , m_mappedTag((RegisterID
)-1)
88 , m_mappedPayload((RegisterID
)-1)
90 , m_lastResultBytecodeRegister(std::numeric_limits
<int>::max())
91 , m_jumpTargetsPosition(0)
97 void JIT::emitTimeoutCheck()
99 Jump skipTimeout
= branchSub32(NonZero
, Imm32(1), timeoutCheckRegister
);
100 JITStubCall
stubCall(this, cti_timeout_check
);
101 stubCall
.addArgument(regT1
, regT0
); // save last result registers.
102 stubCall
.call(timeoutCheckRegister
);
103 stubCall
.getArgument(0, regT1
, regT0
); // reload last result registers.
104 skipTimeout
.link(this);
107 void JIT::emitTimeoutCheck()
109 Jump skipTimeout
= branchSub32(NonZero
, Imm32(1), timeoutCheckRegister
);
110 JITStubCall(this, cti_timeout_check
).call(timeoutCheckRegister
);
111 skipTimeout
.link(this);
113 killLastResultRegister();
117 #define NEXT_OPCODE(name) \
118 m_bytecodeIndex += OPCODE_LENGTH(name); \
121 #if USE(JSVALUE32_64)
122 #define DEFINE_BINARY_OP(name) \
124 JITStubCall stubCall(this, cti_##name); \
125 stubCall.addArgument(currentInstruction[2].u.operand); \
126 stubCall.addArgument(currentInstruction[3].u.operand); \
127 stubCall.call(currentInstruction[1].u.operand); \
131 #define DEFINE_UNARY_OP(name) \
133 JITStubCall stubCall(this, cti_##name); \
134 stubCall.addArgument(currentInstruction[2].u.operand); \
135 stubCall.call(currentInstruction[1].u.operand); \
139 #else // USE(JSVALUE32_64)
141 #define DEFINE_BINARY_OP(name) \
143 JITStubCall stubCall(this, cti_##name); \
144 stubCall.addArgument(currentInstruction[2].u.operand, regT2); \
145 stubCall.addArgument(currentInstruction[3].u.operand, regT2); \
146 stubCall.call(currentInstruction[1].u.operand); \
150 #define DEFINE_UNARY_OP(name) \
152 JITStubCall stubCall(this, cti_##name); \
153 stubCall.addArgument(currentInstruction[2].u.operand, regT2); \
154 stubCall.call(currentInstruction[1].u.operand); \
157 #endif // USE(JSVALUE32_64)
159 #define DEFINE_OP(name) \
161 emit_##name(currentInstruction); \
165 #define DEFINE_SLOWCASE_OP(name) \
167 emitSlow_##name(currentInstruction, iter); \
171 void JIT::privateCompileMainPass()
173 Instruction
* instructionsBegin
= m_codeBlock
->instructions().begin();
174 unsigned instructionCount
= m_codeBlock
->instructions().size();
176 m_propertyAccessInstructionIndex
= 0;
177 m_globalResolveInfoIndex
= 0;
178 m_callLinkInfoIndex
= 0;
180 for (m_bytecodeIndex
= 0; m_bytecodeIndex
< instructionCount
; ) {
181 Instruction
* currentInstruction
= instructionsBegin
+ m_bytecodeIndex
;
182 ASSERT_WITH_MESSAGE(m_interpreter
->isOpcode(currentInstruction
->u
.opcode
), "privateCompileMainPass gone bad @ %d", m_bytecodeIndex
);
184 #if ENABLE(OPCODE_SAMPLING)
185 if (m_bytecodeIndex
> 0) // Avoid the overhead of sampling op_enter twice.
186 sampleInstruction(currentInstruction
);
189 #if !USE(JSVALUE32_64)
190 if (m_labels
[m_bytecodeIndex
].isUsed())
191 killLastResultRegister();
194 m_labels
[m_bytecodeIndex
] = label();
196 switch (m_interpreter
->getOpcodeID(currentInstruction
->u
.opcode
)) {
197 DEFINE_BINARY_OP(op_del_by_val
)
198 #if !USE(JSVALUE32_64)
199 DEFINE_BINARY_OP(op_div
)
201 DEFINE_BINARY_OP(op_in
)
202 DEFINE_BINARY_OP(op_less
)
203 DEFINE_BINARY_OP(op_lesseq
)
204 DEFINE_BINARY_OP(op_urshift
)
205 DEFINE_UNARY_OP(op_get_pnames
)
206 DEFINE_UNARY_OP(op_is_boolean
)
207 DEFINE_UNARY_OP(op_is_function
)
208 DEFINE_UNARY_OP(op_is_number
)
209 DEFINE_UNARY_OP(op_is_object
)
210 DEFINE_UNARY_OP(op_is_string
)
211 DEFINE_UNARY_OP(op_is_undefined
)
212 #if !USE(JSVALUE32_64)
213 DEFINE_UNARY_OP(op_negate
)
215 DEFINE_UNARY_OP(op_typeof
)
223 DEFINE_OP(op_call_eval
)
224 DEFINE_OP(op_call_varargs
)
226 DEFINE_OP(op_construct
)
227 DEFINE_OP(op_construct_verify
)
228 DEFINE_OP(op_convert_this
)
229 DEFINE_OP(op_init_arguments
)
230 DEFINE_OP(op_create_arguments
)
232 DEFINE_OP(op_del_by_id
)
233 #if USE(JSVALUE32_64)
238 DEFINE_OP(op_enter_with_activation
)
240 DEFINE_OP(op_eq_null
)
241 DEFINE_OP(op_get_by_id
)
242 DEFINE_OP(op_get_by_val
)
243 DEFINE_OP(op_get_global_var
)
244 DEFINE_OP(op_get_scoped_var
)
245 DEFINE_OP(op_instanceof
)
246 DEFINE_OP(op_jeq_null
)
249 DEFINE_OP(op_jmp_scopes
)
250 DEFINE_OP(op_jneq_null
)
251 DEFINE_OP(op_jneq_ptr
)
253 DEFINE_OP(op_jnlesseq
)
256 DEFINE_OP(op_load_varargs
)
258 DEFINE_OP(op_loop_if_less
)
259 DEFINE_OP(op_loop_if_lesseq
)
260 DEFINE_OP(op_loop_if_true
)
262 DEFINE_OP(op_method_check
)
266 #if USE(JSVALUE32_64)
270 DEFINE_OP(op_neq_null
)
271 DEFINE_OP(op_new_array
)
272 DEFINE_OP(op_new_error
)
273 DEFINE_OP(op_new_func
)
274 DEFINE_OP(op_new_func_exp
)
275 DEFINE_OP(op_new_object
)
276 DEFINE_OP(op_new_regexp
)
277 DEFINE_OP(op_next_pname
)
279 DEFINE_OP(op_nstricteq
)
280 DEFINE_OP(op_pop_scope
)
281 DEFINE_OP(op_post_dec
)
282 DEFINE_OP(op_post_inc
)
283 DEFINE_OP(op_pre_dec
)
284 DEFINE_OP(op_pre_inc
)
285 DEFINE_OP(op_profile_did_call
)
286 DEFINE_OP(op_profile_will_call
)
287 DEFINE_OP(op_push_new_scope
)
288 DEFINE_OP(op_push_scope
)
289 DEFINE_OP(op_put_by_id
)
290 DEFINE_OP(op_put_by_index
)
291 DEFINE_OP(op_put_by_val
)
292 DEFINE_OP(op_put_getter
)
293 DEFINE_OP(op_put_global_var
)
294 DEFINE_OP(op_put_scoped_var
)
295 DEFINE_OP(op_put_setter
)
296 DEFINE_OP(op_resolve
)
297 DEFINE_OP(op_resolve_base
)
298 DEFINE_OP(op_resolve_global
)
299 DEFINE_OP(op_resolve_skip
)
300 DEFINE_OP(op_resolve_with_base
)
305 DEFINE_OP(op_stricteq
)
307 DEFINE_OP(op_switch_char
)
308 DEFINE_OP(op_switch_imm
)
309 DEFINE_OP(op_switch_string
)
310 DEFINE_OP(op_tear_off_activation
)
311 DEFINE_OP(op_tear_off_arguments
)
313 DEFINE_OP(op_to_jsnumber
)
314 DEFINE_OP(op_to_primitive
)
316 case op_get_array_length
:
317 case op_get_by_id_chain
:
318 case op_get_by_id_generic
:
319 case op_get_by_id_proto
:
320 case op_get_by_id_proto_list
:
321 case op_get_by_id_self
:
322 case op_get_by_id_self_list
:
323 case op_get_string_length
:
324 case op_put_by_id_generic
:
325 case op_put_by_id_replace
:
326 case op_put_by_id_transition
:
327 ASSERT_NOT_REACHED();
331 ASSERT(m_propertyAccessInstructionIndex
== m_codeBlock
->numberOfStructureStubInfos());
332 ASSERT(m_callLinkInfoIndex
== m_codeBlock
->numberOfCallLinkInfos());
335 // Reset this, in order to guard its use with ASSERTs.
336 m_bytecodeIndex
= (unsigned)-1;
341 void JIT::privateCompileLinkPass()
343 unsigned jmpTableCount
= m_jmpTable
.size();
344 for (unsigned i
= 0; i
< jmpTableCount
; ++i
)
345 m_jmpTable
[i
].from
.linkTo(m_labels
[m_jmpTable
[i
].toBytecodeIndex
], this);
349 void JIT::privateCompileSlowCases()
351 Instruction
* instructionsBegin
= m_codeBlock
->instructions().begin();
353 m_propertyAccessInstructionIndex
= 0;
354 #if USE(JSVALUE32_64)
355 m_globalResolveInfoIndex
= 0;
357 m_callLinkInfoIndex
= 0;
359 for (Vector
<SlowCaseEntry
>::iterator iter
= m_slowCases
.begin(); iter
!= m_slowCases
.end();) {
360 #if !USE(JSVALUE32_64)
361 killLastResultRegister();
364 m_bytecodeIndex
= iter
->to
;
366 unsigned firstTo
= m_bytecodeIndex
;
368 Instruction
* currentInstruction
= instructionsBegin
+ m_bytecodeIndex
;
370 switch (m_interpreter
->getOpcodeID(currentInstruction
->u
.opcode
)) {
371 DEFINE_SLOWCASE_OP(op_add
)
372 DEFINE_SLOWCASE_OP(op_bitand
)
373 DEFINE_SLOWCASE_OP(op_bitnot
)
374 DEFINE_SLOWCASE_OP(op_bitor
)
375 DEFINE_SLOWCASE_OP(op_bitxor
)
376 DEFINE_SLOWCASE_OP(op_call
)
377 DEFINE_SLOWCASE_OP(op_call_eval
)
378 DEFINE_SLOWCASE_OP(op_call_varargs
)
379 DEFINE_SLOWCASE_OP(op_construct
)
380 DEFINE_SLOWCASE_OP(op_construct_verify
)
381 DEFINE_SLOWCASE_OP(op_convert_this
)
382 #if USE(JSVALUE32_64)
383 DEFINE_SLOWCASE_OP(op_div
)
385 DEFINE_SLOWCASE_OP(op_eq
)
386 DEFINE_SLOWCASE_OP(op_get_by_id
)
387 DEFINE_SLOWCASE_OP(op_get_by_val
)
388 DEFINE_SLOWCASE_OP(op_instanceof
)
389 DEFINE_SLOWCASE_OP(op_jfalse
)
390 DEFINE_SLOWCASE_OP(op_jnless
)
391 DEFINE_SLOWCASE_OP(op_jnlesseq
)
392 DEFINE_SLOWCASE_OP(op_jtrue
)
393 DEFINE_SLOWCASE_OP(op_loop_if_less
)
394 DEFINE_SLOWCASE_OP(op_loop_if_lesseq
)
395 DEFINE_SLOWCASE_OP(op_loop_if_true
)
396 DEFINE_SLOWCASE_OP(op_lshift
)
397 DEFINE_SLOWCASE_OP(op_method_check
)
398 DEFINE_SLOWCASE_OP(op_mod
)
399 DEFINE_SLOWCASE_OP(op_mul
)
400 #if USE(JSVALUE32_64)
401 DEFINE_SLOWCASE_OP(op_negate
)
403 DEFINE_SLOWCASE_OP(op_neq
)
404 DEFINE_SLOWCASE_OP(op_not
)
405 DEFINE_SLOWCASE_OP(op_nstricteq
)
406 DEFINE_SLOWCASE_OP(op_post_dec
)
407 DEFINE_SLOWCASE_OP(op_post_inc
)
408 DEFINE_SLOWCASE_OP(op_pre_dec
)
409 DEFINE_SLOWCASE_OP(op_pre_inc
)
410 DEFINE_SLOWCASE_OP(op_put_by_id
)
411 DEFINE_SLOWCASE_OP(op_put_by_val
)
412 #if USE(JSVALUE32_64)
413 DEFINE_SLOWCASE_OP(op_resolve_global
)
415 DEFINE_SLOWCASE_OP(op_rshift
)
416 DEFINE_SLOWCASE_OP(op_stricteq
)
417 DEFINE_SLOWCASE_OP(op_sub
)
418 DEFINE_SLOWCASE_OP(op_to_jsnumber
)
419 DEFINE_SLOWCASE_OP(op_to_primitive
)
421 ASSERT_NOT_REACHED();
424 ASSERT_WITH_MESSAGE(iter
== m_slowCases
.end() || firstTo
!= iter
->to
,"Not enough jumps linked in slow case codegen.");
425 ASSERT_WITH_MESSAGE(firstTo
== (iter
- 1)->to
, "Too many jumps linked in slow case codegen.");
427 emitJumpSlowToHot(jump(), 0);
430 #if ENABLE(JIT_OPTIMIZE_PROPERTY_ACCESS)
431 ASSERT(m_propertyAccessInstructionIndex
== m_codeBlock
->numberOfStructureStubInfos());
433 ASSERT(m_callLinkInfoIndex
== m_codeBlock
->numberOfCallLinkInfos());
436 // Reset this, in order to guard its use with ASSERTs.
437 m_bytecodeIndex
= (unsigned)-1;
441 void JIT::privateCompile()
443 sampleCodeBlock(m_codeBlock
);
444 #if ENABLE(OPCODE_SAMPLING)
445 sampleInstruction(m_codeBlock
->instructions().begin());
448 // Could use a pop_m, but would need to offset the following instruction if so.
449 preserveReturnAddressAfterCall(regT2
);
450 emitPutToCallFrameHeader(regT2
, RegisterFile::ReturnPC
);
452 Jump slowRegisterFileCheck
;
453 Label afterRegisterFileCheck
;
454 if (m_codeBlock
->codeType() == FunctionCode
) {
455 // In the case of a fast linked call, we do not set this up in the caller.
456 emitPutImmediateToCallFrameHeader(m_codeBlock
, RegisterFile::CodeBlock
);
458 peek(regT0
, OBJECT_OFFSETOF(JITStackFrame
, registerFile
) / sizeof (void*));
459 addPtr(Imm32(m_codeBlock
->m_numCalleeRegisters
* sizeof(Register
)), callFrameRegister
, regT1
);
461 slowRegisterFileCheck
= branchPtr(Above
, regT1
, Address(regT0
, OBJECT_OFFSETOF(RegisterFile
, m_end
)));
462 afterRegisterFileCheck
= label();
465 privateCompileMainPass();
466 privateCompileLinkPass();
467 privateCompileSlowCases();
469 if (m_codeBlock
->codeType() == FunctionCode
) {
470 slowRegisterFileCheck
.link(this);
472 JITStubCall(this, cti_register_file_check
).call();
474 m_bytecodeIndex
= (unsigned)-1; // Reset this, in order to guard its use with ASSERTs.
476 jump(afterRegisterFileCheck
);
479 ASSERT(m_jmpTable
.isEmpty());
481 LinkBuffer
patchBuffer(this, m_globalData
->executableAllocator
.poolForSize(m_assembler
.size()));
483 // Translate vPC offsets into addresses in JIT generated code, for switch tables.
484 for (unsigned i
= 0; i
< m_switches
.size(); ++i
) {
485 SwitchRecord record
= m_switches
[i
];
486 unsigned bytecodeIndex
= record
.bytecodeIndex
;
488 if (record
.type
!= SwitchRecord::String
) {
489 ASSERT(record
.type
== SwitchRecord::Immediate
|| record
.type
== SwitchRecord::Character
);
490 ASSERT(record
.jumpTable
.simpleJumpTable
->branchOffsets
.size() == record
.jumpTable
.simpleJumpTable
->ctiOffsets
.size());
492 record
.jumpTable
.simpleJumpTable
->ctiDefault
= patchBuffer
.locationOf(m_labels
[bytecodeIndex
+ 3 + record
.defaultOffset
]);
494 for (unsigned j
= 0; j
< record
.jumpTable
.simpleJumpTable
->branchOffsets
.size(); ++j
) {
495 unsigned offset
= record
.jumpTable
.simpleJumpTable
->branchOffsets
[j
];
496 record
.jumpTable
.simpleJumpTable
->ctiOffsets
[j
] = offset
? patchBuffer
.locationOf(m_labels
[bytecodeIndex
+ 3 + offset
]) : record
.jumpTable
.simpleJumpTable
->ctiDefault
;
499 ASSERT(record
.type
== SwitchRecord::String
);
501 record
.jumpTable
.stringJumpTable
->ctiDefault
= patchBuffer
.locationOf(m_labels
[bytecodeIndex
+ 3 + record
.defaultOffset
]);
503 StringJumpTable::StringOffsetTable::iterator end
= record
.jumpTable
.stringJumpTable
->offsetTable
.end();
504 for (StringJumpTable::StringOffsetTable::iterator it
= record
.jumpTable
.stringJumpTable
->offsetTable
.begin(); it
!= end
; ++it
) {
505 unsigned offset
= it
->second
.branchOffset
;
506 it
->second
.ctiOffset
= offset
? patchBuffer
.locationOf(m_labels
[bytecodeIndex
+ 3 + offset
]) : record
.jumpTable
.stringJumpTable
->ctiDefault
;
511 for (size_t i
= 0; i
< m_codeBlock
->numberOfExceptionHandlers(); ++i
) {
512 HandlerInfo
& handler
= m_codeBlock
->exceptionHandler(i
);
513 handler
.nativeCode
= patchBuffer
.locationOf(m_labels
[handler
.target
]);
516 for (Vector
<CallRecord
>::iterator iter
= m_calls
.begin(); iter
!= m_calls
.end(); ++iter
) {
518 patchBuffer
.link(iter
->from
, FunctionPtr(iter
->to
));
521 if (m_codeBlock
->hasExceptionInfo()) {
522 m_codeBlock
->callReturnIndexVector().reserveCapacity(m_calls
.size());
523 for (Vector
<CallRecord
>::iterator iter
= m_calls
.begin(); iter
!= m_calls
.end(); ++iter
)
524 m_codeBlock
->callReturnIndexVector().append(CallReturnOffsetToBytecodeIndex(patchBuffer
.returnAddressOffset(iter
->from
), iter
->bytecodeIndex
));
527 // Link absolute addresses for jsr
528 for (Vector
<JSRInfo
>::iterator iter
= m_jsrSites
.begin(); iter
!= m_jsrSites
.end(); ++iter
)
529 patchBuffer
.patch(iter
->storeLocation
, patchBuffer
.locationOf(iter
->target
).executableAddress());
531 #if ENABLE(JIT_OPTIMIZE_PROPERTY_ACCESS)
532 for (unsigned i
= 0; i
< m_codeBlock
->numberOfStructureStubInfos(); ++i
) {
533 StructureStubInfo
& info
= m_codeBlock
->structureStubInfo(i
);
534 info
.callReturnLocation
= patchBuffer
.locationOf(m_propertyAccessCompilationInfo
[i
].callReturnLocation
);
535 info
.hotPathBegin
= patchBuffer
.locationOf(m_propertyAccessCompilationInfo
[i
].hotPathBegin
);
538 #if ENABLE(JIT_OPTIMIZE_CALL)
539 for (unsigned i
= 0; i
< m_codeBlock
->numberOfCallLinkInfos(); ++i
) {
540 CallLinkInfo
& info
= m_codeBlock
->callLinkInfo(i
);
541 info
.ownerCodeBlock
= m_codeBlock
;
542 info
.callReturnLocation
= patchBuffer
.locationOfNearCall(m_callStructureStubCompilationInfo
[i
].callReturnLocation
);
543 info
.hotPathBegin
= patchBuffer
.locationOf(m_callStructureStubCompilationInfo
[i
].hotPathBegin
);
544 info
.hotPathOther
= patchBuffer
.locationOfNearCall(m_callStructureStubCompilationInfo
[i
].hotPathOther
);
547 unsigned methodCallCount
= m_methodCallCompilationInfo
.size();
548 m_codeBlock
->addMethodCallLinkInfos(methodCallCount
);
549 for (unsigned i
= 0; i
< methodCallCount
; ++i
) {
550 MethodCallLinkInfo
& info
= m_codeBlock
->methodCallLinkInfo(i
);
551 info
.structureLabel
= patchBuffer
.locationOf(m_methodCallCompilationInfo
[i
].structureToCompare
);
552 info
.callReturnLocation
= m_codeBlock
->structureStubInfo(m_methodCallCompilationInfo
[i
].propertyAccessIndex
).callReturnLocation
;
555 m_codeBlock
->setJITCode(patchBuffer
.finalizeCode());
558 #if !USE(JSVALUE32_64)
559 void JIT::emitGetVariableObjectRegister(RegisterID variableObject
, int index
, RegisterID dst
)
561 loadPtr(Address(variableObject
, OBJECT_OFFSETOF(JSVariableObject
, d
)), dst
);
562 loadPtr(Address(dst
, OBJECT_OFFSETOF(JSVariableObject::JSVariableObjectData
, registers
)), dst
);
563 loadPtr(Address(dst
, index
* sizeof(Register
)), dst
);
566 void JIT::emitPutVariableObjectRegister(RegisterID src
, RegisterID variableObject
, int index
)
568 loadPtr(Address(variableObject
, OBJECT_OFFSETOF(JSVariableObject
, d
)), variableObject
);
569 loadPtr(Address(variableObject
, OBJECT_OFFSETOF(JSVariableObject::JSVariableObjectData
, registers
)), variableObject
);
570 storePtr(src
, Address(variableObject
, index
* sizeof(Register
)));
574 #if ENABLE(JIT_OPTIMIZE_CALL)
575 void JIT::unlinkCall(CallLinkInfo
* callLinkInfo
)
577 // When the JSFunction is deleted the pointer embedded in the instruction stream will no longer be valid
578 // (and, if a new JSFunction happened to be constructed at the same location, we could get a false positive
579 // match). Reset the check so it no longer matches.
580 RepatchBuffer
repatchBuffer(callLinkInfo
->ownerCodeBlock
);
581 #if USE(JSVALUE32_64)
582 repatchBuffer
.repatch(callLinkInfo
->hotPathBegin
, 0);
584 repatchBuffer
.repatch(callLinkInfo
->hotPathBegin
, JSValue::encode(JSValue()));
588 void JIT::linkCall(JSFunction
* callee
, CodeBlock
* callerCodeBlock
, CodeBlock
* calleeCodeBlock
, JITCode
& code
, CallLinkInfo
* callLinkInfo
, int callerArgCount
, JSGlobalData
* globalData
)
590 ASSERT(calleeCodeBlock
);
591 RepatchBuffer
repatchBuffer(callerCodeBlock
);
593 // Currently we only link calls with the exact number of arguments.
594 // If this is a native call calleeCodeBlock is null so the number of parameters is unimportant
595 if (callerArgCount
== calleeCodeBlock
->m_numParameters
|| calleeCodeBlock
->codeType() == NativeCode
) {
596 ASSERT(!callLinkInfo
->isLinked());
599 calleeCodeBlock
->addCaller(callLinkInfo
);
601 repatchBuffer
.repatch(callLinkInfo
->hotPathBegin
, callee
);
602 repatchBuffer
.relink(callLinkInfo
->hotPathOther
, code
.addressForCall());
605 // patch the call so we do not continue to try to link.
606 repatchBuffer
.relink(callLinkInfo
->callReturnLocation
, globalData
->jitStubs
.ctiVirtualCall());
608 #endif // ENABLE(JIT_OPTIMIZE_CALL)
612 #endif // ENABLE(JIT)