JITStubs.cpp 128 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512
  1. /*
  2. * Copyright (C) 2008, 2009, 2013 Apple Inc. All rights reserved.
  3. * Copyright (C) 2008 Cameron Zwarich <cwzwarich@uwaterloo.ca>
  4. * Copyright (C) Research In Motion Limited 2010, 2011. All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. *
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
  16. * its contributors may be used to endorse or promote products derived
  17. * from this software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
  20. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  21. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  22. * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
  23. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  24. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  25. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  26. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  28. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. #include "config.h"
  31. #if ENABLE(JIT)
  32. #include "JITStubs.h"
  33. #include "CommonSlowPaths.h"
  34. #include "Arguments.h"
  35. #include "ArrayConstructor.h"
  36. #include "CallFrame.h"
  37. #include "CodeBlock.h"
  38. #include "CodeProfiling.h"
  39. #include "DFGOSREntry.h"
  40. #include "Debugger.h"
  41. #include "ExceptionHelpers.h"
  42. #include "GetterSetter.h"
  43. #include "Heap.h"
  44. #include <wtf/InlineASM.h>
  45. #include "JIT.h"
  46. #include "JITExceptions.h"
  47. #include "JSActivation.h"
  48. #include "JSArray.h"
  49. #include "JSFunction.h"
  50. #include "JSGlobalObjectFunctions.h"
  51. #include "JSNameScope.h"
  52. #include "JSNotAnObject.h"
  53. #include "JSPropertyNameIterator.h"
  54. #include "JSString.h"
  55. #include "JSWithScope.h"
  56. #include "LegacyProfiler.h"
  57. #include "NameInstance.h"
  58. #include "ObjectConstructor.h"
  59. #include "ObjectPrototype.h"
  60. #include "Operations.h"
  61. #include "Parser.h"
  62. #include "RegExpObject.h"
  63. #include "RegExpPrototype.h"
  64. #include "Register.h"
  65. #include "RepatchBuffer.h"
  66. #include "SamplingTool.h"
  67. #include "Strong.h"
  68. #include "StructureRareDataInlines.h"
  69. #include <wtf/StdLibExtras.h>
  70. #include <stdarg.h>
  71. #include <stdio.h>
  72. using namespace std;
  73. namespace JSC {
  74. #if USE(JSVALUE32_64)
  75. #if COMPILER(GCC) && CPU(X86)
  76. // These ASSERTs remind you that, if you change the layout of JITStackFrame, you
  77. // need to change the assembly trampolines below to match.
  78. COMPILE_ASSERT(offsetof(struct JITStackFrame, code) % 16 == 0x0, JITStackFrame_maintains_16byte_stack_alignment);
  79. COMPILE_ASSERT(offsetof(struct JITStackFrame, savedEBX) == 0x3c, JITStackFrame_stub_argument_space_matches_ctiTrampoline);
  80. COMPILE_ASSERT(offsetof(struct JITStackFrame, callFrame) == 0x58, JITStackFrame_callFrame_offset_matches_ctiTrampoline);
  81. COMPILE_ASSERT(offsetof(struct JITStackFrame, code) == 0x50, JITStackFrame_code_offset_matches_ctiTrampoline);
  82. asm (
  83. ".text\n"
  84. ".globl " SYMBOL_STRING(ctiTrampoline) "\n"
  85. HIDE_SYMBOL(ctiTrampoline) "\n"
  86. SYMBOL_STRING(ctiTrampoline) ":" "\n"
  87. "pushl %ebp" "\n"
  88. "movl %esp, %ebp" "\n"
  89. "pushl %esi" "\n"
  90. "pushl %edi" "\n"
  91. "pushl %ebx" "\n"
  92. "subl $0x3c, %esp" "\n"
  93. "movw $0x02FF, %bx" "\n"
  94. "movw %bx, 0(%esp)" "\n"
  95. "fldcw 0(%esp)" "\n"
  96. "movl 0x58(%esp), %edi" "\n"
  97. "call *0x50(%esp)" "\n"
  98. "addl $0x3c, %esp" "\n"
  99. "popl %ebx" "\n"
  100. "popl %edi" "\n"
  101. "popl %esi" "\n"
  102. "popl %ebp" "\n"
  103. "ffree %st(1)" "\n"
  104. "ret" "\n"
  105. ".globl " SYMBOL_STRING(ctiTrampolineEnd) "\n"
  106. HIDE_SYMBOL(ctiTrampolineEnd) "\n"
  107. SYMBOL_STRING(ctiTrampolineEnd) ":" "\n"
  108. );
  109. asm (
  110. ".globl " SYMBOL_STRING(ctiVMThrowTrampoline) "\n"
  111. HIDE_SYMBOL(ctiVMThrowTrampoline) "\n"
  112. SYMBOL_STRING(ctiVMThrowTrampoline) ":" "\n"
  113. "movl %esp, %ecx" "\n"
  114. "call " LOCAL_REFERENCE(cti_vm_throw) "\n"
  115. "int3" "\n"
  116. );
  117. asm (
  118. ".globl " SYMBOL_STRING(ctiOpThrowNotCaught) "\n"
  119. HIDE_SYMBOL(ctiOpThrowNotCaught) "\n"
  120. SYMBOL_STRING(ctiOpThrowNotCaught) ":" "\n"
  121. "addl $0x3c, %esp" "\n"
  122. "popl %ebx" "\n"
  123. "popl %edi" "\n"
  124. "popl %esi" "\n"
  125. "popl %ebp" "\n"
  126. "ret" "\n"
  127. );
  128. #elif COMPILER(GCC) && CPU(X86_64)
  129. // These ASSERTs remind you that, if you change the layout of JITStackFrame, you
  130. // need to change the assembly trampolines below to match.
  131. COMPILE_ASSERT(offsetof(struct JITStackFrame, code) % 32 == 0x0, JITStackFrame_maintains_32byte_stack_alignment);
  132. COMPILE_ASSERT(offsetof(struct JITStackFrame, savedRBX) == 0x48, JITStackFrame_stub_argument_space_matches_ctiTrampoline);
  133. COMPILE_ASSERT(offsetof(struct JITStackFrame, callFrame) == 0x90, JITStackFrame_callFrame_offset_matches_ctiTrampoline);
  134. COMPILE_ASSERT(offsetof(struct JITStackFrame, code) == 0x80, JITStackFrame_code_offset_matches_ctiTrampoline);
  135. asm (
  136. ".globl " SYMBOL_STRING(ctiTrampoline) "\n"
  137. HIDE_SYMBOL(ctiTrampoline) "\n"
  138. SYMBOL_STRING(ctiTrampoline) ":" "\n"
  139. "pushq %rbp" "\n"
  140. "movq %rsp, %rbp" "\n"
  141. "pushq %r12" "\n"
  142. "pushq %r13" "\n"
  143. "pushq %r14" "\n"
  144. "pushq %r15" "\n"
  145. "pushq %rbx" "\n"
  146. "subq $0x48, %rsp" "\n"
  147. "movq $512, %r12" "\n"
  148. "movq $0xFFFF000000000000, %r14" "\n"
  149. "movq $0xFFFF000000000002, %r15" "\n"
  150. "movq 0x90(%rsp), %r13" "\n"
  151. "call *0x80(%rsp)" "\n"
  152. "addq $0x48, %rsp" "\n"
  153. "popq %rbx" "\n"
  154. "popq %r15" "\n"
  155. "popq %r14" "\n"
  156. "popq %r13" "\n"
  157. "popq %r12" "\n"
  158. "popq %rbp" "\n"
  159. "ret" "\n"
  160. ".globl " SYMBOL_STRING(ctiTrampolineEnd) "\n"
  161. HIDE_SYMBOL(ctiTrampolineEnd) "\n"
  162. SYMBOL_STRING(ctiTrampolineEnd) ":" "\n"
  163. );
  164. asm (
  165. ".globl " SYMBOL_STRING(ctiVMThrowTrampoline) "\n"
  166. HIDE_SYMBOL(ctiVMThrowTrampoline) "\n"
  167. SYMBOL_STRING(ctiVMThrowTrampoline) ":" "\n"
  168. "movq %rsp, %rdi" "\n"
  169. "call " LOCAL_REFERENCE(cti_vm_throw) "\n"
  170. "int3" "\n"
  171. );
  172. asm (
  173. ".globl " SYMBOL_STRING(ctiOpThrowNotCaught) "\n"
  174. HIDE_SYMBOL(ctiOpThrowNotCaught) "\n"
  175. SYMBOL_STRING(ctiOpThrowNotCaught) ":" "\n"
  176. "addq $0x48, %rsp" "\n"
  177. "popq %rbx" "\n"
  178. "popq %r15" "\n"
  179. "popq %r14" "\n"
  180. "popq %r13" "\n"
  181. "popq %r12" "\n"
  182. "popq %rbp" "\n"
  183. "ret" "\n"
  184. );
  185. #elif (COMPILER(GCC) || COMPILER(RVCT) || COMPILER(SNC)) && CPU(ARM_THUMB2)
  186. #define THUNK_RETURN_ADDRESS_OFFSET 0x38
  187. #define PRESERVED_RETURN_ADDRESS_OFFSET 0x3C
  188. #define PRESERVED_R4_OFFSET 0x40
  189. #define PRESERVED_R5_OFFSET 0x44
  190. #define PRESERVED_R6_OFFSET 0x48
  191. #define PRESERVED_R7_OFFSET 0x4C
  192. #define PRESERVED_R8_OFFSET 0x50
  193. #define PRESERVED_R9_OFFSET 0x54
  194. #define PRESERVED_R10_OFFSET 0x58
  195. #define PRESERVED_R11_OFFSET 0x5C
  196. #define REGISTER_FILE_OFFSET 0x60
  197. #define FIRST_STACK_ARGUMENT 0x68
  198. #elif (COMPILER(GCC) || COMPILER(MSVC) || COMPILER(RVCT)) && CPU(ARM_TRADITIONAL)
  199. // Also update the MSVC section (defined at DEFINE_STUB_FUNCTION)
  200. // when changing one of the following values.
  201. #define THUNK_RETURN_ADDRESS_OFFSET 64
  202. #define PRESERVEDR4_OFFSET 68
  203. #elif COMPILER(MSVC) && CPU(X86)
  204. // These ASSERTs remind you that, if you change the layout of JITStackFrame, you
  205. // need to change the assembly trampolines below to match.
  206. COMPILE_ASSERT(offsetof(struct JITStackFrame, code) % 16 == 0x0, JITStackFrame_maintains_16byte_stack_alignment);
  207. COMPILE_ASSERT(offsetof(struct JITStackFrame, savedEBX) == 0x3c, JITStackFrame_stub_argument_space_matches_ctiTrampoline);
  208. COMPILE_ASSERT(offsetof(struct JITStackFrame, callFrame) == 0x58, JITStackFrame_callFrame_offset_matches_ctiTrampoline);
  209. COMPILE_ASSERT(offsetof(struct JITStackFrame, code) == 0x50, JITStackFrame_code_offset_matches_ctiTrampoline);
  210. extern "C" {
  211. __declspec(naked) EncodedJSValue ctiTrampoline(void* code, JSStack*, CallFrame*, void* /*unused1*/, void* /*unused2*/, VM*)
  212. {
  213. __asm {
  214. push ebp;
  215. mov ebp, esp;
  216. push esi;
  217. push edi;
  218. push ebx;
  219. sub esp, 0x3c;
  220. mov ecx, esp;
  221. mov edi, [esp + 0x58];
  222. call [esp + 0x50];
  223. add esp, 0x3c;
  224. pop ebx;
  225. pop edi;
  226. pop esi;
  227. pop ebp;
  228. ret;
  229. }
  230. }
  231. __declspec(naked) void ctiVMThrowTrampoline()
  232. {
  233. __asm {
  234. mov ecx, esp;
  235. call cti_vm_throw;
  236. add esp, 0x3c;
  237. pop ebx;
  238. pop edi;
  239. pop esi;
  240. pop ebp;
  241. ret;
  242. }
  243. }
  244. __declspec(naked) void ctiOpThrowNotCaught()
  245. {
  246. __asm {
  247. add esp, 0x3c;
  248. pop ebx;
  249. pop edi;
  250. pop esi;
  251. pop ebp;
  252. ret;
  253. }
  254. }
  255. }
  256. #elif CPU(MIPS)
  257. #define PRESERVED_GP_OFFSET 60
  258. #define PRESERVED_S0_OFFSET 64
  259. #define PRESERVED_S1_OFFSET 68
  260. #define PRESERVED_S2_OFFSET 72
  261. #define PRESERVED_S3_OFFSET 76
  262. #define PRESERVED_S4_OFFSET 80
  263. #define PRESERVED_RETURN_ADDRESS_OFFSET 84
  264. #define THUNK_RETURN_ADDRESS_OFFSET 88
  265. #define REGISTER_FILE_OFFSET 92
  266. #define GLOBAL_DATA_OFFSET 108
  267. #define STACK_LENGTH 112
  268. #elif CPU(SH4)
  269. #define SYMBOL_STRING(name) #name
  270. /* code (r4), JSStack* (r5), CallFrame* (r6), void* unused1 (r7), void* unused2(sp), VM (sp)*/
  271. asm volatile (
  272. ".text\n"
  273. ".globl " SYMBOL_STRING(ctiTrampoline) "\n"
  274. HIDE_SYMBOL(ctiTrampoline) "\n"
  275. SYMBOL_STRING(ctiTrampoline) ":" "\n"
  276. "mov.l r7, @-r15" "\n"
  277. "mov.l r6, @-r15" "\n"
  278. "mov.l r5, @-r15" "\n"
  279. "mov.l r14, @-r15" "\n"
  280. "sts.l pr, @-r15" "\n"
  281. "mov.l r13, @-r15" "\n"
  282. "mov.l r11, @-r15" "\n"
  283. "mov.l r10, @-r15" "\n"
  284. "add #-60, r15" "\n"
  285. "mov r6, r14" "\n"
  286. "jsr @r4" "\n"
  287. "nop" "\n"
  288. "add #60, r15" "\n"
  289. "mov.l @r15+,r10" "\n"
  290. "mov.l @r15+,r11" "\n"
  291. "mov.l @r15+,r13" "\n"
  292. "lds.l @r15+,pr" "\n"
  293. "mov.l @r15+,r14" "\n"
  294. "add #12, r15" "\n"
  295. "rts" "\n"
  296. "nop" "\n"
  297. ".globl " SYMBOL_STRING(ctiTrampolineEnd) "\n"
  298. HIDE_SYMBOL(ctiTrampolineEnd) "\n"
  299. SYMBOL_STRING(ctiTrampolineEnd) ":" "\n"
  300. );
  301. asm volatile (
  302. ".globl " SYMBOL_STRING(ctiVMThrowTrampoline) "\n"
  303. HIDE_SYMBOL(ctiVMThrowTrampoline) "\n"
  304. SYMBOL_STRING(ctiVMThrowTrampoline) ":" "\n"
  305. "mov.l .L2"SYMBOL_STRING(cti_vm_throw)",r0" "\n"
  306. "mov r15, r4" "\n"
  307. "mov.l @(r0,r12),r11" "\n"
  308. "jsr @r11" "\n"
  309. "nop" "\n"
  310. "add #60, r15" "\n"
  311. "mov.l @r15+,r10" "\n"
  312. "mov.l @r15+,r11" "\n"
  313. "mov.l @r15+,r13" "\n"
  314. "lds.l @r15+,pr" "\n"
  315. "mov.l @r15+,r14" "\n"
  316. "add #12, r15" "\n"
  317. "rts" "\n"
  318. "nop" "\n"
  319. ".align 2" "\n"
  320. ".L2"SYMBOL_STRING(cti_vm_throw)":.long " SYMBOL_STRING(cti_vm_throw)"@GOT \n"
  321. );
  322. asm volatile (
  323. ".globl " SYMBOL_STRING(ctiOpThrowNotCaught) "\n"
  324. HIDE_SYMBOL(ctiOpThrowNotCaught) "\n"
  325. SYMBOL_STRING(ctiOpThrowNotCaught) ":" "\n"
  326. "add #60, r15" "\n"
  327. "mov.l @r15+,r10" "\n"
  328. "mov.l @r15+,r11" "\n"
  329. "mov.l @r15+,r13" "\n"
  330. "lds.l @r15+,pr" "\n"
  331. "mov.l @r15+,r14" "\n"
  332. "add #12, r15" "\n"
  333. "rts" "\n"
  334. "nop" "\n"
  335. );
  336. #else
  337. #error "JIT not supported on this platform."
  338. #endif
  339. #else // USE(JSVALUE32_64)
  340. #if COMPILER(GCC) && CPU(X86_64) && !OS(WINDOWS)
  341. // These ASSERTs remind you that, if you change the layout of JITStackFrame, you
  342. // need to change the assembly trampolines below to match.
  343. COMPILE_ASSERT(offsetof(struct JITStackFrame, callFrame) == 0x58, JITStackFrame_callFrame_offset_matches_ctiTrampoline);
  344. COMPILE_ASSERT(offsetof(struct JITStackFrame, code) == 0x48, JITStackFrame_code_offset_matches_ctiTrampoline);
  345. COMPILE_ASSERT(offsetof(struct JITStackFrame, savedRBX) == 0x78, JITStackFrame_stub_argument_space_matches_ctiTrampoline);
  346. asm (
  347. ".text\n"
  348. ".globl " SYMBOL_STRING(ctiTrampoline) "\n"
  349. HIDE_SYMBOL(ctiTrampoline) "\n"
  350. SYMBOL_STRING(ctiTrampoline) ":" "\n"
  351. "pushq %rbp" "\n"
  352. "movq %rsp, %rbp" "\n"
  353. "pushq %r12" "\n"
  354. "pushq %r13" "\n"
  355. "pushq %r14" "\n"
  356. "pushq %r15" "\n"
  357. "pushq %rbx" "\n"
  358. // Form the JIT stubs area
  359. "pushq %r9" "\n"
  360. "pushq %r8" "\n"
  361. "pushq %rcx" "\n"
  362. "pushq %rdx" "\n"
  363. "pushq %rsi" "\n"
  364. "pushq %rdi" "\n"
  365. "subq $0x48, %rsp" "\n"
  366. "movq $512, %r12" "\n"
  367. "movq $0xFFFF000000000000, %r14" "\n"
  368. "movq $0xFFFF000000000002, %r15" "\n"
  369. "movq %rdx, %r13" "\n"
  370. "call *%rdi" "\n"
  371. "addq $0x78, %rsp" "\n"
  372. "popq %rbx" "\n"
  373. "popq %r15" "\n"
  374. "popq %r14" "\n"
  375. "popq %r13" "\n"
  376. "popq %r12" "\n"
  377. "popq %rbp" "\n"
  378. "ret" "\n"
  379. ".globl " SYMBOL_STRING(ctiTrampolineEnd) "\n"
  380. HIDE_SYMBOL(ctiTrampolineEnd) "\n"
  381. SYMBOL_STRING(ctiTrampolineEnd) ":" "\n"
  382. );
  383. asm (
  384. ".globl " SYMBOL_STRING(ctiVMThrowTrampoline) "\n"
  385. HIDE_SYMBOL(ctiVMThrowTrampoline) "\n"
  386. SYMBOL_STRING(ctiVMThrowTrampoline) ":" "\n"
  387. "movq %rsp, %rdi" "\n"
  388. "call " LOCAL_REFERENCE(cti_vm_throw) "\n"
  389. "int3" "\n"
  390. );
  391. asm (
  392. ".globl " SYMBOL_STRING(ctiOpThrowNotCaught) "\n"
  393. HIDE_SYMBOL(ctiOpThrowNotCaught) "\n"
  394. SYMBOL_STRING(ctiOpThrowNotCaught) ":" "\n"
  395. "addq $0x78, %rsp" "\n"
  396. "popq %rbx" "\n"
  397. "popq %r15" "\n"
  398. "popq %r14" "\n"
  399. "popq %r13" "\n"
  400. "popq %r12" "\n"
  401. "popq %rbp" "\n"
  402. "ret" "\n"
  403. );
  404. #elif COMPILER(GCC) && CPU(X86_64) && OS(WINDOWS)
  405. // These ASSERTs remind you that, if you change the layout of JITStackFrame, you
  406. // need to change the assembly trampolines below to match.
  407. COMPILE_ASSERT(offsetof(struct JITStackFrame, code) % 16 == 0x0, JITStackFrame_maintains_16byte_stack_alignment);
  408. COMPILE_ASSERT(offsetof(struct JITStackFrame, savedRBX) == 0x58, JITStackFrame_stub_argument_space_matches_ctiTrampoline);
  409. asm (
  410. ".text\n"
  411. ".globl " SYMBOL_STRING(ctiTrampoline) "\n"
  412. HIDE_SYMBOL(ctiTrampoline) "\n"
  413. SYMBOL_STRING(ctiTrampoline) ":" "\n"
  414. // Dump register parameters to their home address
  415. "movq %r9, 0x20(%rsp)" "\n"
  416. "movq %r8, 0x18(%rsp)" "\n"
  417. "movq %rdx, 0x10(%rsp)" "\n"
  418. "movq %rcx, 0x8(%rsp)" "\n"
  419. "pushq %rbp" "\n"
  420. "movq %rsp, %rbp" "\n"
  421. "pushq %r12" "\n"
  422. "pushq %r13" "\n"
  423. "pushq %r14" "\n"
  424. "pushq %r15" "\n"
  425. "pushq %rbx" "\n"
  426. // Decrease rsp to point to the start of our JITStackFrame
  427. "subq $0x58, %rsp" "\n"
  428. "movq $512, %r12" "\n"
  429. "movq $0xFFFF000000000000, %r14" "\n"
  430. "movq $0xFFFF000000000002, %r15" "\n"
  431. "movq %r8, %r13" "\n"
  432. "call *%rcx" "\n"
  433. "addq $0x58, %rsp" "\n"
  434. "popq %rbx" "\n"
  435. "popq %r15" "\n"
  436. "popq %r14" "\n"
  437. "popq %r13" "\n"
  438. "popq %r12" "\n"
  439. "popq %rbp" "\n"
  440. "ret" "\n"
  441. ".globl " SYMBOL_STRING(ctiTrampolineEnd) "\n"
  442. HIDE_SYMBOL(ctiTrampolineEnd) "\n"
  443. SYMBOL_STRING(ctiTrampolineEnd) ":" "\n"
  444. );
  445. asm (
  446. ".globl " SYMBOL_STRING(ctiVMThrowTrampoline) "\n"
  447. HIDE_SYMBOL(ctiVMThrowTrampoline) "\n"
  448. SYMBOL_STRING(ctiVMThrowTrampoline) ":" "\n"
  449. "movq %rsp, %rcx" "\n"
  450. "call " LOCAL_REFERENCE(cti_vm_throw) "\n"
  451. "int3" "\n"
  452. );
  453. asm (
  454. ".globl " SYMBOL_STRING(ctiOpThrowNotCaught) "\n"
  455. HIDE_SYMBOL(ctiOpThrowNotCaught) "\n"
  456. SYMBOL_STRING(ctiOpThrowNotCaught) ":" "\n"
  457. "addq $0x58, %rsp" "\n"
  458. "popq %rbx" "\n"
  459. "popq %r15" "\n"
  460. "popq %r14" "\n"
  461. "popq %r13" "\n"
  462. "popq %r12" "\n"
  463. "popq %rbp" "\n"
  464. "ret" "\n"
  465. );
  466. #elif COMPILER(MSVC) && CPU(X86_64)
  467. // These ASSERTs remind you that, if you change the layout of JITStackFrame, you
  468. // need to change the assembly trampolines in JITStubsMSVC64.asm to match.
  469. COMPILE_ASSERT(offsetof(struct JITStackFrame, code) % 16 == 0x0, JITStackFrame_maintains_16byte_stack_alignment);
  470. COMPILE_ASSERT(offsetof(struct JITStackFrame, savedRBX) == 0x58, JITStackFrame_stub_argument_space_matches_ctiTrampoline);
  471. #else
  472. #error "JIT not supported on this platform."
  473. #endif
  474. #endif // USE(JSVALUE32_64)
  475. #if CPU(MIPS)
  476. asm (
  477. ".text" "\n"
  478. ".align 2" "\n"
  479. ".set noreorder" "\n"
  480. ".set nomacro" "\n"
  481. ".set nomips16" "\n"
  482. ".globl " SYMBOL_STRING(ctiTrampoline) "\n"
  483. ".ent " SYMBOL_STRING(ctiTrampoline) "\n"
  484. SYMBOL_STRING(ctiTrampoline) ":" "\n"
  485. "addiu $29,$29,-" STRINGIZE_VALUE_OF(STACK_LENGTH) "\n"
  486. "sw $31," STRINGIZE_VALUE_OF(PRESERVED_RETURN_ADDRESS_OFFSET) "($29)" "\n"
  487. "sw $20," STRINGIZE_VALUE_OF(PRESERVED_S4_OFFSET) "($29)" "\n"
  488. "sw $19," STRINGIZE_VALUE_OF(PRESERVED_S3_OFFSET) "($29)" "\n"
  489. "sw $18," STRINGIZE_VALUE_OF(PRESERVED_S2_OFFSET) "($29)" "\n"
  490. "sw $17," STRINGIZE_VALUE_OF(PRESERVED_S1_OFFSET) "($29)" "\n"
  491. "sw $16," STRINGIZE_VALUE_OF(PRESERVED_S0_OFFSET) "($29)" "\n"
  492. #if WTF_MIPS_PIC
  493. "sw $28," STRINGIZE_VALUE_OF(PRESERVED_GP_OFFSET) "($29)" "\n"
  494. #endif
  495. "move $16,$6 # set callFrameRegister" "\n"
  496. "move $25,$4 # move executableAddress to t9" "\n"
  497. "sw $5," STRINGIZE_VALUE_OF(REGISTER_FILE_OFFSET) "($29) # store JSStack to current stack" "\n"
  498. "lw $9," STRINGIZE_VALUE_OF(STACK_LENGTH + 20) "($29) # load vm from previous stack" "\n"
  499. "jalr $25" "\n"
  500. "sw $9," STRINGIZE_VALUE_OF(GLOBAL_DATA_OFFSET) "($29) # store vm to current stack" "\n"
  501. "lw $16," STRINGIZE_VALUE_OF(PRESERVED_S0_OFFSET) "($29)" "\n"
  502. "lw $17," STRINGIZE_VALUE_OF(PRESERVED_S1_OFFSET) "($29)" "\n"
  503. "lw $18," STRINGIZE_VALUE_OF(PRESERVED_S2_OFFSET) "($29)" "\n"
  504. "lw $19," STRINGIZE_VALUE_OF(PRESERVED_S3_OFFSET) "($29)" "\n"
  505. "lw $20," STRINGIZE_VALUE_OF(PRESERVED_S4_OFFSET) "($29)" "\n"
  506. "lw $31," STRINGIZE_VALUE_OF(PRESERVED_RETURN_ADDRESS_OFFSET) "($29)" "\n"
  507. "jr $31" "\n"
  508. "addiu $29,$29," STRINGIZE_VALUE_OF(STACK_LENGTH) "\n"
  509. ".set reorder" "\n"
  510. ".set macro" "\n"
  511. ".end " SYMBOL_STRING(ctiTrampoline) "\n"
  512. ".globl " SYMBOL_STRING(ctiTrampolineEnd) "\n"
  513. HIDE_SYMBOL(ctiTrampolineEnd) "\n"
  514. SYMBOL_STRING(ctiTrampolineEnd) ":" "\n"
  515. );
  516. asm (
  517. ".text" "\n"
  518. ".align 2" "\n"
  519. ".set noreorder" "\n"
  520. ".set nomacro" "\n"
  521. ".set nomips16" "\n"
  522. ".globl " SYMBOL_STRING(ctiVMThrowTrampoline) "\n"
  523. ".ent " SYMBOL_STRING(ctiVMThrowTrampoline) "\n"
  524. SYMBOL_STRING(ctiVMThrowTrampoline) ":" "\n"
  525. #if WTF_MIPS_PIC
  526. ".set macro" "\n"
  527. ".cpload $31" "\n"
  528. "la $25," SYMBOL_STRING(cti_vm_throw) "\n"
  529. ".set nomacro" "\n"
  530. "bal " SYMBOL_STRING(cti_vm_throw) "\n"
  531. "move $4,$29" "\n"
  532. #else
  533. "jal " SYMBOL_STRING(cti_vm_throw) "\n"
  534. "move $4,$29" "\n"
  535. #endif
  536. "lw $16," STRINGIZE_VALUE_OF(PRESERVED_S0_OFFSET) "($29)" "\n"
  537. "lw $17," STRINGIZE_VALUE_OF(PRESERVED_S1_OFFSET) "($29)" "\n"
  538. "lw $18," STRINGIZE_VALUE_OF(PRESERVED_S2_OFFSET) "($29)" "\n"
  539. "lw $19," STRINGIZE_VALUE_OF(PRESERVED_S3_OFFSET) "($29)" "\n"
  540. "lw $20," STRINGIZE_VALUE_OF(PRESERVED_S4_OFFSET) "($29)" "\n"
  541. "lw $31," STRINGIZE_VALUE_OF(PRESERVED_RETURN_ADDRESS_OFFSET) "($29)" "\n"
  542. "jr $31" "\n"
  543. "addiu $29,$29," STRINGIZE_VALUE_OF(STACK_LENGTH) "\n"
  544. ".set reorder" "\n"
  545. ".set macro" "\n"
  546. ".end " SYMBOL_STRING(ctiVMThrowTrampoline) "\n"
  547. );
  548. asm (
  549. ".text" "\n"
  550. ".align 2" "\n"
  551. ".set noreorder" "\n"
  552. ".set nomacro" "\n"
  553. ".set nomips16" "\n"
  554. ".globl " SYMBOL_STRING(ctiOpThrowNotCaught) "\n"
  555. ".ent " SYMBOL_STRING(ctiOpThrowNotCaught) "\n"
  556. SYMBOL_STRING(ctiOpThrowNotCaught) ":" "\n"
  557. "lw $16," STRINGIZE_VALUE_OF(PRESERVED_S0_OFFSET) "($29)" "\n"
  558. "lw $17," STRINGIZE_VALUE_OF(PRESERVED_S1_OFFSET) "($29)" "\n"
  559. "lw $18," STRINGIZE_VALUE_OF(PRESERVED_S2_OFFSET) "($29)" "\n"
  560. "lw $19," STRINGIZE_VALUE_OF(PRESERVED_S3_OFFSET) "($29)" "\n"
  561. "lw $20," STRINGIZE_VALUE_OF(PRESERVED_S4_OFFSET) "($29)" "\n"
  562. "lw $31," STRINGIZE_VALUE_OF(PRESERVED_RETURN_ADDRESS_OFFSET) "($29)" "\n"
  563. "jr $31" "\n"
  564. "addiu $29,$29," STRINGIZE_VALUE_OF(STACK_LENGTH) "\n"
  565. ".set reorder" "\n"
  566. ".set macro" "\n"
  567. ".end " SYMBOL_STRING(ctiOpThrowNotCaught) "\n"
  568. );
  569. #endif
  570. #if (COMPILER(GCC) || COMPILER(SNC)) && CPU(ARM_THUMB2)
  571. asm (
  572. ".text" "\n"
  573. ".align 2" "\n"
  574. ".globl " SYMBOL_STRING(ctiTrampoline) "\n"
  575. HIDE_SYMBOL(ctiTrampoline) "\n"
  576. ".thumb" "\n"
  577. ".thumb_func " THUMB_FUNC_PARAM(ctiTrampoline) "\n"
  578. ARM_THUMB2_FUNC_PROLOGUE(ctiTrampoline)
  579. SYMBOL_STRING(ctiTrampoline) ":" "\n"
  580. "sub sp, sp, #" STRINGIZE_VALUE_OF(FIRST_STACK_ARGUMENT) "\n"
  581. "str lr, [sp, #" STRINGIZE_VALUE_OF(PRESERVED_RETURN_ADDRESS_OFFSET) "]" "\n"
  582. "str r4, [sp, #" STRINGIZE_VALUE_OF(PRESERVED_R4_OFFSET) "]" "\n"
  583. "str r5, [sp, #" STRINGIZE_VALUE_OF(PRESERVED_R5_OFFSET) "]" "\n"
  584. "str r6, [sp, #" STRINGIZE_VALUE_OF(PRESERVED_R6_OFFSET) "]" "\n"
  585. "str r7, [sp, #" STRINGIZE_VALUE_OF(PRESERVED_R7_OFFSET) "]" "\n"
  586. "str r8, [sp, #" STRINGIZE_VALUE_OF(PRESERVED_R8_OFFSET) "]" "\n"
  587. "str r9, [sp, #" STRINGIZE_VALUE_OF(PRESERVED_R9_OFFSET) "]" "\n"
  588. "str r10, [sp, #" STRINGIZE_VALUE_OF(PRESERVED_R10_OFFSET) "]" "\n"
  589. "str r11, [sp, #" STRINGIZE_VALUE_OF(PRESERVED_R11_OFFSET) "]" "\n"
  590. "str r1, [sp, #" STRINGIZE_VALUE_OF(REGISTER_FILE_OFFSET) "]" "\n"
  591. "mov r5, r2" "\n"
  592. "mov r6, #512" "\n"
  593. "blx r0" "\n"
  594. "ldr r11, [sp, #" STRINGIZE_VALUE_OF(PRESERVED_R11_OFFSET) "]" "\n"
  595. "ldr r10, [sp, #" STRINGIZE_VALUE_OF(PRESERVED_R10_OFFSET) "]" "\n"
  596. "ldr r9, [sp, #" STRINGIZE_VALUE_OF(PRESERVED_R9_OFFSET) "]" "\n"
  597. "ldr r8, [sp, #" STRINGIZE_VALUE_OF(PRESERVED_R8_OFFSET) "]" "\n"
  598. "ldr r7, [sp, #" STRINGIZE_VALUE_OF(PRESERVED_R7_OFFSET) "]" "\n"
  599. "ldr r6, [sp, #" STRINGIZE_VALUE_OF(PRESERVED_R6_OFFSET) "]" "\n"
  600. "ldr r5, [sp, #" STRINGIZE_VALUE_OF(PRESERVED_R5_OFFSET) "]" "\n"
  601. "ldr r4, [sp, #" STRINGIZE_VALUE_OF(PRESERVED_R4_OFFSET) "]" "\n"
  602. "ldr lr, [sp, #" STRINGIZE_VALUE_OF(PRESERVED_RETURN_ADDRESS_OFFSET) "]" "\n"
  603. "add sp, sp, #" STRINGIZE_VALUE_OF(FIRST_STACK_ARGUMENT) "\n"
  604. "bx lr" "\n"
  605. ARM_THUMB2_FUNC_EPILOGUE(ctiTrampoline)
  606. ".align 2" "\n"
  607. ".globl " SYMBOL_STRING(ctiTrampolineEnd) "\n"
  608. HIDE_SYMBOL(ctiTrampolineEnd) "\n"
  609. ".thumb" "\n"
  610. ".thumb_func " THUMB_FUNC_PARAM(ctiTrampolineEnd) "\n"
  611. ARM_THUMB2_FUNC_PROLOGUE(ctiTrampolineEnd)
  612. SYMBOL_STRING(ctiTrampolineEnd) ":" "\n"
  613. ARM_THUMB2_FUNC_EPILOGUE(ctiTrampolineEnd)
  614. );
  615. asm (
  616. ".text" "\n"
  617. ".align 2" "\n"
  618. ".globl " SYMBOL_STRING(ctiVMThrowTrampoline) "\n"
  619. HIDE_SYMBOL(ctiVMThrowTrampoline) "\n"
  620. ARM_THUMB2_FUNC_PROLOGUE(ctiVMThrowTrampoline)
  621. ".thumb" "\n"
  622. ".thumb_func " THUMB_FUNC_PARAM(ctiVMThrowTrampoline) "\n"
  623. SYMBOL_STRING(ctiVMThrowTrampoline) ":" "\n"
  624. "mov r0, sp" "\n"
  625. "bl " LOCAL_REFERENCE(cti_vm_throw) "\n"
  626. "ldr r11, [sp, #" STRINGIZE_VALUE_OF(PRESERVED_R11_OFFSET) "]" "\n"
  627. "ldr r10, [sp, #" STRINGIZE_VALUE_OF(PRESERVED_R10_OFFSET) "]" "\n"
  628. "ldr r9, [sp, #" STRINGIZE_VALUE_OF(PRESERVED_R9_OFFSET) "]" "\n"
  629. "ldr r8, [sp, #" STRINGIZE_VALUE_OF(PRESERVED_R8_OFFSET) "]" "\n"
  630. "ldr r7, [sp, #" STRINGIZE_VALUE_OF(PRESERVED_R7_OFFSET) "]" "\n"
  631. "ldr r6, [sp, #" STRINGIZE_VALUE_OF(PRESERVED_R6_OFFSET) "]" "\n"
  632. "ldr r5, [sp, #" STRINGIZE_VALUE_OF(PRESERVED_R5_OFFSET) "]" "\n"
  633. "ldr r4, [sp, #" STRINGIZE_VALUE_OF(PRESERVED_R4_OFFSET) "]" "\n"
  634. "ldr lr, [sp, #" STRINGIZE_VALUE_OF(PRESERVED_RETURN_ADDRESS_OFFSET) "]" "\n"
  635. "add sp, sp, #" STRINGIZE_VALUE_OF(FIRST_STACK_ARGUMENT) "\n"
  636. "bx lr" "\n"
  637. ARM_THUMB2_FUNC_EPILOGUE(ctiVMThrowTrampoline)
  638. );
  639. asm (
  640. ".text" "\n"
  641. ".align 2" "\n"
  642. ".globl " SYMBOL_STRING(ctiOpThrowNotCaught) "\n"
  643. HIDE_SYMBOL(ctiOpThrowNotCaught) "\n"
  644. ".thumb" "\n"
  645. ".thumb_func " THUMB_FUNC_PARAM(ctiOpThrowNotCaught) "\n"
  646. ARM_THUMB2_FUNC_PROLOGUE(ctiOpThrowNotCaught)
  647. SYMBOL_STRING(ctiOpThrowNotCaught) ":" "\n"
  648. "ldr r11, [sp, #" STRINGIZE_VALUE_OF(PRESERVED_R11_OFFSET) "]" "\n"
  649. "ldr r10, [sp, #" STRINGIZE_VALUE_OF(PRESERVED_R10_OFFSET) "]" "\n"
  650. "ldr r9, [sp, #" STRINGIZE_VALUE_OF(PRESERVED_R9_OFFSET) "]" "\n"
  651. "ldr r8, [sp, #" STRINGIZE_VALUE_OF(PRESERVED_R8_OFFSET) "]" "\n"
  652. "ldr r7, [sp, #" STRINGIZE_VALUE_OF(PRESERVED_R7_OFFSET) "]" "\n"
  653. "ldr r6, [sp, #" STRINGIZE_VALUE_OF(PRESERVED_R6_OFFSET) "]" "\n"
  654. "ldr r5, [sp, #" STRINGIZE_VALUE_OF(PRESERVED_R5_OFFSET) "]" "\n"
  655. "ldr r4, [sp, #" STRINGIZE_VALUE_OF(PRESERVED_R4_OFFSET) "]" "\n"
  656. "ldr lr, [sp, #" STRINGIZE_VALUE_OF(PRESERVED_RETURN_ADDRESS_OFFSET) "]" "\n"
  657. "add sp, sp, #" STRINGIZE_VALUE_OF(FIRST_STACK_ARGUMENT) "\n"
  658. "bx lr" "\n"
  659. ARM_THUMB2_FUNC_EPILOGUE(ctiOpThrowNotCaught)
  660. );
  661. #elif COMPILER(GCC) && CPU(ARM_TRADITIONAL)
  662. asm (
  663. ".text" "\n"
  664. ".globl " SYMBOL_STRING(ctiTrampoline) "\n"
  665. HIDE_SYMBOL(ctiTrampoline) "\n"
  666. INLINE_ARM_FUNCTION(ctiTrampoline)
  667. SYMBOL_STRING(ctiTrampoline) ":" "\n"
  668. "stmdb sp!, {r1-r3}" "\n"
  669. "stmdb sp!, {r4-r6, r8-r11, lr}" "\n"
  670. "sub sp, sp, #" STRINGIZE_VALUE_OF(PRESERVEDR4_OFFSET) "\n"
  671. "mov r5, r2" "\n"
  672. "mov r6, #512" "\n"
  673. // r0 contains the code
  674. "blx r0" "\n"
  675. "add sp, sp, #" STRINGIZE_VALUE_OF(PRESERVEDR4_OFFSET) "\n"
  676. "ldmia sp!, {r4-r6, r8-r11, lr}" "\n"
  677. "add sp, sp, #12" "\n"
  678. "bx lr" "\n"
  679. ".globl " SYMBOL_STRING(ctiTrampolineEnd) "\n"
  680. HIDE_SYMBOL(ctiTrampolineEnd) "\n"
  681. SYMBOL_STRING(ctiTrampolineEnd) ":" "\n"
  682. );
  683. asm (
  684. ".text" "\n"
  685. ".globl " SYMBOL_STRING(ctiVMThrowTrampoline) "\n"
  686. HIDE_SYMBOL(ctiVMThrowTrampoline) "\n"
  687. INLINE_ARM_FUNCTION(ctiVMThrowTrampoline)
  688. SYMBOL_STRING(ctiVMThrowTrampoline) ":" "\n"
  689. "mov r0, sp" "\n"
  690. "bl " SYMBOL_STRING(cti_vm_throw) "\n"
  691. // Both has the same return sequence
  692. ".text" "\n"
  693. ".globl " SYMBOL_STRING(ctiOpThrowNotCaught) "\n"
  694. HIDE_SYMBOL(ctiOpThrowNotCaught) "\n"
  695. INLINE_ARM_FUNCTION(ctiOpThrowNotCaught)
  696. SYMBOL_STRING(ctiOpThrowNotCaught) ":" "\n"
  697. "add sp, sp, #" STRINGIZE_VALUE_OF(PRESERVEDR4_OFFSET) "\n"
  698. "ldmia sp!, {r4-r6, r8-r11, lr}" "\n"
  699. "add sp, sp, #12" "\n"
  700. "bx lr" "\n"
  701. );
  702. #elif COMPILER(RVCT) && CPU(ARM_THUMB2)
  703. __asm EncodedJSValue ctiTrampoline(void*, JSStack*, CallFrame*, void* /*unused1*/, void* /*unused2*/, VM*)
  704. {
  705. PRESERVE8
  706. sub sp, sp, # FIRST_STACK_ARGUMENT
  707. str lr, [sp, # PRESERVED_RETURN_ADDRESS_OFFSET ]
  708. str r4, [sp, # PRESERVED_R4_OFFSET ]
  709. str r5, [sp, # PRESERVED_R5_OFFSET ]
  710. str r6, [sp, # PRESERVED_R6_OFFSET ]
  711. str r7, [sp, # PRESERVED_R7_OFFSET ]
  712. str r8, [sp, # PRESERVED_R8_OFFSET ]
  713. str r9, [sp, # PRESERVED_R9_OFFSET ]
  714. str r10, [sp, # PRESERVED_R10_OFFSET ]
  715. str r11, [sp, # PRESERVED_R11_OFFSET ]
  716. str r1, [sp, # REGISTER_FILE_OFFSET ]
  717. mov r5, r2
  718. mov r6, #512
  719. blx r0
  720. ldr r11, [sp, # PRESERVED_R11_OFFSET ]
  721. ldr r10, [sp, # PRESERVED_R10_OFFSET ]
  722. ldr r9, [sp, # PRESERVED_R9_OFFSET ]
  723. ldr r8, [sp, # PRESERVED_R8_OFFSET ]
  724. ldr r7, [sp, # PRESERVED_R7_OFFSET ]
  725. ldr r6, [sp, # PRESERVED_R6_OFFSET ]
  726. ldr r5, [sp, # PRESERVED_R5_OFFSET ]
  727. ldr r4, [sp, # PRESERVED_R4_OFFSET ]
  728. ldr lr, [sp, # PRESERVED_RETURN_ADDRESS_OFFSET ]
  729. add sp, sp, # FIRST_STACK_ARGUMENT
  730. bx lr
  731. }
  732. __asm void ctiVMThrowTrampoline()
  733. {
  734. PRESERVE8
  735. mov r0, sp
  736. bl cti_vm_throw
  737. ldr r11, [sp, # PRESERVED_R11_OFFSET ]
  738. ldr r10, [sp, # PRESERVED_R10_OFFSET ]
  739. ldr r9, [sp, # PRESERVED_R9_OFFSET ]
  740. ldr r8, [sp, # PRESERVED_R8_OFFSET ]
  741. ldr r7, [sp, # PRESERVED_R7_OFFSET ]
  742. ldr r6, [sp, # PRESERVED_R6_OFFSET ]
  743. ldr r6, [sp, # PRESERVED_R6_OFFSET ]
  744. ldr r5, [sp, # PRESERVED_R5_OFFSET ]
  745. ldr r4, [sp, # PRESERVED_R4_OFFSET ]
  746. ldr lr, [sp, # PRESERVED_RETURN_ADDRESS_OFFSET ]
  747. add sp, sp, # FIRST_STACK_ARGUMENT
  748. bx lr
  749. }
  750. __asm void ctiOpThrowNotCaught()
  751. {
  752. PRESERVE8
  753. ldr r11, [sp, # PRESERVED_R11_OFFSET ]
  754. ldr r10, [sp, # PRESERVED_R10_OFFSET ]
  755. ldr r9, [sp, # PRESERVED_R9_OFFSET ]
  756. ldr r8, [sp, # PRESERVED_R8_OFFSET ]
  757. ldr r7, [sp, # PRESERVED_R7_OFFSET ]
  758. ldr r6, [sp, # PRESERVED_R6_OFFSET ]
  759. ldr r6, [sp, # PRESERVED_R6_OFFSET ]
  760. ldr r5, [sp, # PRESERVED_R5_OFFSET ]
  761. ldr r4, [sp, # PRESERVED_R4_OFFSET ]
  762. ldr lr, [sp, # PRESERVED_RETURN_ADDRESS_OFFSET ]
  763. add sp, sp, # FIRST_STACK_ARGUMENT
  764. bx lr
  765. }
  766. #elif COMPILER(RVCT) && CPU(ARM_TRADITIONAL)
  767. __asm EncodedJSValue ctiTrampoline(void*, JSStack*, CallFrame*, void* /*unused1*/, void* /*unused2*/, VM*)
  768. {
  769. ARM
  770. stmdb sp!, {r1-r3}
  771. stmdb sp!, {r4-r6, r8-r11, lr}
  772. sub sp, sp, # PRESERVEDR4_OFFSET
  773. mov r5, r2
  774. mov r6, #512
  775. mov lr, pc
  776. bx r0
  777. add sp, sp, # PRESERVEDR4_OFFSET
  778. ldmia sp!, {r4-r6, r8-r11, lr}
  779. add sp, sp, #12
  780. bx lr
  781. }
  782. __asm void ctiTrampolineEnd()
  783. {
  784. }
  785. __asm void ctiVMThrowTrampoline()
  786. {
  787. ARM
  788. PRESERVE8
  789. mov r0, sp
  790. bl cti_vm_throw
  791. add sp, sp, # PRESERVEDR4_OFFSET
  792. ldmia sp!, {r4-r6, r8-r11, lr}
  793. add sp, sp, #12
  794. bx lr
  795. }
  796. __asm void ctiOpThrowNotCaught()
  797. {
  798. ARM
  799. add sp, sp, # PRESERVEDR4_OFFSET
  800. ldmia sp!, {r4-r8, lr}
  801. add sp, sp, #12
  802. bx lr
  803. }
  804. #endif
  805. #if ENABLE(OPCODE_SAMPLING)
  806. #define CTI_SAMPLER stackFrame.vm->interpreter->sampler()
  807. #else
  808. #define CTI_SAMPLER 0
  809. #endif
  810. void performPlatformSpecificJITAssertions(VM* vm)
  811. {
  812. if (!vm->canUseJIT())
  813. return;
  814. #if CPU(ARM_THUMB2)
  815. // Unfortunate the arm compiler does not like the use of offsetof on JITStackFrame (since it contains non POD types),
  816. // and the OBJECT_OFFSETOF macro does not appear constantish enough for it to be happy with its use in COMPILE_ASSERT
  817. // macros.
  818. ASSERT(OBJECT_OFFSETOF(struct JITStackFrame, preservedReturnAddress) == PRESERVED_RETURN_ADDRESS_OFFSET);
  819. ASSERT(OBJECT_OFFSETOF(struct JITStackFrame, preservedR4) == PRESERVED_R4_OFFSET);
  820. ASSERT(OBJECT_OFFSETOF(struct JITStackFrame, preservedR5) == PRESERVED_R5_OFFSET);
  821. ASSERT(OBJECT_OFFSETOF(struct JITStackFrame, preservedR6) == PRESERVED_R6_OFFSET);
  822. ASSERT(OBJECT_OFFSETOF(struct JITStackFrame, preservedR7) == PRESERVED_R7_OFFSET);
  823. ASSERT(OBJECT_OFFSETOF(struct JITStackFrame, preservedR8) == PRESERVED_R8_OFFSET);
  824. ASSERT(OBJECT_OFFSETOF(struct JITStackFrame, preservedR9) == PRESERVED_R9_OFFSET);
  825. ASSERT(OBJECT_OFFSETOF(struct JITStackFrame, preservedR10) == PRESERVED_R10_OFFSET);
  826. ASSERT(OBJECT_OFFSETOF(struct JITStackFrame, preservedR11) == PRESERVED_R11_OFFSET);
  827. ASSERT(OBJECT_OFFSETOF(struct JITStackFrame, stack) == REGISTER_FILE_OFFSET);
  828. // The fifth argument is the first item already on the stack.
  829. ASSERT(OBJECT_OFFSETOF(struct JITStackFrame, unused1) == FIRST_STACK_ARGUMENT);
  830. ASSERT(OBJECT_OFFSETOF(struct JITStackFrame, thunkReturnAddress) == THUNK_RETURN_ADDRESS_OFFSET);
  831. #elif CPU(ARM_TRADITIONAL)
  832. ASSERT(OBJECT_OFFSETOF(struct JITStackFrame, thunkReturnAddress) == THUNK_RETURN_ADDRESS_OFFSET);
  833. ASSERT(OBJECT_OFFSETOF(struct JITStackFrame, preservedR4) == PRESERVEDR4_OFFSET);
  834. #elif CPU(MIPS)
  835. ASSERT(OBJECT_OFFSETOF(struct JITStackFrame, preservedGP) == PRESERVED_GP_OFFSET);
  836. ASSERT(OBJECT_OFFSETOF(struct JITStackFrame, preservedS0) == PRESERVED_S0_OFFSET);
  837. ASSERT(OBJECT_OFFSETOF(struct JITStackFrame, preservedS1) == PRESERVED_S1_OFFSET);
  838. ASSERT(OBJECT_OFFSETOF(struct JITStackFrame, preservedS2) == PRESERVED_S2_OFFSET);
  839. ASSERT(OBJECT_OFFSETOF(struct JITStackFrame, preservedReturnAddress) == PRESERVED_RETURN_ADDRESS_OFFSET);
  840. ASSERT(OBJECT_OFFSETOF(struct JITStackFrame, thunkReturnAddress) == THUNK_RETURN_ADDRESS_OFFSET);
  841. ASSERT(OBJECT_OFFSETOF(struct JITStackFrame, stack) == REGISTER_FILE_OFFSET);
  842. ASSERT(OBJECT_OFFSETOF(struct JITStackFrame, vm) == GLOBAL_DATA_OFFSET);
  843. #endif
  844. }
  845. NEVER_INLINE static void tryCachePutByID(CallFrame* callFrame, CodeBlock* codeBlock, ReturnAddressPtr returnAddress, JSValue baseValue, const PutPropertySlot& slot, StructureStubInfo* stubInfo, bool direct)
  846. {
  847. // The interpreter checks for recursion here; I do not believe this can occur in CTI.
  848. if (!baseValue.isCell())
  849. return;
  850. // Uncacheable: give up.
  851. if (!slot.isCacheable()) {
  852. ctiPatchCallByReturnAddress(codeBlock, returnAddress, FunctionPtr(direct ? cti_op_put_by_id_direct_generic : cti_op_put_by_id_generic));
  853. return;
  854. }
  855. JSCell* baseCell = baseValue.asCell();
  856. Structure* structure = baseCell->structure();
  857. if (structure->isUncacheableDictionary() || structure->typeInfo().prohibitsPropertyCaching()) {
  858. ctiPatchCallByReturnAddress(codeBlock, returnAddress, FunctionPtr(direct ? cti_op_put_by_id_direct_generic : cti_op_put_by_id_generic));
  859. return;
  860. }
  861. // If baseCell != base, then baseCell must be a proxy for another object.
  862. if (baseCell != slot.base()) {
  863. ctiPatchCallByReturnAddress(codeBlock, returnAddress, FunctionPtr(direct ? cti_op_put_by_id_direct_generic : cti_op_put_by_id_generic));
  864. return;
  865. }
  866. // Cache hit: Specialize instruction and ref Structures.
  867. // Structure transition, cache transition info
  868. if (slot.type() == PutPropertySlot::NewProperty) {
  869. if (structure->isDictionary()) {
  870. ctiPatchCallByReturnAddress(codeBlock, returnAddress, FunctionPtr(direct ? cti_op_put_by_id_direct_generic : cti_op_put_by_id_generic));
  871. return;
  872. }
  873. // put_by_id_transition checks the prototype chain for setters.
  874. if (normalizePrototypeChain(callFrame, baseCell) == InvalidPrototypeChain) {
  875. ctiPatchCallByReturnAddress(codeBlock, returnAddress, FunctionPtr(direct ? cti_op_put_by_id_direct_generic : cti_op_put_by_id_generic));
  876. return;
  877. }
  878. StructureChain* prototypeChain = structure->prototypeChain(callFrame);
  879. ASSERT(structure->previousID()->transitionWatchpointSetHasBeenInvalidated());
  880. stubInfo->initPutByIdTransition(callFrame->vm(), codeBlock->ownerExecutable(), structure->previousID(), structure, prototypeChain, direct);
  881. JIT::compilePutByIdTransition(callFrame->scope()->vm(), codeBlock, stubInfo, structure->previousID(), structure, slot.cachedOffset(), prototypeChain, returnAddress, direct);
  882. return;
  883. }
  884. stubInfo->initPutByIdReplace(callFrame->vm(), codeBlock->ownerExecutable(), structure);
  885. JIT::patchPutByIdReplace(codeBlock, stubInfo, structure, slot.cachedOffset(), returnAddress, direct);
  886. }
  887. NEVER_INLINE static void tryCacheGetByID(CallFrame* callFrame, CodeBlock* codeBlock, ReturnAddressPtr returnAddress, JSValue baseValue, const Identifier& propertyName, const PropertySlot& slot, StructureStubInfo* stubInfo)
  888. {
  889. // FIXME: Write a test that proves we need to check for recursion here just
  890. // like the interpreter does, then add a check for recursion.
  891. // FIXME: Cache property access for immediates.
  892. if (!baseValue.isCell()) {
  893. ctiPatchCallByReturnAddress(codeBlock, returnAddress, FunctionPtr(cti_op_get_by_id_generic));
  894. return;
  895. }
  896. VM* vm = &callFrame->vm();
  897. if (isJSArray(baseValue) && propertyName == callFrame->propertyNames().length) {
  898. JIT::compilePatchGetArrayLength(callFrame->scope()->vm(), codeBlock, returnAddress);
  899. return;
  900. }
  901. if (isJSString(baseValue) && propertyName == callFrame->propertyNames().length) {
  902. // The tradeoff of compiling an patched inline string length access routine does not seem
  903. // to pay off, so we currently only do this for arrays.
  904. ctiPatchCallByReturnAddress(codeBlock, returnAddress, vm->getCTIStub(stringLengthTrampolineGenerator).code());
  905. return;
  906. }
  907. // Uncacheable: give up.
  908. if (!slot.isCacheable()) {
  909. stubInfo->accessType = access_get_by_id_generic;
  910. ctiPatchCallByReturnAddress(codeBlock, returnAddress, FunctionPtr(cti_op_get_by_id_generic));
  911. return;
  912. }
  913. JSCell* baseCell = baseValue.asCell();
  914. Structure* structure = baseCell->structure();
  915. if (structure->isUncacheableDictionary() || structure->typeInfo().prohibitsPropertyCaching()) {
  916. stubInfo->accessType = access_get_by_id_generic;
  917. ctiPatchCallByReturnAddress(codeBlock, returnAddress, FunctionPtr(cti_op_get_by_id_generic));
  918. return;
  919. }
  920. // Cache hit: Specialize instruction and ref Structures.
  921. if (slot.slotBase() == baseValue) {
  922. RELEASE_ASSERT(stubInfo->accessType == access_unset);
  923. if ((slot.cachedPropertyType() != PropertySlot::Value)
  924. || !MacroAssembler::isCompactPtrAlignedAddressOffset(maxOffsetRelativeToPatchedStorage(slot.cachedOffset())))
  925. ctiPatchCallByReturnAddress(codeBlock, returnAddress, FunctionPtr(cti_op_get_by_id_self_fail));
  926. else {
  927. JIT::patchGetByIdSelf(codeBlock, stubInfo, structure, slot.cachedOffset(), returnAddress);
  928. stubInfo->initGetByIdSelf(callFrame->vm(), codeBlock->ownerExecutable(), structure);
  929. }
  930. return;
  931. }
  932. if (structure->isDictionary()) {
  933. stubInfo->accessType = access_get_by_id_generic;
  934. ctiPatchCallByReturnAddress(codeBlock, returnAddress, FunctionPtr(cti_op_get_by_id_generic));
  935. return;
  936. }
  937. if (slot.slotBase() == structure->prototypeForLookup(callFrame)) {
  938. ASSERT(slot.slotBase().isObject());
  939. JSObject* slotBaseObject = asObject(slot.slotBase());
  940. size_t offset = slot.cachedOffset();
  941. if (structure->typeInfo().hasImpureGetOwnPropertySlot()) {
  942. stubInfo->accessType = access_get_by_id_generic;
  943. ctiPatchCallByReturnAddress(codeBlock, returnAddress, FunctionPtr(cti_op_get_by_id_generic));
  944. return;
  945. }
  946. // Since we're accessing a prototype in a loop, it's a good bet that it
  947. // should not be treated as a dictionary.
  948. if (slotBaseObject->structure()->isDictionary()) {
  949. slotBaseObject->flattenDictionaryObject(callFrame->vm());
  950. offset = slotBaseObject->structure()->get(callFrame->vm(), propertyName);
  951. }
  952. stubInfo->initGetByIdProto(callFrame->vm(), codeBlock->ownerExecutable(), structure, slotBaseObject->structure(), slot.cachedPropertyType() == PropertySlot::Value);
  953. ASSERT(!structure->isDictionary());
  954. ASSERT(!slotBaseObject->structure()->isDictionary());
  955. JIT::compileGetByIdProto(callFrame->scope()->vm(), callFrame, codeBlock, stubInfo, structure, slotBaseObject->structure(), propertyName, slot, offset, returnAddress);
  956. return;
  957. }
  958. PropertyOffset offset = slot.cachedOffset();
  959. size_t count = normalizePrototypeChainForChainAccess(callFrame, baseValue, slot.slotBase(), propertyName, offset);
  960. if (count == InvalidPrototypeChain) {
  961. stubInfo->accessType = access_get_by_id_generic;
  962. ctiPatchCallByReturnAddress(codeBlock, returnAddress, FunctionPtr(cti_op_get_by_id_generic));
  963. return;
  964. }
  965. StructureChain* prototypeChain = structure->prototypeChain(callFrame);
  966. stubInfo->initGetByIdChain(callFrame->vm(), codeBlock->ownerExecutable(), structure, prototypeChain, count, slot.cachedPropertyType() == PropertySlot::Value);
  967. JIT::compileGetByIdChain(callFrame->scope()->vm(), callFrame, codeBlock, stubInfo, structure, prototypeChain, count, propertyName, slot, offset, returnAddress);
  968. }
  969. #if !defined(NDEBUG)
  970. extern "C" {
  971. static void jscGeneratedNativeCode()
  972. {
  973. // When executing a JIT stub function (which might do an allocation), we hack the return address
  974. // to pretend to be executing this function, to keep stack logging tools from blowing out
  975. // memory.
  976. }
  977. }
  978. struct StackHack {
  979. ALWAYS_INLINE StackHack(JITStackFrame& stackFrame)
  980. : stackFrame(stackFrame)
  981. , savedReturnAddress(*stackFrame.returnAddressSlot())
  982. {
  983. if (!CodeProfiling::enabled())
  984. *stackFrame.returnAddressSlot() = ReturnAddressPtr(FunctionPtr(jscGeneratedNativeCode));
  985. }
  986. ALWAYS_INLINE ~StackHack()
  987. {
  988. *stackFrame.returnAddressSlot() = savedReturnAddress;
  989. }
  990. JITStackFrame& stackFrame;
  991. ReturnAddressPtr savedReturnAddress;
  992. };
  993. #define STUB_INIT_STACK_FRAME(stackFrame) JITStackFrame& stackFrame = *reinterpret_cast_ptr<JITStackFrame*>(STUB_ARGS); StackHack stackHack(stackFrame)
  994. #define STUB_SET_RETURN_ADDRESS(returnAddress) stackHack.savedReturnAddress = ReturnAddressPtr(returnAddress)
  995. #define STUB_RETURN_ADDRESS stackHack.savedReturnAddress
  996. #else
  997. #define STUB_INIT_STACK_FRAME(stackFrame) JITStackFrame& stackFrame = *reinterpret_cast_ptr<JITStackFrame*>(STUB_ARGS)
  998. #define STUB_SET_RETURN_ADDRESS(returnAddress) *stackFrame.returnAddressSlot() = ReturnAddressPtr(returnAddress)
  999. #define STUB_RETURN_ADDRESS *stackFrame.returnAddressSlot()
  1000. #endif
  1001. // The reason this is not inlined is to avoid having to do a PIC branch
  1002. // to get the address of the ctiVMThrowTrampoline function. It's also
  1003. // good to keep the code size down by leaving as much of the exception
  1004. // handling code out of line as possible.
  1005. static NEVER_INLINE void returnToThrowTrampoline(VM* vm, ReturnAddressPtr exceptionLocation, ReturnAddressPtr& returnAddressSlot)
  1006. {
  1007. RELEASE_ASSERT(vm->exception);
  1008. vm->exceptionLocation = exceptionLocation;
  1009. returnAddressSlot = ReturnAddressPtr(FunctionPtr(ctiVMThrowTrampoline));
  1010. }
  1011. #define VM_THROW_EXCEPTION() \
  1012. do { \
  1013. VM_THROW_EXCEPTION_AT_END(); \
  1014. return 0; \
  1015. } while (0)
  1016. #define VM_THROW_EXCEPTION_AT_END() \
  1017. do {\
  1018. returnToThrowTrampoline(stackFrame.vm, STUB_RETURN_ADDRESS, STUB_RETURN_ADDRESS);\
  1019. } while (0)
  1020. #define CHECK_FOR_EXCEPTION() \
  1021. do { \
  1022. if (UNLIKELY(stackFrame.vm->exception)) \
  1023. VM_THROW_EXCEPTION(); \
  1024. } while (0)
  1025. #define CHECK_FOR_EXCEPTION_AT_END() \
  1026. do { \
  1027. if (UNLIKELY(stackFrame.vm->exception)) \
  1028. VM_THROW_EXCEPTION_AT_END(); \
  1029. } while (0)
  1030. #define CHECK_FOR_EXCEPTION_VOID() \
  1031. do { \
  1032. if (UNLIKELY(stackFrame.vm->exception)) { \
  1033. VM_THROW_EXCEPTION_AT_END(); \
  1034. return; \
  1035. } \
  1036. } while (0)
  1037. // Helper function for JIT stubs that may throw an exception in the middle of
  1038. // processing a function call. This function rolls back the stack to
  1039. // our caller, so exception processing can proceed from a valid state.
  1040. template<typename T> static T throwExceptionFromOpCall(JITStackFrame& jitStackFrame, CallFrame* newCallFrame, ReturnAddressPtr& returnAddressSlot)
  1041. {
  1042. CallFrame* callFrame = newCallFrame->callerFrame();
  1043. ASSERT(callFrame->vm().exception);
  1044. jitStackFrame.callFrame = callFrame;
  1045. callFrame->vm().topCallFrame = callFrame;
  1046. returnToThrowTrampoline(&callFrame->vm(), ReturnAddressPtr(newCallFrame->returnPC()), returnAddressSlot);
  1047. return T();
  1048. }
  1049. template<typename T> static T throwExceptionFromOpCall(JITStackFrame& jitStackFrame, CallFrame* newCallFrame, ReturnAddressPtr& returnAddressSlot, JSValue exception)
  1050. {
  1051. newCallFrame->callerFrame()->vm().exception = exception;
  1052. return throwExceptionFromOpCall<T>(jitStackFrame, newCallFrame, returnAddressSlot);
  1053. }
  1054. #if CPU(ARM_THUMB2) && (COMPILER(GCC) || COMPILER(SNC))
  1055. #define DEFINE_STUB_FUNCTION(rtype, op) \
  1056. extern "C" { \
  1057. rtype JITStubThunked_##op(STUB_ARGS_DECLARATION); \
  1058. }; \
  1059. asm ( \
  1060. ".text" "\n" \
  1061. ".align 2" "\n" \
  1062. ".globl " SYMBOL_STRING(cti_##op) "\n" \
  1063. HIDE_SYMBOL(cti_##op) "\n" \
  1064. ARM_THUMB2_FUNC_PROLOGUE(cti_##op) \
  1065. ".thumb" "\n" \
  1066. ".thumb_func " THUMB_FUNC_PARAM(cti_##op) "\n" \
  1067. SYMBOL_STRING(cti_##op) ":" "\n" \
  1068. "str lr, [sp, #" STRINGIZE_VALUE_OF(THUNK_RETURN_ADDRESS_OFFSET) "]" "\n" \
  1069. "bl " SYMBOL_STRING(JITStubThunked_##op) "\n" \
  1070. "ldr lr, [sp, #" STRINGIZE_VALUE_OF(THUNK_RETURN_ADDRESS_OFFSET) "]" "\n" \
  1071. "bx lr" "\n" \
  1072. ARM_THUMB2_FUNC_EPILOGUE(cti_##op) \
  1073. ); \
  1074. rtype JITStubThunked_##op(STUB_ARGS_DECLARATION) \
  1075. #elif CPU(MIPS)
  1076. #if WTF_MIPS_PIC
  1077. #define DEFINE_STUB_FUNCTION(rtype, op) \
  1078. extern "C" { \
  1079. rtype JITStubThunked_##op(STUB_ARGS_DECLARATION); \
  1080. }; \
  1081. asm ( \
  1082. ".text" "\n" \
  1083. ".align 2" "\n" \
  1084. ".set noreorder" "\n" \
  1085. ".set nomacro" "\n" \
  1086. ".set nomips16" "\n" \
  1087. ".globl " SYMBOL_STRING(cti_##op) "\n" \
  1088. ".ent " SYMBOL_STRING(cti_##op) "\n" \
  1089. SYMBOL_STRING(cti_##op) ":" "\n" \
  1090. ".set macro" "\n" \
  1091. ".cpload $25" "\n" \
  1092. "sw $31," STRINGIZE_VALUE_OF(THUNK_RETURN_ADDRESS_OFFSET) "($29)" "\n" \
  1093. "la $25," SYMBOL_STRING(JITStubThunked_##op) "\n" \
  1094. ".set nomacro" "\n" \
  1095. ".reloc 1f,R_MIPS_JALR," SYMBOL_STRING(JITStubThunked_##op) "\n" \
  1096. "1: jalr $25" "\n" \
  1097. "nop" "\n" \
  1098. "lw $31," STRINGIZE_VALUE_OF(THUNK_RETURN_ADDRESS_OFFSET) "($29)" "\n" \
  1099. "jr $31" "\n" \
  1100. "nop" "\n" \
  1101. ".set reorder" "\n" \
  1102. ".set macro" "\n" \
  1103. ".end " SYMBOL_STRING(cti_##op) "\n" \
  1104. ); \
  1105. rtype JITStubThunked_##op(STUB_ARGS_DECLARATION)
  1106. #else // WTF_MIPS_PIC
  1107. #define DEFINE_STUB_FUNCTION(rtype, op) \
  1108. extern "C" { \
  1109. rtype JITStubThunked_##op(STUB_ARGS_DECLARATION); \
  1110. }; \
  1111. asm ( \
  1112. ".text" "\n" \
  1113. ".align 2" "\n" \
  1114. ".set noreorder" "\n" \
  1115. ".set nomacro" "\n" \
  1116. ".set nomips16" "\n" \
  1117. ".globl " SYMBOL_STRING(cti_##op) "\n" \
  1118. ".ent " SYMBOL_STRING(cti_##op) "\n" \
  1119. SYMBOL_STRING(cti_##op) ":" "\n" \
  1120. "sw $31," STRINGIZE_VALUE_OF(THUNK_RETURN_ADDRESS_OFFSET) "($29)" "\n" \
  1121. "jal " SYMBOL_STRING(JITStubThunked_##op) "\n" \
  1122. "nop" "\n" \
  1123. "lw $31," STRINGIZE_VALUE_OF(THUNK_RETURN_ADDRESS_OFFSET) "($29)" "\n" \
  1124. "jr $31" "\n" \
  1125. "nop" "\n" \
  1126. ".set reorder" "\n" \
  1127. ".set macro" "\n" \
  1128. ".end " SYMBOL_STRING(cti_##op) "\n" \
  1129. ); \
  1130. rtype JITStubThunked_##op(STUB_ARGS_DECLARATION)
  1131. #endif
  1132. #elif CPU(ARM_TRADITIONAL) && COMPILER(GCC)
  1133. #define DEFINE_STUB_FUNCTION(rtype, op) \
  1134. extern "C" { \
  1135. rtype JITStubThunked_##op(STUB_ARGS_DECLARATION); \
  1136. }; \
  1137. asm ( \
  1138. ".globl " SYMBOL_STRING(cti_##op) "\n" \
  1139. INLINE_ARM_FUNCTION(cti_##op) \
  1140. SYMBOL_STRING(cti_##op) ":" "\n" \
  1141. "str lr, [sp, #" STRINGIZE_VALUE_OF(THUNK_RETURN_ADDRESS_OFFSET) "]" "\n" \
  1142. "bl " SYMBOL_STRING(JITStubThunked_##op) "\n" \
  1143. "ldr lr, [sp, #" STRINGIZE_VALUE_OF(THUNK_RETURN_ADDRESS_OFFSET) "]" "\n" \
  1144. "bx lr" "\n" \
  1145. ); \
  1146. rtype JITStubThunked_##op(STUB_ARGS_DECLARATION)
  1147. #elif (CPU(ARM_THUMB2) || CPU(ARM_TRADITIONAL)) && COMPILER(RVCT)
  1148. #define DEFINE_STUB_FUNCTION(rtype, op) rtype JITStubThunked_##op(STUB_ARGS_DECLARATION)
  1149. /* The following is a workaround for RVCT toolchain; precompiler macros are not expanded before the code is passed to the assembler */
  1150. /* The following section is a template to generate code for GeneratedJITStubs_RVCT.h */
  1151. /* The pattern "#xxx#" will be replaced with "xxx" */
  1152. /*
  1153. RVCT(extern "C" #rtype# JITStubThunked_#op#(STUB_ARGS_DECLARATION);)
  1154. RVCT(__asm #rtype# cti_#op#(STUB_ARGS_DECLARATION))
  1155. RVCT({)
  1156. RVCT( PRESERVE8)
  1157. RVCT( IMPORT JITStubThunked_#op#)
  1158. RVCT( str lr, [sp, # THUNK_RETURN_ADDRESS_OFFSET])
  1159. RVCT( bl JITStubThunked_#op#)
  1160. RVCT( ldr lr, [sp, # THUNK_RETURN_ADDRESS_OFFSET])
  1161. RVCT( bx lr)
  1162. RVCT(})
  1163. RVCT()
  1164. */
  1165. /* Include the generated file */
  1166. #include "GeneratedJITStubs_RVCT.h"
  1167. #elif CPU(ARM_TRADITIONAL) && COMPILER(MSVC)
  1168. #define DEFINE_STUB_FUNCTION(rtype, op) extern "C" rtype JITStubThunked_##op(STUB_ARGS_DECLARATION)
  1169. /* The following is a workaround for MSVC toolchain; inline assembler is not supported */
  1170. /* The following section is a template to generate code for GeneratedJITStubs_MSVC.asm */
  1171. /* The pattern "#xxx#" will be replaced with "xxx" */
  1172. /*
  1173. MSVC_BEGIN( AREA Trampoline, CODE)
  1174. MSVC_BEGIN()
  1175. MSVC_BEGIN( EXPORT ctiTrampoline)
  1176. MSVC_BEGIN( EXPORT ctiTrampolineEnd)
  1177. MSVC_BEGIN( EXPORT ctiVMThrowTrampoline)
  1178. MSVC_BEGIN( EXPORT ctiOpThrowNotCaught)
  1179. MSVC_BEGIN()
  1180. MSVC_BEGIN(ctiTrampoline PROC)
  1181. MSVC_BEGIN( stmdb sp!, {r1-r3})
  1182. MSVC_BEGIN( stmdb sp!, {r4-r6, r8-r11, lr})
  1183. MSVC_BEGIN( sub sp, sp, #68 ; sync with PRESERVEDR4_OFFSET)
  1184. MSVC_BEGIN( mov r5, r2)
  1185. MSVC_BEGIN( mov r6, #512)
  1186. MSVC_BEGIN( ; r0 contains the code)
  1187. MSVC_BEGIN( mov lr, pc)
  1188. MSVC_BEGIN( bx r0)
  1189. MSVC_BEGIN( add sp, sp, #68 ; sync with PRESERVEDR4_OFFSET)
  1190. MSVC_BEGIN( ldmia sp!, {r4-r6, r8-r11, lr})
  1191. MSVC_BEGIN( add sp, sp, #12)
  1192. MSVC_BEGIN( bx lr)
  1193. MSVC_BEGIN(ctiTrampolineEnd)
  1194. MSVC_BEGIN(ctiTrampoline ENDP)
  1195. MSVC_BEGIN()
  1196. MSVC_BEGIN(ctiVMThrowTrampoline PROC)
  1197. MSVC_BEGIN( mov r0, sp)
  1198. MSVC_BEGIN( bl cti_vm_throw)
  1199. MSVC_BEGIN(ctiOpThrowNotCaught)
  1200. MSVC_BEGIN( add sp, sp, #68 ; sync with PRESERVEDR4_OFFSET)
  1201. MSVC_BEGIN( ldmia sp!, {r4-r6, r8-r11, lr})
  1202. MSVC_BEGIN( add sp, sp, #12)
  1203. MSVC_BEGIN( bx lr)
  1204. MSVC_BEGIN(ctiVMThrowTrampoline ENDP)
  1205. MSVC_BEGIN()
  1206. MSVC( EXPORT cti_#op#)
  1207. MSVC( IMPORT JITStubThunked_#op#)
  1208. MSVC(cti_#op# PROC)
  1209. MSVC( str lr, [sp, #64] ; sync with THUNK_RETURN_ADDRESS_OFFSET)
  1210. MSVC( bl JITStubThunked_#op#)
  1211. MSVC( ldr lr, [sp, #64] ; sync with THUNK_RETURN_ADDRESS_OFFSET)
  1212. MSVC( bx lr)
  1213. MSVC(cti_#op# ENDP)
  1214. MSVC()
  1215. MSVC_END( END)
  1216. */
  1217. #elif CPU(SH4)
  1218. #define DEFINE_STUB_FUNCTION(rtype, op) \
  1219. extern "C" { \
  1220. rtype JITStubThunked_##op(STUB_ARGS_DECLARATION); \
  1221. }; \
  1222. asm volatile( \
  1223. ".align 2" "\n" \
  1224. ".globl " SYMBOL_STRING(cti_##op) "\n" \
  1225. SYMBOL_STRING(cti_##op) ":" "\n" \
  1226. "sts pr, r11" "\n" \
  1227. "mov.l r11, @(0x38, r15)" "\n" \
  1228. "mov.l .L2"SYMBOL_STRING(JITStubThunked_##op)",r0" "\n" \
  1229. "mov.l @(r0,r12),r11" "\n" \
  1230. "jsr @r11" "\n" \
  1231. "nop" "\n" \
  1232. "mov.l @(0x38, r15), r11 " "\n" \
  1233. "lds r11, pr " "\n" \
  1234. "rts" "\n" \
  1235. "nop" "\n" \
  1236. ".align 2" "\n" \
  1237. ".L2"SYMBOL_STRING(JITStubThunked_##op)":.long " SYMBOL_STRING(JITStubThunked_##op)"@GOT \n" \
  1238. ); \
  1239. rtype JITStubThunked_##op(STUB_ARGS_DECLARATION)
  1240. #else
  1241. #define DEFINE_STUB_FUNCTION(rtype, op) rtype JIT_STUB cti_##op(STUB_ARGS_DECLARATION)
  1242. #endif
  1243. DEFINE_STUB_FUNCTION(EncodedJSValue, op_create_this)
  1244. {
  1245. STUB_INIT_STACK_FRAME(stackFrame);
  1246. CallFrame* callFrame = stackFrame.callFrame;
  1247. size_t inlineCapacity = stackFrame.args[0].int32();
  1248. JSFunction* constructor = jsCast<JSFunction*>(callFrame->callee());
  1249. #if !ASSERT_DISABLED
  1250. ConstructData constructData;
  1251. ASSERT(constructor->methodTable()->getConstructData(constructor, constructData) == ConstructTypeJS);
  1252. #endif
  1253. Structure* structure = constructor->allocationProfile(callFrame, inlineCapacity)->structure();
  1254. JSValue result = constructEmptyObject(callFrame, structure);
  1255. return JSValue::encode(result);
  1256. }
  1257. DEFINE_STUB_FUNCTION(EncodedJSValue, op_convert_this)
  1258. {
  1259. STUB_INIT_STACK_FRAME(stackFrame);
  1260. JSValue v1 = stackFrame.args[0].jsValue();
  1261. CallFrame* callFrame = stackFrame.callFrame;
  1262. ASSERT(v1.isPrimitive());
  1263. JSObject* result = v1.toThisObject(callFrame);
  1264. CHECK_FOR_EXCEPTION_AT_END();
  1265. return JSValue::encode(result);
  1266. }
  1267. DEFINE_STUB_FUNCTION(EncodedJSValue, op_add)
  1268. {
  1269. STUB_INIT_STACK_FRAME(stackFrame);
  1270. JSValue v1 = stackFrame.args[0].jsValue();
  1271. JSValue v2 = stackFrame.args[1].jsValue();
  1272. CallFrame* callFrame = stackFrame.callFrame;
  1273. if (v1.isString() && !v2.isObject()) {
  1274. JSValue result = jsString(callFrame, asString(v1), v2.toString(callFrame));
  1275. CHECK_FOR_EXCEPTION_AT_END();
  1276. return JSValue::encode(result);
  1277. }
  1278. if (v1.isNumber() && v2.isNumber())
  1279. return JSValue::encode(jsNumber(v1.asNumber() + v2.asNumber()));
  1280. // All other cases are pretty uncommon
  1281. JSValue result = jsAddSlowCase(callFrame, v1, v2);
  1282. CHECK_FOR_EXCEPTION_AT_END();
  1283. return JSValue::encode(result);
  1284. }
  1285. DEFINE_STUB_FUNCTION(EncodedJSValue, op_inc)
  1286. {
  1287. STUB_INIT_STACK_FRAME(stackFrame);
  1288. JSValue v = stackFrame.args[0].jsValue();
  1289. CallFrame* callFrame = stackFrame.callFrame;
  1290. JSValue result = jsNumber(v.toNumber(callFrame) + 1);
  1291. CHECK_FOR_EXCEPTION_AT_END();
  1292. return JSValue::encode(result);
  1293. }
  1294. DEFINE_STUB_FUNCTION(void, handle_watchdog_timer)
  1295. {
  1296. STUB_INIT_STACK_FRAME(stackFrame);
  1297. CallFrame* callFrame = stackFrame.callFrame;
  1298. VM* vm = stackFrame.vm;
  1299. if (UNLIKELY(vm->watchdog.didFire(callFrame))) {
  1300. vm->exception = createTerminatedExecutionException(vm);
  1301. VM_THROW_EXCEPTION_AT_END();
  1302. return;
  1303. }
  1304. }
  1305. DEFINE_STUB_FUNCTION(void*, stack_check)
  1306. {
  1307. STUB_INIT_STACK_FRAME(stackFrame);
  1308. CallFrame* callFrame = stackFrame.callFrame;
  1309. if (UNLIKELY(!stackFrame.stack->grow(&callFrame->registers()[callFrame->codeBlock()->m_numCalleeRegisters])))
  1310. return throwExceptionFromOpCall<void*>(stackFrame, callFrame, STUB_RETURN_ADDRESS, createStackOverflowError(callFrame->callerFrame()));
  1311. return callFrame;
  1312. }
  1313. DEFINE_STUB_FUNCTION(JSObject*, op_new_object)
  1314. {
  1315. STUB_INIT_STACK_FRAME(stackFrame);
  1316. return constructEmptyObject(stackFrame.callFrame, stackFrame.args[0].structure());
  1317. }
  1318. DEFINE_STUB_FUNCTION(void, op_put_by_id_generic)
  1319. {
  1320. STUB_INIT_STACK_FRAME(stackFrame);
  1321. PutPropertySlot slot(stackFrame.callFrame->codeBlock()->isStrictMode());
  1322. stackFrame.args[0].jsValue().put(stackFrame.callFrame, stackFrame.args[1].identifier(), stackFrame.args[2].jsValue(), slot);
  1323. CHECK_FOR_EXCEPTION_AT_END();
  1324. }
  1325. DEFINE_STUB_FUNCTION(void, op_put_by_id_direct_generic)
  1326. {
  1327. STUB_INIT_STACK_FRAME(stackFrame);
  1328. PutPropertySlot slot(stackFrame.callFrame->codeBlock()->isStrictMode());
  1329. JSValue baseValue = stackFrame.args[0].jsValue();
  1330. ASSERT(baseValue.isObject());
  1331. asObject(baseValue)->putDirect(stackFrame.callFrame->vm(), stackFrame.args[1].identifier(), stackFrame.args[2].jsValue(), slot);
  1332. CHECK_FOR_EXCEPTION_AT_END();
  1333. }
  1334. DEFINE_STUB_FUNCTION(EncodedJSValue, op_get_by_id_generic)
  1335. {
  1336. STUB_INIT_STACK_FRAME(stackFrame);
  1337. CallFrame* callFrame = stackFrame.callFrame;
  1338. Identifier& ident = stackFrame.args[1].identifier();
  1339. JSValue baseValue = stackFrame.args[0].jsValue();
  1340. PropertySlot slot(baseValue);
  1341. JSValue result = baseValue.get(callFrame, ident, slot);
  1342. CHECK_FOR_EXCEPTION_AT_END();
  1343. return JSValue::encode(result);
  1344. }
  1345. DEFINE_STUB_FUNCTION(void, op_put_by_id)
  1346. {
  1347. STUB_INIT_STACK_FRAME(stackFrame);
  1348. CallFrame* callFrame = stackFrame.callFrame;
  1349. Identifier& ident = stackFrame.args[1].identifier();
  1350. CodeBlock* codeBlock = stackFrame.callFrame->codeBlock();
  1351. StructureStubInfo* stubInfo = &codeBlock->getStubInfo(STUB_RETURN_ADDRESS);
  1352. AccessType accessType = static_cast<AccessType>(stubInfo->accessType);
  1353. PutPropertySlot slot(callFrame->codeBlock()->isStrictMode());
  1354. stackFrame.args[0].jsValue().put(callFrame, ident, stackFrame.args[2].jsValue(), slot);
  1355. if (accessType == static_cast<AccessType>(stubInfo->accessType)) {
  1356. stubInfo->setSeen();
  1357. tryCachePutByID(callFrame, codeBlock, STUB_RETURN_ADDRESS, stackFrame.args[0].jsValue(), slot, stubInfo, false);
  1358. }
  1359. CHECK_FOR_EXCEPTION_AT_END();
  1360. }
  1361. DEFINE_STUB_FUNCTION(void, op_put_by_id_direct)
  1362. {
  1363. STUB_INIT_STACK_FRAME(stackFrame);
  1364. CallFrame* callFrame = stackFrame.callFrame;
  1365. Identifier& ident = stackFrame.args[1].identifier();
  1366. CodeBlock* codeBlock = stackFrame.callFrame->codeBlock();
  1367. StructureStubInfo* stubInfo = &codeBlock->getStubInfo(STUB_RETURN_ADDRESS);
  1368. AccessType accessType = static_cast<AccessType>(stubInfo->accessType);
  1369. PutPropertySlot slot(callFrame->codeBlock()->isStrictMode());
  1370. JSValue baseValue = stackFrame.args[0].jsValue();
  1371. ASSERT(baseValue.isObject());
  1372. asObject(baseValue)->putDirect(callFrame->vm(), ident, stackFrame.args[2].jsValue(), slot);
  1373. if (accessType == static_cast<AccessType>(stubInfo->accessType)) {
  1374. stubInfo->setSeen();
  1375. tryCachePutByID(callFrame, codeBlock, STUB_RETURN_ADDRESS, stackFrame.args[0].jsValue(), slot, stubInfo, true);
  1376. }
  1377. CHECK_FOR_EXCEPTION_AT_END();
  1378. }
  1379. DEFINE_STUB_FUNCTION(void, op_put_by_id_fail)
  1380. {
  1381. STUB_INIT_STACK_FRAME(stackFrame);
  1382. CallFrame* callFrame = stackFrame.callFrame;
  1383. Identifier& ident = stackFrame.args[1].identifier();
  1384. PutPropertySlot slot(callFrame->codeBlock()->isStrictMode());
  1385. stackFrame.args[0].jsValue().put(callFrame, ident, stackFrame.args[2].jsValue(), slot);
  1386. CHECK_FOR_EXCEPTION_AT_END();
  1387. }
  1388. DEFINE_STUB_FUNCTION(void, op_put_by_id_direct_fail)
  1389. {
  1390. STUB_INIT_STACK_FRAME(stackFrame);
  1391. CallFrame* callFrame = stackFrame.callFrame;
  1392. Identifier& ident = stackFrame.args[1].identifier();
  1393. PutPropertySlot slot(callFrame->codeBlock()->isStrictMode());
  1394. JSValue baseValue = stackFrame.args[0].jsValue();
  1395. ASSERT(baseValue.isObject());
  1396. asObject(baseValue)->putDirect(callFrame->vm(), ident, stackFrame.args[2].jsValue(), slot);
  1397. CHECK_FOR_EXCEPTION_AT_END();
  1398. }
  1399. DEFINE_STUB_FUNCTION(JSObject*, op_put_by_id_transition_realloc)
  1400. {
  1401. STUB_INIT_STACK_FRAME(stackFrame);
  1402. JSValue baseValue = stackFrame.args[0].jsValue();
  1403. int32_t oldSize = stackFrame.args[3].int32();
  1404. Structure* newStructure = stackFrame.args[4].structure();
  1405. int32_t newSize = newStructure->outOfLineCapacity();
  1406. ASSERT(oldSize >= 0);
  1407. ASSERT(newSize > oldSize);
  1408. ASSERT(baseValue.isObject());
  1409. JSObject* base = asObject(baseValue);
  1410. VM& vm = *stackFrame.vm;
  1411. Butterfly* butterfly = base->growOutOfLineStorage(vm, oldSize, newSize);
  1412. base->setButterfly(vm, butterfly, newStructure);
  1413. return base;
  1414. }
  1415. DEFINE_STUB_FUNCTION(EncodedJSValue, op_get_by_id)
  1416. {
  1417. STUB_INIT_STACK_FRAME(stackFrame);
  1418. CallFrame* callFrame = stackFrame.callFrame;
  1419. Identifier& ident = stackFrame.args[1].identifier();
  1420. CodeBlock* codeBlock = stackFrame.callFrame->codeBlock();
  1421. StructureStubInfo* stubInfo = &codeBlock->getStubInfo(STUB_RETURN_ADDRESS);
  1422. AccessType accessType = static_cast<AccessType>(stubInfo->accessType);
  1423. JSValue baseValue = stackFrame.args[0].jsValue();
  1424. PropertySlot slot(baseValue);
  1425. JSValue result = baseValue.get(callFrame, ident, slot);
  1426. if (accessType != static_cast<AccessType>(stubInfo->accessType))
  1427. return JSValue::encode(result);
  1428. if (!stubInfo->seenOnce())
  1429. stubInfo->setSeen();
  1430. else
  1431. tryCacheGetByID(callFrame, codeBlock, STUB_RETURN_ADDRESS, baseValue, ident, slot, stubInfo);
  1432. CHECK_FOR_EXCEPTION_AT_END();
  1433. return JSValue::encode(result);
  1434. }
  1435. DEFINE_STUB_FUNCTION(EncodedJSValue, op_get_by_id_self_fail)
  1436. {
  1437. STUB_INIT_STACK_FRAME(stackFrame);
  1438. CallFrame* callFrame = stackFrame.callFrame;
  1439. Identifier& ident = stackFrame.args[1].identifier();
  1440. CodeBlock* codeBlock = callFrame->codeBlock();
  1441. StructureStubInfo* stubInfo = &codeBlock->getStubInfo(STUB_RETURN_ADDRESS);
  1442. AccessType accessType = static_cast<AccessType>(stubInfo->accessType);
  1443. JSValue baseValue = stackFrame.args[0].jsValue();
  1444. PropertySlot slot(baseValue);
  1445. JSValue result = baseValue.get(callFrame, ident, slot);
  1446. if (accessType != static_cast<AccessType>(stubInfo->accessType))
  1447. return JSValue::encode(result);
  1448. CHECK_FOR_EXCEPTION();
  1449. if (baseValue.isCell()
  1450. && slot.isCacheable()
  1451. && !baseValue.asCell()->structure()->isUncacheableDictionary()
  1452. && slot.slotBase() == baseValue) {
  1453. ASSERT(slot.slotBase().isObject());
  1454. PolymorphicAccessStructureList* polymorphicStructureList;
  1455. int listIndex = 1;
  1456. if (stubInfo->accessType == access_unset)
  1457. stubInfo->initGetByIdSelf(callFrame->vm(), codeBlock->ownerExecutable(), baseValue.asCell()->structure());
  1458. if (stubInfo->accessType == access_get_by_id_self) {
  1459. ASSERT(!stubInfo->stubRoutine);
  1460. polymorphicStructureList = new PolymorphicAccessStructureList(callFrame->vm(), codeBlock->ownerExecutable(), 0, stubInfo->u.getByIdSelf.baseObjectStructure.get(), true);
  1461. stubInfo->initGetByIdSelfList(polymorphicStructureList, 1);
  1462. } else {
  1463. polymorphicStructureList = stubInfo->u.getByIdSelfList.structureList;
  1464. listIndex = stubInfo->u.getByIdSelfList.listSize;
  1465. }
  1466. if (listIndex < POLYMORPHIC_LIST_CACHE_SIZE) {
  1467. stubInfo->u.getByIdSelfList.listSize++;
  1468. JIT::compileGetByIdSelfList(callFrame->scope()->vm(), codeBlock, stubInfo, polymorphicStructureList, listIndex, baseValue.asCell()->structure(), ident, slot, slot.cachedOffset());
  1469. if (listIndex == (POLYMORPHIC_LIST_CACHE_SIZE - 1))
  1470. ctiPatchCallByReturnAddress(codeBlock, STUB_RETURN_ADDRESS, FunctionPtr(cti_op_get_by_id_generic));
  1471. }
  1472. } else
  1473. ctiPatchCallByReturnAddress(callFrame->codeBlock(), STUB_RETURN_ADDRESS, FunctionPtr(cti_op_get_by_id_generic));
  1474. return JSValue::encode(result);
  1475. }
  1476. static PolymorphicAccessStructureList* getPolymorphicAccessStructureListSlot(VM& vm, ScriptExecutable* owner, StructureStubInfo* stubInfo, int& listIndex)
  1477. {
  1478. PolymorphicAccessStructureList* prototypeStructureList = 0;
  1479. listIndex = 1;
  1480. switch (stubInfo->accessType) {
  1481. case access_get_by_id_proto:
  1482. prototypeStructureList = new PolymorphicAccessStructureList(vm, owner, stubInfo->stubRoutine, stubInfo->u.getByIdProto.baseObjectStructure.get(), stubInfo->u.getByIdProto.prototypeStructure.get(), true);
  1483. stubInfo->stubRoutine.clear();
  1484. stubInfo->initGetByIdProtoList(prototypeStructureList, 2);
  1485. break;
  1486. case access_get_by_id_chain:
  1487. prototypeStructureList = new PolymorphicAccessStructureList(vm, owner, stubInfo->stubRoutine, stubInfo->u.getByIdChain.baseObjectStructure.get(), stubInfo->u.getByIdChain.chain.get(), true);
  1488. stubInfo->stubRoutine.clear();
  1489. stubInfo->initGetByIdProtoList(prototypeStructureList, 2);
  1490. break;
  1491. case access_get_by_id_proto_list:
  1492. prototypeStructureList = stubInfo->u.getByIdProtoList.structureList;
  1493. listIndex = stubInfo->u.getByIdProtoList.listSize;
  1494. if (listIndex < POLYMORPHIC_LIST_CACHE_SIZE)
  1495. stubInfo->u.getByIdProtoList.listSize++;
  1496. break;
  1497. default:
  1498. RELEASE_ASSERT_NOT_REACHED();
  1499. }
  1500. ASSERT(listIndex <= POLYMORPHIC_LIST_CACHE_SIZE);
  1501. return prototypeStructureList;
  1502. }
  1503. DEFINE_STUB_FUNCTION(EncodedJSValue, op_get_by_id_getter_stub)
  1504. {
  1505. STUB_INIT_STACK_FRAME(stackFrame);
  1506. CallFrame* callFrame = stackFrame.callFrame;
  1507. GetterSetter* getterSetter = asGetterSetter(stackFrame.args[0].jsObject());
  1508. if (!getterSetter->getter())
  1509. return JSValue::encode(jsUndefined());
  1510. JSObject* getter = asObject(getterSetter->getter());
  1511. CallData callData;
  1512. CallType callType = getter->methodTable()->getCallData(getter, callData);
  1513. JSValue result = call(callFrame, getter, callType, callData, stackFrame.args[1].jsObject(), ArgList());
  1514. if (callFrame->hadException())
  1515. returnToThrowTrampoline(&callFrame->vm(), stackFrame.args[2].returnAddress(), STUB_RETURN_ADDRESS);
  1516. return JSValue::encode(result);
  1517. }
  1518. DEFINE_STUB_FUNCTION(EncodedJSValue, op_get_by_id_custom_stub)
  1519. {
  1520. STUB_INIT_STACK_FRAME(stackFrame);
  1521. CallFrame* callFrame = stackFrame.callFrame;
  1522. JSObject* slotBase = stackFrame.args[0].jsObject();
  1523. PropertySlot::GetValueFunc getter = reinterpret_cast<PropertySlot::GetValueFunc>(stackFrame.args[1].asPointer);
  1524. const Identifier& ident = stackFrame.args[2].identifier();
  1525. JSValue result = getter(callFrame, slotBase, ident);
  1526. if (callFrame->hadException())
  1527. returnToThrowTrampoline(&callFrame->vm(), stackFrame.args[3].returnAddress(), STUB_RETURN_ADDRESS);
  1528. return JSValue::encode(result);
  1529. }
  1530. DEFINE_STUB_FUNCTION(EncodedJSValue, op_get_by_id_proto_list)
  1531. {
  1532. STUB_INIT_STACK_FRAME(stackFrame);
  1533. CallFrame* callFrame = stackFrame.callFrame;
  1534. const Identifier& propertyName = stackFrame.args[1].identifier();
  1535. CodeBlock* codeBlock = callFrame->codeBlock();
  1536. StructureStubInfo* stubInfo = &codeBlock->getStubInfo(STUB_RETURN_ADDRESS);
  1537. AccessType accessType = static_cast<AccessType>(stubInfo->accessType);
  1538. JSValue baseValue = stackFrame.args[0].jsValue();
  1539. PropertySlot slot(baseValue);
  1540. JSValue result = baseValue.get(callFrame, propertyName, slot);
  1541. CHECK_FOR_EXCEPTION();
  1542. if (accessType != static_cast<AccessType>(stubInfo->accessType)
  1543. || !baseValue.isCell()
  1544. || !slot.isCacheable()
  1545. || baseValue.asCell()->structure()->isDictionary()
  1546. || baseValue.asCell()->structure()->typeInfo().prohibitsPropertyCaching()) {
  1547. ctiPatchCallByReturnAddress(callFrame->codeBlock(), STUB_RETURN_ADDRESS, FunctionPtr(cti_op_get_by_id_proto_fail));
  1548. return JSValue::encode(result);
  1549. }
  1550. Structure* structure = baseValue.asCell()->structure();
  1551. ASSERT(slot.slotBase().isObject());
  1552. JSObject* slotBaseObject = asObject(slot.slotBase());
  1553. PropertyOffset offset = slot.cachedOffset();
  1554. if (slot.slotBase() == baseValue)
  1555. ctiPatchCallByReturnAddress(codeBlock, STUB_RETURN_ADDRESS, FunctionPtr(cti_op_get_by_id_proto_fail));
  1556. else if (slot.slotBase() == baseValue.asCell()->structure()->prototypeForLookup(callFrame)) {
  1557. ASSERT(!baseValue.asCell()->structure()->isDictionary());
  1558. if (baseValue.asCell()->structure()->typeInfo().hasImpureGetOwnPropertySlot()) {
  1559. ctiPatchCallByReturnAddress(codeBlock, STUB_RETURN_ADDRESS, FunctionPtr(cti_op_get_by_id_proto_fail));
  1560. return JSValue::encode(result);
  1561. }
  1562. // Since we're accessing a prototype in a loop, it's a good bet that it
  1563. // should not be treated as a dictionary.
  1564. if (slotBaseObject->structure()->isDictionary()) {
  1565. slotBaseObject->flattenDictionaryObject(callFrame->vm());
  1566. offset = slotBaseObject->structure()->get(callFrame->vm(), propertyName);
  1567. }
  1568. int listIndex;
  1569. PolymorphicAccessStructureList* prototypeStructureList = getPolymorphicAccessStructureListSlot(callFrame->vm(), codeBlock->ownerExecutable(), stubInfo, listIndex);
  1570. if (listIndex < POLYMORPHIC_LIST_CACHE_SIZE) {
  1571. JIT::compileGetByIdProtoList(callFrame->scope()->vm(), callFrame, codeBlock, stubInfo, prototypeStructureList, listIndex, structure, slotBaseObject->structure(), propertyName, slot, offset);
  1572. if (listIndex == (POLYMORPHIC_LIST_CACHE_SIZE - 1))
  1573. ctiPatchCallByReturnAddress(codeBlock, STUB_RETURN_ADDRESS, FunctionPtr(cti_op_get_by_id_proto_list_full));
  1574. }
  1575. } else {
  1576. size_t count = normalizePrototypeChainForChainAccess(callFrame, baseValue, slot.slotBase(), propertyName, offset);
  1577. if (count == InvalidPrototypeChain) {
  1578. ctiPatchCallByReturnAddress(codeBlock, STUB_RETURN_ADDRESS, FunctionPtr(cti_op_get_by_id_proto_fail));
  1579. return JSValue::encode(result);
  1580. }
  1581. ASSERT(!baseValue.asCell()->structure()->isDictionary());
  1582. int listIndex;
  1583. PolymorphicAccessStructureList* prototypeStructureList = getPolymorphicAccessStructureListSlot(callFrame->vm(), codeBlock->ownerExecutable(), stubInfo, listIndex);
  1584. if (listIndex < POLYMORPHIC_LIST_CACHE_SIZE) {
  1585. StructureChain* protoChain = structure->prototypeChain(callFrame);
  1586. JIT::compileGetByIdChainList(callFrame->scope()->vm(), callFrame, codeBlock, stubInfo, prototypeStructureList, listIndex, structure, protoChain, count, propertyName, slot, offset);
  1587. if (listIndex == (POLYMORPHIC_LIST_CACHE_SIZE - 1))
  1588. ctiPatchCallByReturnAddress(codeBlock, STUB_RETURN_ADDRESS, FunctionPtr(cti_op_get_by_id_proto_list_full));
  1589. }
  1590. }
  1591. return JSValue::encode(result);
  1592. }
  1593. DEFINE_STUB_FUNCTION(EncodedJSValue, op_get_by_id_proto_list_full)
  1594. {
  1595. STUB_INIT_STACK_FRAME(stackFrame);
  1596. JSValue baseValue = stackFrame.args[0].jsValue();
  1597. PropertySlot slot(baseValue);
  1598. JSValue result = baseValue.get(stackFrame.callFrame, stackFrame.args[1].identifier(), slot);
  1599. CHECK_FOR_EXCEPTION_AT_END();
  1600. return JSValue::encode(result);
  1601. }
  1602. DEFINE_STUB_FUNCTION(EncodedJSValue, op_get_by_id_proto_fail)
  1603. {
  1604. STUB_INIT_STACK_FRAME(stackFrame);
  1605. JSValue baseValue = stackFrame.args[0].jsValue();
  1606. PropertySlot slot(baseValue);
  1607. JSValue result = baseValue.get(stackFrame.callFrame, stackFrame.args[1].identifier(), slot);
  1608. CHECK_FOR_EXCEPTION_AT_END();
  1609. return JSValue::encode(result);
  1610. }
  1611. DEFINE_STUB_FUNCTION(EncodedJSValue, op_get_by_id_array_fail)
  1612. {
  1613. STUB_INIT_STACK_FRAME(stackFrame);
  1614. JSValue baseValue = stackFrame.args[0].jsValue();
  1615. PropertySlot slot(baseValue);
  1616. JSValue result = baseValue.get(stackFrame.callFrame, stackFrame.args[1].identifier(), slot);
  1617. CHECK_FOR_EXCEPTION_AT_END();
  1618. return JSValue::encode(result);
  1619. }
  1620. DEFINE_STUB_FUNCTION(EncodedJSValue, op_get_by_id_string_fail)
  1621. {
  1622. STUB_INIT_STACK_FRAME(stackFrame);
  1623. JSValue baseValue = stackFrame.args[0].jsValue();
  1624. PropertySlot slot(baseValue);
  1625. JSValue result = baseValue.get(stackFrame.callFrame, stackFrame.args[1].identifier(), slot);
  1626. CHECK_FOR_EXCEPTION_AT_END();
  1627. return JSValue::encode(result);
  1628. }
  1629. DEFINE_STUB_FUNCTION(EncodedJSValue, op_check_has_instance)
  1630. {
  1631. STUB_INIT_STACK_FRAME(stackFrame);
  1632. CallFrame* callFrame = stackFrame.callFrame;
  1633. JSValue value = stackFrame.args[0].jsValue();
  1634. JSValue baseVal = stackFrame.args[1].jsValue();
  1635. if (baseVal.isObject()) {
  1636. JSObject* baseObject = asObject(baseVal);
  1637. ASSERT(!baseObject->structure()->typeInfo().implementsDefaultHasInstance());
  1638. if (baseObject->structure()->typeInfo().implementsHasInstance()) {
  1639. bool result = baseObject->methodTable()->customHasInstance(baseObject, callFrame, value);
  1640. CHECK_FOR_EXCEPTION_AT_END();
  1641. return JSValue::encode(jsBoolean(result));
  1642. }
  1643. }
  1644. stackFrame.vm->exception = createInvalidParamError(callFrame, "instanceof", baseVal);
  1645. VM_THROW_EXCEPTION_AT_END();
  1646. return JSValue::encode(JSValue());
  1647. }
  1648. #if ENABLE(DFG_JIT)
  1649. DEFINE_STUB_FUNCTION(void, optimize)
  1650. {
  1651. STUB_INIT_STACK_FRAME(stackFrame);
  1652. CallFrame* callFrame = stackFrame.callFrame;
  1653. CodeBlock* codeBlock = callFrame->codeBlock();
  1654. unsigned bytecodeIndex = stackFrame.args[0].int32();
  1655. #if ENABLE(JIT_VERBOSE_OSR)
  1656. dataLog(
  1657. *codeBlock, ": Entered optimize with bytecodeIndex = ", bytecodeIndex,
  1658. ", executeCounter = ", codeBlock->jitExecuteCounter(),
  1659. ", optimizationDelayCounter = ", codeBlock->reoptimizationRetryCounter(),
  1660. ", exitCounter = ");
  1661. if (codeBlock->hasOptimizedReplacement())
  1662. dataLog(codeBlock->replacement()->osrExitCounter());
  1663. else
  1664. dataLog("N/A");
  1665. dataLog("\n");
  1666. #endif
  1667. if (!codeBlock->checkIfOptimizationThresholdReached()) {
  1668. codeBlock->updateAllPredictions();
  1669. #if ENABLE(JIT_VERBOSE_OSR)
  1670. dataLog("Choosing not to optimize ", *codeBlock, " yet.\n");
  1671. #endif
  1672. return;
  1673. }
  1674. if (codeBlock->hasOptimizedReplacement()) {
  1675. #if ENABLE(JIT_VERBOSE_OSR)
  1676. dataLog("Considering OSR ", *codeBlock, " -> ", *codeBlock->replacement(), ".\n");
  1677. #endif
  1678. // If we have an optimized replacement, then it must be the case that we entered
  1679. // cti_optimize from a loop. That's because is there's an optimized replacement,
  1680. // then all calls to this function will be relinked to the replacement and so
  1681. // the prologue OSR will never fire.
  1682. // This is an interesting threshold check. Consider that a function OSR exits
  1683. // in the middle of a loop, while having a relatively low exit count. The exit
  1684. // will reset the execution counter to some target threshold, meaning that this
  1685. // code won't be reached until that loop heats up for >=1000 executions. But then
  1686. // we do a second check here, to see if we should either reoptimize, or just
  1687. // attempt OSR entry. Hence it might even be correct for
  1688. // shouldReoptimizeFromLoopNow() to always return true. But we make it do some
  1689. // additional checking anyway, to reduce the amount of recompilation thrashing.
  1690. if (codeBlock->replacement()->shouldReoptimizeFromLoopNow()) {
  1691. #if ENABLE(JIT_VERBOSE_OSR)
  1692. dataLog("Triggering reoptimization of ", *codeBlock, "(", *codeBlock->replacement(), ") (in loop).\n");
  1693. #endif
  1694. codeBlock->reoptimize();
  1695. return;
  1696. }
  1697. } else {
  1698. if (!codeBlock->shouldOptimizeNow()) {
  1699. #if ENABLE(JIT_VERBOSE_OSR)
  1700. dataLog("Delaying optimization for ", *codeBlock, " (in loop) because of insufficient profiling.\n");
  1701. #endif
  1702. return;
  1703. }
  1704. #if ENABLE(JIT_VERBOSE_OSR)
  1705. dataLog("Triggering optimized compilation of ", *codeBlock, "\n");
  1706. #endif
  1707. JSScope* scope = callFrame->scope();
  1708. JSObject* error = codeBlock->compileOptimized(callFrame, scope, bytecodeIndex);
  1709. #if ENABLE(JIT_VERBOSE_OSR)
  1710. if (error)
  1711. dataLog("WARNING: optimized compilation failed.\n");
  1712. #else
  1713. UNUSED_PARAM(error);
  1714. #endif
  1715. if (codeBlock->replacement() == codeBlock) {
  1716. #if ENABLE(JIT_VERBOSE_OSR)
  1717. dataLog("Optimizing ", *codeBlock, " failed.\n");
  1718. #endif
  1719. ASSERT(codeBlock->getJITType() == JITCode::BaselineJIT);
  1720. codeBlock->dontOptimizeAnytimeSoon();
  1721. return;
  1722. }
  1723. }
  1724. CodeBlock* optimizedCodeBlock = codeBlock->replacement();
  1725. ASSERT(optimizedCodeBlock->getJITType() == JITCode::DFGJIT);
  1726. if (void* address = DFG::prepareOSREntry(callFrame, optimizedCodeBlock, bytecodeIndex)) {
  1727. if (Options::showDFGDisassembly()) {
  1728. dataLog(
  1729. "Performing OSR ", *codeBlock, " -> ", *optimizedCodeBlock, ", address ",
  1730. RawPointer((STUB_RETURN_ADDRESS).value()), " -> ", RawPointer(address), ".\n");
  1731. }
  1732. #if ENABLE(JIT_VERBOSE_OSR)
  1733. dataLog("Optimizing ", *codeBlock, " succeeded, performing OSR after a delay of ", codeBlock->optimizationDelayCounter(), ".\n");
  1734. #endif
  1735. codeBlock->optimizeSoon();
  1736. STUB_SET_RETURN_ADDRESS(address);
  1737. return;
  1738. }
  1739. #if ENABLE(JIT_VERBOSE_OSR)
  1740. dataLog("Optimizing ", *codeBlock, " succeeded, OSR failed, after a delay of ", codeBlock->optimizationDelayCounter(), ".\n");
  1741. #endif
  1742. // Count the OSR failure as a speculation failure. If this happens a lot, then
  1743. // reoptimize.
  1744. optimizedCodeBlock->countOSRExit();
  1745. #if ENABLE(JIT_VERBOSE_OSR)
  1746. dataLog("Encountered OSR failure ", *codeBlock, " -> ", *codeBlock->replacement(), ".\n");
  1747. #endif
  1748. // We are a lot more conservative about triggering reoptimization after OSR failure than
  1749. // before it. If we enter the optimize_from_loop trigger with a bucket full of fail
  1750. // already, then we really would like to reoptimize immediately. But this case covers
  1751. // something else: there weren't many (or any) speculation failures before, but we just
  1752. // failed to enter the speculative code because some variable had the wrong value or
  1753. // because the OSR code decided for any spurious reason that it did not want to OSR
  1754. // right now. So, we only trigger reoptimization only upon the more conservative (non-loop)
  1755. // reoptimization trigger.
  1756. if (optimizedCodeBlock->shouldReoptimizeNow()) {
  1757. #if ENABLE(JIT_VERBOSE_OSR)
  1758. dataLog("Triggering reoptimization of ", *codeBlock, " -> ", *codeBlock->replacement(), " (after OSR fail).\n");
  1759. #endif
  1760. codeBlock->reoptimize();
  1761. return;
  1762. }
  1763. // OSR failed this time, but it might succeed next time! Let the code run a bit
  1764. // longer and then try again.
  1765. codeBlock->optimizeAfterWarmUp();
  1766. }
  1767. #endif // ENABLE(DFG_JIT)
  1768. DEFINE_STUB_FUNCTION(EncodedJSValue, op_instanceof)
  1769. {
  1770. STUB_INIT_STACK_FRAME(stackFrame);
  1771. CallFrame* callFrame = stackFrame.callFrame;
  1772. JSValue value = stackFrame.args[0].jsValue();
  1773. JSValue proto = stackFrame.args[1].jsValue();
  1774. ASSERT(!value.isObject() || !proto.isObject());
  1775. bool result = JSObject::defaultHasInstance(callFrame, value, proto);
  1776. CHECK_FOR_EXCEPTION_AT_END();
  1777. return JSValue::encode(jsBoolean(result));
  1778. }
  1779. DEFINE_STUB_FUNCTION(EncodedJSValue, op_del_by_id)
  1780. {
  1781. STUB_INIT_STACK_FRAME(stackFrame);
  1782. CallFrame* callFrame = stackFrame.callFrame;
  1783. JSObject* baseObj = stackFrame.args[0].jsValue().toObject(callFrame);
  1784. bool couldDelete = baseObj->methodTable()->deleteProperty(baseObj, callFrame, stackFrame.args[1].identifier());
  1785. JSValue result = jsBoolean(couldDelete);
  1786. if (!couldDelete && callFrame->codeBlock()->isStrictMode())
  1787. stackFrame.vm->exception = createTypeError(stackFrame.callFrame, "Unable to delete property.");
  1788. CHECK_FOR_EXCEPTION_AT_END();
  1789. return JSValue::encode(result);
  1790. }
  1791. DEFINE_STUB_FUNCTION(EncodedJSValue, op_mul)
  1792. {
  1793. STUB_INIT_STACK_FRAME(stackFrame);
  1794. JSValue src1 = stackFrame.args[0].jsValue();
  1795. JSValue src2 = stackFrame.args[1].jsValue();
  1796. if (src1.isNumber() && src2.isNumber())
  1797. return JSValue::encode(jsNumber(src1.asNumber() * src2.asNumber()));
  1798. CallFrame* callFrame = stackFrame.callFrame;
  1799. JSValue result = jsNumber(src1.toNumber(callFrame) * src2.toNumber(callFrame));
  1800. CHECK_FOR_EXCEPTION_AT_END();
  1801. return JSValue::encode(result);
  1802. }
  1803. DEFINE_STUB_FUNCTION(JSObject*, op_new_func)
  1804. {
  1805. STUB_INIT_STACK_FRAME(stackFrame);
  1806. ASSERT(stackFrame.callFrame->codeBlock()->codeType() != FunctionCode || !stackFrame.callFrame->codeBlock()->needsFullScopeChain() || stackFrame.callFrame->uncheckedR(stackFrame.callFrame->codeBlock()->activationRegister()).jsValue());
  1807. return JSFunction::create(stackFrame.callFrame, stackFrame.args[0].function(), stackFrame.callFrame->scope());
  1808. }
  1809. inline void* jitCompileFor(CallFrame* callFrame, CodeSpecializationKind kind)
  1810. {
  1811. // This function is called by cti_op_call_jitCompile() and
  1812. // cti_op_construct_jitCompile() JIT glue trampolines to compile the
  1813. // callee function that we want to call. Both cti glue trampolines are
  1814. // called by JIT'ed code which has pushed a frame and initialized most of
  1815. // the frame content except for the codeBlock.
  1816. //
  1817. // Normally, the prologue of the callee is supposed to set the frame's cb
  1818. // pointer to the cb of the callee. But in this case, the callee code does
  1819. // not exist yet until it is compiled below. The compilation process will
  1820. // allocate memory which may trigger a GC. The GC, in turn, will scan the
  1821. // JSStack, and will expect the frame's cb to either be valid or 0. If
  1822. // we don't initialize it, the GC will be accessing invalid memory and may
  1823. // crash.
  1824. //
  1825. // Hence, we should nullify it here before proceeding with the compilation.
  1826. callFrame->setCodeBlock(0);
  1827. JSFunction* function = jsCast<JSFunction*>(callFrame->callee());
  1828. ASSERT(!function->isHostFunction());
  1829. FunctionExecutable* executable = function->jsExecutable();
  1830. JSScope* callDataScopeChain = function->scope();
  1831. JSObject* error = executable->compileFor(callFrame, callDataScopeChain, kind);
  1832. if (!error)
  1833. return function;
  1834. callFrame->vm().exception = error;
  1835. return 0;
  1836. }
  1837. DEFINE_STUB_FUNCTION(void*, op_call_jitCompile)
  1838. {
  1839. STUB_INIT_STACK_FRAME(stackFrame);
  1840. #if !ASSERT_DISABLED
  1841. CallData callData;
  1842. ASSERT(stackFrame.callFrame->callee()->methodTable()->getCallData(stackFrame.callFrame->callee(), callData) == CallTypeJS);
  1843. #endif
  1844. CallFrame* callFrame = stackFrame.callFrame;
  1845. void* result = jitCompileFor(callFrame, CodeForCall);
  1846. if (!result)
  1847. return throwExceptionFromOpCall<void*>(stackFrame, callFrame, STUB_RETURN_ADDRESS);
  1848. return result;
  1849. }
  1850. DEFINE_STUB_FUNCTION(void*, op_construct_jitCompile)
  1851. {
  1852. STUB_INIT_STACK_FRAME(stackFrame);
  1853. #if !ASSERT_DISABLED
  1854. ConstructData constructData;
  1855. ASSERT(jsCast<JSFunction*>(stackFrame.callFrame->callee())->methodTable()->getConstructData(stackFrame.callFrame->callee(), constructData) == ConstructTypeJS);
  1856. #endif
  1857. CallFrame* callFrame = stackFrame.callFrame;
  1858. void* result = jitCompileFor(callFrame, CodeForConstruct);
  1859. if (!result)
  1860. return throwExceptionFromOpCall<void*>(stackFrame, callFrame, STUB_RETURN_ADDRESS);
  1861. return result;
  1862. }
  1863. DEFINE_STUB_FUNCTION(void*, op_call_arityCheck)
  1864. {
  1865. STUB_INIT_STACK_FRAME(stackFrame);
  1866. CallFrame* callFrame = stackFrame.callFrame;
  1867. CallFrame* newCallFrame = CommonSlowPaths::arityCheckFor(callFrame, stackFrame.stack, CodeForCall);
  1868. if (!newCallFrame)
  1869. return throwExceptionFromOpCall<void*>(stackFrame, callFrame, STUB_RETURN_ADDRESS, createStackOverflowError(callFrame->callerFrame()));
  1870. return newCallFrame;
  1871. }
  1872. DEFINE_STUB_FUNCTION(void*, op_construct_arityCheck)
  1873. {
  1874. STUB_INIT_STACK_FRAME(stackFrame);
  1875. CallFrame* callFrame = stackFrame.callFrame;
  1876. CallFrame* newCallFrame = CommonSlowPaths::arityCheckFor(callFrame, stackFrame.stack, CodeForConstruct);
  1877. if (!newCallFrame)
  1878. return throwExceptionFromOpCall<void*>(stackFrame, callFrame, STUB_RETURN_ADDRESS, createStackOverflowError(callFrame->callerFrame()));
  1879. return newCallFrame;
  1880. }
  1881. inline void* lazyLinkFor(CallFrame* callFrame, CodeSpecializationKind kind)
  1882. {
  1883. JSFunction* callee = jsCast<JSFunction*>(callFrame->callee());
  1884. ExecutableBase* executable = callee->executable();
  1885. MacroAssemblerCodePtr codePtr;
  1886. CodeBlock* codeBlock = 0;
  1887. CallLinkInfo* callLinkInfo = &callFrame->callerFrame()->codeBlock()->getCallLinkInfo(callFrame->returnPC());
  1888. // This function is called by cti_vm_lazyLinkCall() and
  1889. // cti_lazyLinkConstruct JIT glue trampolines to link the callee function
  1890. // that we want to call. Both cti glue trampolines are called by JIT'ed
  1891. // code which has pushed a frame and initialized most of the frame content
  1892. // except for the codeBlock.
  1893. //
  1894. // Normally, the prologue of the callee is supposed to set the frame's cb
  1895. // field to the cb of the callee. But in this case, the callee may not
  1896. // exist yet, and if not, it will be generated in the compilation below.
  1897. // The compilation will allocate memory which may trigger a GC. The GC, in
  1898. // turn, will scan the JSStack, and will expect the frame's cb to be valid
  1899. // or 0. If we don't initialize it, the GC will be accessing invalid
  1900. // memory and may crash.
  1901. //
  1902. // Hence, we should nullify it here before proceeding with the compilation.
  1903. callFrame->setCodeBlock(0);
  1904. if (executable->isHostFunction())
  1905. codePtr = executable->generatedJITCodeFor(kind).addressForCall();
  1906. else {
  1907. FunctionExecutable* functionExecutable = static_cast<FunctionExecutable*>(executable);
  1908. if (JSObject* error = functionExecutable->compileFor(callFrame, callee->scope(), kind)) {
  1909. callFrame->vm().exception = error;
  1910. return 0;
  1911. }
  1912. codeBlock = &functionExecutable->generatedBytecodeFor(kind);
  1913. if (callFrame->argumentCountIncludingThis() < static_cast<size_t>(codeBlock->numParameters())
  1914. || callLinkInfo->callType == CallLinkInfo::CallVarargs)
  1915. codePtr = functionExecutable->generatedJITCodeWithArityCheckFor(kind);
  1916. else
  1917. codePtr = functionExecutable->generatedJITCodeFor(kind).addressForCall();
  1918. }
  1919. if (!callLinkInfo->seenOnce())
  1920. callLinkInfo->setSeen();
  1921. else
  1922. JIT::linkFor(callee, callFrame->callerFrame()->codeBlock(), codeBlock, codePtr, callLinkInfo, &callFrame->vm(), kind);
  1923. return codePtr.executableAddress();
  1924. }
  1925. DEFINE_STUB_FUNCTION(void*, vm_lazyLinkCall)
  1926. {
  1927. STUB_INIT_STACK_FRAME(stackFrame);
  1928. CallFrame* callFrame = stackFrame.callFrame;
  1929. void* result = lazyLinkFor(callFrame, CodeForCall);
  1930. if (!result)
  1931. return throwExceptionFromOpCall<void*>(stackFrame, callFrame, STUB_RETURN_ADDRESS);
  1932. return result;
  1933. }
  1934. DEFINE_STUB_FUNCTION(void*, vm_lazyLinkClosureCall)
  1935. {
  1936. STUB_INIT_STACK_FRAME(stackFrame);
  1937. CallFrame* callFrame = stackFrame.callFrame;
  1938. CodeBlock* callerCodeBlock = callFrame->callerFrame()->codeBlock();
  1939. VM* vm = callerCodeBlock->vm();
  1940. CallLinkInfo* callLinkInfo = &callerCodeBlock->getCallLinkInfo(callFrame->returnPC());
  1941. JSFunction* callee = jsCast<JSFunction*>(callFrame->callee());
  1942. ExecutableBase* executable = callee->executable();
  1943. Structure* structure = callee->structure();
  1944. ASSERT(callLinkInfo->callType == CallLinkInfo::Call);
  1945. ASSERT(callLinkInfo->isLinked());
  1946. ASSERT(callLinkInfo->callee);
  1947. ASSERT(callee != callLinkInfo->callee.get());
  1948. bool shouldLink = false;
  1949. CodeBlock* calleeCodeBlock = 0;
  1950. MacroAssemblerCodePtr codePtr;
  1951. if (executable == callLinkInfo->callee.get()->executable()
  1952. && structure == callLinkInfo->callee.get()->structure()) {
  1953. shouldLink = true;
  1954. ASSERT(executable->hasJITCodeForCall());
  1955. codePtr = executable->generatedJITCodeForCall().addressForCall();
  1956. if (!callee->executable()->isHostFunction()) {
  1957. calleeCodeBlock = &jsCast<FunctionExecutable*>(executable)->generatedBytecodeForCall();
  1958. if (callFrame->argumentCountIncludingThis() < static_cast<size_t>(calleeCodeBlock->numParameters())) {
  1959. shouldLink = false;
  1960. codePtr = executable->generatedJITCodeWithArityCheckFor(CodeForCall);
  1961. }
  1962. }
  1963. } else if (callee->isHostFunction())
  1964. codePtr = executable->generatedJITCodeForCall().addressForCall();
  1965. else {
  1966. // Need to clear the code block before compilation, because compilation can GC.
  1967. callFrame->setCodeBlock(0);
  1968. FunctionExecutable* functionExecutable = jsCast<FunctionExecutable*>(executable);
  1969. JSScope* scopeChain = callee->scope();
  1970. JSObject* error = functionExecutable->compileFor(callFrame, scopeChain, CodeForCall);
  1971. if (error) {
  1972. callFrame->vm().exception = error;
  1973. return 0;
  1974. }
  1975. codePtr = functionExecutable->generatedJITCodeWithArityCheckFor(CodeForCall);
  1976. }
  1977. if (shouldLink) {
  1978. ASSERT(codePtr);
  1979. JIT::compileClosureCall(vm, callLinkInfo, callerCodeBlock, calleeCodeBlock, structure, executable, codePtr);
  1980. callLinkInfo->hasSeenClosure = true;
  1981. } else
  1982. JIT::linkSlowCall(callerCodeBlock, callLinkInfo);
  1983. return codePtr.executableAddress();
  1984. }
  1985. DEFINE_STUB_FUNCTION(void*, vm_lazyLinkConstruct)
  1986. {
  1987. STUB_INIT_STACK_FRAME(stackFrame);
  1988. CallFrame* callFrame = stackFrame.callFrame;
  1989. void* result = lazyLinkFor(callFrame, CodeForConstruct);
  1990. if (!result)
  1991. return throwExceptionFromOpCall<void*>(stackFrame, callFrame, STUB_RETURN_ADDRESS);
  1992. return result;
  1993. }
  1994. DEFINE_STUB_FUNCTION(JSObject*, op_push_activation)
  1995. {
  1996. STUB_INIT_STACK_FRAME(stackFrame);
  1997. JSActivation* activation = JSActivation::create(stackFrame.callFrame->vm(), stackFrame.callFrame, stackFrame.callFrame->codeBlock());
  1998. stackFrame.callFrame->setScope(activation);
  1999. return activation;
  2000. }
  2001. DEFINE_STUB_FUNCTION(EncodedJSValue, op_call_NotJSFunction)
  2002. {
  2003. STUB_INIT_STACK_FRAME(stackFrame);
  2004. CallFrame* callFrame = stackFrame.callFrame;
  2005. JSValue callee = callFrame->calleeAsValue();
  2006. CallData callData;
  2007. CallType callType = getCallData(callee, callData);
  2008. ASSERT(callType != CallTypeJS);
  2009. if (callType != CallTypeHost) {
  2010. ASSERT(callType == CallTypeNone);
  2011. return throwExceptionFromOpCall<EncodedJSValue>(stackFrame, callFrame, STUB_RETURN_ADDRESS, createNotAFunctionError(callFrame->callerFrame(), callee));
  2012. }
  2013. EncodedJSValue returnValue;
  2014. {
  2015. SamplingTool::CallRecord callRecord(CTI_SAMPLER, true);
  2016. returnValue = callData.native.function(callFrame);
  2017. }
  2018. if (stackFrame.vm->exception)
  2019. return throwExceptionFromOpCall<EncodedJSValue>(stackFrame, callFrame, STUB_RETURN_ADDRESS);
  2020. return returnValue;
  2021. }
  2022. DEFINE_STUB_FUNCTION(EncodedJSValue, op_create_arguments)
  2023. {
  2024. STUB_INIT_STACK_FRAME(stackFrame);
  2025. Arguments* arguments = Arguments::create(*stackFrame.vm, stackFrame.callFrame);
  2026. return JSValue::encode(JSValue(arguments));
  2027. }
  2028. DEFINE_STUB_FUNCTION(void, op_tear_off_activation)
  2029. {
  2030. STUB_INIT_STACK_FRAME(stackFrame);
  2031. ASSERT(stackFrame.callFrame->codeBlock()->needsFullScopeChain());
  2032. jsCast<JSActivation*>(stackFrame.args[0].jsValue())->tearOff(*stackFrame.vm);
  2033. }
  2034. DEFINE_STUB_FUNCTION(void, op_tear_off_arguments)
  2035. {
  2036. STUB_INIT_STACK_FRAME(stackFrame);
  2037. CallFrame* callFrame = stackFrame.callFrame;
  2038. ASSERT(callFrame->codeBlock()->usesArguments());
  2039. Arguments* arguments = jsCast<Arguments*>(stackFrame.args[0].jsValue());
  2040. if (JSValue activationValue = stackFrame.args[1].jsValue()) {
  2041. arguments->didTearOffActivation(callFrame, jsCast<JSActivation*>(activationValue));
  2042. return;
  2043. }
  2044. arguments->tearOff(callFrame);
  2045. }
  2046. DEFINE_STUB_FUNCTION(void, op_profile_will_call)
  2047. {
  2048. STUB_INIT_STACK_FRAME(stackFrame);
  2049. if (LegacyProfiler* profiler = stackFrame.vm->enabledProfiler())
  2050. profiler->willExecute(stackFrame.callFrame, stackFrame.args[0].jsValue());
  2051. }
  2052. DEFINE_STUB_FUNCTION(void, op_profile_did_call)
  2053. {
  2054. STUB_INIT_STACK_FRAME(stackFrame);
  2055. if (LegacyProfiler* profiler = stackFrame.vm->enabledProfiler())
  2056. profiler->didExecute(stackFrame.callFrame, stackFrame.args[0].jsValue());
  2057. }
  2058. DEFINE_STUB_FUNCTION(JSObject*, op_new_array)
  2059. {
  2060. STUB_INIT_STACK_FRAME(stackFrame);
  2061. return constructArray(stackFrame.callFrame, stackFrame.args[2].arrayAllocationProfile(), reinterpret_cast<JSValue*>(&stackFrame.callFrame->registers()[stackFrame.args[0].int32()]), stackFrame.args[1].int32());
  2062. }
  2063. DEFINE_STUB_FUNCTION(JSObject*, op_new_array_with_size)
  2064. {
  2065. STUB_INIT_STACK_FRAME(stackFrame);
  2066. return constructArrayWithSizeQuirk(stackFrame.callFrame, stackFrame.args[1].arrayAllocationProfile(), stackFrame.callFrame->lexicalGlobalObject(), stackFrame.args[0].jsValue());
  2067. }
  2068. DEFINE_STUB_FUNCTION(JSObject*, op_new_array_buffer)
  2069. {
  2070. STUB_INIT_STACK_FRAME(stackFrame);
  2071. return constructArray(stackFrame.callFrame, stackFrame.args[2].arrayAllocationProfile(), stackFrame.callFrame->codeBlock()->constantBuffer(stackFrame.args[0].int32()), stackFrame.args[1].int32());
  2072. }
  2073. DEFINE_STUB_FUNCTION(void, op_init_global_const_check)
  2074. {
  2075. STUB_INIT_STACK_FRAME(stackFrame);
  2076. CallFrame* callFrame = stackFrame.callFrame;
  2077. CodeBlock* codeBlock = callFrame->codeBlock();
  2078. symbolTablePut(codeBlock->globalObject(), callFrame, codeBlock->identifier(stackFrame.args[1].int32()), stackFrame.args[0].jsValue(), true);
  2079. }
  2080. DEFINE_STUB_FUNCTION(EncodedJSValue, op_resolve)
  2081. {
  2082. STUB_INIT_STACK_FRAME(stackFrame);
  2083. CallFrame* callFrame = stackFrame.callFrame;
  2084. JSValue result = JSScope::resolve(callFrame, stackFrame.args[0].identifier(), stackFrame.args[1].resolveOperations());
  2085. CHECK_FOR_EXCEPTION_AT_END();
  2086. return JSValue::encode(result);
  2087. }
  2088. DEFINE_STUB_FUNCTION(void, op_put_to_base)
  2089. {
  2090. STUB_INIT_STACK_FRAME(stackFrame);
  2091. CallFrame* callFrame = stackFrame.callFrame;
  2092. JSValue base = callFrame->r(stackFrame.args[0].int32()).jsValue();
  2093. JSValue value = callFrame->r(stackFrame.args[2].int32()).jsValue();
  2094. JSScope::resolvePut(callFrame, base, stackFrame.args[1].identifier(), value, stackFrame.args[3].putToBaseOperation());
  2095. CHECK_FOR_EXCEPTION_AT_END();
  2096. }
  2097. DEFINE_STUB_FUNCTION(EncodedJSValue, op_construct_NotJSConstruct)
  2098. {
  2099. STUB_INIT_STACK_FRAME(stackFrame);
  2100. CallFrame* callFrame = stackFrame.callFrame;
  2101. JSValue callee = callFrame->calleeAsValue();
  2102. ConstructData constructData;
  2103. ConstructType constructType = getConstructData(callee, constructData);
  2104. ASSERT(constructType != ConstructTypeJS);
  2105. if (constructType != ConstructTypeHost) {
  2106. ASSERT(constructType == ConstructTypeNone);
  2107. return throwExceptionFromOpCall<EncodedJSValue>(stackFrame, callFrame, STUB_RETURN_ADDRESS, createNotAConstructorError(callFrame->callerFrame(), callee));
  2108. }
  2109. EncodedJSValue returnValue;
  2110. {
  2111. SamplingTool::CallRecord callRecord(CTI_SAMPLER, true);
  2112. returnValue = constructData.native.function(callFrame);
  2113. }
  2114. if (stackFrame.vm->exception)
  2115. return throwExceptionFromOpCall<EncodedJSValue>(stackFrame, callFrame, STUB_RETURN_ADDRESS);
  2116. return returnValue;
  2117. }
  2118. static JSValue getByVal(
  2119. CallFrame* callFrame, JSValue baseValue, JSValue subscript, ReturnAddressPtr returnAddress)
  2120. {
  2121. if (LIKELY(baseValue.isCell() && subscript.isString())) {
  2122. if (JSValue result = baseValue.asCell()->fastGetOwnProperty(callFrame, asString(subscript)->value(callFrame)))
  2123. return result;
  2124. }
  2125. if (subscript.isUInt32()) {
  2126. uint32_t i = subscript.asUInt32();
  2127. if (isJSString(baseValue) && asString(baseValue)->canGetIndex(i)) {
  2128. ctiPatchCallByReturnAddress(callFrame->codeBlock(), returnAddress, FunctionPtr(cti_op_get_by_val_string));
  2129. return asString(baseValue)->getIndex(callFrame, i);
  2130. }
  2131. return baseValue.get(callFrame, i);
  2132. }
  2133. if (isName(subscript))
  2134. return baseValue.get(callFrame, jsCast<NameInstance*>(subscript.asCell())->privateName());
  2135. Identifier property(callFrame, subscript.toString(callFrame)->value(callFrame));
  2136. return baseValue.get(callFrame, property);
  2137. }
  2138. DEFINE_STUB_FUNCTION(EncodedJSValue, op_get_by_val)
  2139. {
  2140. STUB_INIT_STACK_FRAME(stackFrame);
  2141. CallFrame* callFrame = stackFrame.callFrame;
  2142. JSValue baseValue = stackFrame.args[0].jsValue();
  2143. JSValue subscript = stackFrame.args[1].jsValue();
  2144. if (baseValue.isObject() && subscript.isInt32()) {
  2145. // See if it's worth optimizing this at all.
  2146. JSObject* object = asObject(baseValue);
  2147. bool didOptimize = false;
  2148. unsigned bytecodeOffset = callFrame->bytecodeOffsetForNonDFGCode();
  2149. ASSERT(bytecodeOffset);
  2150. ByValInfo& byValInfo = callFrame->codeBlock()->getByValInfo(bytecodeOffset - 1);
  2151. ASSERT(!byValInfo.stubRoutine);
  2152. if (hasOptimizableIndexing(object->structure())) {
  2153. // Attempt to optimize.
  2154. JITArrayMode arrayMode = jitArrayModeForStructure(object->structure());
  2155. if (arrayMode != byValInfo.arrayMode) {
  2156. JIT::compileGetByVal(&callFrame->vm(), callFrame->codeBlock(), &byValInfo, STUB_RETURN_ADDRESS, arrayMode);
  2157. didOptimize = true;
  2158. }
  2159. }
  2160. if (!didOptimize) {
  2161. // If we take slow path more than 10 times without patching then make sure we
  2162. // never make that mistake again. Or, if we failed to patch and we have some object
  2163. // that intercepts indexed get, then don't even wait until 10 times. For cases
  2164. // where we see non-index-intercepting objects, this gives 10 iterations worth of
  2165. // opportunity for us to observe that the get_by_val may be polymorphic.
  2166. if (++byValInfo.slowPathCount >= 10
  2167. || object->structure()->typeInfo().interceptsGetOwnPropertySlotByIndexEvenWhenLengthIsNotZero()) {
  2168. // Don't ever try to optimize.
  2169. RepatchBuffer repatchBuffer(callFrame->codeBlock());
  2170. repatchBuffer.relinkCallerToFunction(STUB_RETURN_ADDRESS, FunctionPtr(cti_op_get_by_val_generic));
  2171. }
  2172. }
  2173. }
  2174. JSValue result = getByVal(callFrame, baseValue, subscript, STUB_RETURN_ADDRESS);
  2175. CHECK_FOR_EXCEPTION();
  2176. return JSValue::encode(result);
  2177. }
  2178. DEFINE_STUB_FUNCTION(EncodedJSValue, op_get_by_val_generic)
  2179. {
  2180. STUB_INIT_STACK_FRAME(stackFrame);
  2181. CallFrame* callFrame = stackFrame.callFrame;
  2182. JSValue baseValue = stackFrame.args[0].jsValue();
  2183. JSValue subscript = stackFrame.args[1].jsValue();
  2184. JSValue result = getByVal(callFrame, baseValue, subscript, STUB_RETURN_ADDRESS);
  2185. CHECK_FOR_EXCEPTION();
  2186. return JSValue::encode(result);
  2187. }
  2188. DEFINE_STUB_FUNCTION(EncodedJSValue, op_get_by_val_string)
  2189. {
  2190. STUB_INIT_STACK_FRAME(stackFrame);
  2191. CallFrame* callFrame = stackFrame.callFrame;
  2192. JSValue baseValue = stackFrame.args[0].jsValue();
  2193. JSValue subscript = stackFrame.args[1].jsValue();
  2194. JSValue result;
  2195. if (LIKELY(subscript.isUInt32())) {
  2196. uint32_t i = subscript.asUInt32();
  2197. if (isJSString(baseValue) && asString(baseValue)->canGetIndex(i))
  2198. result = asString(baseValue)->getIndex(callFrame, i);
  2199. else {
  2200. result = baseValue.get(callFrame, i);
  2201. if (!isJSString(baseValue))
  2202. ctiPatchCallByReturnAddress(callFrame->codeBlock(), STUB_RETURN_ADDRESS, FunctionPtr(cti_op_get_by_val));
  2203. }
  2204. } else if (isName(subscript))
  2205. result = baseValue.get(callFrame, jsCast<NameInstance*>(subscript.asCell())->privateName());
  2206. else {
  2207. Identifier property(callFrame, subscript.toString(callFrame)->value(callFrame));
  2208. result = baseValue.get(callFrame, property);
  2209. }
  2210. CHECK_FOR_EXCEPTION_AT_END();
  2211. return JSValue::encode(result);
  2212. }
  2213. DEFINE_STUB_FUNCTION(EncodedJSValue, op_sub)
  2214. {
  2215. STUB_INIT_STACK_FRAME(stackFrame);
  2216. JSValue src1 = stackFrame.args[0].jsValue();
  2217. JSValue src2 = stackFrame.args[1].jsValue();
  2218. if (src1.isNumber() && src2.isNumber())
  2219. return JSValue::encode(jsNumber(src1.asNumber() - src2.asNumber()));
  2220. CallFrame* callFrame = stackFrame.callFrame;
  2221. JSValue result = jsNumber(src1.toNumber(callFrame) - src2.toNumber(callFrame));
  2222. CHECK_FOR_EXCEPTION_AT_END();
  2223. return JSValue::encode(result);
  2224. }
  2225. static void putByVal(CallFrame* callFrame, JSValue baseValue, JSValue subscript, JSValue value)
  2226. {
  2227. if (LIKELY(subscript.isUInt32())) {
  2228. uint32_t i = subscript.asUInt32();
  2229. if (baseValue.isObject()) {
  2230. JSObject* object = asObject(baseValue);
  2231. if (object->canSetIndexQuickly(i))
  2232. object->setIndexQuickly(callFrame->vm(), i, value);
  2233. else
  2234. object->methodTable()->putByIndex(object, callFrame, i, value, callFrame->codeBlock()->isStrictMode());
  2235. } else
  2236. baseValue.putByIndex(callFrame, i, value, callFrame->codeBlock()->isStrictMode());
  2237. } else if (isName(subscript)) {
  2238. PutPropertySlot slot(callFrame->codeBlock()->isStrictMode());
  2239. baseValue.put(callFrame, jsCast<NameInstance*>(subscript.asCell())->privateName(), value, slot);
  2240. } else {
  2241. Identifier property(callFrame, subscript.toString(callFrame)->value(callFrame));
  2242. if (!callFrame->vm().exception) { // Don't put to an object if toString threw an exception.
  2243. PutPropertySlot slot(callFrame->codeBlock()->isStrictMode());
  2244. baseValue.put(callFrame, property, value, slot);
  2245. }
  2246. }
  2247. }
  2248. DEFINE_STUB_FUNCTION(void, op_put_by_val)
  2249. {
  2250. STUB_INIT_STACK_FRAME(stackFrame);
  2251. CallFrame* callFrame = stackFrame.callFrame;
  2252. JSValue baseValue = stackFrame.args[0].jsValue();
  2253. JSValue subscript = stackFrame.args[1].jsValue();
  2254. JSValue value = stackFrame.args[2].jsValue();
  2255. if (baseValue.isObject() && subscript.isInt32()) {
  2256. // See if it's worth optimizing at all.
  2257. JSObject* object = asObject(baseValue);
  2258. bool didOptimize = false;
  2259. unsigned bytecodeOffset = callFrame->bytecodeOffsetForNonDFGCode();
  2260. ASSERT(bytecodeOffset);
  2261. ByValInfo& byValInfo = callFrame->codeBlock()->getByValInfo(bytecodeOffset - 1);
  2262. ASSERT(!byValInfo.stubRoutine);
  2263. if (hasOptimizableIndexing(object->structure())) {
  2264. // Attempt to optimize.
  2265. JITArrayMode arrayMode = jitArrayModeForStructure(object->structure());
  2266. if (arrayMode != byValInfo.arrayMode) {
  2267. JIT::compilePutByVal(&callFrame->vm(), callFrame->codeBlock(), &byValInfo, STUB_RETURN_ADDRESS, arrayMode);
  2268. didOptimize = true;
  2269. }
  2270. }
  2271. if (!didOptimize) {
  2272. // If we take slow path more than 10 times without patching then make sure we
  2273. // never make that mistake again. Or, if we failed to patch and we have some object
  2274. // that intercepts indexed get, then don't even wait until 10 times. For cases
  2275. // where we see non-index-intercepting objects, this gives 10 iterations worth of
  2276. // opportunity for us to observe that the get_by_val may be polymorphic.
  2277. if (++byValInfo.slowPathCount >= 10
  2278. || object->structure()->typeInfo().interceptsGetOwnPropertySlotByIndexEvenWhenLengthIsNotZero()) {
  2279. // Don't ever try to optimize.
  2280. RepatchBuffer repatchBuffer(callFrame->codeBlock());
  2281. repatchBuffer.relinkCallerToFunction(STUB_RETURN_ADDRESS, FunctionPtr(cti_op_put_by_val_generic));
  2282. }
  2283. }
  2284. }
  2285. putByVal(callFrame, baseValue, subscript, value);
  2286. CHECK_FOR_EXCEPTION_AT_END();
  2287. }
  2288. DEFINE_STUB_FUNCTION(void, op_put_by_val_generic)
  2289. {
  2290. STUB_INIT_STACK_FRAME(stackFrame);
  2291. CallFrame* callFrame = stackFrame.callFrame;
  2292. JSValue baseValue = stackFrame.args[0].jsValue();
  2293. JSValue subscript = stackFrame.args[1].jsValue();
  2294. JSValue value = stackFrame.args[2].jsValue();
  2295. putByVal(callFrame, baseValue, subscript, value);
  2296. CHECK_FOR_EXCEPTION_AT_END();
  2297. }
  2298. DEFINE_STUB_FUNCTION(EncodedJSValue, op_less)
  2299. {
  2300. STUB_INIT_STACK_FRAME(stackFrame);
  2301. CallFrame* callFrame = stackFrame.callFrame;
  2302. JSValue result = jsBoolean(jsLess<true>(callFrame, stackFrame.args[0].jsValue(), stackFrame.args[1].jsValue()));
  2303. CHECK_FOR_EXCEPTION_AT_END();
  2304. return JSValue::encode(result);
  2305. }
  2306. DEFINE_STUB_FUNCTION(EncodedJSValue, op_lesseq)
  2307. {
  2308. STUB_INIT_STACK_FRAME(stackFrame);
  2309. CallFrame* callFrame = stackFrame.callFrame;
  2310. JSValue result = jsBoolean(jsLessEq<true>(callFrame, stackFrame.args[0].jsValue(), stackFrame.args[1].jsValue()));
  2311. CHECK_FOR_EXCEPTION_AT_END();
  2312. return JSValue::encode(result);
  2313. }
  2314. DEFINE_STUB_FUNCTION(EncodedJSValue, op_greater)
  2315. {
  2316. STUB_INIT_STACK_FRAME(stackFrame);
  2317. CallFrame* callFrame = stackFrame.callFrame;
  2318. JSValue result = jsBoolean(jsLess<false>(callFrame, stackFrame.args[1].jsValue(), stackFrame.args[0].jsValue()));
  2319. CHECK_FOR_EXCEPTION_AT_END();
  2320. return JSValue::encode(result);
  2321. }
  2322. DEFINE_STUB_FUNCTION(EncodedJSValue, op_greatereq)
  2323. {
  2324. STUB_INIT_STACK_FRAME(stackFrame);
  2325. CallFrame* callFrame = stackFrame.callFrame;
  2326. JSValue result = jsBoolean(jsLessEq<false>(callFrame, stackFrame.args[1].jsValue(), stackFrame.args[0].jsValue()));
  2327. CHECK_FOR_EXCEPTION_AT_END();
  2328. return JSValue::encode(result);
  2329. }
  2330. DEFINE_STUB_FUNCTION(void*, op_load_varargs)
  2331. {
  2332. STUB_INIT_STACK_FRAME(stackFrame);
  2333. CallFrame* callFrame = stackFrame.callFrame;
  2334. JSStack* stack = stackFrame.stack;
  2335. JSValue thisValue = stackFrame.args[0].jsValue();
  2336. JSValue arguments = stackFrame.args[1].jsValue();
  2337. int firstFreeRegister = stackFrame.args[2].int32();
  2338. CallFrame* newCallFrame = loadVarargs(callFrame, stack, thisValue, arguments, firstFreeRegister);
  2339. if (!newCallFrame)
  2340. VM_THROW_EXCEPTION();
  2341. return newCallFrame;
  2342. }
  2343. DEFINE_STUB_FUNCTION(EncodedJSValue, op_negate)
  2344. {
  2345. STUB_INIT_STACK_FRAME(stackFrame);
  2346. JSValue src = stackFrame.args[0].jsValue();
  2347. if (src.isNumber())
  2348. return JSValue::encode(jsNumber(-src.asNumber()));
  2349. CallFrame* callFrame = stackFrame.callFrame;
  2350. JSValue result = jsNumber(-src.toNumber(callFrame));
  2351. CHECK_FOR_EXCEPTION_AT_END();
  2352. return JSValue::encode(result);
  2353. }
  2354. DEFINE_STUB_FUNCTION(EncodedJSValue, op_resolve_base)
  2355. {
  2356. STUB_INIT_STACK_FRAME(stackFrame);
  2357. return JSValue::encode(JSScope::resolveBase(stackFrame.callFrame, stackFrame.args[0].identifier(), false, stackFrame.args[1].resolveOperations(), stackFrame.args[2].putToBaseOperation()));
  2358. }
  2359. DEFINE_STUB_FUNCTION(EncodedJSValue, op_resolve_base_strict_put)
  2360. {
  2361. STUB_INIT_STACK_FRAME(stackFrame);
  2362. if (JSValue result = JSScope::resolveBase(stackFrame.callFrame, stackFrame.args[0].identifier(), true, stackFrame.args[1].resolveOperations(), stackFrame.args[2].putToBaseOperation()))
  2363. return JSValue::encode(result);
  2364. VM_THROW_EXCEPTION();
  2365. }
  2366. DEFINE_STUB_FUNCTION(EncodedJSValue, op_div)
  2367. {
  2368. STUB_INIT_STACK_FRAME(stackFrame);
  2369. JSValue src1 = stackFrame.args[0].jsValue();
  2370. JSValue src2 = stackFrame.args[1].jsValue();
  2371. if (src1.isNumber() && src2.isNumber())
  2372. return JSValue::encode(jsNumber(src1.asNumber() / src2.asNumber()));
  2373. CallFrame* callFrame = stackFrame.callFrame;
  2374. JSValue result = jsNumber(src1.toNumber(callFrame) / src2.toNumber(callFrame));
  2375. CHECK_FOR_EXCEPTION_AT_END();
  2376. return JSValue::encode(result);
  2377. }
  2378. DEFINE_STUB_FUNCTION(EncodedJSValue, op_dec)
  2379. {
  2380. STUB_INIT_STACK_FRAME(stackFrame);
  2381. JSValue v = stackFrame.args[0].jsValue();
  2382. CallFrame* callFrame = stackFrame.callFrame;
  2383. JSValue result = jsNumber(v.toNumber(callFrame) - 1);
  2384. CHECK_FOR_EXCEPTION_AT_END();
  2385. return JSValue::encode(result);
  2386. }
  2387. DEFINE_STUB_FUNCTION(int, op_jless)
  2388. {
  2389. STUB_INIT_STACK_FRAME(stackFrame);
  2390. JSValue src1 = stackFrame.args[0].jsValue();
  2391. JSValue src2 = stackFrame.args[1].jsValue();
  2392. CallFrame* callFrame = stackFrame.callFrame;
  2393. bool result = jsLess<true>(callFrame, src1, src2);
  2394. CHECK_FOR_EXCEPTION_AT_END();
  2395. return result;
  2396. }
  2397. DEFINE_STUB_FUNCTION(int, op_jlesseq)
  2398. {
  2399. STUB_INIT_STACK_FRAME(stackFrame);
  2400. JSValue src1 = stackFrame.args[0].jsValue();
  2401. JSValue src2 = stackFrame.args[1].jsValue();
  2402. CallFrame* callFrame = stackFrame.callFrame;
  2403. bool result = jsLessEq<true>(callFrame, src1, src2);
  2404. CHECK_FOR_EXCEPTION_AT_END();
  2405. return result;
  2406. }
  2407. DEFINE_STUB_FUNCTION(int, op_jgreater)
  2408. {
  2409. STUB_INIT_STACK_FRAME(stackFrame);
  2410. JSValue src1 = stackFrame.args[0].jsValue();
  2411. JSValue src2 = stackFrame.args[1].jsValue();
  2412. CallFrame* callFrame = stackFrame.callFrame;
  2413. bool result = jsLess<false>(callFrame, src2, src1);
  2414. CHECK_FOR_EXCEPTION_AT_END();
  2415. return result;
  2416. }
  2417. DEFINE_STUB_FUNCTION(int, op_jgreatereq)
  2418. {
  2419. STUB_INIT_STACK_FRAME(stackFrame);
  2420. JSValue src1 = stackFrame.args[0].jsValue();
  2421. JSValue src2 = stackFrame.args[1].jsValue();
  2422. CallFrame* callFrame = stackFrame.callFrame;
  2423. bool result = jsLessEq<false>(callFrame, src2, src1);
  2424. CHECK_FOR_EXCEPTION_AT_END();
  2425. return result;
  2426. }
  2427. DEFINE_STUB_FUNCTION(EncodedJSValue, op_not)
  2428. {
  2429. STUB_INIT_STACK_FRAME(stackFrame);
  2430. JSValue src = stackFrame.args[0].jsValue();
  2431. JSValue result = jsBoolean(!src.toBoolean(stackFrame.callFrame));
  2432. CHECK_FOR_EXCEPTION_AT_END();
  2433. return JSValue::encode(result);
  2434. }
  2435. DEFINE_STUB_FUNCTION(int, op_jtrue)
  2436. {
  2437. STUB_INIT_STACK_FRAME(stackFrame);
  2438. JSValue src1 = stackFrame.args[0].jsValue();
  2439. bool result = src1.toBoolean(stackFrame.callFrame);
  2440. CHECK_FOR_EXCEPTION_AT_END();
  2441. return result;
  2442. }
  2443. DEFINE_STUB_FUNCTION(int, op_eq)
  2444. {
  2445. STUB_INIT_STACK_FRAME(stackFrame);
  2446. JSValue src1 = stackFrame.args[0].jsValue();
  2447. JSValue src2 = stackFrame.args[1].jsValue();
  2448. #if USE(JSVALUE32_64)
  2449. start:
  2450. if (src2.isUndefined()) {
  2451. return src1.isNull() ||
  2452. (src1.isCell() && src1.asCell()->structure()->masqueradesAsUndefined(stackFrame.callFrame->lexicalGlobalObject()))
  2453. || src1.isUndefined();
  2454. }
  2455. if (src2.isNull()) {
  2456. return src1.isUndefined() ||
  2457. (src1.isCell() && src1.asCell()->structure()->masqueradesAsUndefined(stackFrame.callFrame->lexicalGlobalObject()))
  2458. || src1.isNull();
  2459. }
  2460. if (src1.isInt32()) {
  2461. if (src2.isDouble())
  2462. return src1.asInt32() == src2.asDouble();
  2463. double d = src2.toNumber(stackFrame.callFrame);
  2464. CHECK_FOR_EXCEPTION();
  2465. return src1.asInt32() == d;
  2466. }
  2467. if (src1.isDouble()) {
  2468. if (src2.isInt32())
  2469. return src1.asDouble() == src2.asInt32();
  2470. double d = src2.toNumber(stackFrame.callFrame);
  2471. CHECK_FOR_EXCEPTION();
  2472. return src1.asDouble() == d;
  2473. }
  2474. if (src1.isTrue()) {
  2475. if (src2.isFalse())
  2476. return false;
  2477. double d = src2.toNumber(stackFrame.callFrame);
  2478. CHECK_FOR_EXCEPTION();
  2479. return d == 1.0;
  2480. }
  2481. if (src1.isFalse()) {
  2482. if (src2.isTrue())
  2483. return false;
  2484. double d = src2.toNumber(stackFrame.callFrame);
  2485. CHECK_FOR_EXCEPTION();
  2486. return d == 0.0;
  2487. }
  2488. if (src1.isUndefined())
  2489. return src2.isCell() && src2.asCell()->structure()->masqueradesAsUndefined(stackFrame.callFrame->lexicalGlobalObject());
  2490. if (src1.isNull())
  2491. return src2.isCell() && src2.asCell()->structure()->masqueradesAsUndefined(stackFrame.callFrame->lexicalGlobalObject());
  2492. JSCell* cell1 = src1.asCell();
  2493. if (cell1->isString()) {
  2494. if (src2.isInt32())
  2495. return jsToNumber(jsCast<JSString*>(cell1)->value(stackFrame.callFrame)) == src2.asInt32();
  2496. if (src2.isDouble())
  2497. return jsToNumber(jsCast<JSString*>(cell1)->value(stackFrame.callFrame)) == src2.asDouble();
  2498. if (src2.isTrue())
  2499. return jsToNumber(jsCast<JSString*>(cell1)->value(stackFrame.callFrame)) == 1.0;
  2500. if (src2.isFalse())
  2501. return jsToNumber(jsCast<JSString*>(cell1)->value(stackFrame.callFrame)) == 0.0;
  2502. JSCell* cell2 = src2.asCell();
  2503. if (cell2->isString())
  2504. return jsCast<JSString*>(cell1)->value(stackFrame.callFrame) == jsCast<JSString*>(cell2)->value(stackFrame.callFrame);
  2505. src2 = asObject(cell2)->toPrimitive(stackFrame.callFrame);
  2506. CHECK_FOR_EXCEPTION();
  2507. goto start;
  2508. }
  2509. if (src2.isObject())
  2510. return asObject(cell1) == asObject(src2);
  2511. src1 = asObject(cell1)->toPrimitive(stackFrame.callFrame);
  2512. CHECK_FOR_EXCEPTION();
  2513. goto start;
  2514. #else // USE(JSVALUE32_64)
  2515. CallFrame* callFrame = stackFrame.callFrame;
  2516. bool result = JSValue::equalSlowCaseInline(callFrame, src1, src2);
  2517. CHECK_FOR_EXCEPTION_AT_END();
  2518. return result;
  2519. #endif // USE(JSVALUE32_64)
  2520. }
  2521. DEFINE_STUB_FUNCTION(int, op_eq_strings)
  2522. {
  2523. #if USE(JSVALUE32_64)
  2524. STUB_INIT_STACK_FRAME(stackFrame);
  2525. JSString* string1 = stackFrame.args[0].jsString();
  2526. JSString* string2 = stackFrame.args[1].jsString();
  2527. ASSERT(string1->isString());
  2528. ASSERT(string2->isString());
  2529. return string1->value(stackFrame.callFrame) == string2->value(stackFrame.callFrame);
  2530. #else
  2531. UNUSED_PARAM(args);
  2532. RELEASE_ASSERT_NOT_REACHED();
  2533. return 0;
  2534. #endif
  2535. }
  2536. DEFINE_STUB_FUNCTION(EncodedJSValue, op_lshift)
  2537. {
  2538. STUB_INIT_STACK_FRAME(stackFrame);
  2539. JSValue val = stackFrame.args[0].jsValue();
  2540. JSValue shift = stackFrame.args[1].jsValue();
  2541. CallFrame* callFrame = stackFrame.callFrame;
  2542. JSValue result = jsNumber((val.toInt32(callFrame)) << (shift.toUInt32(callFrame) & 0x1f));
  2543. CHECK_FOR_EXCEPTION_AT_END();
  2544. return JSValue::encode(result);
  2545. }
  2546. DEFINE_STUB_FUNCTION(EncodedJSValue, op_bitand)
  2547. {
  2548. STUB_INIT_STACK_FRAME(stackFrame);
  2549. JSValue src1 = stackFrame.args[0].jsValue();
  2550. JSValue src2 = stackFrame.args[1].jsValue();
  2551. ASSERT(!src1.isInt32() || !src2.isInt32());
  2552. CallFrame* callFrame = stackFrame.callFrame;
  2553. JSValue result = jsNumber(src1.toInt32(callFrame) & src2.toInt32(callFrame));
  2554. CHECK_FOR_EXCEPTION_AT_END();
  2555. return JSValue::encode(result);
  2556. }
  2557. DEFINE_STUB_FUNCTION(EncodedJSValue, op_rshift)
  2558. {
  2559. STUB_INIT_STACK_FRAME(stackFrame);
  2560. JSValue val = stackFrame.args[0].jsValue();
  2561. JSValue shift = stackFrame.args[1].jsValue();
  2562. CallFrame* callFrame = stackFrame.callFrame;
  2563. JSValue result = jsNumber((val.toInt32(callFrame)) >> (shift.toUInt32(callFrame) & 0x1f));
  2564. CHECK_FOR_EXCEPTION_AT_END();
  2565. return JSValue::encode(result);
  2566. }
  2567. DEFINE_STUB_FUNCTION(EncodedJSValue, op_resolve_with_base)
  2568. {
  2569. STUB_INIT_STACK_FRAME(stackFrame);
  2570. CallFrame* callFrame = stackFrame.callFrame;
  2571. JSValue result = JSScope::resolveWithBase(callFrame, stackFrame.args[0].identifier(), &callFrame->registers()[stackFrame.args[1].int32()], stackFrame.args[2].resolveOperations(), stackFrame.args[3].putToBaseOperation());
  2572. CHECK_FOR_EXCEPTION_AT_END();
  2573. return JSValue::encode(result);
  2574. }
  2575. DEFINE_STUB_FUNCTION(EncodedJSValue, op_resolve_with_this)
  2576. {
  2577. STUB_INIT_STACK_FRAME(stackFrame);
  2578. CallFrame* callFrame = stackFrame.callFrame;
  2579. JSValue result = JSScope::resolveWithThis(callFrame, stackFrame.args[0].identifier(), &callFrame->registers()[stackFrame.args[1].int32()], stackFrame.args[2].resolveOperations());
  2580. CHECK_FOR_EXCEPTION_AT_END();
  2581. return JSValue::encode(result);
  2582. }
  2583. DEFINE_STUB_FUNCTION(JSObject*, op_new_func_exp)
  2584. {
  2585. STUB_INIT_STACK_FRAME(stackFrame);
  2586. CallFrame* callFrame = stackFrame.callFrame;
  2587. FunctionExecutable* function = stackFrame.args[0].function();
  2588. JSFunction* func = JSFunction::create(callFrame, function, callFrame->scope());
  2589. ASSERT(callFrame->codeBlock()->codeType() != FunctionCode || !callFrame->codeBlock()->needsFullScopeChain() || callFrame->uncheckedR(callFrame->codeBlock()->activationRegister()).jsValue());
  2590. return func;
  2591. }
  2592. DEFINE_STUB_FUNCTION(EncodedJSValue, op_mod)
  2593. {
  2594. STUB_INIT_STACK_FRAME(stackFrame);
  2595. JSValue dividendValue = stackFrame.args[0].jsValue();
  2596. JSValue divisorValue = stackFrame.args[1].jsValue();
  2597. CallFrame* callFrame = stackFrame.callFrame;
  2598. double d = dividendValue.toNumber(callFrame);
  2599. JSValue result = jsNumber(fmod(d, divisorValue.toNumber(callFrame)));
  2600. CHECK_FOR_EXCEPTION_AT_END();
  2601. return JSValue::encode(result);
  2602. }
  2603. DEFINE_STUB_FUNCTION(EncodedJSValue, op_urshift)
  2604. {
  2605. STUB_INIT_STACK_FRAME(stackFrame);
  2606. JSValue val = stackFrame.args[0].jsValue();
  2607. JSValue shift = stackFrame.args[1].jsValue();
  2608. CallFrame* callFrame = stackFrame.callFrame;
  2609. JSValue result = jsNumber((val.toUInt32(callFrame)) >> (shift.toUInt32(callFrame) & 0x1f));
  2610. CHECK_FOR_EXCEPTION_AT_END();
  2611. return JSValue::encode(result);
  2612. }
  2613. DEFINE_STUB_FUNCTION(EncodedJSValue, op_bitxor)
  2614. {
  2615. STUB_INIT_STACK_FRAME(stackFrame);
  2616. JSValue src1 = stackFrame.args[0].jsValue();
  2617. JSValue src2 = stackFrame.args[1].jsValue();
  2618. CallFrame* callFrame = stackFrame.callFrame;
  2619. JSValue result = jsNumber(src1.toInt32(callFrame) ^ src2.toInt32(callFrame));
  2620. CHECK_FOR_EXCEPTION_AT_END();
  2621. return JSValue::encode(result);
  2622. }
  2623. DEFINE_STUB_FUNCTION(JSObject*, op_new_regexp)
  2624. {
  2625. STUB_INIT_STACK_FRAME(stackFrame);
  2626. CallFrame* callFrame = stackFrame.callFrame;
  2627. RegExp* regExp = stackFrame.args[0].regExp();
  2628. if (!regExp->isValid()) {
  2629. stackFrame.vm->exception = createSyntaxError(callFrame, "Invalid flags supplied to RegExp constructor.");
  2630. VM_THROW_EXCEPTION();
  2631. }
  2632. return RegExpObject::create(*stackFrame.vm, stackFrame.callFrame->lexicalGlobalObject(), stackFrame.callFrame->lexicalGlobalObject()->regExpStructure(), regExp);
  2633. }
  2634. DEFINE_STUB_FUNCTION(EncodedJSValue, op_bitor)
  2635. {
  2636. STUB_INIT_STACK_FRAME(stackFrame);
  2637. JSValue src1 = stackFrame.args[0].jsValue();
  2638. JSValue src2 = stackFrame.args[1].jsValue();
  2639. CallFrame* callFrame = stackFrame.callFrame;
  2640. JSValue result = jsNumber(src1.toInt32(callFrame) | src2.toInt32(callFrame));
  2641. CHECK_FOR_EXCEPTION_AT_END();
  2642. return JSValue::encode(result);
  2643. }
  2644. DEFINE_STUB_FUNCTION(EncodedJSValue, op_call_eval)
  2645. {
  2646. STUB_INIT_STACK_FRAME(stackFrame);
  2647. CallFrame* callFrame = stackFrame.callFrame;
  2648. CallFrame* callerFrame = callFrame->callerFrame();
  2649. ASSERT(callFrame->callerFrame()->codeBlock()->codeType() != FunctionCode
  2650. || !callFrame->callerFrame()->codeBlock()->needsFullScopeChain()
  2651. || callFrame->callerFrame()->uncheckedR(callFrame->callerFrame()->codeBlock()->activationRegister()).jsValue());
  2652. callFrame->setScope(callerFrame->scope());
  2653. callFrame->setReturnPC(static_cast<Instruction*>((STUB_RETURN_ADDRESS).value()));
  2654. callFrame->setCodeBlock(0);
  2655. if (!isHostFunction(callFrame->calleeAsValue(), globalFuncEval))
  2656. return JSValue::encode(JSValue());
  2657. JSValue result = eval(callFrame);
  2658. if (stackFrame.vm->exception)
  2659. return throwExceptionFromOpCall<EncodedJSValue>(stackFrame, callFrame, STUB_RETURN_ADDRESS);
  2660. return JSValue::encode(result);
  2661. }
  2662. DEFINE_STUB_FUNCTION(void*, op_throw)
  2663. {
  2664. STUB_INIT_STACK_FRAME(stackFrame);
  2665. ExceptionHandler handler = jitThrow(stackFrame.vm, stackFrame.callFrame, stackFrame.args[0].jsValue(), STUB_RETURN_ADDRESS);
  2666. STUB_SET_RETURN_ADDRESS(handler.catchRoutine);
  2667. return handler.callFrame;
  2668. }
  2669. DEFINE_STUB_FUNCTION(JSPropertyNameIterator*, op_get_pnames)
  2670. {
  2671. STUB_INIT_STACK_FRAME(stackFrame);
  2672. CallFrame* callFrame = stackFrame.callFrame;
  2673. JSObject* o = stackFrame.args[0].jsObject();
  2674. Structure* structure = o->structure();
  2675. JSPropertyNameIterator* jsPropertyNameIterator = structure->enumerationCache();
  2676. if (!jsPropertyNameIterator || jsPropertyNameIterator->cachedPrototypeChain() != structure->prototypeChain(callFrame))
  2677. jsPropertyNameIterator = JSPropertyNameIterator::create(callFrame, o);
  2678. return jsPropertyNameIterator;
  2679. }
  2680. DEFINE_STUB_FUNCTION(int, has_property)
  2681. {
  2682. STUB_INIT_STACK_FRAME(stackFrame);
  2683. JSObject* base = stackFrame.args[0].jsObject();
  2684. JSString* property = stackFrame.args[1].jsString();
  2685. int result = base->hasProperty(stackFrame.callFrame, Identifier(stackFrame.callFrame, property->value(stackFrame.callFrame)));
  2686. CHECK_FOR_EXCEPTION_AT_END();
  2687. return result;
  2688. }
  2689. DEFINE_STUB_FUNCTION(void, op_push_with_scope)
  2690. {
  2691. STUB_INIT_STACK_FRAME(stackFrame);
  2692. JSObject* o = stackFrame.args[0].jsValue().toObject(stackFrame.callFrame);
  2693. CHECK_FOR_EXCEPTION_VOID();
  2694. stackFrame.callFrame->setScope(JSWithScope::create(stackFrame.callFrame, o));
  2695. }
  2696. DEFINE_STUB_FUNCTION(void, op_pop_scope)
  2697. {
  2698. STUB_INIT_STACK_FRAME(stackFrame);
  2699. stackFrame.callFrame->setScope(stackFrame.callFrame->scope()->next());
  2700. }
  2701. DEFINE_STUB_FUNCTION(EncodedJSValue, op_typeof)
  2702. {
  2703. STUB_INIT_STACK_FRAME(stackFrame);
  2704. return JSValue::encode(jsTypeStringForValue(stackFrame.callFrame, stackFrame.args[0].jsValue()));
  2705. }
  2706. DEFINE_STUB_FUNCTION(EncodedJSValue, op_is_object)
  2707. {
  2708. STUB_INIT_STACK_FRAME(stackFrame);
  2709. return JSValue::encode(jsBoolean(jsIsObjectType(stackFrame.callFrame, stackFrame.args[0].jsValue())));
  2710. }
  2711. DEFINE_STUB_FUNCTION(EncodedJSValue, op_is_function)
  2712. {
  2713. STUB_INIT_STACK_FRAME(stackFrame);
  2714. return JSValue::encode(jsBoolean(jsIsFunctionType(stackFrame.args[0].jsValue())));
  2715. }
  2716. DEFINE_STUB_FUNCTION(EncodedJSValue, op_stricteq)
  2717. {
  2718. STUB_INIT_STACK_FRAME(stackFrame);
  2719. JSValue src1 = stackFrame.args[0].jsValue();
  2720. JSValue src2 = stackFrame.args[1].jsValue();
  2721. bool result = JSValue::strictEqual(stackFrame.callFrame, src1, src2);
  2722. CHECK_FOR_EXCEPTION_AT_END();
  2723. return JSValue::encode(jsBoolean(result));
  2724. }
  2725. DEFINE_STUB_FUNCTION(EncodedJSValue, op_to_primitive)
  2726. {
  2727. STUB_INIT_STACK_FRAME(stackFrame);
  2728. return JSValue::encode(stackFrame.args[0].jsValue().toPrimitive(stackFrame.callFrame));
  2729. }
  2730. DEFINE_STUB_FUNCTION(EncodedJSValue, op_strcat)
  2731. {
  2732. STUB_INIT_STACK_FRAME(stackFrame);
  2733. JSValue result = jsString(stackFrame.callFrame, &stackFrame.callFrame->registers()[stackFrame.args[0].int32()], stackFrame.args[1].int32());
  2734. CHECK_FOR_EXCEPTION_AT_END();
  2735. return JSValue::encode(result);
  2736. }
  2737. DEFINE_STUB_FUNCTION(EncodedJSValue, op_nstricteq)
  2738. {
  2739. STUB_INIT_STACK_FRAME(stackFrame);
  2740. JSValue src1 = stackFrame.args[0].jsValue();
  2741. JSValue src2 = stackFrame.args[1].jsValue();
  2742. bool result = !JSValue::strictEqual(stackFrame.callFrame, src1, src2);
  2743. CHECK_FOR_EXCEPTION_AT_END();
  2744. return JSValue::encode(jsBoolean(result));
  2745. }
  2746. DEFINE_STUB_FUNCTION(EncodedJSValue, op_to_number)
  2747. {
  2748. STUB_INIT_STACK_FRAME(stackFrame);
  2749. JSValue src = stackFrame.args[0].jsValue();
  2750. CallFrame* callFrame = stackFrame.callFrame;
  2751. double number = src.toNumber(callFrame);
  2752. CHECK_FOR_EXCEPTION_AT_END();
  2753. return JSValue::encode(jsNumber(number));
  2754. }
  2755. DEFINE_STUB_FUNCTION(EncodedJSValue, op_in)
  2756. {
  2757. STUB_INIT_STACK_FRAME(stackFrame);
  2758. CallFrame* callFrame = stackFrame.callFrame;
  2759. JSValue baseVal = stackFrame.args[1].jsValue();
  2760. if (!baseVal.isObject()) {
  2761. stackFrame.vm->exception = createInvalidParamError(stackFrame.callFrame, "in", baseVal);
  2762. VM_THROW_EXCEPTION();
  2763. }
  2764. JSValue propName = stackFrame.args[0].jsValue();
  2765. JSObject* baseObj = asObject(baseVal);
  2766. uint32_t i;
  2767. if (propName.getUInt32(i))
  2768. return JSValue::encode(jsBoolean(baseObj->hasProperty(callFrame, i)));
  2769. if (isName(propName))
  2770. return JSValue::encode(jsBoolean(baseObj->hasProperty(callFrame, jsCast<NameInstance*>(propName.asCell())->privateName())));
  2771. Identifier property(callFrame, propName.toString(callFrame)->value(callFrame));
  2772. CHECK_FOR_EXCEPTION();
  2773. return JSValue::encode(jsBoolean(baseObj->hasProperty(callFrame, property)));
  2774. }
  2775. DEFINE_STUB_FUNCTION(void, op_push_name_scope)
  2776. {
  2777. STUB_INIT_STACK_FRAME(stackFrame);
  2778. JSNameScope* scope = JSNameScope::create(stackFrame.callFrame, stackFrame.args[0].identifier(), stackFrame.args[1].jsValue(), stackFrame.args[2].int32());
  2779. CallFrame* callFrame = stackFrame.callFrame;
  2780. callFrame->setScope(scope);
  2781. }
  2782. DEFINE_STUB_FUNCTION(void, op_put_by_index)
  2783. {
  2784. STUB_INIT_STACK_FRAME(stackFrame);
  2785. CallFrame* callFrame = stackFrame.callFrame;
  2786. unsigned property = stackFrame.args[1].int32();
  2787. JSValue arrayValue = stackFrame.args[0].jsValue();
  2788. ASSERT(isJSArray(arrayValue));
  2789. asArray(arrayValue)->putDirectIndex(callFrame, property, stackFrame.args[2].jsValue());
  2790. }
  2791. DEFINE_STUB_FUNCTION(void*, op_switch_imm)
  2792. {
  2793. STUB_INIT_STACK_FRAME(stackFrame);
  2794. JSValue scrutinee = stackFrame.args[0].jsValue();
  2795. unsigned tableIndex = stackFrame.args[1].int32();
  2796. CallFrame* callFrame = stackFrame.callFrame;
  2797. CodeBlock* codeBlock = callFrame->codeBlock();
  2798. if (scrutinee.isInt32())
  2799. return codeBlock->immediateSwitchJumpTable(tableIndex).ctiForValue(scrutinee.asInt32()).executableAddress();
  2800. if (scrutinee.isDouble() && scrutinee.asDouble() == static_cast<int32_t>(scrutinee.asDouble()))
  2801. return codeBlock->immediateSwitchJumpTable(tableIndex).ctiForValue(static_cast<int32_t>(scrutinee.asDouble())).executableAddress();
  2802. return codeBlock->immediateSwitchJumpTable(tableIndex).ctiDefault.executableAddress();
  2803. }
  2804. DEFINE_STUB_FUNCTION(void*, op_switch_char)
  2805. {
  2806. STUB_INIT_STACK_FRAME(stackFrame);
  2807. JSValue scrutinee = stackFrame.args[0].jsValue();
  2808. unsigned tableIndex = stackFrame.args[1].int32();
  2809. CallFrame* callFrame = stackFrame.callFrame;
  2810. CodeBlock* codeBlock = callFrame->codeBlock();
  2811. void* result = codeBlock->characterSwitchJumpTable(tableIndex).ctiDefault.executableAddress();
  2812. if (scrutinee.isString()) {
  2813. StringImpl* value = asString(scrutinee)->value(callFrame).impl();
  2814. if (value->length() == 1)
  2815. result = codeBlock->characterSwitchJumpTable(tableIndex).ctiForValue((*value)[0]).executableAddress();
  2816. }
  2817. CHECK_FOR_EXCEPTION_AT_END();
  2818. return result;
  2819. }
  2820. DEFINE_STUB_FUNCTION(void*, op_switch_string)
  2821. {
  2822. STUB_INIT_STACK_FRAME(stackFrame);
  2823. JSValue scrutinee = stackFrame.args[0].jsValue();
  2824. unsigned tableIndex = stackFrame.args[1].int32();
  2825. CallFrame* callFrame = stackFrame.callFrame;
  2826. CodeBlock* codeBlock = callFrame->codeBlock();
  2827. void* result = codeBlock->stringSwitchJumpTable(tableIndex).ctiDefault.executableAddress();
  2828. if (scrutinee.isString()) {
  2829. StringImpl* value = asString(scrutinee)->value(callFrame).impl();
  2830. result = codeBlock->stringSwitchJumpTable(tableIndex).ctiForValue(value).executableAddress();
  2831. }
  2832. CHECK_FOR_EXCEPTION_AT_END();
  2833. return result;
  2834. }
  2835. DEFINE_STUB_FUNCTION(EncodedJSValue, op_del_by_val)
  2836. {
  2837. STUB_INIT_STACK_FRAME(stackFrame);
  2838. CallFrame* callFrame = stackFrame.callFrame;
  2839. JSValue baseValue = stackFrame.args[0].jsValue();
  2840. JSObject* baseObj = baseValue.toObject(callFrame); // may throw
  2841. JSValue subscript = stackFrame.args[1].jsValue();
  2842. bool result;
  2843. uint32_t i;
  2844. if (subscript.getUInt32(i))
  2845. result = baseObj->methodTable()->deletePropertyByIndex(baseObj, callFrame, i);
  2846. else if (isName(subscript))
  2847. result = baseObj->methodTable()->deleteProperty(baseObj, callFrame, jsCast<NameInstance*>(subscript.asCell())->privateName());
  2848. else {
  2849. CHECK_FOR_EXCEPTION();
  2850. Identifier property(callFrame, subscript.toString(callFrame)->value(callFrame));
  2851. CHECK_FOR_EXCEPTION();
  2852. result = baseObj->methodTable()->deleteProperty(baseObj, callFrame, property);
  2853. }
  2854. if (!result && callFrame->codeBlock()->isStrictMode())
  2855. stackFrame.vm->exception = createTypeError(stackFrame.callFrame, "Unable to delete property.");
  2856. CHECK_FOR_EXCEPTION_AT_END();
  2857. return JSValue::encode(jsBoolean(result));
  2858. }
  2859. DEFINE_STUB_FUNCTION(void, op_put_getter_setter)
  2860. {
  2861. STUB_INIT_STACK_FRAME(stackFrame);
  2862. CallFrame* callFrame = stackFrame.callFrame;
  2863. ASSERT(stackFrame.args[0].jsValue().isObject());
  2864. JSObject* baseObj = asObject(stackFrame.args[0].jsValue());
  2865. GetterSetter* accessor = GetterSetter::create(callFrame);
  2866. JSValue getter = stackFrame.args[2].jsValue();
  2867. JSValue setter = stackFrame.args[3].jsValue();
  2868. ASSERT(getter.isObject() || getter.isUndefined());
  2869. ASSERT(setter.isObject() || setter.isUndefined());
  2870. ASSERT(getter.isObject() || setter.isObject());
  2871. if (!getter.isUndefined())
  2872. accessor->setGetter(callFrame->vm(), asObject(getter));
  2873. if (!setter.isUndefined())
  2874. accessor->setSetter(callFrame->vm(), asObject(setter));
  2875. baseObj->putDirectAccessor(callFrame, stackFrame.args[1].identifier(), accessor, Accessor);
  2876. }
  2877. DEFINE_STUB_FUNCTION(void, op_throw_static_error)
  2878. {
  2879. STUB_INIT_STACK_FRAME(stackFrame);
  2880. CallFrame* callFrame = stackFrame.callFrame;
  2881. String message = stackFrame.args[0].jsValue().toString(callFrame)->value(callFrame);
  2882. if (stackFrame.args[1].asInt32)
  2883. stackFrame.vm->exception = createReferenceError(callFrame, message);
  2884. else
  2885. stackFrame.vm->exception = createTypeError(callFrame, message);
  2886. VM_THROW_EXCEPTION_AT_END();
  2887. }
  2888. DEFINE_STUB_FUNCTION(void, op_debug)
  2889. {
  2890. STUB_INIT_STACK_FRAME(stackFrame);
  2891. CallFrame* callFrame = stackFrame.callFrame;
  2892. int debugHookID = stackFrame.args[0].int32();
  2893. int firstLine = stackFrame.args[1].int32();
  2894. int lastLine = stackFrame.args[2].int32();
  2895. int column = stackFrame.args[3].int32();
  2896. stackFrame.vm->interpreter->debug(callFrame, static_cast<DebugHookID>(debugHookID), firstLine, lastLine, column);
  2897. }
  2898. DEFINE_STUB_FUNCTION(void*, vm_throw)
  2899. {
  2900. STUB_INIT_STACK_FRAME(stackFrame);
  2901. VM* vm = stackFrame.vm;
  2902. ExceptionHandler handler = jitThrow(vm, stackFrame.callFrame, vm->exception, vm->exceptionLocation);
  2903. STUB_SET_RETURN_ADDRESS(handler.catchRoutine);
  2904. return handler.callFrame;
  2905. }
  2906. DEFINE_STUB_FUNCTION(EncodedJSValue, to_object)
  2907. {
  2908. STUB_INIT_STACK_FRAME(stackFrame);
  2909. CallFrame* callFrame = stackFrame.callFrame;
  2910. return JSValue::encode(stackFrame.args[0].jsValue().toObject(callFrame));
  2911. }
  2912. } // namespace JSC
  2913. #endif // ENABLE(JIT)