JIT.cpp 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966
  1. /*
  2. * Copyright (C) 2008, 2009, 2012, 2013 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. #include "config.h"
  26. #if ENABLE(JIT)
  27. #if !(ENABLE(DETACHED_JIT) && !BUILDING_DETACHED_JIT)
  28. #include "JIT.h"
  29. // This probably does not belong here; adding here for now as a quick Windows build fix.
  30. #if ENABLE(ASSEMBLER) && CPU(X86) && !OS(MAC_OS_X)
  31. #include "MacroAssembler.h"
  32. JSC::MacroAssemblerX86Common::SSE2CheckState JSC::MacroAssemblerX86Common::s_sse2CheckState = NotCheckedSSE2;
  33. #endif
  34. #include "CodeBlock.h"
  35. #include <wtf/CryptographicallyRandomNumber.h>
  36. #include "DFGNode.h" // for DFG_SUCCESS_STATS
  37. #include "Interpreter.h"
  38. #include "JITInlines.h"
  39. #include "JITStubCall.h"
  40. #include "JSArray.h"
  41. #include "JSFunction.h"
  42. #include "LinkBuffer.h"
  43. #include "Operations.h"
  44. #include "RepatchBuffer.h"
  45. #include "ResultType.h"
  46. #include "SamplingTool.h"
  47. using namespace std;
  48. namespace JSC {
  49. void ctiPatchNearCallByReturnAddress(CodeBlock* codeblock, ReturnAddressPtr returnAddress, MacroAssemblerCodePtr newCalleeFunction)
  50. {
  51. RepatchBuffer repatchBuffer(codeblock);
  52. repatchBuffer.relinkNearCallerToTrampoline(returnAddress, newCalleeFunction);
  53. }
  54. void ctiPatchCallByReturnAddress(CodeBlock* codeblock, ReturnAddressPtr returnAddress, MacroAssemblerCodePtr newCalleeFunction)
  55. {
  56. RepatchBuffer repatchBuffer(codeblock);
  57. repatchBuffer.relinkCallerToTrampoline(returnAddress, newCalleeFunction);
  58. }
  59. void ctiPatchCallByReturnAddress(CodeBlock* codeblock, ReturnAddressPtr returnAddress, FunctionPtr newCalleeFunction)
  60. {
  61. RepatchBuffer repatchBuffer(codeblock);
  62. repatchBuffer.relinkCallerToFunction(returnAddress, newCalleeFunction);
  63. }
  64. JIT::JIT(VM* vm, CodeBlock* codeBlock)
  65. : m_interpreter(vm->interpreter)
  66. , m_vm(vm)
  67. , m_codeBlock(codeBlock)
  68. , m_labels(codeBlock ? codeBlock->numberOfInstructions() : 0)
  69. , m_bytecodeOffset((unsigned)-1)
  70. , m_propertyAccessInstructionIndex(UINT_MAX)
  71. , m_byValInstructionIndex(UINT_MAX)
  72. , m_globalResolveInfoIndex(UINT_MAX)
  73. , m_callLinkInfoIndex(UINT_MAX)
  74. #if USE(JSVALUE32_64)
  75. , m_jumpTargetIndex(0)
  76. , m_mappedBytecodeOffset((unsigned)-1)
  77. , m_mappedVirtualRegisterIndex(JSStack::ReturnPC)
  78. , m_mappedTag((RegisterID)-1)
  79. , m_mappedPayload((RegisterID)-1)
  80. #else
  81. , m_lastResultBytecodeRegister(std::numeric_limits<int>::max())
  82. , m_jumpTargetsPosition(0)
  83. #endif
  84. , m_randomGenerator(cryptographicallyRandomNumber())
  85. #if ENABLE(VALUE_PROFILER)
  86. , m_canBeOptimized(false)
  87. , m_shouldEmitProfiling(false)
  88. #endif
  89. {
  90. }
  91. #if ENABLE(DFG_JIT)
  92. void JIT::emitEnterOptimizationCheck()
  93. {
  94. if (!canBeOptimized())
  95. return;
  96. Jump skipOptimize = branchAdd32(Signed, TrustedImm32(Options::executionCounterIncrementForReturn()), AbsoluteAddress(m_codeBlock->addressOfJITExecuteCounter()));
  97. JITStubCall stubCall(this, cti_optimize);
  98. stubCall.addArgument(TrustedImm32(m_bytecodeOffset));
  99. ASSERT(!m_bytecodeOffset);
  100. stubCall.call();
  101. skipOptimize.link(this);
  102. }
  103. #endif
  104. #define NEXT_OPCODE(name) \
  105. m_bytecodeOffset += OPCODE_LENGTH(name); \
  106. break;
  107. #if USE(JSVALUE32_64)
  108. #define DEFINE_BINARY_OP(name) \
  109. case name: { \
  110. JITStubCall stubCall(this, cti_##name); \
  111. stubCall.addArgument(currentInstruction[2].u.operand); \
  112. stubCall.addArgument(currentInstruction[3].u.operand); \
  113. stubCall.call(currentInstruction[1].u.operand); \
  114. NEXT_OPCODE(name); \
  115. }
  116. #define DEFINE_UNARY_OP(name) \
  117. case name: { \
  118. JITStubCall stubCall(this, cti_##name); \
  119. stubCall.addArgument(currentInstruction[2].u.operand); \
  120. stubCall.call(currentInstruction[1].u.operand); \
  121. NEXT_OPCODE(name); \
  122. }
  123. #else // USE(JSVALUE32_64)
  124. #define DEFINE_BINARY_OP(name) \
  125. case name: { \
  126. JITStubCall stubCall(this, cti_##name); \
  127. stubCall.addArgument(currentInstruction[2].u.operand, regT2); \
  128. stubCall.addArgument(currentInstruction[3].u.operand, regT2); \
  129. stubCall.call(currentInstruction[1].u.operand); \
  130. NEXT_OPCODE(name); \
  131. }
  132. #define DEFINE_UNARY_OP(name) \
  133. case name: { \
  134. JITStubCall stubCall(this, cti_##name); \
  135. stubCall.addArgument(currentInstruction[2].u.operand, regT2); \
  136. stubCall.call(currentInstruction[1].u.operand); \
  137. NEXT_OPCODE(name); \
  138. }
  139. #endif // USE(JSVALUE32_64)
  140. #define DEFINE_OP(name) \
  141. case name: { \
  142. emit_##name(currentInstruction); \
  143. NEXT_OPCODE(name); \
  144. }
  145. #define DEFINE_SLOWCASE_OP(name) \
  146. case name: { \
  147. emitSlow_##name(currentInstruction, iter); \
  148. NEXT_OPCODE(name); \
  149. }
  150. void JIT::privateCompileMainPass()
  151. {
  152. Instruction* instructionsBegin = m_codeBlock->instructions().begin();
  153. unsigned instructionCount = m_codeBlock->instructions().size();
  154. m_globalResolveInfoIndex = 0;
  155. m_callLinkInfoIndex = 0;
  156. for (m_bytecodeOffset = 0; m_bytecodeOffset < instructionCount; ) {
  157. #if !(ENABLE(DETACHED_JIT) && BUILDING_DETACHED_JIT)
  158. if (m_disassembler)
  159. m_disassembler->setForBytecodeMainPath(m_bytecodeOffset, label());
  160. #else
  161. #pragma message "re-enable profiling support"
  162. #endif
  163. Instruction* currentInstruction = instructionsBegin + m_bytecodeOffset;
  164. ASSERT_WITH_MESSAGE(m_interpreter->isOpcode(currentInstruction->u.opcode), "privateCompileMainPass gone bad @ %d", m_bytecodeOffset);
  165. #if ENABLE(OPCODE_SAMPLING)
  166. if (m_bytecodeOffset > 0) // Avoid the overhead of sampling op_enter twice.
  167. sampleInstruction(currentInstruction);
  168. #endif
  169. #if USE(JSVALUE64)
  170. if (atJumpTarget())
  171. killLastResultRegister();
  172. #endif
  173. m_labels[m_bytecodeOffset] = label();
  174. #if ENABLE(JIT_VERBOSE)
  175. dataLogF("Old JIT emitting code for bc#%u at offset 0x%lx.\n", m_bytecodeOffset, (long)debugOffset());
  176. #endif
  177. OpcodeID opcodeID = m_interpreter->getOpcodeID(currentInstruction->u.opcode);
  178. #pragma message ("re-enable profiling support")
  179. #if !(ENABLE(DETACHED_JIT) && BUILDING_DETACHED_JIT)
  180. if (m_compilation && opcodeID != op_call_put_result) {
  181. add64(
  182. TrustedImm32(1),
  183. AbsoluteAddress(m_compilation->executionCounterFor(Profiler::OriginStack(Profiler::Origin(
  184. m_compilation->bytecodes(), m_bytecodeOffset)))->address()));
  185. }
  186. #endif
  187. switch (opcodeID) {
  188. DEFINE_BINARY_OP(op_del_by_val)
  189. DEFINE_BINARY_OP(op_in)
  190. DEFINE_BINARY_OP(op_less)
  191. DEFINE_BINARY_OP(op_lesseq)
  192. DEFINE_BINARY_OP(op_greater)
  193. DEFINE_BINARY_OP(op_greatereq)
  194. DEFINE_UNARY_OP(op_is_function)
  195. DEFINE_UNARY_OP(op_is_object)
  196. DEFINE_UNARY_OP(op_typeof)
  197. DEFINE_OP(op_add)
  198. DEFINE_OP(op_bitand)
  199. DEFINE_OP(op_bitor)
  200. DEFINE_OP(op_bitxor)
  201. DEFINE_OP(op_call)
  202. DEFINE_OP(op_call_eval)
  203. DEFINE_OP(op_call_varargs)
  204. DEFINE_OP(op_catch)
  205. DEFINE_OP(op_construct)
  206. DEFINE_OP(op_get_callee)
  207. DEFINE_OP(op_create_this)
  208. DEFINE_OP(op_convert_this)
  209. DEFINE_OP(op_init_lazy_reg)
  210. DEFINE_OP(op_create_arguments)
  211. DEFINE_OP(op_debug)
  212. DEFINE_OP(op_del_by_id)
  213. DEFINE_OP(op_div)
  214. DEFINE_OP(op_end)
  215. DEFINE_OP(op_enter)
  216. DEFINE_OP(op_create_activation)
  217. DEFINE_OP(op_eq)
  218. DEFINE_OP(op_eq_null)
  219. case op_get_by_id_out_of_line:
  220. case op_get_array_length:
  221. DEFINE_OP(op_get_by_id)
  222. DEFINE_OP(op_get_arguments_length)
  223. DEFINE_OP(op_get_by_val)
  224. DEFINE_OP(op_get_argument_by_val)
  225. DEFINE_OP(op_get_by_pname)
  226. DEFINE_OP(op_get_pnames)
  227. DEFINE_OP(op_check_has_instance)
  228. DEFINE_OP(op_instanceof)
  229. DEFINE_OP(op_is_undefined)
  230. DEFINE_OP(op_is_boolean)
  231. DEFINE_OP(op_is_number)
  232. DEFINE_OP(op_is_string)
  233. DEFINE_OP(op_jeq_null)
  234. DEFINE_OP(op_jfalse)
  235. DEFINE_OP(op_jmp)
  236. DEFINE_OP(op_jneq_null)
  237. DEFINE_OP(op_jneq_ptr)
  238. DEFINE_OP(op_jless)
  239. DEFINE_OP(op_jlesseq)
  240. DEFINE_OP(op_jgreater)
  241. DEFINE_OP(op_jgreatereq)
  242. DEFINE_OP(op_jnless)
  243. DEFINE_OP(op_jnlesseq)
  244. DEFINE_OP(op_jngreater)
  245. DEFINE_OP(op_jngreatereq)
  246. DEFINE_OP(op_jtrue)
  247. DEFINE_OP(op_loop_hint)
  248. DEFINE_OP(op_lshift)
  249. DEFINE_OP(op_mod)
  250. DEFINE_OP(op_mov)
  251. DEFINE_OP(op_mul)
  252. DEFINE_OP(op_negate)
  253. DEFINE_OP(op_neq)
  254. DEFINE_OP(op_neq_null)
  255. DEFINE_OP(op_new_array)
  256. DEFINE_OP(op_new_array_with_size)
  257. DEFINE_OP(op_new_array_buffer)
  258. DEFINE_OP(op_new_func)
  259. DEFINE_OP(op_new_func_exp)
  260. DEFINE_OP(op_new_object)
  261. DEFINE_OP(op_new_regexp)
  262. DEFINE_OP(op_next_pname)
  263. DEFINE_OP(op_not)
  264. DEFINE_OP(op_nstricteq)
  265. DEFINE_OP(op_pop_scope)
  266. DEFINE_OP(op_dec)
  267. DEFINE_OP(op_inc)
  268. DEFINE_OP(op_profile_did_call)
  269. DEFINE_OP(op_profile_will_call)
  270. DEFINE_OP(op_push_name_scope)
  271. DEFINE_OP(op_push_with_scope)
  272. case op_put_by_id_out_of_line:
  273. case op_put_by_id_transition_direct:
  274. case op_put_by_id_transition_normal:
  275. case op_put_by_id_transition_direct_out_of_line:
  276. case op_put_by_id_transition_normal_out_of_line:
  277. DEFINE_OP(op_put_by_id)
  278. DEFINE_OP(op_put_by_index)
  279. DEFINE_OP(op_put_by_val)
  280. DEFINE_OP(op_put_getter_setter)
  281. case op_init_global_const_nop:
  282. NEXT_OPCODE(op_init_global_const_nop);
  283. DEFINE_OP(op_init_global_const)
  284. DEFINE_OP(op_init_global_const_check)
  285. case op_resolve_global_property:
  286. case op_resolve_global_var:
  287. case op_resolve_scoped_var:
  288. case op_resolve_scoped_var_on_top_scope:
  289. case op_resolve_scoped_var_with_top_scope_check:
  290. DEFINE_OP(op_resolve)
  291. case op_resolve_base_to_global:
  292. case op_resolve_base_to_global_dynamic:
  293. case op_resolve_base_to_scope:
  294. case op_resolve_base_to_scope_with_top_scope_check:
  295. DEFINE_OP(op_resolve_base)
  296. case op_put_to_base_variable:
  297. DEFINE_OP(op_put_to_base)
  298. DEFINE_OP(op_resolve_with_base)
  299. DEFINE_OP(op_resolve_with_this)
  300. DEFINE_OP(op_ret)
  301. DEFINE_OP(op_call_put_result)
  302. DEFINE_OP(op_ret_object_or_this)
  303. DEFINE_OP(op_rshift)
  304. DEFINE_OP(op_urshift)
  305. DEFINE_OP(op_strcat)
  306. DEFINE_OP(op_stricteq)
  307. DEFINE_OP(op_sub)
  308. DEFINE_OP(op_switch_char)
  309. DEFINE_OP(op_switch_imm)
  310. DEFINE_OP(op_switch_string)
  311. DEFINE_OP(op_tear_off_activation)
  312. DEFINE_OP(op_tear_off_arguments)
  313. DEFINE_OP(op_throw)
  314. DEFINE_OP(op_throw_static_error)
  315. DEFINE_OP(op_to_number)
  316. DEFINE_OP(op_to_primitive)
  317. DEFINE_OP(op_get_scoped_var)
  318. DEFINE_OP(op_put_scoped_var)
  319. case op_get_by_id_chain:
  320. case op_get_by_id_generic:
  321. case op_get_by_id_proto:
  322. case op_get_by_id_self:
  323. case op_get_by_id_getter_chain:
  324. case op_get_by_id_getter_proto:
  325. case op_get_by_id_getter_self:
  326. case op_get_by_id_custom_chain:
  327. case op_get_by_id_custom_proto:
  328. case op_get_by_id_custom_self:
  329. case op_get_string_length:
  330. case op_put_by_id_generic:
  331. case op_put_by_id_replace:
  332. case op_put_by_id_transition:
  333. RELEASE_ASSERT_NOT_REACHED();
  334. }
  335. }
  336. RELEASE_ASSERT(m_callLinkInfoIndex == m_callStructureStubCompilationInfo.size());
  337. #ifndef NDEBUG
  338. // Reset this, in order to guard its use with ASSERTs.
  339. m_bytecodeOffset = (unsigned)-1;
  340. #endif
  341. }
  342. void JIT::privateCompileLinkPass()
  343. {
  344. unsigned jmpTableCount = m_jmpTable.size();
  345. for (unsigned i = 0; i < jmpTableCount; ++i)
  346. m_jmpTable[i].from.linkTo(m_labels[m_jmpTable[i].toBytecodeOffset], this);
  347. m_jmpTable.clear();
  348. }
  349. void JIT::privateCompileSlowCases()
  350. {
  351. Instruction* instructionsBegin = m_codeBlock->instructions().begin();
  352. m_propertyAccessInstructionIndex = 0;
  353. m_byValInstructionIndex = 0;
  354. m_globalResolveInfoIndex = 0;
  355. m_callLinkInfoIndex = 0;
  356. #if ENABLE(VALUE_PROFILER)
  357. // Use this to assert that slow-path code associates new profiling sites with existing
  358. // ValueProfiles rather than creating new ones. This ensures that for a given instruction
  359. // (say, get_by_id) we get combined statistics for both the fast-path executions of that
  360. // instructions and the slow-path executions. Furthermore, if the slow-path code created
  361. // new ValueProfiles then the ValueProfiles would no longer be sorted by bytecode offset,
  362. // which would break the invariant necessary to use CodeBlock::valueProfileForBytecodeOffset().
  363. unsigned numberOfValueProfiles = m_codeBlock->numberOfValueProfiles();
  364. #endif
  365. for (Vector<SlowCaseEntry>::iterator iter = m_slowCases.begin(); iter != m_slowCases.end();) {
  366. #if USE(JSVALUE64)
  367. killLastResultRegister();
  368. #endif
  369. m_bytecodeOffset = iter->to;
  370. unsigned firstTo = m_bytecodeOffset;
  371. Instruction* currentInstruction = instructionsBegin + m_bytecodeOffset;
  372. #if ENABLE(VALUE_PROFILER)
  373. RareCaseProfile* rareCaseProfile = 0;
  374. if (shouldEmitProfiling())
  375. rareCaseProfile = m_codeBlock->addRareCaseProfile(m_bytecodeOffset);
  376. #endif
  377. #if ENABLE(JIT_VERBOSE)
  378. dataLogF("Old JIT emitting slow code for bc#%u at offset 0x%lx.\n", m_bytecodeOffset, (long)debugOffset());
  379. #endif
  380. #if !(ENABLE(DETACHED_JIT) && BUILDING_DETACHED_JIT)
  381. if (m_disassembler)
  382. m_disassembler->setForBytecodeSlowPath(m_bytecodeOffset, label());
  383. #else
  384. #pragma message "disassembler disabled"
  385. #endif
  386. switch (m_interpreter->getOpcodeID(currentInstruction->u.opcode)) {
  387. DEFINE_SLOWCASE_OP(op_add)
  388. DEFINE_SLOWCASE_OP(op_bitand)
  389. DEFINE_SLOWCASE_OP(op_bitor)
  390. DEFINE_SLOWCASE_OP(op_bitxor)
  391. DEFINE_SLOWCASE_OP(op_call)
  392. DEFINE_SLOWCASE_OP(op_call_eval)
  393. DEFINE_SLOWCASE_OP(op_call_varargs)
  394. DEFINE_SLOWCASE_OP(op_construct)
  395. DEFINE_SLOWCASE_OP(op_convert_this)
  396. DEFINE_SLOWCASE_OP(op_create_this)
  397. DEFINE_SLOWCASE_OP(op_div)
  398. DEFINE_SLOWCASE_OP(op_eq)
  399. case op_get_by_id_out_of_line:
  400. case op_get_array_length:
  401. DEFINE_SLOWCASE_OP(op_get_by_id)
  402. DEFINE_SLOWCASE_OP(op_get_arguments_length)
  403. DEFINE_SLOWCASE_OP(op_get_by_val)
  404. DEFINE_SLOWCASE_OP(op_get_argument_by_val)
  405. DEFINE_SLOWCASE_OP(op_get_by_pname)
  406. DEFINE_SLOWCASE_OP(op_check_has_instance)
  407. DEFINE_SLOWCASE_OP(op_instanceof)
  408. DEFINE_SLOWCASE_OP(op_jfalse)
  409. DEFINE_SLOWCASE_OP(op_jless)
  410. DEFINE_SLOWCASE_OP(op_jlesseq)
  411. DEFINE_SLOWCASE_OP(op_jgreater)
  412. DEFINE_SLOWCASE_OP(op_jgreatereq)
  413. DEFINE_SLOWCASE_OP(op_jnless)
  414. DEFINE_SLOWCASE_OP(op_jnlesseq)
  415. DEFINE_SLOWCASE_OP(op_jngreater)
  416. DEFINE_SLOWCASE_OP(op_jngreatereq)
  417. DEFINE_SLOWCASE_OP(op_jtrue)
  418. DEFINE_SLOWCASE_OP(op_loop_hint)
  419. DEFINE_SLOWCASE_OP(op_lshift)
  420. DEFINE_SLOWCASE_OP(op_mod)
  421. DEFINE_SLOWCASE_OP(op_mul)
  422. DEFINE_SLOWCASE_OP(op_negate)
  423. DEFINE_SLOWCASE_OP(op_neq)
  424. DEFINE_SLOWCASE_OP(op_new_object)
  425. DEFINE_SLOWCASE_OP(op_not)
  426. DEFINE_SLOWCASE_OP(op_nstricteq)
  427. DEFINE_SLOWCASE_OP(op_dec)
  428. DEFINE_SLOWCASE_OP(op_inc)
  429. case op_put_by_id_out_of_line:
  430. case op_put_by_id_transition_direct:
  431. case op_put_by_id_transition_normal:
  432. case op_put_by_id_transition_direct_out_of_line:
  433. case op_put_by_id_transition_normal_out_of_line:
  434. DEFINE_SLOWCASE_OP(op_put_by_id)
  435. DEFINE_SLOWCASE_OP(op_put_by_val)
  436. DEFINE_SLOWCASE_OP(op_init_global_const_check);
  437. DEFINE_SLOWCASE_OP(op_rshift)
  438. DEFINE_SLOWCASE_OP(op_urshift)
  439. DEFINE_SLOWCASE_OP(op_stricteq)
  440. DEFINE_SLOWCASE_OP(op_sub)
  441. DEFINE_SLOWCASE_OP(op_to_number)
  442. DEFINE_SLOWCASE_OP(op_to_primitive)
  443. case op_resolve_global_property:
  444. case op_resolve_global_var:
  445. case op_resolve_scoped_var:
  446. case op_resolve_scoped_var_on_top_scope:
  447. case op_resolve_scoped_var_with_top_scope_check:
  448. DEFINE_SLOWCASE_OP(op_resolve)
  449. case op_resolve_base_to_global:
  450. case op_resolve_base_to_global_dynamic:
  451. case op_resolve_base_to_scope:
  452. case op_resolve_base_to_scope_with_top_scope_check:
  453. DEFINE_SLOWCASE_OP(op_resolve_base)
  454. DEFINE_SLOWCASE_OP(op_resolve_with_base)
  455. DEFINE_SLOWCASE_OP(op_resolve_with_this)
  456. case op_put_to_base_variable:
  457. DEFINE_SLOWCASE_OP(op_put_to_base)
  458. default:
  459. RELEASE_ASSERT_NOT_REACHED();
  460. }
  461. RELEASE_ASSERT_WITH_MESSAGE(iter == m_slowCases.end() || firstTo != iter->to, "Not enough jumps linked in slow case codegen.");
  462. RELEASE_ASSERT_WITH_MESSAGE(firstTo == (iter - 1)->to, "Too many jumps linked in slow case codegen.");
  463. #if ENABLE(VALUE_PROFILER)
  464. if (shouldEmitProfiling())
  465. add32(TrustedImm32(1), AbsoluteAddress(&rareCaseProfile->m_counter));
  466. #endif
  467. emitJumpSlowToHot(jump(), 0);
  468. }
  469. RELEASE_ASSERT(m_propertyAccessInstructionIndex == m_propertyAccessCompilationInfo.size());
  470. RELEASE_ASSERT(m_callLinkInfoIndex == m_callStructureStubCompilationInfo.size());
  471. #if ENABLE(VALUE_PROFILER)
  472. RELEASE_ASSERT(numberOfValueProfiles == m_codeBlock->numberOfValueProfiles());
  473. #endif
  474. #ifndef NDEBUG
  475. // Reset this, in order to guard its use with ASSERTs.
  476. m_bytecodeOffset = (unsigned)-1;
  477. #endif
  478. }
  479. ALWAYS_INLINE void PropertyStubCompilationInfo::copyToStubInfo(StructureStubInfo& info, LinkBuffer &linkBuffer)
  480. {
  481. ASSERT(bytecodeIndex != std::numeric_limits<unsigned>::max());
  482. info.bytecodeIndex = bytecodeIndex;
  483. info.callReturnLocation = linkBuffer.locationOf(callReturnLocation);
  484. info.hotPathBegin = linkBuffer.locationOf(hotPathBegin);
  485. switch (m_type) {
  486. case GetById: {
  487. CodeLocationLabel hotPathBeginLocation = linkBuffer.locationOf(hotPathBegin);
  488. info.patch.baseline.u.get.structureToCompare = MacroAssembler::differenceBetweenCodePtr(hotPathBeginLocation, linkBuffer.locationOf(getStructureToCompare));
  489. info.patch.baseline.u.get.structureCheck = MacroAssembler::differenceBetweenCodePtr(hotPathBeginLocation, linkBuffer.locationOf(getStructureCheck));
  490. info.patch.baseline.u.get.propertyStorageLoad = MacroAssembler::differenceBetweenCodePtr(hotPathBeginLocation, linkBuffer.locationOf(propertyStorageLoad));
  491. #if USE(JSVALUE64)
  492. info.patch.baseline.u.get.displacementLabel = MacroAssembler::differenceBetweenCodePtr(hotPathBeginLocation, linkBuffer.locationOf(getDisplacementLabel));
  493. #else
  494. info.patch.baseline.u.get.displacementLabel1 = MacroAssembler::differenceBetweenCodePtr(hotPathBeginLocation, linkBuffer.locationOf(getDisplacementLabel1));
  495. info.patch.baseline.u.get.displacementLabel2 = MacroAssembler::differenceBetweenCodePtr(hotPathBeginLocation, linkBuffer.locationOf(getDisplacementLabel2));
  496. #endif
  497. info.patch.baseline.u.get.putResult = MacroAssembler::differenceBetweenCodePtr(hotPathBeginLocation, linkBuffer.locationOf(getPutResult));
  498. info.patch.baseline.u.get.coldPathBegin = MacroAssembler::differenceBetweenCodePtr(linkBuffer.locationOf(getColdPathBegin), linkBuffer.locationOf(callReturnLocation));
  499. break;
  500. }
  501. case PutById:
  502. CodeLocationLabel hotPathBeginLocation = linkBuffer.locationOf(hotPathBegin);
  503. info.patch.baseline.u.put.structureToCompare = MacroAssembler::differenceBetweenCodePtr(hotPathBeginLocation, linkBuffer.locationOf(putStructureToCompare));
  504. info.patch.baseline.u.put.propertyStorageLoad = MacroAssembler::differenceBetweenCodePtr(hotPathBeginLocation, linkBuffer.locationOf(propertyStorageLoad));
  505. #if USE(JSVALUE64)
  506. info.patch.baseline.u.put.displacementLabel = MacroAssembler::differenceBetweenCodePtr(hotPathBeginLocation, linkBuffer.locationOf(putDisplacementLabel));
  507. #else
  508. info.patch.baseline.u.put.displacementLabel1 = MacroAssembler::differenceBetweenCodePtr(hotPathBeginLocation, linkBuffer.locationOf(putDisplacementLabel1));
  509. info.patch.baseline.u.put.displacementLabel2 = MacroAssembler::differenceBetweenCodePtr(hotPathBeginLocation, linkBuffer.locationOf(putDisplacementLabel2));
  510. #endif
  511. break;
  512. }
  513. }
  514. JITCode JIT::privateCompile(CodePtr* functionEntryArityCheck, JITCompilationEffort effort)
  515. {
  516. #if ENABLE(JIT_VERBOSE_OSR)
  517. printf("Compiling JIT code!\n");
  518. #endif
  519. #if ENABLE(VALUE_PROFILER)
  520. DFG::CapabilityLevel level = m_codeBlock->canCompileWithDFG();
  521. switch (level) {
  522. case DFG::CannotCompile:
  523. m_canBeOptimized = false;
  524. m_shouldEmitProfiling = false;
  525. break;
  526. case DFG::MayInline:
  527. m_canBeOptimized = false;
  528. m_canBeOptimizedOrInlined = true;
  529. m_shouldEmitProfiling = true;
  530. break;
  531. case DFG::CanCompile:
  532. m_canBeOptimized = true;
  533. m_canBeOptimizedOrInlined = true;
  534. m_shouldEmitProfiling = true;
  535. break;
  536. default:
  537. RELEASE_ASSERT_NOT_REACHED();
  538. break;
  539. }
  540. #endif
  541. #if !(ENABLE(DETACHED_JIT) && BUILDING_DETACHED_JIT)
  542. if (Options::showDisassembly() || m_vm->m_perBytecodeProfiler)
  543. m_disassembler = adoptPtr(new JITDisassembler(m_codeBlock));
  544. if (m_vm->m_perBytecodeProfiler) {
  545. m_compilation = m_vm->m_perBytecodeProfiler->newCompilation(m_codeBlock, Profiler::Baseline);
  546. m_compilation->addProfiledBytecodes(*m_vm->m_perBytecodeProfiler, m_codeBlock);
  547. }
  548. if (m_disassembler)
  549. m_disassembler->setStartOfCode(label());
  550. #else
  551. #pragma message "profiler and disassembler is disabled"
  552. #endif
  553. // Just add a little bit of randomness to the codegen
  554. if (m_randomGenerator.getUint32() & 1)
  555. nop();
  556. preserveReturnAddressAfterCall(regT2);
  557. emitPutToCallFrameHeader(regT2, JSStack::ReturnPC);
  558. emitPutImmediateToCallFrameHeader(m_codeBlock, JSStack::CodeBlock);
  559. Label beginLabel(this);
  560. sampleCodeBlock(m_codeBlock);
  561. #if ENABLE(OPCODE_SAMPLING)
  562. sampleInstruction(m_codeBlock->instructions().begin());
  563. #endif
  564. Jump stackCheck;
  565. if (m_codeBlock->codeType() == FunctionCode) {
  566. #if ENABLE(DFG_JIT)
  567. #if DFG_ENABLE(SUCCESS_STATS)
  568. static SamplingCounter counter("orignalJIT");
  569. emitCount(counter);
  570. #endif
  571. #endif
  572. #if ENABLE(VALUE_PROFILER)
  573. ASSERT(m_bytecodeOffset == (unsigned)-1);
  574. if (shouldEmitProfiling()) {
  575. for (int argument = 0; argument < m_codeBlock->numParameters(); ++argument) {
  576. // If this is a constructor, then we want to put in a dummy profiling site (to
  577. // keep things consistent) but we don't actually want to record the dummy value.
  578. if (m_codeBlock->m_isConstructor && !argument)
  579. continue;
  580. int offset = CallFrame::argumentOffsetIncludingThis(argument) * static_cast<int>(sizeof(Register));
  581. #if USE(JSVALUE64)
  582. load64(Address(callFrameRegister, offset), regT0);
  583. #elif USE(JSVALUE32_64)
  584. load32(Address(callFrameRegister, offset + OBJECT_OFFSETOF(JSValue, u.asBits.payload)), regT0);
  585. load32(Address(callFrameRegister, offset + OBJECT_OFFSETOF(JSValue, u.asBits.tag)), regT1);
  586. #endif
  587. emitValueProfilingSite(m_codeBlock->valueProfileForArgument(argument));
  588. }
  589. }
  590. #endif
  591. addPtr(TrustedImm32(m_codeBlock->m_numCalleeRegisters * sizeof(Register)), callFrameRegister, regT1);
  592. stackCheck = branchPtr(Below, AbsoluteAddress(m_vm->interpreter->stack().addressOfEnd()), regT1);
  593. }
  594. Label functionBody = label();
  595. privateCompileMainPass();
  596. privateCompileLinkPass();
  597. privateCompileSlowCases();
  598. #if !(ENABLE(DETACHED_JIT) && BUILDING_DETACHED_JIT)
  599. if (m_disassembler)
  600. m_disassembler->setEndOfSlowPath(label());
  601. #else
  602. #pragma message "disassembler is disabled"
  603. #endif
  604. Label arityCheck;
  605. if (m_codeBlock->codeType() == FunctionCode) {
  606. stackCheck.link(this);
  607. m_bytecodeOffset = 0;
  608. JITStubCall(this, cti_stack_check).call();
  609. #ifndef NDEBUG
  610. m_bytecodeOffset = (unsigned)-1; // Reset this, in order to guard its use with ASSERTs.
  611. #endif
  612. jump(functionBody);
  613. arityCheck = label();
  614. preserveReturnAddressAfterCall(regT2);
  615. emitPutToCallFrameHeader(regT2, JSStack::ReturnPC);
  616. emitPutImmediateToCallFrameHeader(m_codeBlock, JSStack::CodeBlock);
  617. load32(payloadFor(JSStack::ArgumentCount), regT1);
  618. branch32(AboveOrEqual, regT1, TrustedImm32(m_codeBlock->m_numParameters)).linkTo(beginLabel, this);
  619. m_bytecodeOffset = 0;
  620. JITStubCall(this, m_codeBlock->m_isConstructor ? cti_op_construct_arityCheck : cti_op_call_arityCheck).call(callFrameRegister);
  621. #if !ASSERT_DISABLED
  622. m_bytecodeOffset = (unsigned)-1; // Reset this, in order to guard its use with ASSERTs.
  623. #endif
  624. jump(beginLabel);
  625. }
  626. ASSERT(m_jmpTable.isEmpty());
  627. #if !(ENABLE(DETACHED_JIT) && BUILDING_DETACHED_JIT)
  628. if (m_disassembler)
  629. m_disassembler->setEndOfCode(label());
  630. #else
  631. #pragma message "profiler and disassembler is disabled"
  632. #endif
  633. LinkBuffer patchBuffer(*m_vm, this, m_codeBlock, effort);
  634. if (patchBuffer.didFailToAllocate())
  635. return JITCode();
  636. // Translate vPC offsets into addresses in JIT generated code, for switch tables.
  637. for (unsigned i = 0; i < m_switches.size(); ++i) {
  638. SwitchRecord record = m_switches[i];
  639. unsigned bytecodeOffset = record.bytecodeOffset;
  640. if (record.type != SwitchRecord::String) {
  641. ASSERT(record.type == SwitchRecord::Immediate || record.type == SwitchRecord::Character);
  642. ASSERT(record.jumpTable.simpleJumpTable->branchOffsets.size() == record.jumpTable.simpleJumpTable->ctiOffsets.size());
  643. record.jumpTable.simpleJumpTable->ctiDefault = patchBuffer.locationOf(m_labels[bytecodeOffset + record.defaultOffset]);
  644. for (unsigned j = 0; j < record.jumpTable.simpleJumpTable->branchOffsets.size(); ++j) {
  645. unsigned offset = record.jumpTable.simpleJumpTable->branchOffsets[j];
  646. record.jumpTable.simpleJumpTable->ctiOffsets[j] = offset ? patchBuffer.locationOf(m_labels[bytecodeOffset + offset]) : record.jumpTable.simpleJumpTable->ctiDefault;
  647. }
  648. } else {
  649. ASSERT(record.type == SwitchRecord::String);
  650. record.jumpTable.stringJumpTable->ctiDefault = patchBuffer.locationOf(m_labels[bytecodeOffset + record.defaultOffset]);
  651. StringJumpTable::StringOffsetTable::iterator end = record.jumpTable.stringJumpTable->offsetTable.end();
  652. for (StringJumpTable::StringOffsetTable::iterator it = record.jumpTable.stringJumpTable->offsetTable.begin(); it != end; ++it) {
  653. unsigned offset = it->value.branchOffset;
  654. it->value.ctiOffset = offset ? patchBuffer.locationOf(m_labels[bytecodeOffset + offset]) : record.jumpTable.stringJumpTable->ctiDefault;
  655. }
  656. }
  657. }
  658. for (size_t i = 0; i < m_codeBlock->numberOfExceptionHandlers(); ++i) {
  659. HandlerInfo& handler = m_codeBlock->exceptionHandler(i);
  660. handler.nativeCode = patchBuffer.locationOf(m_labels[handler.target]);
  661. }
  662. for (Vector<CallRecord>::iterator iter = m_calls.begin(); iter != m_calls.end(); ++iter) {
  663. if (iter->to)
  664. patchBuffer.link(iter->from, FunctionPtr(iter->to));
  665. }
  666. m_codeBlock->callReturnIndexVector().reserveCapacity(m_calls.size());
  667. for (Vector<CallRecord>::iterator iter = m_calls.begin(); iter != m_calls.end(); ++iter)
  668. m_codeBlock->callReturnIndexVector().append(CallReturnOffsetToBytecodeOffset(patchBuffer.returnAddressOffset(iter->from), iter->bytecodeOffset));
  669. m_codeBlock->setNumberOfStructureStubInfos(m_propertyAccessCompilationInfo.size());
  670. for (unsigned i = 0; i < m_propertyAccessCompilationInfo.size(); ++i)
  671. m_propertyAccessCompilationInfo[i].copyToStubInfo(m_codeBlock->structureStubInfo(i), patchBuffer);
  672. m_codeBlock->setNumberOfByValInfos(m_byValCompilationInfo.size());
  673. for (unsigned i = 0; i < m_byValCompilationInfo.size(); ++i) {
  674. CodeLocationJump badTypeJump = CodeLocationJump(patchBuffer.locationOf(m_byValCompilationInfo[i].badTypeJump));
  675. CodeLocationLabel doneTarget = patchBuffer.locationOf(m_byValCompilationInfo[i].doneTarget);
  676. CodeLocationLabel slowPathTarget = patchBuffer.locationOf(m_byValCompilationInfo[i].slowPathTarget);
  677. CodeLocationCall returnAddress = patchBuffer.locationOf(m_byValCompilationInfo[i].returnAddress);
  678. m_codeBlock->byValInfo(i) = ByValInfo(
  679. m_byValCompilationInfo[i].bytecodeIndex,
  680. badTypeJump,
  681. m_byValCompilationInfo[i].arrayMode,
  682. differenceBetweenCodePtr(badTypeJump, doneTarget),
  683. differenceBetweenCodePtr(returnAddress, slowPathTarget));
  684. }
  685. m_codeBlock->setNumberOfCallLinkInfos(m_callStructureStubCompilationInfo.size());
  686. for (unsigned i = 0; i < m_codeBlock->numberOfCallLinkInfos(); ++i) {
  687. CallLinkInfo& info = m_codeBlock->callLinkInfo(i);
  688. info.callType = m_callStructureStubCompilationInfo[i].callType;
  689. info.codeOrigin = CodeOrigin(m_callStructureStubCompilationInfo[i].bytecodeIndex);
  690. info.callReturnLocation = patchBuffer.locationOfNearCall(m_callStructureStubCompilationInfo[i].callReturnLocation);
  691. info.hotPathBegin = patchBuffer.locationOf(m_callStructureStubCompilationInfo[i].hotPathBegin);
  692. info.hotPathOther = patchBuffer.locationOfNearCall(m_callStructureStubCompilationInfo[i].hotPathOther);
  693. info.calleeGPR = regT0;
  694. }
  695. #if ENABLE(DFG_JIT) || ENABLE(LLINT)
  696. if (canBeOptimizedOrInlined()
  697. #if ENABLE(LLINT)
  698. || true
  699. #endif
  700. ) {
  701. CompactJITCodeMap::Encoder jitCodeMapEncoder;
  702. for (unsigned bytecodeOffset = 0; bytecodeOffset < m_labels.size(); ++bytecodeOffset) {
  703. if (m_labels[bytecodeOffset].isSet())
  704. jitCodeMapEncoder.append(bytecodeOffset, patchBuffer.offsetOf(m_labels[bytecodeOffset]));
  705. }
  706. m_codeBlock->setJITCodeMap(jitCodeMapEncoder.finish());
  707. }
  708. #endif
  709. if (m_codeBlock->codeType() == FunctionCode && functionEntryArityCheck)
  710. *functionEntryArityCheck = patchBuffer.locationOf(arityCheck);
  711. #if !(ENABLE(DETACHED_JIT) && BUILDING_DETACHED_JIT)
  712. if (Options::showDisassembly())
  713. m_disassembler->dump(patchBuffer);
  714. if (m_compilation)
  715. m_disassembler->reportToProfiler(m_compilation.get(), patchBuffer);
  716. #else
  717. #pragma message "profiler and disassembler disabled"
  718. #endif
  719. CodeRef result = patchBuffer.finalizeCodeWithoutDisassembly();
  720. m_vm->machineCodeBytesPerBytecodeWordForBaselineJIT.add(
  721. static_cast<double>(result.size()) /
  722. static_cast<double>(m_codeBlock->instructions().size()));
  723. m_codeBlock->shrinkToFit(CodeBlock::LateShrink);
  724. #if ENABLE(JIT_VERBOSE)
  725. dataLogF("JIT generated code for %p at [%p, %p).\n", m_codeBlock, result.executableMemory()->start(), result.executableMemory()->end());
  726. #endif
  727. return JITCode(result, JITCode::BaselineJIT);
  728. }
  729. JITCode JIT::compile(VM* vm, CodeBlock* codeBlock, JITCompilationEffort effort, CodePtr* functionEntryArityCheck)
  730. {
  731. return JIT(vm, codeBlock).privateCompile(functionEntryArityCheck, effort);
  732. }
  733. void JIT::compileClosureCall(VM* vm, CallLinkInfo* callLinkInfo, CodeBlock* callerCodeBlock, CodeBlock* calleeCodeBlock, Structure* expectedStructure, ExecutableBase* expectedExecutable, MacroAssemblerCodePtr codePtr)
  734. {
  735. JIT jit(vm, callerCodeBlock);
  736. jit.m_bytecodeOffset = callLinkInfo->codeOrigin.bytecodeIndex;
  737. jit.privateCompileClosureCall(callLinkInfo, calleeCodeBlock, expectedStructure, expectedExecutable, codePtr);
  738. }
  739. void JIT::compileGetByIdProto(VM* vm, CallFrame* callFrame, CodeBlock* codeBlock, StructureStubInfo* stubInfo, Structure* structure, Structure* prototypeStructure, const Identifier& ident, const PropertySlot& slot, PropertyOffset cachedOffset, ReturnAddressPtr returnAddress)
  740. {
  741. JIT jit(vm, codeBlock);
  742. jit.m_bytecodeOffset = stubInfo->bytecodeIndex;
  743. jit.privateCompileGetByIdProto(stubInfo, structure, prototypeStructure, ident, slot, cachedOffset, returnAddress, callFrame);
  744. }
  745. void JIT::compileGetByIdSelfList(VM* vm, CodeBlock* codeBlock, StructureStubInfo* stubInfo, PolymorphicAccessStructureList* polymorphicStructures, int currentIndex, Structure* structure, const Identifier& ident, const PropertySlot& slot, PropertyOffset cachedOffset)
  746. {
  747. JIT jit(vm, codeBlock);
  748. jit.m_bytecodeOffset = stubInfo->bytecodeIndex;
  749. jit.privateCompileGetByIdSelfList(stubInfo, polymorphicStructures, currentIndex, structure, ident, slot, cachedOffset);
  750. }
  751. void JIT::compileGetByIdProtoList(VM* vm, CallFrame* callFrame, CodeBlock* codeBlock, StructureStubInfo* stubInfo, PolymorphicAccessStructureList* prototypeStructureList, int currentIndex, Structure* structure, Structure* prototypeStructure, const Identifier& ident, const PropertySlot& slot, PropertyOffset cachedOffset)
  752. {
  753. JIT jit(vm, codeBlock);
  754. jit.m_bytecodeOffset = stubInfo->bytecodeIndex;
  755. jit.privateCompileGetByIdProtoList(stubInfo, prototypeStructureList, currentIndex, structure, prototypeStructure, ident, slot, cachedOffset, callFrame);
  756. }
  757. void JIT::compileGetByIdChainList(VM* vm, CallFrame* callFrame, CodeBlock* codeBlock, StructureStubInfo* stubInfo, PolymorphicAccessStructureList* prototypeStructureList, int currentIndex, Structure* structure, StructureChain* chain, size_t count, const Identifier& ident, const PropertySlot& slot, PropertyOffset cachedOffset)
  758. {
  759. JIT jit(vm, codeBlock);
  760. jit.m_bytecodeOffset = stubInfo->bytecodeIndex;
  761. jit.privateCompileGetByIdChainList(stubInfo, prototypeStructureList, currentIndex, structure, chain, count, ident, slot, cachedOffset, callFrame);
  762. }
  763. void JIT::compileGetByIdChain(VM* vm, CallFrame* callFrame, CodeBlock* codeBlock, StructureStubInfo* stubInfo, Structure* structure, StructureChain* chain, size_t count, const Identifier& ident, const PropertySlot& slot, PropertyOffset cachedOffset, ReturnAddressPtr returnAddress)
  764. {
  765. JIT jit(vm, codeBlock);
  766. jit.m_bytecodeOffset = stubInfo->bytecodeIndex;
  767. jit.privateCompileGetByIdChain(stubInfo, structure, chain, count, ident, slot, cachedOffset, returnAddress, callFrame);
  768. }
  769. void JIT::compilePutByIdTransition(VM* vm, CodeBlock* codeBlock, StructureStubInfo* stubInfo, Structure* oldStructure, Structure* newStructure, PropertyOffset cachedOffset, StructureChain* chain, ReturnAddressPtr returnAddress, bool direct)
  770. {
  771. JIT jit(vm, codeBlock);
  772. jit.m_bytecodeOffset = stubInfo->bytecodeIndex;
  773. jit.privateCompilePutByIdTransition(stubInfo, oldStructure, newStructure, cachedOffset, chain, returnAddress, direct);
  774. }
  775. void JIT::compileGetByVal(VM* vm, CodeBlock* codeBlock, ByValInfo* byValInfo, ReturnAddressPtr returnAddress, JITArrayMode arrayMode)
  776. {
  777. JIT jit(vm, codeBlock);
  778. jit.m_bytecodeOffset = byValInfo->bytecodeIndex;
  779. jit.privateCompileGetByVal(byValInfo, returnAddress, arrayMode);
  780. }
  781. void JIT::compilePutByVal(VM* vm, CodeBlock* codeBlock, ByValInfo* byValInfo, ReturnAddressPtr returnAddress, JITArrayMode arrayMode)
  782. {
  783. JIT jit(vm, codeBlock);
  784. jit.m_bytecodeOffset = byValInfo->bytecodeIndex;
  785. jit.privateCompilePutByVal(byValInfo, returnAddress, arrayMode);
  786. }
  787. JIT::CodeRef JIT::compileCTINativeCall(VM* vm, NativeFunction func)
  788. {
  789. if (!vm->canUseJIT()) {
  790. #if ENABLE(LLINT)
  791. return CodeRef::createLLIntCodeRef(llint_native_call_trampoline);
  792. #else
  793. return CodeRef();
  794. #endif
  795. }
  796. JIT jit(vm, 0);
  797. return jit.privateCompileCTINativeCall(vm, func);
  798. }
  799. void JIT::compilePatchGetArrayLength(VM* vm, CodeBlock* codeBlock, ReturnAddressPtr returnAddress)
  800. {
  801. JIT jit(vm, codeBlock);
  802. #if ENABLE(DFG_JIT)
  803. // Force profiling to be enabled during stub generation.
  804. jit.m_canBeOptimized = true;
  805. jit.m_canBeOptimizedOrInlined = true;
  806. jit.m_shouldEmitProfiling = true;
  807. #endif // ENABLE(DFG_JIT)
  808. return jit.privateCompilePatchGetArrayLength(returnAddress);
  809. }
  810. void JIT::linkFor(JSFunction* callee, CodeBlock* callerCodeBlock, CodeBlock* calleeCodeBlock, JIT::CodePtr code, CallLinkInfo* callLinkInfo, VM* vm, CodeSpecializationKind kind)
  811. {
  812. RepatchBuffer repatchBuffer(callerCodeBlock);
  813. ASSERT(!callLinkInfo->isLinked());
  814. callLinkInfo->callee.set(*vm, callLinkInfo->hotPathBegin, callerCodeBlock->ownerExecutable(), callee);
  815. callLinkInfo->lastSeenCallee.set(*vm, callerCodeBlock->ownerExecutable(), callee);
  816. repatchBuffer.relink(callLinkInfo->hotPathOther, code);
  817. if (calleeCodeBlock)
  818. calleeCodeBlock->linkIncomingCall(callLinkInfo);
  819. // Patch the slow patch so we do not continue to try to link.
  820. if (kind == CodeForCall) {
  821. ASSERT(callLinkInfo->callType == CallLinkInfo::Call
  822. || callLinkInfo->callType == CallLinkInfo::CallVarargs);
  823. if (callLinkInfo->callType == CallLinkInfo::Call) {
  824. repatchBuffer.relink(callLinkInfo->callReturnLocation, vm->getCTIStub(linkClosureCallGenerator).code());
  825. return;
  826. }
  827. repatchBuffer.relink(callLinkInfo->callReturnLocation, vm->getCTIStub(virtualCallGenerator).code());
  828. return;
  829. }
  830. ASSERT(kind == CodeForConstruct);
  831. repatchBuffer.relink(callLinkInfo->callReturnLocation, vm->getCTIStub(virtualConstructGenerator).code());
  832. }
  833. void JIT::linkSlowCall(CodeBlock* callerCodeBlock, CallLinkInfo* callLinkInfo)
  834. {
  835. RepatchBuffer repatchBuffer(callerCodeBlock);
  836. repatchBuffer.relink(callLinkInfo->callReturnLocation, callerCodeBlock->vm()->getCTIStub(virtualCallGenerator).code());
  837. }
  838. } // namespace JSC
  839. #endif // #if !(ENABLE(DETACHED_JIT) && !BUILDING_DETACHED_JIT)
  840. #endif // ENABLE(JIT)