JITOpcodes.cpp 65 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727
  1. /*
  2. * Copyright (C) 2009, 2012 Apple Inc. All rights reserved.
  3. * Copyright (C) 2010 Patrick Gansterer <paroga@paroga.com>
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. *
  14. * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
  15. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  16. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  17. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
  18. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  19. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  20. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  21. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  22. * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  23. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  24. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. #include "config.h"
  27. #if ENABLE(JIT)
  28. #if !(ENABLE(DETACHED_JIT) && !BUILDING_DETACHED_JIT)
  29. #include "JIT.h"
  30. #include "Arguments.h"
  31. #include "CopiedSpaceInlines.h"
  32. #include "Heap.h"
  33. #include "JITInlines.h"
  34. #include "JITStubCall.h"
  35. #include "JSArray.h"
  36. #include "JSCell.h"
  37. #include "JSFunction.h"
  38. #include "JSPropertyNameIterator.h"
  39. #include "LinkBuffer.h"
  40. namespace JSC {
  41. #if USE(JSVALUE64)
  42. JIT::CodeRef JIT::privateCompileCTINativeCall(VM* vm, NativeFunction)
  43. {
  44. return vm->getCTIStub(nativeCallGenerator);
  45. }
  46. void JIT::emit_op_mov(Instruction* currentInstruction)
  47. {
  48. int dst = currentInstruction[1].u.operand;
  49. int src = currentInstruction[2].u.operand;
  50. if (canBeOptimizedOrInlined()) {
  51. // Use simpler approach, since the DFG thinks that the last result register
  52. // is always set to the destination on every operation.
  53. emitGetVirtualRegister(src, regT0);
  54. emitPutVirtualRegister(dst);
  55. } else {
  56. if (m_codeBlock->isConstantRegisterIndex(src)) {
  57. if (!getConstantOperand(src).isNumber())
  58. store64(TrustedImm64(JSValue::encode(getConstantOperand(src))), Address(callFrameRegister, dst * sizeof(Register)));
  59. else
  60. store64(Imm64(JSValue::encode(getConstantOperand(src))), Address(callFrameRegister, dst * sizeof(Register)));
  61. if (dst == m_lastResultBytecodeRegister)
  62. killLastResultRegister();
  63. } else if ((src == m_lastResultBytecodeRegister) || (dst == m_lastResultBytecodeRegister)) {
  64. // If either the src or dst is the cached register go though
  65. // get/put registers to make sure we track this correctly.
  66. emitGetVirtualRegister(src, regT0);
  67. emitPutVirtualRegister(dst);
  68. } else {
  69. // Perform the copy via regT1; do not disturb any mapping in regT0.
  70. load64(Address(callFrameRegister, src * sizeof(Register)), regT1);
  71. store64(regT1, Address(callFrameRegister, dst * sizeof(Register)));
  72. }
  73. }
  74. }
  75. void JIT::emit_op_end(Instruction* currentInstruction)
  76. {
  77. RELEASE_ASSERT(returnValueRegister != callFrameRegister);
  78. emitGetVirtualRegister(currentInstruction[1].u.operand, returnValueRegister);
  79. restoreReturnAddressBeforeReturn(Address(callFrameRegister, JSStack::ReturnPC * static_cast<int>(sizeof(Register))));
  80. ret();
  81. }
  82. void JIT::emit_op_jmp(Instruction* currentInstruction)
  83. {
  84. unsigned target = currentInstruction[1].u.operand;
  85. addJump(jump(), target);
  86. }
  87. void JIT::emit_op_new_object(Instruction* currentInstruction)
  88. {
  89. Structure* structure = currentInstruction[3].u.objectAllocationProfile->structure();
  90. size_t allocationSize = JSObject::allocationSize(structure->inlineCapacity());
  91. MarkedAllocator* allocator = &m_vm->heap.allocatorForObjectWithoutDestructor(allocationSize);
  92. RegisterID resultReg = regT0;
  93. RegisterID allocatorReg = regT1;
  94. RegisterID scratchReg = regT2;
  95. move(TrustedImmPtr(allocator), allocatorReg);
  96. emitAllocateJSObject(allocatorReg, TrustedImmPtr(structure), resultReg, scratchReg);
  97. emitPutVirtualRegister(currentInstruction[1].u.operand);
  98. }
  99. void JIT::emitSlow_op_new_object(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
  100. {
  101. linkSlowCase(iter);
  102. JITStubCall stubCall(this, cti_op_new_object);
  103. stubCall.addArgument(TrustedImmPtr(currentInstruction[3].u.objectAllocationProfile->structure()));
  104. stubCall.call(currentInstruction[1].u.operand);
  105. }
  106. void JIT::emit_op_check_has_instance(Instruction* currentInstruction)
  107. {
  108. unsigned baseVal = currentInstruction[3].u.operand;
  109. emitGetVirtualRegister(baseVal, regT0);
  110. // Check that baseVal is a cell.
  111. emitJumpSlowCaseIfNotJSCell(regT0, baseVal);
  112. // Check that baseVal 'ImplementsHasInstance'.
  113. loadPtr(Address(regT0, JSCell::structureOffset()), regT0);
  114. addSlowCase(branchTest8(Zero, Address(regT0, Structure::typeInfoFlagsOffset()), TrustedImm32(ImplementsDefaultHasInstance)));
  115. }
  116. void JIT::emit_op_instanceof(Instruction* currentInstruction)
  117. {
  118. unsigned dst = currentInstruction[1].u.operand;
  119. unsigned value = currentInstruction[2].u.operand;
  120. unsigned proto = currentInstruction[3].u.operand;
  121. // Load the operands (baseVal, proto, and value respectively) into registers.
  122. // We use regT0 for baseVal since we will be done with this first, and we can then use it for the result.
  123. emitGetVirtualRegister(value, regT2);
  124. emitGetVirtualRegister(proto, regT1);
  125. // Check that proto are cells. baseVal must be a cell - this is checked by op_check_has_instance.
  126. emitJumpSlowCaseIfNotJSCell(regT2, value);
  127. emitJumpSlowCaseIfNotJSCell(regT1, proto);
  128. // Check that prototype is an object
  129. loadPtr(Address(regT1, JSCell::structureOffset()), regT3);
  130. addSlowCase(emitJumpIfNotObject(regT3));
  131. // Optimistically load the result true, and start looping.
  132. // Initially, regT1 still contains proto and regT2 still contains value.
  133. // As we loop regT2 will be updated with its prototype, recursively walking the prototype chain.
  134. move(TrustedImm64(JSValue::encode(jsBoolean(true))), regT0);
  135. Label loop(this);
  136. // Load the prototype of the object in regT2. If this is equal to regT1 - WIN!
  137. // Otherwise, check if we've hit null - if we have then drop out of the loop, if not go again.
  138. loadPtr(Address(regT2, JSCell::structureOffset()), regT2);
  139. load64(Address(regT2, Structure::prototypeOffset()), regT2);
  140. Jump isInstance = branchPtr(Equal, regT2, regT1);
  141. emitJumpIfJSCell(regT2).linkTo(loop, this);
  142. // We get here either by dropping out of the loop, or if value was not an Object. Result is false.
  143. move(TrustedImm64(JSValue::encode(jsBoolean(false))), regT0);
  144. // isInstance jumps right down to here, to skip setting the result to false (it has already set true).
  145. isInstance.link(this);
  146. emitPutVirtualRegister(dst);
  147. }
  148. void JIT::emit_op_is_undefined(Instruction* currentInstruction)
  149. {
  150. unsigned dst = currentInstruction[1].u.operand;
  151. unsigned value = currentInstruction[2].u.operand;
  152. emitGetVirtualRegister(value, regT0);
  153. Jump isCell = emitJumpIfJSCell(regT0);
  154. compare64(Equal, regT0, TrustedImm32(ValueUndefined), regT0);
  155. Jump done = jump();
  156. isCell.link(this);
  157. loadPtr(Address(regT0, JSCell::structureOffset()), regT1);
  158. Jump isMasqueradesAsUndefined = branchTest8(NonZero, Address(regT1, Structure::typeInfoFlagsOffset()), TrustedImm32(MasqueradesAsUndefined));
  159. move(TrustedImm32(0), regT0);
  160. Jump notMasqueradesAsUndefined = jump();
  161. isMasqueradesAsUndefined.link(this);
  162. move(TrustedImmPtr(m_codeBlock->globalObject()), regT0);
  163. loadPtr(Address(regT1, Structure::globalObjectOffset()), regT1);
  164. comparePtr(Equal, regT0, regT1, regT0);
  165. notMasqueradesAsUndefined.link(this);
  166. done.link(this);
  167. emitTagAsBoolImmediate(regT0);
  168. emitPutVirtualRegister(dst);
  169. }
  170. void JIT::emit_op_is_boolean(Instruction* currentInstruction)
  171. {
  172. unsigned dst = currentInstruction[1].u.operand;
  173. unsigned value = currentInstruction[2].u.operand;
  174. emitGetVirtualRegister(value, regT0);
  175. xor64(TrustedImm32(static_cast<int32_t>(ValueFalse)), regT0);
  176. test64(Zero, regT0, TrustedImm32(static_cast<int32_t>(~1)), regT0);
  177. emitTagAsBoolImmediate(regT0);
  178. emitPutVirtualRegister(dst);
  179. }
  180. void JIT::emit_op_is_number(Instruction* currentInstruction)
  181. {
  182. unsigned dst = currentInstruction[1].u.operand;
  183. unsigned value = currentInstruction[2].u.operand;
  184. emitGetVirtualRegister(value, regT0);
  185. test64(NonZero, regT0, tagTypeNumberRegister, regT0);
  186. emitTagAsBoolImmediate(regT0);
  187. emitPutVirtualRegister(dst);
  188. }
  189. void JIT::emit_op_is_string(Instruction* currentInstruction)
  190. {
  191. unsigned dst = currentInstruction[1].u.operand;
  192. unsigned value = currentInstruction[2].u.operand;
  193. emitGetVirtualRegister(value, regT0);
  194. Jump isNotCell = emitJumpIfNotJSCell(regT0);
  195. loadPtr(Address(regT0, JSCell::structureOffset()), regT1);
  196. compare8(Equal, Address(regT1, Structure::typeInfoTypeOffset()), TrustedImm32(StringType), regT0);
  197. emitTagAsBoolImmediate(regT0);
  198. Jump done = jump();
  199. isNotCell.link(this);
  200. move(TrustedImm32(ValueFalse), regT0);
  201. done.link(this);
  202. emitPutVirtualRegister(dst);
  203. }
  204. void JIT::emit_op_call(Instruction* currentInstruction)
  205. {
  206. compileOpCall(op_call, currentInstruction, m_callLinkInfoIndex++);
  207. }
  208. void JIT::emit_op_call_eval(Instruction* currentInstruction)
  209. {
  210. compileOpCall(op_call_eval, currentInstruction, m_callLinkInfoIndex);
  211. }
  212. void JIT::emit_op_call_varargs(Instruction* currentInstruction)
  213. {
  214. compileOpCall(op_call_varargs, currentInstruction, m_callLinkInfoIndex++);
  215. }
  216. void JIT::emit_op_construct(Instruction* currentInstruction)
  217. {
  218. compileOpCall(op_construct, currentInstruction, m_callLinkInfoIndex++);
  219. }
  220. void JIT::emit_op_tear_off_activation(Instruction* currentInstruction)
  221. {
  222. int activation = currentInstruction[1].u.operand;
  223. Jump activationNotCreated = branchTest64(Zero, addressFor(activation));
  224. JITStubCall stubCall(this, cti_op_tear_off_activation);
  225. stubCall.addArgument(activation, regT2);
  226. stubCall.call();
  227. activationNotCreated.link(this);
  228. }
  229. void JIT::emit_op_tear_off_arguments(Instruction* currentInstruction)
  230. {
  231. int arguments = currentInstruction[1].u.operand;
  232. int activation = currentInstruction[2].u.operand;
  233. Jump argsNotCreated = branchTest64(Zero, Address(callFrameRegister, sizeof(Register) * (unmodifiedArgumentsRegister(arguments))));
  234. JITStubCall stubCall(this, cti_op_tear_off_arguments);
  235. stubCall.addArgument(unmodifiedArgumentsRegister(arguments), regT2);
  236. stubCall.addArgument(activation, regT2);
  237. stubCall.call();
  238. argsNotCreated.link(this);
  239. }
  240. void JIT::emit_op_ret(Instruction* currentInstruction)
  241. {
  242. ASSERT(callFrameRegister != regT1);
  243. ASSERT(regT1 != returnValueRegister);
  244. ASSERT(returnValueRegister != callFrameRegister);
  245. // Return the result in %eax.
  246. emitGetVirtualRegister(currentInstruction[1].u.operand, returnValueRegister);
  247. // Grab the return address.
  248. emitGetFromCallFrameHeaderPtr(JSStack::ReturnPC, regT1);
  249. // Restore our caller's "r".
  250. emitGetFromCallFrameHeaderPtr(JSStack::CallerFrame, callFrameRegister);
  251. // Return.
  252. restoreReturnAddressBeforeReturn(regT1);
  253. ret();
  254. }
  255. void JIT::emit_op_ret_object_or_this(Instruction* currentInstruction)
  256. {
  257. ASSERT(callFrameRegister != regT1);
  258. ASSERT(regT1 != returnValueRegister);
  259. ASSERT(returnValueRegister != callFrameRegister);
  260. // Return the result in %eax.
  261. emitGetVirtualRegister(currentInstruction[1].u.operand, returnValueRegister);
  262. Jump notJSCell = emitJumpIfNotJSCell(returnValueRegister);
  263. loadPtr(Address(returnValueRegister, JSCell::structureOffset()), regT2);
  264. Jump notObject = emitJumpIfNotObject(regT2);
  265. // Grab the return address.
  266. emitGetFromCallFrameHeaderPtr(JSStack::ReturnPC, regT1);
  267. // Restore our caller's "r".
  268. emitGetFromCallFrameHeaderPtr(JSStack::CallerFrame, callFrameRegister);
  269. // Return.
  270. restoreReturnAddressBeforeReturn(regT1);
  271. ret();
  272. // Return 'this' in %eax.
  273. notJSCell.link(this);
  274. notObject.link(this);
  275. emitGetVirtualRegister(currentInstruction[2].u.operand, returnValueRegister);
  276. // Grab the return address.
  277. emitGetFromCallFrameHeaderPtr(JSStack::ReturnPC, regT1);
  278. // Restore our caller's "r".
  279. emitGetFromCallFrameHeaderPtr(JSStack::CallerFrame, callFrameRegister);
  280. // Return.
  281. restoreReturnAddressBeforeReturn(regT1);
  282. ret();
  283. }
  284. void JIT::emit_op_to_primitive(Instruction* currentInstruction)
  285. {
  286. int dst = currentInstruction[1].u.operand;
  287. int src = currentInstruction[2].u.operand;
  288. emitGetVirtualRegister(src, regT0);
  289. Jump isImm = emitJumpIfNotJSCell(regT0);
  290. addSlowCase(branchPtr(NotEqual, Address(regT0, JSCell::structureOffset()), TrustedImmPtr(m_vm->stringStructure.get())));
  291. isImm.link(this);
  292. if (dst != src)
  293. emitPutVirtualRegister(dst);
  294. }
  295. void JIT::emit_op_strcat(Instruction* currentInstruction)
  296. {
  297. JITStubCall stubCall(this, cti_op_strcat);
  298. stubCall.addArgument(TrustedImm32(currentInstruction[2].u.operand));
  299. stubCall.addArgument(TrustedImm32(currentInstruction[3].u.operand));
  300. stubCall.call(currentInstruction[1].u.operand);
  301. }
  302. void JIT::emit_op_not(Instruction* currentInstruction)
  303. {
  304. emitGetVirtualRegister(currentInstruction[2].u.operand, regT0);
  305. // Invert against JSValue(false); if the value was tagged as a boolean, then all bits will be
  306. // clear other than the low bit (which will be 0 or 1 for false or true inputs respectively).
  307. // Then invert against JSValue(true), which will add the tag back in, and flip the low bit.
  308. xor64(TrustedImm32(static_cast<int32_t>(ValueFalse)), regT0);
  309. addSlowCase(branchTestPtr(NonZero, regT0, TrustedImm32(static_cast<int32_t>(~1))));
  310. xor64(TrustedImm32(static_cast<int32_t>(ValueTrue)), regT0);
  311. emitPutVirtualRegister(currentInstruction[1].u.operand);
  312. }
  313. void JIT::emit_op_jfalse(Instruction* currentInstruction)
  314. {
  315. unsigned target = currentInstruction[2].u.operand;
  316. emitGetVirtualRegister(currentInstruction[1].u.operand, regT0);
  317. addJump(branch64(Equal, regT0, TrustedImm64(JSValue::encode(jsNumber(0)))), target);
  318. Jump isNonZero = emitJumpIfImmediateInteger(regT0);
  319. addJump(branch64(Equal, regT0, TrustedImm64(JSValue::encode(jsBoolean(false)))), target);
  320. addSlowCase(branch64(NotEqual, regT0, TrustedImm64(JSValue::encode(jsBoolean(true)))));
  321. isNonZero.link(this);
  322. }
  323. void JIT::emit_op_jeq_null(Instruction* currentInstruction)
  324. {
  325. unsigned src = currentInstruction[1].u.operand;
  326. unsigned target = currentInstruction[2].u.operand;
  327. emitGetVirtualRegister(src, regT0);
  328. Jump isImmediate = emitJumpIfNotJSCell(regT0);
  329. // First, handle JSCell cases - check MasqueradesAsUndefined bit on the structure.
  330. loadPtr(Address(regT0, JSCell::structureOffset()), regT2);
  331. Jump isNotMasqueradesAsUndefined = branchTest8(Zero, Address(regT2, Structure::typeInfoFlagsOffset()), TrustedImm32(MasqueradesAsUndefined));
  332. move(TrustedImmPtr(m_codeBlock->globalObject()), regT0);
  333. addJump(branchPtr(Equal, Address(regT2, Structure::globalObjectOffset()), regT0), target);
  334. Jump masqueradesGlobalObjectIsForeign = jump();
  335. // Now handle the immediate cases - undefined & null
  336. isImmediate.link(this);
  337. and64(TrustedImm32(~TagBitUndefined), regT0);
  338. addJump(branch64(Equal, regT0, TrustedImm64(JSValue::encode(jsNull()))), target);
  339. isNotMasqueradesAsUndefined.link(this);
  340. masqueradesGlobalObjectIsForeign.link(this);
  341. };
  342. void JIT::emit_op_jneq_null(Instruction* currentInstruction)
  343. {
  344. unsigned src = currentInstruction[1].u.operand;
  345. unsigned target = currentInstruction[2].u.operand;
  346. emitGetVirtualRegister(src, regT0);
  347. Jump isImmediate = emitJumpIfNotJSCell(regT0);
  348. // First, handle JSCell cases - check MasqueradesAsUndefined bit on the structure.
  349. loadPtr(Address(regT0, JSCell::structureOffset()), regT2);
  350. addJump(branchTest8(Zero, Address(regT2, Structure::typeInfoFlagsOffset()), TrustedImm32(MasqueradesAsUndefined)), target);
  351. move(TrustedImmPtr(m_codeBlock->globalObject()), regT0);
  352. addJump(branchPtr(NotEqual, Address(regT2, Structure::globalObjectOffset()), regT0), target);
  353. Jump wasNotImmediate = jump();
  354. // Now handle the immediate cases - undefined & null
  355. isImmediate.link(this);
  356. and64(TrustedImm32(~TagBitUndefined), regT0);
  357. addJump(branch64(NotEqual, regT0, TrustedImm64(JSValue::encode(jsNull()))), target);
  358. wasNotImmediate.link(this);
  359. }
  360. void JIT::emit_op_jneq_ptr(Instruction* currentInstruction)
  361. {
  362. unsigned src = currentInstruction[1].u.operand;
  363. Special::Pointer ptr = currentInstruction[2].u.specialPointer;
  364. unsigned target = currentInstruction[3].u.operand;
  365. emitGetVirtualRegister(src, regT0);
  366. addJump(branchPtr(NotEqual, regT0, TrustedImmPtr(actualPointerFor(m_codeBlock, ptr))), target);
  367. }
  368. void JIT::emit_op_eq(Instruction* currentInstruction)
  369. {
  370. emitGetVirtualRegisters(currentInstruction[2].u.operand, regT0, currentInstruction[3].u.operand, regT1);
  371. emitJumpSlowCaseIfNotImmediateIntegers(regT0, regT1, regT2);
  372. compare32(Equal, regT1, regT0, regT0);
  373. emitTagAsBoolImmediate(regT0);
  374. emitPutVirtualRegister(currentInstruction[1].u.operand);
  375. }
  376. void JIT::emit_op_jtrue(Instruction* currentInstruction)
  377. {
  378. unsigned target = currentInstruction[2].u.operand;
  379. emitGetVirtualRegister(currentInstruction[1].u.operand, regT0);
  380. Jump isZero = branch64(Equal, regT0, TrustedImm64(JSValue::encode(jsNumber(0))));
  381. addJump(emitJumpIfImmediateInteger(regT0), target);
  382. addJump(branch64(Equal, regT0, TrustedImm64(JSValue::encode(jsBoolean(true)))), target);
  383. addSlowCase(branch64(NotEqual, regT0, TrustedImm64(JSValue::encode(jsBoolean(false)))));
  384. isZero.link(this);
  385. }
  386. void JIT::emit_op_neq(Instruction* currentInstruction)
  387. {
  388. emitGetVirtualRegisters(currentInstruction[2].u.operand, regT0, currentInstruction[3].u.operand, regT1);
  389. emitJumpSlowCaseIfNotImmediateIntegers(regT0, regT1, regT2);
  390. compare32(NotEqual, regT1, regT0, regT0);
  391. emitTagAsBoolImmediate(regT0);
  392. emitPutVirtualRegister(currentInstruction[1].u.operand);
  393. }
  394. void JIT::emit_op_bitxor(Instruction* currentInstruction)
  395. {
  396. emitGetVirtualRegisters(currentInstruction[2].u.operand, regT0, currentInstruction[3].u.operand, regT1);
  397. emitJumpSlowCaseIfNotImmediateIntegers(regT0, regT1, regT2);
  398. xor64(regT1, regT0);
  399. emitFastArithReTagImmediate(regT0, regT0);
  400. emitPutVirtualRegister(currentInstruction[1].u.operand);
  401. }
  402. void JIT::emit_op_bitor(Instruction* currentInstruction)
  403. {
  404. emitGetVirtualRegisters(currentInstruction[2].u.operand, regT0, currentInstruction[3].u.operand, regT1);
  405. emitJumpSlowCaseIfNotImmediateIntegers(regT0, regT1, regT2);
  406. or64(regT1, regT0);
  407. emitPutVirtualRegister(currentInstruction[1].u.operand);
  408. }
  409. void JIT::emit_op_throw(Instruction* currentInstruction)
  410. {
  411. JITStubCall stubCall(this, cti_op_throw);
  412. stubCall.addArgument(currentInstruction[1].u.operand, regT2);
  413. stubCall.call();
  414. ASSERT(regT0 == returnValueRegister);
  415. #ifndef NDEBUG
  416. // cti_op_throw always changes it's return address,
  417. // this point in the code should never be reached.
  418. breakpoint();
  419. #endif
  420. }
  421. void JIT::emit_op_get_pnames(Instruction* currentInstruction)
  422. {
  423. int dst = currentInstruction[1].u.operand;
  424. int base = currentInstruction[2].u.operand;
  425. int i = currentInstruction[3].u.operand;
  426. int size = currentInstruction[4].u.operand;
  427. int breakTarget = currentInstruction[5].u.operand;
  428. JumpList isNotObject;
  429. emitGetVirtualRegister(base, regT0);
  430. if (!m_codeBlock->isKnownNotImmediate(base))
  431. isNotObject.append(emitJumpIfNotJSCell(regT0));
  432. if (base != m_codeBlock->thisRegister() || m_codeBlock->isStrictMode()) {
  433. loadPtr(Address(regT0, JSCell::structureOffset()), regT2);
  434. isNotObject.append(emitJumpIfNotObject(regT2));
  435. }
  436. // We could inline the case where you have a valid cache, but
  437. // this call doesn't seem to be hot.
  438. Label isObject(this);
  439. JITStubCall getPnamesStubCall(this, cti_op_get_pnames);
  440. getPnamesStubCall.addArgument(regT0);
  441. getPnamesStubCall.call(dst);
  442. load32(Address(regT0, OBJECT_OFFSETOF(JSPropertyNameIterator, m_jsStringsSize)), regT3);
  443. store64(tagTypeNumberRegister, addressFor(i));
  444. store32(TrustedImm32(Int32Tag), intTagFor(size));
  445. store32(regT3, intPayloadFor(size));
  446. Jump end = jump();
  447. isNotObject.link(this);
  448. move(regT0, regT1);
  449. and32(TrustedImm32(~TagBitUndefined), regT1);
  450. addJump(branch32(Equal, regT1, TrustedImm32(ValueNull)), breakTarget);
  451. JITStubCall toObjectStubCall(this, cti_to_object);
  452. toObjectStubCall.addArgument(regT0);
  453. toObjectStubCall.call(base);
  454. jump().linkTo(isObject, this);
  455. end.link(this);
  456. }
  457. void JIT::emit_op_next_pname(Instruction* currentInstruction)
  458. {
  459. int dst = currentInstruction[1].u.operand;
  460. int base = currentInstruction[2].u.operand;
  461. int i = currentInstruction[3].u.operand;
  462. int size = currentInstruction[4].u.operand;
  463. int it = currentInstruction[5].u.operand;
  464. int target = currentInstruction[6].u.operand;
  465. JumpList callHasProperty;
  466. Label begin(this);
  467. load32(intPayloadFor(i), regT0);
  468. Jump end = branch32(Equal, regT0, intPayloadFor(size));
  469. // Grab key @ i
  470. loadPtr(addressFor(it), regT1);
  471. loadPtr(Address(regT1, OBJECT_OFFSETOF(JSPropertyNameIterator, m_jsStrings)), regT2);
  472. load64(BaseIndex(regT2, regT0, TimesEight), regT2);
  473. emitPutVirtualRegister(dst, regT2);
  474. // Increment i
  475. add32(TrustedImm32(1), regT0);
  476. store32(regT0, intPayloadFor(i));
  477. // Verify that i is valid:
  478. emitGetVirtualRegister(base, regT0);
  479. // Test base's structure
  480. loadPtr(Address(regT0, JSCell::structureOffset()), regT2);
  481. callHasProperty.append(branchPtr(NotEqual, regT2, Address(Address(regT1, OBJECT_OFFSETOF(JSPropertyNameIterator, m_cachedStructure)))));
  482. // Test base's prototype chain
  483. loadPtr(Address(Address(regT1, OBJECT_OFFSETOF(JSPropertyNameIterator, m_cachedPrototypeChain))), regT3);
  484. loadPtr(Address(regT3, OBJECT_OFFSETOF(StructureChain, m_vector)), regT3);
  485. addJump(branchTestPtr(Zero, Address(regT3)), target);
  486. Label checkPrototype(this);
  487. load64(Address(regT2, Structure::prototypeOffset()), regT2);
  488. callHasProperty.append(emitJumpIfNotJSCell(regT2));
  489. loadPtr(Address(regT2, JSCell::structureOffset()), regT2);
  490. callHasProperty.append(branchPtr(NotEqual, regT2, Address(regT3)));
  491. addPtr(TrustedImm32(sizeof(Structure*)), regT3);
  492. branchTestPtr(NonZero, Address(regT3)).linkTo(checkPrototype, this);
  493. // Continue loop.
  494. addJump(jump(), target);
  495. // Slow case: Ask the object if i is valid.
  496. callHasProperty.link(this);
  497. emitGetVirtualRegister(dst, regT1);
  498. JITStubCall stubCall(this, cti_has_property);
  499. stubCall.addArgument(regT0);
  500. stubCall.addArgument(regT1);
  501. stubCall.call();
  502. // Test for valid key.
  503. addJump(branchTest32(NonZero, regT0), target);
  504. jump().linkTo(begin, this);
  505. // End of loop.
  506. end.link(this);
  507. }
  508. void JIT::emit_op_push_with_scope(Instruction* currentInstruction)
  509. {
  510. JITStubCall stubCall(this, cti_op_push_with_scope);
  511. stubCall.addArgument(currentInstruction[1].u.operand, regT2);
  512. stubCall.call();
  513. }
  514. void JIT::emit_op_pop_scope(Instruction*)
  515. {
  516. JITStubCall(this, cti_op_pop_scope).call();
  517. }
  518. void JIT::compileOpStrictEq(Instruction* currentInstruction, CompileOpStrictEqType type)
  519. {
  520. unsigned dst = currentInstruction[1].u.operand;
  521. unsigned src1 = currentInstruction[2].u.operand;
  522. unsigned src2 = currentInstruction[3].u.operand;
  523. emitGetVirtualRegisters(src1, regT0, src2, regT1);
  524. // Jump slow if both are cells (to cover strings).
  525. move(regT0, regT2);
  526. or64(regT1, regT2);
  527. addSlowCase(emitJumpIfJSCell(regT2));
  528. // Jump slow if either is a double. First test if it's an integer, which is fine, and then test
  529. // if it's a double.
  530. Jump leftOK = emitJumpIfImmediateInteger(regT0);
  531. addSlowCase(emitJumpIfImmediateNumber(regT0));
  532. leftOK.link(this);
  533. Jump rightOK = emitJumpIfImmediateInteger(regT1);
  534. addSlowCase(emitJumpIfImmediateNumber(regT1));
  535. rightOK.link(this);
  536. if (type == OpStrictEq)
  537. compare64(Equal, regT1, regT0, regT0);
  538. else
  539. compare64(NotEqual, regT1, regT0, regT0);
  540. emitTagAsBoolImmediate(regT0);
  541. emitPutVirtualRegister(dst);
  542. }
  543. void JIT::emit_op_stricteq(Instruction* currentInstruction)
  544. {
  545. compileOpStrictEq(currentInstruction, OpStrictEq);
  546. }
  547. void JIT::emit_op_nstricteq(Instruction* currentInstruction)
  548. {
  549. compileOpStrictEq(currentInstruction, OpNStrictEq);
  550. }
  551. void JIT::emit_op_to_number(Instruction* currentInstruction)
  552. {
  553. int srcVReg = currentInstruction[2].u.operand;
  554. emitGetVirtualRegister(srcVReg, regT0);
  555. addSlowCase(emitJumpIfNotImmediateNumber(regT0));
  556. emitPutVirtualRegister(currentInstruction[1].u.operand);
  557. }
  558. void JIT::emit_op_push_name_scope(Instruction* currentInstruction)
  559. {
  560. JITStubCall stubCall(this, cti_op_push_name_scope);
  561. stubCall.addArgument(TrustedImmPtr(&m_codeBlock->identifier(currentInstruction[1].u.operand)));
  562. stubCall.addArgument(currentInstruction[2].u.operand, regT2);
  563. stubCall.addArgument(TrustedImm32(currentInstruction[3].u.operand));
  564. stubCall.call();
  565. }
  566. void JIT::emit_op_catch(Instruction* currentInstruction)
  567. {
  568. killLastResultRegister(); // FIXME: Implicitly treat op_catch as a labeled statement, and remove this line of code.
  569. move(regT0, callFrameRegister);
  570. peek(regT3, OBJECT_OFFSETOF(struct JITStackFrame, vm) / sizeof(void*));
  571. load64(Address(regT3, OBJECT_OFFSETOF(VM, exception)), regT0);
  572. store64(TrustedImm64(JSValue::encode(JSValue())), Address(regT3, OBJECT_OFFSETOF(VM, exception)));
  573. emitPutVirtualRegister(currentInstruction[1].u.operand);
  574. }
  575. void JIT::emit_op_switch_imm(Instruction* currentInstruction)
  576. {
  577. unsigned tableIndex = currentInstruction[1].u.operand;
  578. unsigned defaultOffset = currentInstruction[2].u.operand;
  579. unsigned scrutinee = currentInstruction[3].u.operand;
  580. // create jump table for switch destinations, track this switch statement.
  581. SimpleJumpTable* jumpTable = &m_codeBlock->immediateSwitchJumpTable(tableIndex);
  582. m_switches.append(SwitchRecord(jumpTable, m_bytecodeOffset, defaultOffset, SwitchRecord::Immediate));
  583. jumpTable->ctiOffsets.grow(jumpTable->branchOffsets.size());
  584. JITStubCall stubCall(this, cti_op_switch_imm);
  585. stubCall.addArgument(scrutinee, regT2);
  586. stubCall.addArgument(TrustedImm32(tableIndex));
  587. stubCall.call();
  588. jump(regT0);
  589. }
  590. void JIT::emit_op_switch_char(Instruction* currentInstruction)
  591. {
  592. unsigned tableIndex = currentInstruction[1].u.operand;
  593. unsigned defaultOffset = currentInstruction[2].u.operand;
  594. unsigned scrutinee = currentInstruction[3].u.operand;
  595. // create jump table for switch destinations, track this switch statement.
  596. SimpleJumpTable* jumpTable = &m_codeBlock->characterSwitchJumpTable(tableIndex);
  597. m_switches.append(SwitchRecord(jumpTable, m_bytecodeOffset, defaultOffset, SwitchRecord::Character));
  598. jumpTable->ctiOffsets.grow(jumpTable->branchOffsets.size());
  599. JITStubCall stubCall(this, cti_op_switch_char);
  600. stubCall.addArgument(scrutinee, regT2);
  601. stubCall.addArgument(TrustedImm32(tableIndex));
  602. stubCall.call();
  603. jump(regT0);
  604. }
  605. void JIT::emit_op_switch_string(Instruction* currentInstruction)
  606. {
  607. unsigned tableIndex = currentInstruction[1].u.operand;
  608. unsigned defaultOffset = currentInstruction[2].u.operand;
  609. unsigned scrutinee = currentInstruction[3].u.operand;
  610. // create jump table for switch destinations, track this switch statement.
  611. StringJumpTable* jumpTable = &m_codeBlock->stringSwitchJumpTable(tableIndex);
  612. m_switches.append(SwitchRecord(jumpTable, m_bytecodeOffset, defaultOffset));
  613. JITStubCall stubCall(this, cti_op_switch_string);
  614. stubCall.addArgument(scrutinee, regT2);
  615. stubCall.addArgument(TrustedImm32(tableIndex));
  616. stubCall.call();
  617. jump(regT0);
  618. }
  619. void JIT::emit_op_throw_static_error(Instruction* currentInstruction)
  620. {
  621. JITStubCall stubCall(this, cti_op_throw_static_error);
  622. if (!m_codeBlock->getConstant(currentInstruction[1].u.operand).isNumber())
  623. stubCall.addArgument(TrustedImm64(JSValue::encode(m_codeBlock->getConstant(currentInstruction[1].u.operand))));
  624. else
  625. stubCall.addArgument(Imm64(JSValue::encode(m_codeBlock->getConstant(currentInstruction[1].u.operand))));
  626. stubCall.addArgument(TrustedImm32(currentInstruction[2].u.operand));
  627. stubCall.call();
  628. }
  629. void JIT::emit_op_debug(Instruction* currentInstruction)
  630. {
  631. #if ENABLE(DEBUG_WITH_BREAKPOINT)
  632. UNUSED_PARAM(currentInstruction);
  633. breakpoint();
  634. #else
  635. JITStubCall stubCall(this, cti_op_debug);
  636. stubCall.addArgument(TrustedImm32(currentInstruction[1].u.operand));
  637. stubCall.addArgument(TrustedImm32(currentInstruction[2].u.operand));
  638. stubCall.addArgument(TrustedImm32(currentInstruction[3].u.operand));
  639. stubCall.addArgument(TrustedImm32(currentInstruction[4].u.operand));
  640. stubCall.call();
  641. #endif
  642. }
  643. void JIT::emit_op_eq_null(Instruction* currentInstruction)
  644. {
  645. unsigned dst = currentInstruction[1].u.operand;
  646. unsigned src1 = currentInstruction[2].u.operand;
  647. emitGetVirtualRegister(src1, regT0);
  648. Jump isImmediate = emitJumpIfNotJSCell(regT0);
  649. loadPtr(Address(regT0, JSCell::structureOffset()), regT2);
  650. Jump isMasqueradesAsUndefined = branchTest8(NonZero, Address(regT2, Structure::typeInfoFlagsOffset()), TrustedImm32(MasqueradesAsUndefined));
  651. move(TrustedImm32(0), regT0);
  652. Jump wasNotMasqueradesAsUndefined = jump();
  653. isMasqueradesAsUndefined.link(this);
  654. move(TrustedImmPtr(m_codeBlock->globalObject()), regT0);
  655. loadPtr(Address(regT2, Structure::globalObjectOffset()), regT2);
  656. comparePtr(Equal, regT0, regT2, regT0);
  657. Jump wasNotImmediate = jump();
  658. isImmediate.link(this);
  659. and64(TrustedImm32(~TagBitUndefined), regT0);
  660. compare64(Equal, regT0, TrustedImm32(ValueNull), regT0);
  661. wasNotImmediate.link(this);
  662. wasNotMasqueradesAsUndefined.link(this);
  663. emitTagAsBoolImmediate(regT0);
  664. emitPutVirtualRegister(dst);
  665. }
  666. void JIT::emit_op_neq_null(Instruction* currentInstruction)
  667. {
  668. unsigned dst = currentInstruction[1].u.operand;
  669. unsigned src1 = currentInstruction[2].u.operand;
  670. emitGetVirtualRegister(src1, regT0);
  671. Jump isImmediate = emitJumpIfNotJSCell(regT0);
  672. loadPtr(Address(regT0, JSCell::structureOffset()), regT2);
  673. Jump isMasqueradesAsUndefined = branchTest8(NonZero, Address(regT2, Structure::typeInfoFlagsOffset()), TrustedImm32(MasqueradesAsUndefined));
  674. move(TrustedImm32(1), regT0);
  675. Jump wasNotMasqueradesAsUndefined = jump();
  676. isMasqueradesAsUndefined.link(this);
  677. move(TrustedImmPtr(m_codeBlock->globalObject()), regT0);
  678. loadPtr(Address(regT2, Structure::globalObjectOffset()), regT2);
  679. comparePtr(NotEqual, regT0, regT2, regT0);
  680. Jump wasNotImmediate = jump();
  681. isImmediate.link(this);
  682. and64(TrustedImm32(~TagBitUndefined), regT0);
  683. compare64(NotEqual, regT0, TrustedImm32(ValueNull), regT0);
  684. wasNotImmediate.link(this);
  685. wasNotMasqueradesAsUndefined.link(this);
  686. emitTagAsBoolImmediate(regT0);
  687. emitPutVirtualRegister(dst);
  688. }
  689. void JIT::emit_op_enter(Instruction*)
  690. {
  691. emitEnterOptimizationCheck();
  692. // Even though CTI doesn't use them, we initialize our constant
  693. // registers to zap stale pointers, to avoid unnecessarily prolonging
  694. // object lifetime and increasing GC pressure.
  695. size_t count = m_codeBlock->m_numVars;
  696. for (size_t j = 0; j < count; ++j)
  697. emitInitRegister(j);
  698. }
  699. void JIT::emit_op_create_activation(Instruction* currentInstruction)
  700. {
  701. unsigned dst = currentInstruction[1].u.operand;
  702. Jump activationCreated = branchTest64(NonZero, Address(callFrameRegister, sizeof(Register) * dst));
  703. JITStubCall(this, cti_op_push_activation).call(currentInstruction[1].u.operand);
  704. emitPutVirtualRegister(dst);
  705. activationCreated.link(this);
  706. }
  707. void JIT::emit_op_create_arguments(Instruction* currentInstruction)
  708. {
  709. unsigned dst = currentInstruction[1].u.operand;
  710. Jump argsCreated = branchTest64(NonZero, Address(callFrameRegister, sizeof(Register) * dst));
  711. JITStubCall(this, cti_op_create_arguments).call();
  712. emitPutVirtualRegister(dst);
  713. emitPutVirtualRegister(unmodifiedArgumentsRegister(dst));
  714. argsCreated.link(this);
  715. }
  716. void JIT::emit_op_init_lazy_reg(Instruction* currentInstruction)
  717. {
  718. unsigned dst = currentInstruction[1].u.operand;
  719. store64(TrustedImm64((int64_t)0), Address(callFrameRegister, sizeof(Register) * dst));
  720. }
  721. void JIT::emit_op_convert_this(Instruction* currentInstruction)
  722. {
  723. emitGetVirtualRegister(currentInstruction[1].u.operand, regT1);
  724. emitJumpSlowCaseIfNotJSCell(regT1);
  725. if (shouldEmitProfiling()) {
  726. loadPtr(Address(regT1, JSCell::structureOffset()), regT0);
  727. emitValueProfilingSite();
  728. }
  729. addSlowCase(branchPtr(Equal, Address(regT1, JSCell::structureOffset()), TrustedImmPtr(m_vm->stringStructure.get())));
  730. }
  731. void JIT::emit_op_get_callee(Instruction* currentInstruction)
  732. {
  733. unsigned result = currentInstruction[1].u.operand;
  734. emitGetFromCallFrameHeaderPtr(JSStack::Callee, regT0);
  735. emitValueProfilingSite();
  736. emitPutVirtualRegister(result);
  737. }
  738. void JIT::emit_op_create_this(Instruction* currentInstruction)
  739. {
  740. int callee = currentInstruction[2].u.operand;
  741. RegisterID calleeReg = regT0;
  742. RegisterID resultReg = regT0;
  743. RegisterID allocatorReg = regT1;
  744. RegisterID structureReg = regT2;
  745. RegisterID scratchReg = regT3;
  746. emitGetVirtualRegister(callee, calleeReg);
  747. loadPtr(Address(calleeReg, JSFunction::offsetOfAllocationProfile() + ObjectAllocationProfile::offsetOfAllocator()), allocatorReg);
  748. loadPtr(Address(calleeReg, JSFunction::offsetOfAllocationProfile() + ObjectAllocationProfile::offsetOfStructure()), structureReg);
  749. addSlowCase(branchTestPtr(Zero, allocatorReg));
  750. emitAllocateJSObject(allocatorReg, structureReg, resultReg, scratchReg);
  751. emitPutVirtualRegister(currentInstruction[1].u.operand);
  752. }
  753. void JIT::emitSlow_op_create_this(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
  754. {
  755. linkSlowCase(iter); // doesn't have an allocation profile
  756. linkSlowCase(iter); // allocation failed
  757. JITStubCall stubCall(this, cti_op_create_this);
  758. stubCall.addArgument(TrustedImm32(currentInstruction[3].u.operand));
  759. stubCall.call(currentInstruction[1].u.operand);
  760. }
  761. void JIT::emit_op_profile_will_call(Instruction* currentInstruction)
  762. {
  763. JITStubCall stubCall(this, cti_op_profile_will_call);
  764. stubCall.addArgument(currentInstruction[1].u.operand, regT1);
  765. stubCall.call();
  766. }
  767. void JIT::emit_op_profile_did_call(Instruction* currentInstruction)
  768. {
  769. JITStubCall stubCall(this, cti_op_profile_did_call);
  770. stubCall.addArgument(currentInstruction[1].u.operand, regT1);
  771. stubCall.call();
  772. }
  773. // Slow cases
  774. void JIT::emitSlow_op_convert_this(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
  775. {
  776. void* globalThis = m_codeBlock->globalObject()->globalThis();
  777. linkSlowCase(iter);
  778. if (shouldEmitProfiling())
  779. move(TrustedImm64((JSValue::encode(jsUndefined()))), regT0);
  780. Jump isNotUndefined = branch64(NotEqual, regT1, TrustedImm64(JSValue::encode(jsUndefined())));
  781. emitValueProfilingSite();
  782. move(TrustedImm64(JSValue::encode(JSValue(static_cast<JSCell*>(globalThis)))), regT0);
  783. emitPutVirtualRegister(currentInstruction[1].u.operand, regT0);
  784. emitJumpSlowToHot(jump(), OPCODE_LENGTH(op_convert_this));
  785. linkSlowCase(iter);
  786. if (shouldEmitProfiling())
  787. move(TrustedImm64(JSValue::encode(m_vm->stringStructure.get())), regT0);
  788. isNotUndefined.link(this);
  789. emitValueProfilingSite();
  790. JITStubCall stubCall(this, cti_op_convert_this);
  791. stubCall.addArgument(regT1);
  792. stubCall.call(currentInstruction[1].u.operand);
  793. }
  794. void JIT::emitSlow_op_to_primitive(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
  795. {
  796. linkSlowCase(iter);
  797. JITStubCall stubCall(this, cti_op_to_primitive);
  798. stubCall.addArgument(regT0);
  799. stubCall.call(currentInstruction[1].u.operand);
  800. }
  801. void JIT::emitSlow_op_not(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
  802. {
  803. linkSlowCase(iter);
  804. xor64(TrustedImm32(static_cast<int32_t>(ValueFalse)), regT0);
  805. JITStubCall stubCall(this, cti_op_not);
  806. stubCall.addArgument(regT0);
  807. stubCall.call(currentInstruction[1].u.operand);
  808. }
  809. void JIT::emitSlow_op_jfalse(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
  810. {
  811. linkSlowCase(iter);
  812. JITStubCall stubCall(this, cti_op_jtrue);
  813. stubCall.addArgument(regT0);
  814. stubCall.call();
  815. emitJumpSlowToHot(branchTest32(Zero, regT0), currentInstruction[2].u.operand); // inverted!
  816. }
  817. void JIT::emitSlow_op_jtrue(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
  818. {
  819. linkSlowCase(iter);
  820. JITStubCall stubCall(this, cti_op_jtrue);
  821. stubCall.addArgument(regT0);
  822. stubCall.call();
  823. emitJumpSlowToHot(branchTest32(NonZero, regT0), currentInstruction[2].u.operand);
  824. }
  825. void JIT::emitSlow_op_bitxor(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
  826. {
  827. linkSlowCase(iter);
  828. JITStubCall stubCall(this, cti_op_bitxor);
  829. stubCall.addArgument(regT0);
  830. stubCall.addArgument(regT1);
  831. stubCall.call(currentInstruction[1].u.operand);
  832. }
  833. void JIT::emitSlow_op_bitor(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
  834. {
  835. linkSlowCase(iter);
  836. JITStubCall stubCall(this, cti_op_bitor);
  837. stubCall.addArgument(regT0);
  838. stubCall.addArgument(regT1);
  839. stubCall.call(currentInstruction[1].u.operand);
  840. }
  841. void JIT::emitSlow_op_eq(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
  842. {
  843. linkSlowCase(iter);
  844. JITStubCall stubCall(this, cti_op_eq);
  845. stubCall.addArgument(regT0);
  846. stubCall.addArgument(regT1);
  847. stubCall.call();
  848. emitTagAsBoolImmediate(regT0);
  849. emitPutVirtualRegister(currentInstruction[1].u.operand);
  850. }
  851. void JIT::emitSlow_op_neq(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
  852. {
  853. linkSlowCase(iter);
  854. JITStubCall stubCall(this, cti_op_eq);
  855. stubCall.addArgument(regT0);
  856. stubCall.addArgument(regT1);
  857. stubCall.call();
  858. xor32(TrustedImm32(0x1), regT0);
  859. emitTagAsBoolImmediate(regT0);
  860. emitPutVirtualRegister(currentInstruction[1].u.operand);
  861. }
  862. void JIT::emitSlow_op_stricteq(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
  863. {
  864. linkSlowCase(iter);
  865. linkSlowCase(iter);
  866. linkSlowCase(iter);
  867. JITStubCall stubCall(this, cti_op_stricteq);
  868. stubCall.addArgument(regT0);
  869. stubCall.addArgument(regT1);
  870. stubCall.call(currentInstruction[1].u.operand);
  871. }
  872. void JIT::emitSlow_op_nstricteq(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
  873. {
  874. linkSlowCase(iter);
  875. linkSlowCase(iter);
  876. linkSlowCase(iter);
  877. JITStubCall stubCall(this, cti_op_nstricteq);
  878. stubCall.addArgument(regT0);
  879. stubCall.addArgument(regT1);
  880. stubCall.call(currentInstruction[1].u.operand);
  881. }
  882. void JIT::emitSlow_op_check_has_instance(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
  883. {
  884. unsigned dst = currentInstruction[1].u.operand;
  885. unsigned value = currentInstruction[2].u.operand;
  886. unsigned baseVal = currentInstruction[3].u.operand;
  887. linkSlowCaseIfNotJSCell(iter, baseVal);
  888. linkSlowCase(iter);
  889. JITStubCall stubCall(this, cti_op_check_has_instance);
  890. stubCall.addArgument(value, regT2);
  891. stubCall.addArgument(baseVal, regT2);
  892. stubCall.call(dst);
  893. emitJumpSlowToHot(jump(), currentInstruction[4].u.operand);
  894. }
  895. void JIT::emitSlow_op_instanceof(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
  896. {
  897. unsigned dst = currentInstruction[1].u.operand;
  898. unsigned value = currentInstruction[2].u.operand;
  899. unsigned proto = currentInstruction[3].u.operand;
  900. linkSlowCaseIfNotJSCell(iter, value);
  901. linkSlowCaseIfNotJSCell(iter, proto);
  902. linkSlowCase(iter);
  903. JITStubCall stubCall(this, cti_op_instanceof);
  904. stubCall.addArgument(value, regT2);
  905. stubCall.addArgument(proto, regT2);
  906. stubCall.call(dst);
  907. }
  908. void JIT::emitSlow_op_call(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
  909. {
  910. compileOpCallSlowCase(op_call, currentInstruction, iter, m_callLinkInfoIndex++);
  911. }
  912. void JIT::emitSlow_op_call_eval(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
  913. {
  914. compileOpCallSlowCase(op_call_eval, currentInstruction, iter, m_callLinkInfoIndex);
  915. }
  916. void JIT::emitSlow_op_call_varargs(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
  917. {
  918. compileOpCallSlowCase(op_call_varargs, currentInstruction, iter, m_callLinkInfoIndex++);
  919. }
  920. void JIT::emitSlow_op_construct(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
  921. {
  922. compileOpCallSlowCase(op_construct, currentInstruction, iter, m_callLinkInfoIndex++);
  923. }
  924. void JIT::emitSlow_op_to_number(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
  925. {
  926. linkSlowCase(iter);
  927. JITStubCall stubCall(this, cti_op_to_number);
  928. stubCall.addArgument(regT0);
  929. stubCall.call(currentInstruction[1].u.operand);
  930. }
  931. void JIT::emit_op_get_arguments_length(Instruction* currentInstruction)
  932. {
  933. int dst = currentInstruction[1].u.operand;
  934. int argumentsRegister = currentInstruction[2].u.operand;
  935. addSlowCase(branchTest64(NonZero, addressFor(argumentsRegister)));
  936. emitGetFromCallFrameHeader32(JSStack::ArgumentCount, regT0);
  937. sub32(TrustedImm32(1), regT0);
  938. emitFastArithReTagImmediate(regT0, regT0);
  939. emitPutVirtualRegister(dst, regT0);
  940. }
  941. void JIT::emitSlow_op_get_arguments_length(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
  942. {
  943. linkSlowCase(iter);
  944. unsigned dst = currentInstruction[1].u.operand;
  945. unsigned base = currentInstruction[2].u.operand;
  946. Identifier* ident = &(m_codeBlock->identifier(currentInstruction[3].u.operand));
  947. emitGetVirtualRegister(base, regT0);
  948. JITStubCall stubCall(this, cti_op_get_by_id_generic);
  949. stubCall.addArgument(regT0);
  950. stubCall.addArgument(TrustedImmPtr(ident));
  951. stubCall.call(dst);
  952. }
  953. void JIT::emit_op_get_argument_by_val(Instruction* currentInstruction)
  954. {
  955. int dst = currentInstruction[1].u.operand;
  956. int argumentsRegister = currentInstruction[2].u.operand;
  957. int property = currentInstruction[3].u.operand;
  958. addSlowCase(branchTest64(NonZero, addressFor(argumentsRegister)));
  959. emitGetVirtualRegister(property, regT1);
  960. addSlowCase(emitJumpIfNotImmediateInteger(regT1));
  961. add32(TrustedImm32(1), regT1);
  962. // regT1 now contains the integer index of the argument we want, including this
  963. emitGetFromCallFrameHeader32(JSStack::ArgumentCount, regT2);
  964. addSlowCase(branch32(AboveOrEqual, regT1, regT2));
  965. neg32(regT1);
  966. signExtend32ToPtr(regT1, regT1);
  967. load64(BaseIndex(callFrameRegister, regT1, TimesEight, CallFrame::thisArgumentOffset() * static_cast<int>(sizeof(Register))), regT0);
  968. emitValueProfilingSite();
  969. emitPutVirtualRegister(dst, regT0);
  970. }
  971. void JIT::emitSlow_op_get_argument_by_val(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
  972. {
  973. unsigned dst = currentInstruction[1].u.operand;
  974. unsigned arguments = currentInstruction[2].u.operand;
  975. unsigned property = currentInstruction[3].u.operand;
  976. linkSlowCase(iter);
  977. Jump skipArgumentsCreation = jump();
  978. linkSlowCase(iter);
  979. linkSlowCase(iter);
  980. JITStubCall(this, cti_op_create_arguments).call();
  981. emitPutVirtualRegister(arguments);
  982. emitPutVirtualRegister(unmodifiedArgumentsRegister(arguments));
  983. skipArgumentsCreation.link(this);
  984. JITStubCall stubCall(this, cti_op_get_by_val_generic);
  985. stubCall.addArgument(arguments, regT2);
  986. stubCall.addArgument(property, regT2);
  987. stubCall.callWithValueProfiling(dst);
  988. }
  989. void JIT::emit_op_put_to_base(Instruction* currentInstruction)
  990. {
  991. int base = currentInstruction[1].u.operand;
  992. int id = currentInstruction[2].u.operand;
  993. int value = currentInstruction[3].u.operand;
  994. PutToBaseOperation* operation = currentInstruction[4].u.putToBaseOperation;
  995. switch (operation->m_kind) {
  996. case PutToBaseOperation::GlobalVariablePutChecked:
  997. addSlowCase(branchTest8(NonZero, AbsoluteAddress(operation->m_predicatePointer)));
  998. case PutToBaseOperation::GlobalVariablePut: {
  999. JSGlobalObject* globalObject = m_codeBlock->globalObject();
  1000. if (operation->m_isDynamic) {
  1001. emitGetVirtualRegister(base, regT0);
  1002. addSlowCase(branchPtr(NotEqual, regT0, TrustedImmPtr(globalObject)));
  1003. }
  1004. emitGetVirtualRegister(value, regT0);
  1005. store64(regT0, operation->m_registerAddress);
  1006. if (Heap::isWriteBarrierEnabled())
  1007. emitWriteBarrier(globalObject, regT0, regT2, ShouldFilterImmediates, WriteBarrierForVariableAccess);
  1008. return;
  1009. }
  1010. case PutToBaseOperation::VariablePut: {
  1011. emitGetVirtualRegisters(base, regT0, value, regT1);
  1012. loadPtr(Address(regT0, JSVariableObject::offsetOfRegisters()), regT2);
  1013. store64(regT1, Address(regT2, operation->m_offset * sizeof(Register)));
  1014. if (Heap::isWriteBarrierEnabled())
  1015. emitWriteBarrier(regT0, regT1, regT2, regT3, ShouldFilterImmediates, WriteBarrierForVariableAccess);
  1016. return;
  1017. }
  1018. case PutToBaseOperation::GlobalPropertyPut: {
  1019. emitGetVirtualRegisters(base, regT0, value, regT1);
  1020. loadPtr(&operation->m_structure, regT2);
  1021. addSlowCase(branchPtr(NotEqual, Address(regT0, JSCell::structureOffset()), regT2));
  1022. ASSERT(!operation->m_structure || !operation->m_structure->inlineCapacity());
  1023. loadPtr(Address(regT0, JSObject::butterflyOffset()), regT2);
  1024. load32(&operation->m_offsetInButterfly, regT3);
  1025. signExtend32ToPtr(regT3, regT3);
  1026. store64(regT1, BaseIndex(regT2, regT3, TimesEight));
  1027. if (Heap::isWriteBarrierEnabled())
  1028. emitWriteBarrier(regT0, regT1, regT2, regT3, ShouldFilterImmediates, WriteBarrierForVariableAccess);
  1029. return;
  1030. }
  1031. case PutToBaseOperation::Uninitialised:
  1032. case PutToBaseOperation::Readonly:
  1033. case PutToBaseOperation::Generic:
  1034. JITStubCall stubCall(this, cti_op_put_to_base);
  1035. stubCall.addArgument(TrustedImm32(base));
  1036. stubCall.addArgument(TrustedImmPtr(&m_codeBlock->identifier(id)));
  1037. stubCall.addArgument(TrustedImm32(value));
  1038. stubCall.addArgument(TrustedImmPtr(operation));
  1039. stubCall.call();
  1040. return;
  1041. }
  1042. }
  1043. #endif // USE(JSVALUE64)
  1044. void JIT::emit_op_loop_hint(Instruction*)
  1045. {
  1046. // Emit the JIT optimization check:
  1047. if (canBeOptimized())
  1048. addSlowCase(branchAdd32(PositiveOrZero, TrustedImm32(Options::executionCounterIncrementForLoop()),
  1049. AbsoluteAddress(m_codeBlock->addressOfJITExecuteCounter())));
  1050. // Emit the watchdog timer check:
  1051. if (m_vm->watchdog.isEnabled())
  1052. addSlowCase(branchTest8(NonZero, AbsoluteAddress(m_vm->watchdog.timerDidFireAddress())));
  1053. }
  1054. void JIT::emitSlow_op_loop_hint(Instruction*, Vector<SlowCaseEntry>::iterator& iter)
  1055. {
  1056. #if ENABLE(DFG_JIT)
  1057. // Emit the slow path for the JIT optimization check:
  1058. if (canBeOptimized()) {
  1059. linkSlowCase(iter);
  1060. JITStubCall stubCall(this, cti_optimize);
  1061. stubCall.addArgument(TrustedImm32(m_bytecodeOffset));
  1062. stubCall.call();
  1063. emitJumpSlowToHot(jump(), OPCODE_LENGTH(op_loop_hint));
  1064. }
  1065. #endif
  1066. // Emit the slow path of the watchdog timer check:
  1067. if (m_vm->watchdog.isEnabled()) {
  1068. linkSlowCase(iter);
  1069. JITStubCall stubCall(this, cti_handle_watchdog_timer);
  1070. stubCall.call();
  1071. emitJumpSlowToHot(jump(), OPCODE_LENGTH(op_loop_hint));
  1072. }
  1073. }
  1074. void JIT::emit_resolve_operations(ResolveOperations* resolveOperations, const int* baseVR, const int* valueVR)
  1075. {
  1076. #if USE(JSVALUE32_64)
  1077. unmap();
  1078. #else
  1079. killLastResultRegister();
  1080. #endif
  1081. if (resolveOperations->isEmpty()) {
  1082. addSlowCase(jump());
  1083. return;
  1084. }
  1085. const RegisterID value = regT0;
  1086. #if USE(JSVALUE32_64)
  1087. const RegisterID valueTag = regT1;
  1088. #endif
  1089. const RegisterID scope = regT2;
  1090. const RegisterID scratch = regT3;
  1091. JSGlobalObject* globalObject = m_codeBlock->globalObject();
  1092. ResolveOperation* pc = resolveOperations->data();
  1093. emitGetFromCallFrameHeaderPtr(JSStack::ScopeChain, scope);
  1094. bool setBase = false;
  1095. bool resolvingBase = true;
  1096. while (resolvingBase) {
  1097. switch (pc->m_operation) {
  1098. case ResolveOperation::ReturnGlobalObjectAsBase:
  1099. move(TrustedImmPtr(globalObject), value);
  1100. #if USE(JSVALUE32_64)
  1101. move(TrustedImm32(JSValue::CellTag), valueTag);
  1102. #endif
  1103. emitValueProfilingSite();
  1104. emitStoreCell(*baseVR, value);
  1105. return;
  1106. case ResolveOperation::SetBaseToGlobal:
  1107. RELEASE_ASSERT(baseVR);
  1108. setBase = true;
  1109. move(TrustedImmPtr(globalObject), scratch);
  1110. emitStoreCell(*baseVR, scratch);
  1111. resolvingBase = false;
  1112. ++pc;
  1113. break;
  1114. case ResolveOperation::SetBaseToUndefined: {
  1115. RELEASE_ASSERT(baseVR);
  1116. setBase = true;
  1117. #if USE(JSVALUE64)
  1118. move(TrustedImm64(JSValue::encode(jsUndefined())), scratch);
  1119. emitPutVirtualRegister(*baseVR, scratch);
  1120. #else
  1121. emitStore(*baseVR, jsUndefined());
  1122. #endif
  1123. resolvingBase = false;
  1124. ++pc;
  1125. break;
  1126. }
  1127. case ResolveOperation::SetBaseToScope:
  1128. RELEASE_ASSERT(baseVR);
  1129. setBase = true;
  1130. emitStoreCell(*baseVR, scope);
  1131. resolvingBase = false;
  1132. ++pc;
  1133. break;
  1134. case ResolveOperation::ReturnScopeAsBase:
  1135. emitStoreCell(*baseVR, scope);
  1136. RELEASE_ASSERT(value == regT0);
  1137. move(scope, value);
  1138. #if USE(JSVALUE32_64)
  1139. move(TrustedImm32(JSValue::CellTag), valueTag);
  1140. #endif
  1141. emitValueProfilingSite();
  1142. return;
  1143. case ResolveOperation::SkipTopScopeNode: {
  1144. #if USE(JSVALUE32_64)
  1145. Jump activationNotCreated = branch32(Equal, tagFor(m_codeBlock->activationRegister()), TrustedImm32(JSValue::EmptyValueTag));
  1146. #else
  1147. Jump activationNotCreated = branchTest64(Zero, addressFor(m_codeBlock->activationRegister()));
  1148. #endif
  1149. loadPtr(Address(scope, JSScope::offsetOfNext()), scope);
  1150. activationNotCreated.link(this);
  1151. ++pc;
  1152. break;
  1153. }
  1154. case ResolveOperation::CheckForDynamicEntriesBeforeGlobalScope: {
  1155. move(scope, regT3);
  1156. loadPtr(Address(regT3, JSScope::offsetOfNext()), regT1);
  1157. Jump atTopOfScope = branchTestPtr(Zero, regT1);
  1158. Label loopStart = label();
  1159. loadPtr(Address(regT3, JSCell::structureOffset()), regT2);
  1160. Jump isActivation = branchPtr(Equal, regT2, TrustedImmPtr(globalObject->activationStructure()));
  1161. addSlowCase(branchPtr(NotEqual, regT2, TrustedImmPtr(globalObject->nameScopeStructure())));
  1162. isActivation.link(this);
  1163. move(regT1, regT3);
  1164. loadPtr(Address(regT3, JSScope::offsetOfNext()), regT1);
  1165. branchTestPtr(NonZero, regT1, loopStart);
  1166. atTopOfScope.link(this);
  1167. ++pc;
  1168. break;
  1169. }
  1170. case ResolveOperation::SkipScopes: {
  1171. for (int i = 0; i < pc->m_scopesToSkip; i++)
  1172. loadPtr(Address(scope, JSScope::offsetOfNext()), scope);
  1173. ++pc;
  1174. break;
  1175. }
  1176. case ResolveOperation::Fail:
  1177. addSlowCase(jump());
  1178. return;
  1179. default:
  1180. resolvingBase = false;
  1181. }
  1182. }
  1183. if (baseVR && !setBase)
  1184. emitStoreCell(*baseVR, scope);
  1185. RELEASE_ASSERT(valueVR);
  1186. ResolveOperation* resolveValueOperation = pc;
  1187. switch (resolveValueOperation->m_operation) {
  1188. case ResolveOperation::GetAndReturnGlobalProperty: {
  1189. // Verify structure.
  1190. move(TrustedImmPtr(globalObject), regT2);
  1191. move(TrustedImmPtr(resolveValueOperation), regT3);
  1192. loadPtr(Address(regT3, OBJECT_OFFSETOF(ResolveOperation, m_structure)), regT1);
  1193. addSlowCase(branchPtr(NotEqual, regT1, Address(regT2, JSCell::structureOffset())));
  1194. // Load property.
  1195. load32(Address(regT3, OBJECT_OFFSETOF(ResolveOperation, m_offset)), regT3);
  1196. // regT2: GlobalObject
  1197. // regT3: offset
  1198. #if USE(JSVALUE32_64)
  1199. compileGetDirectOffset(regT2, valueTag, value, regT3, KnownNotFinal);
  1200. #else
  1201. compileGetDirectOffset(regT2, value, regT3, regT1, KnownNotFinal);
  1202. #endif
  1203. break;
  1204. }
  1205. case ResolveOperation::GetAndReturnGlobalVarWatchable:
  1206. case ResolveOperation::GetAndReturnGlobalVar: {
  1207. #if USE(JSVALUE32_64)
  1208. load32(reinterpret_cast<char*>(pc->m_registerAddress) + OBJECT_OFFSETOF(JSValue, u.asBits.tag), valueTag);
  1209. load32(reinterpret_cast<char*>(pc->m_registerAddress) + OBJECT_OFFSETOF(JSValue, u.asBits.payload), value);
  1210. #else
  1211. load64(reinterpret_cast<char*>(pc->m_registerAddress), value);
  1212. #endif
  1213. break;
  1214. }
  1215. case ResolveOperation::GetAndReturnScopedVar: {
  1216. loadPtr(Address(scope, JSVariableObject::offsetOfRegisters()), scope);
  1217. #if USE(JSVALUE32_64)
  1218. load32(Address(scope, pc->m_offset * sizeof(Register) + OBJECT_OFFSETOF(JSValue, u.asBits.tag)), valueTag);
  1219. load32(Address(scope, pc->m_offset * sizeof(Register) + OBJECT_OFFSETOF(JSValue, u.asBits.payload)), value);
  1220. #else
  1221. load64(Address(scope, pc->m_offset * sizeof(Register)), value);
  1222. #endif
  1223. break;
  1224. }
  1225. default:
  1226. CRASH();
  1227. return;
  1228. }
  1229. #if USE(JSVALUE32_64)
  1230. emitStore(*valueVR, valueTag, value);
  1231. #else
  1232. emitPutVirtualRegister(*valueVR, value);
  1233. #endif
  1234. emitValueProfilingSite();
  1235. }
  1236. void JIT::emitSlow_link_resolve_operations(ResolveOperations* resolveOperations, Vector<SlowCaseEntry>::iterator& iter)
  1237. {
  1238. if (resolveOperations->isEmpty()) {
  1239. linkSlowCase(iter);
  1240. return;
  1241. }
  1242. ResolveOperation* pc = resolveOperations->data();
  1243. bool resolvingBase = true;
  1244. while (resolvingBase) {
  1245. switch (pc->m_operation) {
  1246. case ResolveOperation::ReturnGlobalObjectAsBase:
  1247. return;
  1248. case ResolveOperation::SetBaseToGlobal:
  1249. resolvingBase = false;
  1250. ++pc;
  1251. break;
  1252. case ResolveOperation::SetBaseToUndefined: {
  1253. resolvingBase = false;
  1254. ++pc;
  1255. break;
  1256. }
  1257. case ResolveOperation::SetBaseToScope:
  1258. resolvingBase = false;
  1259. ++pc;
  1260. break;
  1261. case ResolveOperation::ReturnScopeAsBase:
  1262. return;
  1263. case ResolveOperation::SkipTopScopeNode: {
  1264. ++pc;
  1265. break;
  1266. }
  1267. case ResolveOperation::SkipScopes:
  1268. ++pc;
  1269. break;
  1270. case ResolveOperation::Fail:
  1271. linkSlowCase(iter);
  1272. return;
  1273. case ResolveOperation::CheckForDynamicEntriesBeforeGlobalScope: {
  1274. linkSlowCase(iter);
  1275. ++pc;
  1276. break;
  1277. }
  1278. default:
  1279. resolvingBase = false;
  1280. }
  1281. }
  1282. ResolveOperation* resolveValueOperation = pc;
  1283. switch (resolveValueOperation->m_operation) {
  1284. case ResolveOperation::GetAndReturnGlobalProperty: {
  1285. linkSlowCase(iter);
  1286. break;
  1287. }
  1288. case ResolveOperation::GetAndReturnGlobalVarWatchable:
  1289. case ResolveOperation::GetAndReturnGlobalVar:
  1290. break;
  1291. case ResolveOperation::GetAndReturnScopedVar:
  1292. break;
  1293. default:
  1294. CRASH();
  1295. return;
  1296. }
  1297. }
  1298. void JIT::emit_op_resolve(Instruction* currentInstruction)
  1299. {
  1300. ResolveOperations* operations = currentInstruction[3].u.resolveOperations;
  1301. int dst = currentInstruction[1].u.operand;
  1302. emit_resolve_operations(operations, 0, &dst);
  1303. }
  1304. void JIT::emitSlow_op_resolve(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
  1305. {
  1306. ResolveOperations* operations = currentInstruction[3].u.resolveOperations;
  1307. emitSlow_link_resolve_operations(operations, iter);
  1308. JITStubCall stubCall(this, cti_op_resolve);
  1309. stubCall.addArgument(TrustedImmPtr(&m_codeBlock->identifier(currentInstruction[2].u.operand)));
  1310. stubCall.addArgument(TrustedImmPtr(currentInstruction[3].u.resolveOperations));
  1311. stubCall.callWithValueProfiling(currentInstruction[1].u.operand);
  1312. }
  1313. void JIT::emit_op_resolve_base(Instruction* currentInstruction)
  1314. {
  1315. ResolveOperations* operations = currentInstruction[4].u.resolveOperations;
  1316. int dst = currentInstruction[1].u.operand;
  1317. emit_resolve_operations(operations, &dst, 0);
  1318. }
  1319. void JIT::emitSlow_op_resolve_base(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
  1320. {
  1321. ResolveOperations* operations = currentInstruction[4].u.resolveOperations;
  1322. emitSlow_link_resolve_operations(operations, iter);
  1323. JITStubCall stubCall(this, currentInstruction[3].u.operand ? cti_op_resolve_base_strict_put : cti_op_resolve_base);
  1324. stubCall.addArgument(TrustedImmPtr(&m_codeBlock->identifier(currentInstruction[2].u.operand)));
  1325. stubCall.addArgument(TrustedImmPtr(currentInstruction[4].u.resolveOperations));
  1326. stubCall.addArgument(TrustedImmPtr(currentInstruction[5].u.putToBaseOperation));
  1327. stubCall.callWithValueProfiling(currentInstruction[1].u.operand);
  1328. }
  1329. void JIT::emit_op_resolve_with_base(Instruction* currentInstruction)
  1330. {
  1331. ResolveOperations* operations = currentInstruction[4].u.resolveOperations;
  1332. int base = currentInstruction[1].u.operand;
  1333. int value = currentInstruction[2].u.operand;
  1334. emit_resolve_operations(operations, &base, &value);
  1335. }
  1336. void JIT::emitSlow_op_resolve_with_base(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
  1337. {
  1338. ResolveOperations* operations = currentInstruction[4].u.resolveOperations;
  1339. emitSlow_link_resolve_operations(operations, iter);
  1340. JITStubCall stubCall(this, cti_op_resolve_with_base);
  1341. stubCall.addArgument(TrustedImmPtr(&m_codeBlock->identifier(currentInstruction[3].u.operand)));
  1342. stubCall.addArgument(TrustedImm32(currentInstruction[1].u.operand));
  1343. stubCall.addArgument(TrustedImmPtr(currentInstruction[4].u.resolveOperations));
  1344. stubCall.addArgument(TrustedImmPtr(currentInstruction[5].u.putToBaseOperation));
  1345. stubCall.callWithValueProfiling(currentInstruction[2].u.operand);
  1346. }
  1347. void JIT::emit_op_resolve_with_this(Instruction* currentInstruction)
  1348. {
  1349. ResolveOperations* operations = currentInstruction[4].u.resolveOperations;
  1350. int base = currentInstruction[1].u.operand;
  1351. int value = currentInstruction[2].u.operand;
  1352. emit_resolve_operations(operations, &base, &value);
  1353. }
  1354. void JIT::emitSlow_op_resolve_with_this(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
  1355. {
  1356. ResolveOperations* operations = currentInstruction[4].u.resolveOperations;
  1357. emitSlow_link_resolve_operations(operations, iter);
  1358. JITStubCall stubCall(this, cti_op_resolve_with_this);
  1359. stubCall.addArgument(TrustedImmPtr(&m_codeBlock->identifier(currentInstruction[3].u.operand)));
  1360. stubCall.addArgument(TrustedImm32(currentInstruction[1].u.operand));
  1361. stubCall.addArgument(TrustedImmPtr(currentInstruction[4].u.resolveOperations));
  1362. stubCall.callWithValueProfiling(currentInstruction[2].u.operand);
  1363. }
  1364. void JIT::emitSlow_op_put_to_base(Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter)
  1365. {
  1366. int base = currentInstruction[1].u.operand;
  1367. int id = currentInstruction[2].u.operand;
  1368. int value = currentInstruction[3].u.operand;
  1369. PutToBaseOperation* putToBaseOperation = currentInstruction[4].u.putToBaseOperation;
  1370. switch (putToBaseOperation->m_kind) {
  1371. case PutToBaseOperation::VariablePut:
  1372. return;
  1373. case PutToBaseOperation::GlobalVariablePutChecked:
  1374. linkSlowCase(iter);
  1375. case PutToBaseOperation::GlobalVariablePut:
  1376. if (!putToBaseOperation->m_isDynamic)
  1377. return;
  1378. linkSlowCase(iter);
  1379. break;
  1380. case PutToBaseOperation::Uninitialised:
  1381. case PutToBaseOperation::Readonly:
  1382. case PutToBaseOperation::Generic:
  1383. return;
  1384. case PutToBaseOperation::GlobalPropertyPut:
  1385. linkSlowCase(iter);
  1386. break;
  1387. }
  1388. JITStubCall stubCall(this, cti_op_put_to_base);
  1389. stubCall.addArgument(TrustedImm32(base));
  1390. stubCall.addArgument(TrustedImmPtr(&m_codeBlock->identifier(id)));
  1391. stubCall.addArgument(TrustedImm32(value));
  1392. stubCall.addArgument(TrustedImmPtr(putToBaseOperation));
  1393. stubCall.call();
  1394. }
  1395. void JIT::emit_op_new_regexp(Instruction* currentInstruction)
  1396. {
  1397. JITStubCall stubCall(this, cti_op_new_regexp);
  1398. stubCall.addArgument(TrustedImmPtr(m_codeBlock->regexp(currentInstruction[2].u.operand)));
  1399. stubCall.call(currentInstruction[1].u.operand);
  1400. }
  1401. void JIT::emit_op_new_func(Instruction* currentInstruction)
  1402. {
  1403. Jump lazyJump;
  1404. int dst = currentInstruction[1].u.operand;
  1405. if (currentInstruction[3].u.operand) {
  1406. #if USE(JSVALUE32_64)
  1407. lazyJump = branch32(NotEqual, tagFor(dst), TrustedImm32(JSValue::EmptyValueTag));
  1408. #else
  1409. lazyJump = branchTest64(NonZero, addressFor(dst));
  1410. #endif
  1411. }
  1412. JITStubCall stubCall(this, cti_op_new_func);
  1413. stubCall.addArgument(TrustedImmPtr(m_codeBlock->functionDecl(currentInstruction[2].u.operand)));
  1414. stubCall.call(dst);
  1415. if (currentInstruction[3].u.operand) {
  1416. #if USE(JSVALUE32_64)
  1417. unmap();
  1418. #else
  1419. killLastResultRegister();
  1420. #endif
  1421. lazyJump.link(this);
  1422. }
  1423. }
  1424. void JIT::emit_op_new_func_exp(Instruction* currentInstruction)
  1425. {
  1426. JITStubCall stubCall(this, cti_op_new_func_exp);
  1427. stubCall.addArgument(TrustedImmPtr(m_codeBlock->functionExpr(currentInstruction[2].u.operand)));
  1428. stubCall.call(currentInstruction[1].u.operand);
  1429. }
  1430. void JIT::emit_op_new_array(Instruction* currentInstruction)
  1431. {
  1432. JITStubCall stubCall(this, cti_op_new_array);
  1433. stubCall.addArgument(TrustedImm32(currentInstruction[2].u.operand));
  1434. stubCall.addArgument(TrustedImm32(currentInstruction[3].u.operand));
  1435. stubCall.addArgument(TrustedImmPtr(currentInstruction[4].u.arrayAllocationProfile));
  1436. stubCall.call(currentInstruction[1].u.operand);
  1437. }
  1438. void JIT::emit_op_new_array_with_size(Instruction* currentInstruction)
  1439. {
  1440. JITStubCall stubCall(this, cti_op_new_array_with_size);
  1441. #if USE(JSVALUE64)
  1442. stubCall.addArgument(currentInstruction[2].u.operand, regT2);
  1443. #else
  1444. stubCall.addArgument(currentInstruction[2].u.operand);
  1445. #endif
  1446. stubCall.addArgument(TrustedImmPtr(currentInstruction[3].u.arrayAllocationProfile));
  1447. stubCall.call(currentInstruction[1].u.operand);
  1448. }
  1449. void JIT::emit_op_new_array_buffer(Instruction* currentInstruction)
  1450. {
  1451. JITStubCall stubCall(this, cti_op_new_array_buffer);
  1452. stubCall.addArgument(TrustedImm32(currentInstruction[2].u.operand));
  1453. stubCall.addArgument(TrustedImm32(currentInstruction[3].u.operand));
  1454. stubCall.addArgument(TrustedImmPtr(currentInstruction[4].u.arrayAllocationProfile));
  1455. stubCall.call(currentInstruction[1].u.operand);
  1456. }
  1457. } // namespace JSC
  1458. #endif // !(ENABLE(DETACHED_JIT) && !BUILDING_DETACHED_JIT)
  1459. #endif // ENABLE(JIT)